use of org.openscience.cdk.io.MDLReader in project ambit-mirror by ideaconsult.
the class SizeDescriptorTest method getTestMolecule.
public IAtomContainer getTestMolecule() throws Exception {
IAtomContainer mol = new AtomContainer();
MDLReader reader = new MDLReader(getClass().getClassLoader().getResourceAsStream("ambit2/descriptors/size/224824.sdf"));
mol = (IAtomContainer) reader.read(mol);
reader.close();
return mol;
}
use of org.openscience.cdk.io.MDLReader in project cdk by cdk.
the class ConjugatedPiSystemsDetectorTest method testPiSystemWithCumulativeDB.
/**
* A unit test for JUnit
*
*@return Description of the Return Value
*/
@Test
public void testPiSystemWithCumulativeDB() throws Exception {
logger.info("Entering testPiSystemWithCumulativeDB.");
IAtomContainer mol;
String filename = "piSystemCumulative.mol";
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins);
IChemFile chemFile = (IChemFile) reader.read((ChemObject) new ChemFile());
mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
Aromaticity.cdkLegacy().apply(mol);
IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol);
Assert.assertEquals(2, acSet.getAtomContainerCount());
IAtomContainer ac1 = acSet.getAtomContainer(0);
Assert.assertEquals(4, ac1.getAtomCount());
Assert.assertEquals(3, ac1.getBondCount());
for (int i = 0; i < ac1.getAtomCount(); i++) {
Assert.assertTrue(mol.contains(ac1.getAtom(i)));
}
for (int i = 0; i < ac1.getBondCount(); i++) {
Assert.assertTrue(mol.contains(ac1.getBond(i)));
}
IAtomContainer ac2 = acSet.getAtomContainer(0);
Assert.assertEquals(4, ac2.getAtomCount());
Assert.assertEquals(3, ac2.getBondCount());
for (int i = 0; i < ac2.getAtomCount(); i++) {
Assert.assertTrue(mol.contains(ac1.getAtom(i)));
}
for (int i = 0; i < ac2.getBondCount(); i++) {
Assert.assertTrue(mol.contains(ac1.getBond(i)));
}
}
use of org.openscience.cdk.io.MDLReader in project cdk by cdk.
the class ChemFileManipulatorTest method testGetAllAtomContainers_IChemFile.
@Test
public void testGetAllAtomContainers_IChemFile() throws Exception {
String filename = "prev2000.sd";
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins, Mode.STRICT);
ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(2, containersList.size());
}
use of org.openscience.cdk.io.MDLReader in project cdk by cdk.
the class MoleculeFactory method loadMolecule.
public static IAtomContainer loadMolecule(String inFile) {
ChemFile chemFile;
IChemSequence chemSequence;
IChemModel chemModel;
IAtomContainerSet setOfMolecules;
IAtomContainer molecule = null;
try (FileInputStream fis = new FileInputStream(inFile);
MDLReader mr = new MDLReader(fis)) {
chemFile = (ChemFile) mr.read((ChemObject) new ChemFile());
mr.close();
chemSequence = chemFile.getChemSequence(0);
chemModel = chemSequence.getChemModel(0);
setOfMolecules = chemModel.getMoleculeSet();
molecule = setOfMolecules.getAtomContainer(0);
for (int i = 0; i < molecule.getAtomCount(); i++) {
molecule.getAtom(i).setPoint2d(null);
}
} catch (CDKException | IOException exc) {
// we just return null if something went wrong
logger.error("An exception occurred while loading a molecule: " + inFile);
logger.debug(exc);
}
return molecule;
}
use of org.openscience.cdk.io.MDLReader in project cdk by cdk.
the class SmilesGeneratorTest method testSFBug1014344.
/**
* @cdk.bug 1014344
*/
@Category(SlowTest.class)
// MDL -> CML (slow) -> SMILES round tripping
@Test
public void testSFBug1014344() throws Exception {
String filename = "bug1014344-1.mol";
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins, Mode.STRICT);
IAtomContainer mol1 = reader.read(new AtomContainer());
addImplicitHydrogens(mol1);
SmilesGenerator sg = new SmilesGenerator();
String molSmiles = sg.create(mol1);
StringWriter output = new StringWriter();
CMLWriter cmlWriter = new CMLWriter(output);
cmlWriter.write(mol1);
CMLReader cmlreader = new CMLReader(new ByteArrayInputStream(output.toString().getBytes()));
IAtomContainer mol2 = ((IChemFile) cmlreader.read(new ChemFile())).getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
addImplicitHydrogens(mol2);
String cmlSmiles = sg.create(new AtomContainer(mol2));
Assert.assertEquals(molSmiles, cmlSmiles);
}
Aggregations