Search in sources :

Example 1 with IReactionScheme

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

the class ReactionScheme method clone.

/**
 * Clones this ReactionScheme object and its content.
 *
 * @return    The cloned object
 */
@Override
public Object clone() throws CloneNotSupportedException {
    IReactionScheme clone = new ReactionScheme();
    for (IReactionScheme scheme : this.reactionSchemes()) {
        clone.add((IReactionScheme) scheme.clone());
    }
    for (IReaction reaction : reactions()) {
        clone.addReaction((IReaction) reaction.clone());
    }
    // clone the properties
    if (getProperties() != null) {
        Map<Object, Object> properties = getProperties();
        Map<Object, Object> clonedHashtable = new HashMap<>();
        for (Object key : properties.keySet()) {
            Object value = properties.get(key);
            clonedHashtable.put(key, value);
        }
        clone.addProperties(clonedHashtable);
    }
    return clone;
}
Also used : IReactionScheme(org.openscience.cdk.interfaces.IReactionScheme) HashMap(java.util.HashMap) IReactionScheme(org.openscience.cdk.interfaces.IReactionScheme) IReaction(org.openscience.cdk.interfaces.IReaction)

Example 2 with IReactionScheme

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

the class ReactionSchemeManipulator method setScheme.

/**
 * Create a IReactionScheme given as a top a IReaction. If it doesn't exist any subsequent reaction
 * return null;
 *
 * @param reaction       The IReaction as a top
 * @param reactionSet    The IReactionSet to extract a IReactionScheme
 * @return               The IReactionScheme
 */
private static IReactionScheme setScheme(IReaction reaction, IReactionSet reactionSet) {
    IReactionScheme reactionScheme = reaction.getBuilder().newInstance(IReactionScheme.class);
    IReactionSet reactConSet = extractSubsequentReaction(reaction, reactionSet);
    if (reactConSet.getReactionCount() != 0) {
        for (IReaction reactionInt : reactConSet.reactions()) {
            reactionScheme.addReaction(reactionInt);
            IReactionScheme newRScheme = setScheme(reactionInt, reactionSet);
            if (newRScheme.getReactionCount() != 0 || newRScheme.getReactionSchemeCount() != 0) {
                reactionScheme.add(newRScheme);
            }
        }
    }
    return reactionScheme;
}
Also used : IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IReactionScheme(org.openscience.cdk.interfaces.IReactionScheme) IReaction(org.openscience.cdk.interfaces.IReaction)

Example 3 with IReactionScheme

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

the class ReactionSchemeManipulatorTest method testGetAllMolecules_IReactionScheme3.

@Test
public void testGetAllMolecules_IReactionScheme3() {
    IReactionScheme scheme1 = builder.newInstance(IReactionScheme.class);
    IReactionScheme scheme11 = builder.newInstance(IReactionScheme.class);
    IReaction reaction1 = builder.newInstance(IReaction.class);
    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    reaction1.addProduct(molecule);
    reaction1.addReactant(builder.newInstance(IAtomContainer.class));
    scheme11.addReaction(reaction1);
    IReaction reaction2 = builder.newInstance(IReaction.class);
    reaction2.addProduct(builder.newInstance(IAtomContainer.class));
    reaction2.addReactant(molecule);
    scheme11.addReaction(reaction2);
    scheme1.add(scheme11);
    IReactionScheme scheme12 = builder.newInstance(IReactionScheme.class);
    IReaction reaction3 = builder.newInstance(IReaction.class);
    reaction3.addProduct(builder.newInstance(IAtomContainer.class));
    reaction3.addReactant(molecule);
    scheme12.addReaction(reaction3);
    scheme1.add(scheme12);
    IReaction reaction11 = builder.newInstance(IReaction.class);
    reaction11.addProduct(builder.newInstance(IAtomContainer.class));
    scheme1.addReaction(reaction11);
    Assert.assertEquals(5, ReactionSchemeManipulator.getAllAtomContainers(scheme1).getAtomContainerCount());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionScheme(org.openscience.cdk.interfaces.IReactionScheme) IReaction(org.openscience.cdk.interfaces.IReaction) Test(org.junit.Test)

Example 4 with IReactionScheme

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

the class ReactionSchemeManipulatorTest method testGetAllMolecules_IReactionScheme.

@Test
public void testGetAllMolecules_IReactionScheme() {
    IReactionScheme reactionScheme = builder.newInstance(IReactionScheme.class);
    IReaction reaction1 = builder.newInstance(IReaction.class);
    reaction1.addProduct(builder.newInstance(IAtomContainer.class));
    IReaction reaction2 = builder.newInstance(IReaction.class);
    reaction2.addProduct(builder.newInstance(IAtomContainer.class));
    // 1
    reactionScheme.addReaction(reaction1);
    // 2
    reactionScheme.addReaction(reaction2);
    Assert.assertEquals(2, ReactionSchemeManipulator.getAllAtomContainers(reactionScheme).getAtomContainerCount());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionScheme(org.openscience.cdk.interfaces.IReactionScheme) IReaction(org.openscience.cdk.interfaces.IReaction) Test(org.junit.Test)

Example 5 with IReactionScheme

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

the class ReactionSchemeManipulatorTest method testGetAllReactions_IReactionScheme.

@Test
public void testGetAllReactions_IReactionScheme() {
    IReactionScheme scheme1 = builder.newInstance(IReactionScheme.class);
    IReactionScheme scheme11 = builder.newInstance(IReactionScheme.class);
    IReaction reaction1 = builder.newInstance(IReaction.class);
    IAtomContainer startMol = builder.newInstance(IAtomContainer.class);
    startMol.setID("startMol");
    reaction1.addReactant(startMol);
    IAtomContainer mitMol = builder.newInstance(IAtomContainer.class);
    mitMol.setID("mitMol");
    reaction1.addProduct(mitMol);
    scheme11.addReaction(reaction1);
    IReaction reaction2 = builder.newInstance(IReaction.class);
    reaction2.addProduct(builder.newInstance(IAtomContainer.class));
    reaction2.addReactant(builder.newInstance(IAtomContainer.class));
    scheme11.addReaction(reaction2);
    scheme1.add(scheme11);
    IReactionScheme scheme12 = builder.newInstance(IReactionScheme.class);
    IReaction reaction3 = builder.newInstance(IReaction.class);
    IAtomContainer finalMol = builder.newInstance(IAtomContainer.class);
    finalMol.setID("finalMol");
    reaction3.addProduct(finalMol);
    reaction3.addReactant(startMol);
    scheme12.addReaction(reaction3);
    scheme1.add(scheme12);
    IReaction reaction11 = builder.newInstance(IReaction.class);
    reaction11.addProduct(builder.newInstance(IAtomContainer.class));
    scheme1.addReaction(reaction11);
    IReactionSet reactionSet = ReactionSchemeManipulator.getAllReactions(scheme1);
    Assert.assertEquals(4, reactionSet.getReactionCount());
    Assert.assertEquals(reaction1, reactionSet.getReaction(0));
    Assert.assertEquals(reaction2, reactionSet.getReaction(1));
    Assert.assertEquals(reaction3, reactionSet.getReaction(2));
    Assert.assertEquals(reaction11, reactionSet.getReaction(3));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IReactionScheme(org.openscience.cdk.interfaces.IReactionScheme) IReaction(org.openscience.cdk.interfaces.IReaction) Test(org.junit.Test)

Aggregations

IReactionScheme (org.openscience.cdk.interfaces.IReactionScheme)28 Test (org.junit.Test)23 IReaction (org.openscience.cdk.interfaces.IReaction)17 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)11 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)5 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)3 AbstractReactionSchemeTest (org.openscience.cdk.test.interfaces.AbstractReactionSchemeTest)3 HashMap (java.util.HashMap)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Attribute (nu.xom.Attribute)1 Document (nu.xom.Document)1 Element (nu.xom.Element)1 Serializer (nu.xom.Serializer)1 CDKException (org.openscience.cdk.exception.CDKException)1 IAtom (org.openscience.cdk.interfaces.IAtom)1 IBond (org.openscience.cdk.interfaces.IBond)1 IChemFile (org.openscience.cdk.interfaces.IChemFile)1 IChemModel (org.openscience.cdk.interfaces.IChemModel)1