use of org.openscience.cdk.io.CMLReader in project ambit-mirror by ideaconsult.
the class MoleculeTools method readCMLMolecule.
public static IAtomContainer readCMLMolecule(InputStream in) throws Exception {
IAtomContainer mol = null;
CMLReader reader = new CMLReader(in);
IChemFile obj = null;
obj = (IChemFile) reader.read(newChemFile(SilentChemObjectBuilder.getInstance()));
int n = obj.getChemSequenceCount();
if (n > 1)
logger.finest("> 1 sequence in a record");
for (int j = 0; j < n; j++) {
IChemSequence seq = obj.getChemSequence(j);
int m = seq.getChemModelCount();
if (m > 1)
logger.finest("> 1 model in a record");
for (int k = 0; k < m; k++) {
IChemModel mod = seq.getChemModel(k);
IAtomContainerSet som = mod.getMoleculeSet();
if (som.getAtomContainerCount() > 1)
logger.finest("> 1 molecule in a record");
for (int l = 0; l < som.getAtomContainerCount(); l++) {
mol = som.getAtomContainer(l);
return mol;
}
}
}
reader = null;
return mol;
}
use of org.openscience.cdk.io.CMLReader in project ambit-mirror by ideaconsult.
the class TestCML method parseCMLString.
public static IChemFile parseCMLString(String cmlString) throws Exception {
IChemFile chemFile = null;
CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes()));
chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile());
return chemFile;
}
use of org.openscience.cdk.io.CMLReader in project ambit-mirror by ideaconsult.
the class TestCML method parseCMLString.
public static IChemFile parseCMLString(String cmlString) throws Exception {
IChemFile chemFile = null;
CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes()));
chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile());
return chemFile;
}
use of org.openscience.cdk.io.CMLReader in project cdk by cdk.
the class ConjugatedPiSystemsDetectorTest method readCMLMolecule.
/**
* A unit test for JUnit
*
* @cdk.inchi
*
*@return Description of the Return Value
*/
private IAtomContainer readCMLMolecule(String filename) throws Exception {
IAtomContainer mol;
logger.debug("Filename: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
CMLReader reader = new CMLReader(ins);
IChemFile file = reader.read(new ChemFile());
Assert.assertNotNull(file);
Assert.assertEquals(1, file.getChemSequenceCount());
IChemSequence sequence = file.getChemSequence(0);
Assert.assertNotNull(sequence);
Assert.assertEquals(1, sequence.getChemModelCount());
IChemModel chemModel = sequence.getChemModel(0);
Assert.assertNotNull(chemModel);
IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
Assert.assertNotNull(moleculeSet);
Assert.assertEquals(1, moleculeSet.getAtomContainerCount());
mol = moleculeSet.getAtomContainer(0);
Assert.assertNotNull(mol);
return mol;
}
use of org.openscience.cdk.io.CMLReader in project cdk by cdk.
the class JumboTest method testCephNS.
/**
* Special CML characteristics:
* - use of cml: namespace
* - X2D only
*/
@Test
public void testCephNS() throws Exception {
String filename = "ceph-ns.xml";
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
CMLReader reader = new CMLReader(ins);
IChemFile chemFile = reader.read(new org.openscience.cdk.ChemFile());
reader.close();
// test the resulting ChemFile content
Assert.assertNotNull(chemFile);
Assert.assertEquals(chemFile.getChemSequenceCount(), 1);
IChemSequence seq = chemFile.getChemSequence(0);
Assert.assertNotNull(seq);
Assert.assertEquals(seq.getChemModelCount(), 1);
IChemModel model = seq.getChemModel(0);
Assert.assertNotNull(model);
Assert.assertEquals(model.getMoleculeSet().getAtomContainerCount(), 1);
// test the molecule
IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0);
Assert.assertNotNull(mol);
Assert.assertEquals(mol.getAtomCount(), 15);
Assert.assertEquals(mol.getBondCount(), 16);
Assert.assertFalse(GeometryUtil.has3DCoordinates(mol));
Assert.assertTrue(GeometryUtil.has2DCoordinates(mol));
}
Aggregations