Search in sources :

Example 1 with IChemSequence

use of org.openscience.cdk.interfaces.IChemSequence 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 IChemSequence

use of org.openscience.cdk.interfaces.IChemSequence in project ambit-mirror by ideaconsult.

the class CdkJmolAdapter method openBufferedReader.

/* **************************************************************
	 * the file related methods
	 * **************************************************************/
public Object openBufferedReader(String name, BufferedReader bufferedReader) {
    IChemFile chemFile = null;
    try {
        ISimpleChemObjectReader chemObjectReader = null;
        try {
            chemObjectReader = new ReaderFactory().createReader(bufferedReader);
        } catch (IOException ex) {
            return "Jmol: Error determining input format: " + ex;
        }
        if (chemObjectReader == null) {
            return "Jmol: unrecognized input format";
        }
        chemFile = (IChemFile) chemObjectReader.read(new org.openscience.cdk.ChemFile());
    } catch (CDKException ex) {
        return "Error reading input:" + ex;
    }
    if (chemFile == null)
        return "unknown error reading file";
    try {
        AtomTypeFactory factory = AtomTypeFactory.getInstance("pdb_atomtypes.txt", chemFile.getBuilder());
        // IAtomContainer atomContainer = (IAtomContainer)ChemFileManipulator.getAllInOneContainer(chemFile);
        Iterator<IChemSequence> seq = chemFile.chemSequences().iterator();
        while (seq.hasNext()) {
            Iterator<IChemModel> model = seq.next().chemModels().iterator();
            while (model.hasNext()) {
                Iterator<IAtomContainer> c = model.next().getMoleculeSet().atomContainers().iterator();
                while (c.hasNext()) {
                    Iterator<IAtom> it = c.next().atoms().iterator();
                    while (it.hasNext()) {
                        IAtom atom = it.next();
                        try {
                            factory.configure(atom);
                        } catch (CDKException exception) {
                            bcLogger.severe("Could not configure atom: " + atom);
                            bcLogger.log(Level.SEVERE, "  because: " + exception.getMessage(), exception);
                        }
                    }
                }
            }
        }
        return chemFile;
    } catch (Exception x) {
        return "Error configuring atoms input:" + x;
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IChemFile(org.openscience.cdk.interfaces.IChemFile) ReaderFactory(org.openscience.cdk.io.ReaderFactory) IChemModel(org.openscience.cdk.interfaces.IChemModel) IOException(java.io.IOException) AtomTypeFactory(org.openscience.cdk.config.AtomTypeFactory) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with IChemSequence

use of org.openscience.cdk.interfaces.IChemSequence in project cdk by cdk.

the class ChemSequenceTest method testChemSequence.

@Test
public void testChemSequence() {
    IChemSequence cs = new ChemSequence();
    Assert.assertNotNull(cs);
}
Also used : IChemSequence(org.openscience.cdk.interfaces.IChemSequence) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) AbstractChemSequenceTest(org.openscience.cdk.test.interfaces.AbstractChemSequenceTest) Test(org.junit.Test)

Example 4 with IChemSequence

use of org.openscience.cdk.interfaces.IChemSequence in project cdk by cdk.

the class ChemFile method toString.

/**
 * Returns a String representation of this class. It implements
 * RFC #9.
 *
 *@return    String representation of the Object
 */
@Override
public String toString() {
    StringBuilder buffer = new StringBuilder();
    buffer.append("ChemFile(#S=");
    buffer.append(chemSequenceCount);
    if (chemSequenceCount > 0) {
        for (IChemSequence iChemSequence : chemSequences()) {
            buffer.append(", ");
            buffer.append(iChemSequence.toString());
        }
    }
    buffer.append(')');
    return buffer.toString();
}
Also used : IChemSequence(org.openscience.cdk.interfaces.IChemSequence)

Example 5 with IChemSequence

use of org.openscience.cdk.interfaces.IChemSequence 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)

Aggregations

IChemSequence (org.openscience.cdk.interfaces.IChemSequence)91 IChemModel (org.openscience.cdk.interfaces.IChemModel)79 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)58 Test (org.junit.Test)53 IChemFile (org.openscience.cdk.interfaces.IChemFile)45 InputStream (java.io.InputStream)39 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)32 ChemFile (org.openscience.cdk.ChemFile)24 CMLReader (org.openscience.cdk.io.CMLReader)24 IOException (java.io.IOException)18 CDKException (org.openscience.cdk.exception.CDKException)16 IAtom (org.openscience.cdk.interfaces.IAtom)13 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)13 ICrystal (org.openscience.cdk.interfaces.ICrystal)11 ChemObject (org.openscience.cdk.ChemObject)10 IRingSet (org.openscience.cdk.interfaces.IRingSet)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Point3d (javax.vecmath.Point3d)7 Element (nu.xom.Element)6 IChemObject (org.openscience.cdk.interfaces.IChemObject)6