LoginSignup
0
0

More than 5 years have passed since last update.

CDK(Chemical Development Toolkit)を使ってみる

Last updated at Posted at 2019-03-17

はじめに

Javaから化合物をハンドリング可能なオープンソースであるCDK(ChemicalDevelopmentToolkit)の最新版を使ってみた。ここではソースを書いてビルド、実行するまでを記載する。

環境

  • Java 11
  • IntelliJ IDEA (Community版)
  • CDK2.2

準備

CDKのサイトからたどれるGitHubよりcdk2.2のjarファイルをダウンロードし、プロジェクトのライブラリに追加しておく。

ソース

プロジェクトを作成後、以下のソース(CountHeavyAtoms.javaで作成)をビルドして実行すればOKだ。
CDK2.2になってかなりAPIも変わっているため、CDKのサイトのJavaDocを参考にしてほしい。

import java.io.*;
import org.openscience.cdk.io.iterator.IteratingSDFReader;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.interfaces.IAtom;

public class CountHeavyAtoms {
    public static void main(String[] args) {
        FileReader sdfile = null;

        try {
            /* CDK does not automatically understand gzipped files */
            sdfile = new FileReader(new File("solubility.train.sdf"));
        } catch (FileNotFoundException e) {
            System.err.println("benzodiazepine.sdf not found");
            System.exit(1);
        }

        IteratingSDFReader mdliter = new IteratingSDFReader(sdfile,
                DefaultChemObjectBuilder.getInstance());

        while (mdliter.hasNext()) {
            IAtomContainer mol = (IAtomContainer) mdliter.next();
            int numHeavies = 0;
            for (IAtom atom : mol.atoms()) {
                if (atom.getAtomicNumber() > 1) {
                    numHeavies++;
                }
            }
            System.out.println(numHeavies);
        }
    }
}

今後は記述子計算なども試したい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0