Hi,
I just downloaded one sdf file from PubChem that contains 25,000
entries
(ftp://ftp.ncbi.nlm.nih.gov/pubchem/Compound/CURRENT-Full/SDF/Compound_00000001_00025000.sdf.gz).
I tried to read the atomcontainers using
ChemFileManipulator.getAllAtomContainers [code attached] but got an
out of memory error. Is there a way to get the atom containers one by
one?
Thanks,
Bala.
import org.openscience.cdk.io.ReaderFactory;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesGenerator;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.io.IChemObjectReader;
import java.io.FileInputStream;
import java.util.List;
import java.io.FileNotFoundException;
import java.io.IOException;
public class CDKFileReadTest {
public static void main(String[] args) throws CDKException {
if ( args.length < 1 ) {
System.err.println("Please specify a file to read");
System.exit(-1);
}
FileInputStream in = null;
try {
in = new FileInputStream(args[0]);
} catch (FileNotFoundException f) {
System.err.println("File Not Found: " + args[0]);
f.printStackTrace();
System.exit(-1);
}
IChemObjectReader cor = null;
try {
cor = new ReaderFactory().createReader(in);
} catch (IOException ioe) {
System.err.println("There was some Input/Output error while opening file: " + args[0]);
ioe.printStackTrace();
System.exit(-1);
}
IChemFile content = (IChemFile)cor.read(DefaultChemObjectBuilder.getInstance().newChemFile());
System.out.println("Read the file");
List containers = ChemFileManipulator.getAllAtomContainers(content);
System.out.println("Got " + containers.size() + " atom containers");
SmilesGenerator sg = new SmilesGenerator();
for (int i = 0; i < containers.size(); i++) {
IAtomContainer container = (IAtomContainer)containers.get(i);
System.out.println(sg.createSMILES(new Molecule(container)));
}
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user