CDKを.NET環境で使うためのやり方が紹介されていたのでやってみました。
Using the CDK with the .Net framework and Mono
まずjavaのjarファイルを.NETのクラスライブラリー化するためのツールIKVMをダウンロードします。私が落としたのは「ikvmbin-0.42.0.3」です。
ついでCDKのjarファイルを落とします。私が落としたのは「cdk-1.2.4.1.jar」です。
IKVMを使ってこのCDKをdll化します。
コマンドプロンプトでikvm.exeのあるフォルダーに移動して
ikvmc -assembly:cdk_dotnet -target:library cdk-1.2.4.1.jar
と打つとcdk_dotnet.dllが出来ます。この際にWarningが多く出ますが無視。
VisualStudio2008のC#のコンソールアプリケーションを作成して、参照設定にcdk_dotnet.dllを含めikvmのbinフォルダーの中のdllをすべて登録します。
これでCDKが使えるようになりました。
具体的なコードは上記のサンプルコードを参照してください。Molファイルを読み込んで計算値を出力してくれました。
using System;
namespace CDK_test
{
    //Using aliases for convenience and to avoid importing whole
    //packages
    using FReader = java.io.FileReader;
    using TPSA = org.openscience.cdk.qsar.descriptors.molecular.TPSADescriptor;
    using LogP = org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor;
    using DoubleResult = org.openscience.cdk.qsar.result.DoubleResult;
    using Builder = org.openscience.cdk.DefaultChemObjectBuilder;
    using IMol = org.openscience.cdk.interfaces.IMolecule;
    using MolReader = org.openscience.cdk.io.iterator.IteratingMDLReader;
    using Consts = org.openscience.cdk.CDKConstants;
    class Program
    {
        static void Main(string[] args)
        {
            FReader fReader = new FReader("C:\Test.mol");
            MolReader molReader = new MolReader(fReader, Builder.getInstance());
            IMol mol;
            DoubleResult dr;
            LogP logP = new LogP();
            TPSA tpsa = new TPSA();
            double logPVal, tpsaVal;
            string name;
            while (molReader.hasNext())
            {
                mol = (IMol)molReader.next();
                dr = (DoubleResult)logP.calculate(mol).getValue();
                logPVal = dr.doubleValue();
                dr = (DoubleResult)tpsa.calculate(mol).getValue();
                tpsaVal = dr.doubleValue();
                //the title of each mol in the file is the name of the mol
                name = (String)mol.getProperty(Consts.TITLE);
                Console.WriteLine("{0} {1} {2}", name, logPVal, tpsaVal);
            }
            Console.ReadLine();
        }
    }
}
今回は純粋な.NETのclass libraryしか参照していないので、そのままSpotfireのツールに出来そうです。

 
0 件のコメント:
コメントを投稿