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;
}
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;
}
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());
}
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());
}
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));
}
Aggregations