/** * * @param reactionSet * @throws java.lang.Exception */ public synchronized void standardize(IReactionSet reactionSet) throws Exception { for (IReaction reaction : reactionSet.reactions()) { IReaction standardizedReaction = standardize(reaction); reactionSet.addReaction(standardizedReaction); } }
/** * Get all Reactions object containing a Molecule as a Product from a set of * Reactions. * * @param reactSet The set of reaction to inspect * @param molecule The molecule to find as a product * @return The IReactionSet */ public static IReactionSet getRelevantReactionsAsProduct(IReactionSet reactSet, IAtomContainer molecule) { IReactionSet newReactSet = reactSet.getBuilder().newInstance(IReactionSet.class); for (IReaction reaction : reactSet.reactions()) { for (IAtomContainer atomContainer : reaction.getProducts().atomContainers()) if (atomContainer.equals(molecule)) newReactSet.addReaction(reaction); } return newReactSet; }
/** * Get all Reactions object containing a Molecule as a Reactant from a set * of Reactions. * * @param reactSet The set of reaction to inspect * @param molecule The molecule to find as a reactant * @return The IReactionSet */ public static IReactionSet getRelevantReactionsAsReactant(IReactionSet reactSet, IAtomContainer molecule) { IReactionSet newReactSet = reactSet.getBuilder().newInstance(IReactionSet.class); for (IReaction reaction : reactSet.reactions()) { for (IAtomContainer atomContainer : reaction.getReactants().atomContainers()) if (atomContainer.equals(molecule)) newReactSet.addReaction(reaction); } return newReactSet; }
@Override public <T extends IChemObject> T read(T object) throws CDKException { if (object instanceof IReaction) { return (T) readReaction(object.getBuilder()); } 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 { throw new CDKException("Only supported are Reaction and ChemModel, and not " + object.getClass().getName() + "."); } }
@Test public void testGetReactionCount() { IReactionSet reactionSet = (IReactionSet) newChemObject(); reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 1 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 2 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 3 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 4 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 5 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 6 (force growing) Assert.assertEquals(6, reactionSet.getReactionCount()); }
/** * Method to test whether the class complies with RFC #9. */ @Test public void testToString() { IReactionSet reactionSet = (IReactionSet) newChemObject(); String description = reactionSet.toString(); for (int i = 0; i < description.length(); i++) { Assert.assertTrue(description.charAt(i) != '\n'); Assert.assertTrue(description.charAt(i) != '\r'); } IReaction reaction = reactionSet.getBuilder().newInstance(IReaction.class); reactionSet.addReaction(reaction); description = reactionSet.toString(); for (int i = 0; i < description.length(); i++) { Assert.assertTrue(description.charAt(i) != '\n'); Assert.assertTrue(description.charAt(i) != '\r'); } }
@Test public void testGetReaction_int() { IReactionSet reactionSet = (IReactionSet) newChemObject(); reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 1 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 2 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 3 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 4 for (int i = 0; i < reactionSet.getReactionCount(); i++) { Assert.assertNotNull(reactionSet.getReaction(i)); } }
@Test public void testReactions() { IReactionSet reactionSet = (IReactionSet) newChemObject(); reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 1 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 2 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 3 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 4 Iterator<IReaction> reactionIter = reactionSet.reactions().iterator(); Assert.assertNotNull(reactionIter); int count = 0; while (reactionIter.hasNext()) { Assert.assertNotNull(reactionIter.next()); ++count; } Assert.assertEquals(4, count); }
@Test public void testAddReaction_IReaction() { IReactionSet reactionSet = (IReactionSet) newChemObject(); reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 1 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 2 IReaction third = reactionSet.getBuilder().newInstance(IReaction.class); reactionSet.addReaction(third); // 3 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 4 Assert.assertEquals(4, reactionSet.getReactionCount()); Assert.assertEquals(third, reactionSet.getReaction(2)); }
@Test public void testGetAllMolecules_IReactionSet() { IReactionSet reactionSet = builder.newInstance(IReactionSet.class); reactionSet.addReaction(builder.newInstance(IReaction.class)); // 1 reactionSet.addReaction(builder.newInstance(IReaction.class)); // 2 Assert.assertEquals(0, ReactionSetManipulator.getAllMolecules(reactionSet).getAtomContainerCount()); }
@Test public void testRemoveReaction_int() { IReactionSet reactionSet = (IReactionSet) newChemObject(); reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 1 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 2 reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); // 3 Assert.assertEquals(3, reactionSet.getReactionCount()); reactionSet.removeReaction(1); Assert.assertEquals(2, reactionSet.getReactionCount()); Assert.assertNotNull(reactionSet.getReaction(0)); Assert.assertNotNull(reactionSet.getReaction(1)); }
@Test public void testRemoveAllReactions() { IReactionSet reactionSet = (IReactionSet) newChemObject(); reactionSet.addReaction(reactionSet.getBuilder().newInstance(IReaction.class)); reactionSet.removeAllReactions(); Assert.assertEquals(0, reactionSet.getReactionCount()); }
@Test public void testGetAllMolecules_IReactionSet2() { IReactionSet reactionSet = builder.newInstance(IReactionSet.class); IReaction reaction1 = builder.newInstance(IReaction.class); IAtomContainer molecule = builder.newInstance(IAtomContainer.class); reaction1.addProduct(molecule); reaction1.addReactant(builder.newInstance(IAtomContainer.class)); reactionSet.addReaction(reaction1); IReaction reaction2 = builder.newInstance(IReaction.class); reaction2.addProduct(builder.newInstance(IAtomContainer.class)); reaction2.addReactant(molecule); reactionSet.addReaction(reaction2); Assert.assertEquals(3, ReactionSetManipulator.getAllMolecules(reactionSet).getAtomContainerCount()); }
@Test @Override public void testStateChanged_IChemObjectChangeEvent() { ChemObjectListenerImpl listener = new ChemObjectListenerImpl(); IReactionSet chemObject = (IReactionSet) newChemObject(); chemObject.addListener(listener); chemObject.addReaction(chemObject.getBuilder().newInstance(IReaction.class)); Assert.assertTrue(listener.changed); listener.reset(); Assert.assertFalse(listener.changed); }
public void redo() { chemModel.getMoleculeSet().removeAtomContainer(movedContainer); IReaction reaction = chemModel.getBuilder().newInstance(IReaction.class); reaction.setID(reactionID); IAtomContainer mol=chemModel.getBuilder().newInstance(IAtomContainer.class,movedContainer); mol.setID(movedContainer.getID()); if(reactantOrProduct) reaction.addReactant(mol); else reaction.addProduct(mol); if(chemModel.getReactionSet()==null) chemModel.setReactionSet(chemModel.getBuilder().newInstance(IReactionSet.class)); chemModel.getReactionSet().addReaction(reaction); chemModel.getMoleculeSet().removeAtomContainer(oldContainer); }
@Test public void testIsEmpty() { IReactionSet set = (IReactionSet) newChemObject(); Assert.assertTrue("new reaction set should be empty", set.isEmpty()); set.addReaction(set.getBuilder().newInstance(IReaction.class)); Assert.assertFalse("reaction set with a single reaction should not be empty", set.isEmpty()); set.removeAllReactions(); Assert.assertTrue("reaction set with all reactions removed should be empty", set.isEmpty()); }
/** * Test if we get the expected {@link IllegalArgumentException} when we pass * an {@link IAtomContainer} without 2D coordinates. */ @Test(expected = IllegalArgumentException.class) public void testCalculateBounds_IReactionSet_SingleAtom() { IAtomContainer container = new AtomContainer(); container.addAtom(container.getBuilder().newInstance(IAtom.class, "C")); IReaction reaction = container.getBuilder().newInstance(IReaction.class); reaction.addReactant(container.getBuilder().newInstance(IAtomContainer.class, container)); IReactionSet set = container.getBuilder().newInstance(IReactionSet.class); set.addReaction(reaction); BoundsCalculator.calculateBounds(set); }
@Test public void testStateChanged_EventPropagation_ReactionSet() { ChemObjectListenerImpl listener = new ChemObjectListenerImpl(); IChemModel chemObject = (IChemModel) newChemObject(); chemObject.addListener(listener); IReactionSet reactionSet = chemObject.getBuilder().newInstance(IReactionSet.class); chemObject.setReactionSet(reactionSet); Assert.assertTrue(listener.changed); // reset the listener listener.reset(); Assert.assertFalse(listener.changed); // changing the set should trigger a change event in the IChemModel reactionSet.addReaction(chemObject.getBuilder().newInstance(IReaction.class)); Assert.assertTrue(listener.changed); }
@Test public void testIsEmpty_ReactionSet() { IChemModel model = (IChemModel) newChemObject(); IChemObjectBuilder builder = model.getBuilder(); IAtomContainer molecule = builder.newInstance(IAtomContainer.class); IReaction reaction = builder.newInstance(IReaction.class); reaction.addReactant(molecule); IReactionSet set = builder.newInstance(IReactionSet.class); model.setReactionSet(set); Assert.assertTrue("model has an empty reaction set and should be empty", model.isEmpty()); set.addReaction(reaction); Assert.assertFalse("model has a reaction set and should not be empty", model.isEmpty()); model.setReactionSet(null); Assert.assertTrue("model has no reaction set", model.isEmpty()); }
/** * Test if we get the expected {@link IllegalArgumentException} when we pass * an {@link IAtomContainer} without 2D coordinates. */ @Test(expected = IllegalArgumentException.class) public void testCalculateBounds_IReactionSet() { IAtomContainer container = new AtomContainer(); container.addAtom(container.getBuilder().newInstance(IAtom.class, "C")); container.addAtom(container.getBuilder().newInstance(IAtom.class, "C")); IReaction reaction = container.getBuilder().newInstance(IReaction.class); reaction.addReactant(container.getBuilder().newInstance(IAtomContainer.class, container)); IReactionSet set = container.getBuilder().newInstance(IReactionSet.class); set.addReaction(reaction); BoundsCalculator.calculateBounds(set); }