Search in sources :

Example 1 with CMLReader

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;
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IChemFile(org.openscience.cdk.interfaces.IChemFile) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemSequence(org.openscience.cdk.interfaces.IChemSequence)

Example 2 with CMLReader

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;
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) ByteArrayInputStream(java.io.ByteArrayInputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile)

Example 3 with CMLReader

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;
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) ByteArrayInputStream(java.io.ByteArrayInputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile)

Example 4 with CMLReader

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;
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemSequence(org.openscience.cdk.interfaces.IChemSequence)

Example 5 with CMLReader

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));
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) Test(org.junit.Test)

Aggregations

CMLReader (org.openscience.cdk.io.CMLReader)74 IChemFile (org.openscience.cdk.interfaces.IChemFile)72 InputStream (java.io.InputStream)59 Test (org.junit.Test)57 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)51 IChemModel (org.openscience.cdk.interfaces.IChemModel)47 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)47 ChemFile (org.openscience.cdk.ChemFile)41 ByteArrayInputStream (java.io.ByteArrayInputStream)18 IReaction (org.openscience.cdk.interfaces.IReaction)11 ChemFile (org.openscience.cdk.silent.ChemFile)9 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)8 IAtom (org.openscience.cdk.interfaces.IAtom)6 StringWriter (java.io.StringWriter)4 Element (nu.xom.Element)4 CMLWriter (org.openscience.cdk.io.CMLWriter)4 SlowTest (org.openscience.cdk.test.SlowTest)4 Vector (java.util.Vector)3 AtomContainer (org.openscience.cdk.AtomContainer)3 MDLReader (org.openscience.cdk.io.MDLReader)3