Search in sources :

Example 26 with IChemSequence

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

the class VASPReader method readChemFile.

private IChemFile readChemFile(IChemFile file) throws CDKException, IOException {
    IChemSequence seq = readChemSequence(file.getBuilder().newInstance(IChemSequence.class));
    file.addChemSequence(seq);
    return file;
}
Also used : IChemSequence(org.openscience.cdk.interfaces.IChemSequence)

Example 27 with IChemSequence

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

the class MDLRXNV2000Reader method read.

/**
 * Takes an object which subclasses IChemObject, e.g.Molecule, and will read
 * this (from file, database, internet etc). If the specific implementation
 * does not support a specific IChemObject it will throw an Exception.
 *
 * @param  object                              The object that subclasses
 *      IChemObject
 * @return                                     The IChemObject read
 * @exception  CDKException
 */
@Override
public <T extends IChemObject> T read(T object) throws CDKException {
    if (object instanceof IReaction) {
        return (T) readReaction(object.getBuilder());
    } else if (object instanceof IReactionSet) {
        IReactionSet reactionSet = object.getBuilder().newInstance(IReactionSet.class);
        reactionSet.addReaction(readReaction(object.getBuilder()));
        return (T) reactionSet;
    } else if (object instanceof IChemModel) {
        IChemModel model = object.getBuilder().newInstance(IChemModel.class);
        IReactionSet reactionSet = object.getBuilder().newInstance(IReactionSet.class);
        reactionSet.addReaction(readReaction(object.getBuilder()));
        model.setReactionSet(reactionSet);
        return (T) model;
    } else if (object instanceof IChemFile) {
        IChemFile chemFile = object.getBuilder().newInstance(IChemFile.class);
        IChemSequence sequence = object.getBuilder().newInstance(IChemSequence.class);
        sequence.addChemModel(read(object.getBuilder().newInstance(IChemModel.class)));
        chemFile.addChemSequence(sequence);
        return (T) chemFile;
    } else {
        throw new CDKException("Only supported are Reaction and ChemModel, and not " + object.getClass().getName() + ".");
    }
}
Also used : IReactionSet(org.openscience.cdk.interfaces.IReactionSet) CDKException(org.openscience.cdk.exception.CDKException) IChemFile(org.openscience.cdk.interfaces.IChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IReaction(org.openscience.cdk.interfaces.IReaction) IChemSequence(org.openscience.cdk.interfaces.IChemSequence)

Example 28 with IChemSequence

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

the class SDFReaderTest method testMultipleDataFields.

@Test
public void testMultipleDataFields() throws Exception {
    String filename = "bug1587283.mol";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    MDLV2000Reader reader = new MDLV2000Reader(ins);
    IChemFile fileContents = reader.read(new ChemFile());
    reader.close();
    Assert.assertEquals(1, fileContents.getChemSequenceCount());
    IChemSequence sequence = fileContents.getChemSequence(0);
    Assert.assertNotNull(sequence);
    Assert.assertEquals(1, sequence.getChemModelCount());
    IChemModel model = sequence.getChemModel(0);
    Assert.assertNotNull(model);
    IAtomContainerSet som = model.getMoleculeSet();
    Assert.assertNotNull(som);
    Assert.assertEquals(1, som.getAtomContainerCount());
    IAtomContainer m = som.getAtomContainer(0);
    Assert.assertNotNull(m);
    Assert.assertEquals("B02", m.getProperty("id_no"));
    Assert.assertEquals("2-2", m.getProperty("eductkey"));
    Assert.assertEquals("1", m.getProperty("Step"));
    Assert.assertEquals("2", m.getProperty("Pos"));
    Assert.assertEquals("B02", m.getProperty("Tag"));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.ChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 29 with IChemSequence

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

the class CML2Test method testCMLConciseFormula.

/**
 * Only Molecule with concise MolecularFormula
 */
@Test
public void testCMLConciseFormula() throws Exception {
    String filename = "cmlConciseFormula.cml";
    logger.info("Testing: " + filename);
    InputStream ins = this.getClass().getResourceAsStream(filename);
    CMLReader reader = new CMLReader(ins);
    IChemFile chemFile = reader.read(new 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);
    IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0);
    Assert.assertNotNull(mol);
    // FIXME: REACT: It should return two different formulas
    Assert.assertEquals("[C 18 H 21 Cl 2 Mn 1 N 5 O 1]", mol.getProperty(CDKConstants.FORMULA).toString());
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.ChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) Test(org.junit.Test)

Example 30 with IChemSequence

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

the class CML2Test method testCMLWithFormula.

/**
 * @cdk.bug 1560486
 */
@Test
public void testCMLWithFormula() throws Exception {
    String filename = "cmlWithFormula.cml";
    logger.info("Testing: " + filename);
    InputStream ins = this.getClass().getResourceAsStream(filename);
    CMLReader reader = new CMLReader(ins);
    IChemFile chemFile = reader.read(new 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);
    IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0);
    Assert.assertNotNull(mol);
    Assert.assertEquals("a", mol.getID());
    Assert.assertEquals("a1", mol.getAtom(0).getID());
    Assert.assertEquals(27, mol.getAtomCount());
    Assert.assertEquals(32, mol.getBondCount());
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.ChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) Test(org.junit.Test)

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