使用CDK解析SDF文件

使用CDK解析SDF文件

package com.founder.cdk;

import Java.io.File;
import Java.io.FileNotFoundException;
import Java.io.FileReader;
import Java.util.List;

import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemObject;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.io.MDLReader;
import org.openscience.cdk.io.MDLV2000Reader;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;

public class ReadSDFTest {

 /**
  * @param args
  * @throws CDKException
  * @throws FileNotFoundException
  */
 public static void main(String[] args) throws CDKException, FileNotFoundException {
  String filename = "H:\\molecules.sdf";
       
//  InputStream ins = ReadSDFTest.class.getClassLoader().getResourceAsStream(filename);
//  MDLReader reader = new MDLReader(ins);

   //alternatively, you can specify a file directly
   MDLV2000Reader reader = new MDLV2000Reader(new FileReader(new File(filename)));

  ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
  
  List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
  
  Molecule molecule = null;
  for (IAtomContainer mol : containersList) {
   molecule = (Molecule) mol;
   System.out.println(molecule.getProperties());
   System.out.println(molecule.getProperty("CD_MOLWEIGHT"));
//   Fingerprinter fp = new Fingerprinter();
//   BitSet bt = fp.getFingerprint(molecule);
//   System.out.println(bt);
  }
 }

}

你可能感兴趣的:(使用CDK解析SDF文件)