use of org.openscience.cdk.io.MDLV2000Reader in project MetFragRelaunched by ipb-halle.
the class OnlineChemSpiderDatabase method getAtomContainerFromString.
/**
* @param sdfString
* @return
* @throws CDKException
*/
protected ArrayList<IAtomContainer> getAtomContainerFromString(String sdfString) {
MDLV2000Reader reader = new MDLV2000Reader(new StringReader(sdfString));
java.util.List<IAtomContainer> containersList;
java.util.ArrayList<IAtomContainer> ret = new ArrayList<IAtomContainer>();
ChemFile chemFile = null;
try {
chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
} catch (CDKException e) {
try {
reader.close();
} catch (IOException e1) {
}
this.logger.error("Error: Could not perform database query. This could be caused by a temporal database timeout. Try again later.");
return new ArrayList<IAtomContainer>();
}
containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
for (IAtomContainer container : containersList) {
ret.add(container);
}
try {
reader.close();
} catch (IOException e) {
this.logger.error("Error: Could not perform database query. This could be caused by a temporal database timeout. Try again later.");
return new ArrayList<IAtomContainer>();
}
return ret;
}
use of org.openscience.cdk.io.MDLV2000Reader in project ambit-mirror by ideaconsult.
the class MoleculeTools method readMolfile.
public static IAtomContainer readMolfile(String molfile) throws Exception {
MDLV2000Reader r = null;
try {
StringReader reader = new StringReader(molfile);
r = new MDLV2000Reader(reader);
r.addSetting(new BooleanIOSetting("AddStereoElements", IOSetting.Importance.HIGH, "Assign stereo configurations to stereocenters utilising 2D/3D coordinates.", "false"));
/*
* Properties customSettings = new Properties();
* customSettings.setProperty("AddStereoElements", "false");
* PropertiesListener listener = new
* PropertiesListener(customSettings);
* r.addChemObjectIOListener(listener);
*/
IAtomContainer mol = r.read(new AtomContainer());
reader.close();
return mol;
} finally {
try {
r.close();
} catch (Exception x) {
}
}
}
use of org.openscience.cdk.io.MDLV2000Reader in project ambit-mirror by ideaconsult.
the class MDLV2000ReaderExtendedTest method readSGroup.
protected IChemObject readSGroup(String dir, String file) throws Exception {
MDLV2000Reader reader = new MDLV2000Reader(MDLV2000Reader.class.getClassLoader().getResourceAsStream(dir + file), IChemObjectReader.Mode.RELAXED);
IAtomContainer mol = MoleculeTools.newMolecule(SilentChemObjectBuilder.getInstance());
IChemObject newMol = reader.read(mol);
reader.close();
return newMol;
}
use of org.openscience.cdk.io.MDLV2000Reader in project ambit-mirror by ideaconsult.
the class MDLV2000ReaderExtendedTest method testRGP.
@Test
public void testRGP() throws Exception {
File[] files = new File("src/test/resources/ambit2/core/data/M__RGP").listFiles();
if (files == null)
throw new Exception("Files not found");
for (File file : files) try {
MDLV2000Reader reader = new MDLV2000Reader(new FileInputStream(file));
IAtomContainer mol = MoleculeTools.newMolecule(SilentChemObjectBuilder.getInstance());
reader.read(mol);
reader.close();
} catch (Exception x) {
System.err.println(file.getName());
x.printStackTrace();
// throw new Exception(file.getName(),x);
}
}
use of org.openscience.cdk.io.MDLV2000Reader in project cdk by cdk.
the class ChemModelManipulatorTest method testGetAllAtomContainers_IChemModel.
@Test
public void testGetAllAtomContainers_IChemModel() throws Exception {
String filename = "a-pinene.mol";
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
ChemModel chemFile = (ChemModel) reader.read((ChemObject) new ChemModel());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemModelManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
}
Aggregations