Skip to content

Instantly share code, notes, and snippets.

@rajarshi
Created February 19, 2011 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajarshi/835128 to your computer and use it in GitHub Desktop.
Save rajarshi/835128 to your computer and use it in GitHub Desktop.
Weird SDF output
package net.sf.cdk.tools;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.MoleculeSet;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.io.MDLV2000Reader;
import org.openscience.cdk.io.SDFWriter;
import org.openscience.cdk.io.listener.PropertiesListener;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
/**
* A one line summary.
*
* @author Rajarshi Guha
*/
public class foo {
public static void main(String[] args) throws CDKException, IOException {
MDLV2000Reader reader = new MDLV2000Reader(new FileReader("/Users/guhar/tmp/nci10_original.sdf"));
ChemFile chemFile = reader.read(new ChemFile());
List<IAtomContainer> mols = ChemFileManipulator.getAllAtomContainers(chemFile);
for (int i = 0; i < mols.size(); i++) {
try {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mols.get(i));
} catch (CDKException e) {
}
}
SDFWriter writer = new SDFWriter(new FileWriter("foo.sdf"));
Properties sdfWriterProps = new Properties();
sdfWriterProps.put("writeProperties", "false");
writer.addChemObjectIOListener(
new PropertiesListener(sdfWriterProps)
);
writer.customizeJob();
IMoleculeSet molset = new MoleculeSet();
for (IAtomContainer mol : mols) molset.addAtomContainer(mol);
writer.write(molset);
writer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment