Search in sources :

Example 11 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class ExtraReaderFactoryTest method expectReader.

void expectReader(String filename, IResourceFormat expectedFormat) throws Exception {
    InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
    Assert.assertNotNull("Cannot find file: " + filename, ins);
    if (expectedFormat instanceof IChemFormatMatcher) {
        factory.registerFormat((IChemFormatMatcher) expectedFormat);
    }
    ISimpleChemObjectReader reader = factory.createReader(ins);
    Assert.assertNotNull(reader);
    Assert.assertEquals(((IChemFormat) expectedFormat).getReaderClassName(), reader.getClass().getName());
    // now try reading something from it
    IChemObject[] objects = { new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction() };
    boolean read = false;
    for (int i = 0; (i < objects.length && !read); i++) {
        if (reader.accepts(objects[i].getClass())) {
            IChemObject chemObject = reader.read(objects[i]);
            Assert.assertNotNull("Reader accepted a " + objects[i].getClass().getName() + " but failed to read it", chemObject);
            read = true;
        }
    }
    Assert.assertTrue("Reading an IChemObject from the Reader did not work properly.", read);
}
Also used : IChemFormatMatcher(org.openscience.cdk.io.formats.IChemFormatMatcher) IChemObject(org.openscience.cdk.interfaces.IChemObject) ChemModel(org.openscience.cdk.ChemModel) AtomContainer(org.openscience.cdk.AtomContainer) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) Reaction(org.openscience.cdk.Reaction)

Example 12 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class MDLRXNV3000ReaderTest method testReadReactions1.

/**
 * @cdk.bug 1849925
 */
@Test
public void testReadReactions1() throws Exception {
    String filename1 = "reaction_v3.rxn";
    logger.info("Testing: " + filename1);
    InputStream ins1 = this.getClass().getResourceAsStream(filename1);
    MDLRXNV3000Reader reader1 = new MDLRXNV3000Reader(ins1, Mode.STRICT);
    IReaction reaction1 = new Reaction();
    reaction1 = reader1.read(reaction1);
    reader1.close();
    Assert.assertNotNull(reaction1);
    Assert.assertEquals(1, reaction1.getReactantCount());
    Assert.assertEquals(1, reaction1.getProductCount());
    IAtomContainer reactant = reaction1.getReactants().getAtomContainer(0);
    Assert.assertNotNull(reactant);
    Assert.assertEquals(32, reactant.getAtomCount());
    Assert.assertEquals(29, reactant.getBondCount());
    IAtomContainer product = reaction1.getProducts().getAtomContainer(0);
    Assert.assertNotNull(product);
    Assert.assertEquals(32, product.getAtomCount());
    Assert.assertEquals(29, product.getBondCount());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IReaction(org.openscience.cdk.interfaces.IReaction) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 13 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class MDLRXNReaderTest method testReadReactions2.

@Test
public void testReadReactions2() throws Exception {
    String filename2 = "reaction-2.rxn";
    logger.info("Testing: " + filename2);
    InputStream ins2 = this.getClass().getResourceAsStream(filename2);
    MDLRXNReader reader2 = new MDLRXNReader(ins2);
    IReaction reaction2 = new Reaction();
    reaction2 = reader2.read(reaction2);
    reader2.close();
    Assert.assertNotNull(reaction2);
    Assert.assertEquals(2, reaction2.getReactantCount());
    Assert.assertEquals(2, reaction2.getProductCount());
}
Also used : InputStream(java.io.InputStream) IReaction(org.openscience.cdk.interfaces.IReaction) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 14 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class MDLRXNReaderTest method testReadReactions1.

@Test
public void testReadReactions1() throws Exception {
    String filename1 = "reaction-1.rxn";
    logger.info("Testing: " + filename1);
    InputStream ins1 = this.getClass().getResourceAsStream(filename1);
    MDLRXNReader reader1 = new MDLRXNReader(ins1);
    IReaction reaction1 = new Reaction();
    reaction1 = reader1.read(reaction1);
    reader1.close();
    Assert.assertNotNull(reaction1);
    Assert.assertEquals(2, reaction1.getReactantCount());
    Assert.assertEquals(1, reaction1.getProductCount());
    IAtomContainerSet educts = reaction1.getReactants();
    // Check Atom symbols of first educt
    String[] atomSymbolsOfEduct1 = { "C", "C", "O", "Cl" };
    for (int i = 0; i < educts.getAtomContainer(0).getAtomCount(); i++) {
        Assert.assertEquals(atomSymbolsOfEduct1[i], educts.getAtomContainer(0).getAtom(i).getSymbol());
    }
    // Check Atom symbols of second educt
    for (int i = 0; i < educts.getAtomContainer(1).getAtomCount(); i++) {
        Assert.assertEquals("C", educts.getAtomContainer(1).getAtom(i).getSymbol());
    }
    // Check Atom symbols of first product
    IAtomContainerSet products = reaction1.getProducts();
    String[] atomSymbolsOfProduct1 = { "C", "C", "C", "C", "C", "C", "C", "O", "C" };
    for (int i = 0; i < products.getAtomContainer(0).getAtomCount(); i++) {
        Assert.assertEquals(atomSymbolsOfProduct1[i], products.getAtomContainer(0).getAtom(i).getSymbol());
    }
}
Also used : InputStream(java.io.InputStream) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IReaction(org.openscience.cdk.interfaces.IReaction) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 15 with Reaction

use of org.openscience.cdk.Reaction in project cdk by cdk.

the class MDLRXNV2000ReaderTest method testAgentParts.

@Test
public void testAgentParts() throws Exception {
    try (InputStream in = this.getClass().getResourceAsStream("ethylesterification.mol");
        MDLRXNV2000Reader rdr = new MDLRXNV2000Reader(in)) {
        IReaction reaction = rdr.read(new Reaction());
        assertThat(reaction.getAgents().getAtomContainerCount(), is(1));
    }
}
Also used : InputStream(java.io.InputStream) IReaction(org.openscience.cdk.interfaces.IReaction) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Aggregations

Reaction (org.openscience.cdk.Reaction)30 IReaction (org.openscience.cdk.interfaces.IReaction)28 Test (org.junit.Test)23 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)23 AtomContainer (org.openscience.cdk.AtomContainer)19 IAtom (org.openscience.cdk.interfaces.IAtom)16 Atom (org.openscience.cdk.Atom)15 InputStream (java.io.InputStream)12 Point2d (javax.vecmath.Point2d)8 ChemModel (org.openscience.cdk.ChemModel)8 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)8 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)8 IChemModel (org.openscience.cdk.interfaces.IChemModel)6 Bond (org.openscience.cdk.Bond)5 ReactionSet (org.openscience.cdk.ReactionSet)5 IBond (org.openscience.cdk.interfaces.IBond)5 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)5 ChemFile (org.openscience.cdk.ChemFile)4 Before (org.junit.Before)3 IChemObject (org.openscience.cdk.interfaces.IChemObject)3