Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r12013]: cdk-qa / trunk / projects / 080813-00001 / extractCDKmol2AtomTypes.bsh Maximize Restore History

Download this file

extractCDKmol2AtomTypes.bsh    35 lines (33 with data), 1.2 kB

#!/usr/bin/bsh

import java.io.File;
import java.io.FileReader;
import java.util.Iterator;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.atomtype.SybylAtomTypeMatcher;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.io.iterator.IteratingMDLReader;

SybylAtomTypeMatcher matcher = SybylAtomTypeMatcher.getInstance(DefaultChemObjectBuilder.getInstance());
File file = new File("10_p0.1.sdf");
IteratingMDLReader reader = new IteratingMDLReader(
  new FileInputStream(file), DefaultChemObjectBuilder.getInstance()
);
int counter = 0;
while (reader.hasNext() && counter < 1000) {
  IMolecule molecule = (IMolecule)reader.next();
  print(molecule.getProperty(CDKConstants.TITLE));
  Iterator atoms = molecule.atoms();
  while (atoms.hasNext()) {
    IAtom atom = (IAtom)atoms.next();
    try {
      IAtomType type = matcher.findMatchingAtomType(molecule, atom);
      print(type.getAtomTypeName());
    } catch (Exception exception) {
      print("null");
    }
  }
  counter++;
}
print("\n");