/** * 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; }
IReaction r = readReaction(setOfReactions.getBuilder()); if (r != null) { setOfReactions.addReaction(r); r = readReaction(setOfReactions.getBuilder());
/** * get all Molecules object from a set of Reactions. * * @param set The set of reaction to inspect * @return The IAtomContanerSet */ public static IAtomContainerSet getAllMolecules(IReactionSet set) { IAtomContainerSet moleculeSet = set.getBuilder().newInstance(IAtomContainerSet.class); for (IReaction reaction : set.reactions()) { IAtomContainerSet molecules = ReactionManipulator.getAllMolecules(reaction); for (IAtomContainer ac : molecules.atomContainers()) { boolean contain = false; for (IAtomContainer atomContainer : moleculeSet.atomContainers()) { if (atomContainer.equals(ac)) { contain = true; break; } } if (!contain) moleculeSet.addAtomContainer(ac); } } return moleculeSet; }
@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()); }
/** * Create a IReactionScheme give a IReactionSet object. * * @param reactionSet The IReactionSet * @return The IReactionScheme */ public static IReactionScheme createReactionScheme(IReactionSet reactionSet) { IReactionScheme reactionScheme = reactionSet.getBuilder().newInstance(IReactionScheme.class); // Looking for those reactants which doesn't have any precursor. They are the top. ArrayList<IReaction> listTopR = new ArrayList<IReaction>(); for (IReaction reaction : reactionSet.reactions()) { if (extractPrecursorReaction(reaction, reactionSet).getReactionCount() == 0) listTopR.add(reaction); } for (IReaction reaction : listTopR) { reactionScheme.addReaction(reaction); IReactionScheme newReactionScheme = setScheme(reaction, reactionSet); if (newReactionScheme.getReactionCount() != 0 || newReactionScheme.getReactionSchemeCount() != 0) reactionScheme.add(newReactionScheme); } return reactionScheme; }
/** * 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)); }
private static IAtomContainerSet getReactionPath(IAtomContainer reactant, IAtomContainer finalMol, IReactionSet reactionSet) { IAtomContainerSet allSet = reactionSet.getBuilder().newInstance(IAtomContainerSet.class); for (IReaction reaction : reactionSet.reactions()) { for (IAtomContainer reactant2 : reaction.getReactants().atomContainers()) { if (reactant2.equals(reactant)) { for (IAtomContainer product : reaction.getProducts().atomContainers()) { if (!product.equals(finalMol)) { IAtomContainerSet allSet2 = getReactionPath(product, finalMol, reactionSet); if (allSet2.getAtomContainerCount() != 0) { allSet.addAtomContainer(reactant); allSet.add(allSet2); } } else { allSet.addAtomContainer(product); return allSet; } } } } } return allSet; } }
/** * Get all Reactions object containing a Molecule from a set of Reactions. * * @param reactSet The set of reaction to inspect * @param molecule The molecule to find * @return The IReactionSet */ public static IReactionSet getRelevantReactions(IReactionSet reactSet, IAtomContainer molecule) { IReactionSet newReactSet = reactSet.getBuilder().newInstance(IReactionSet.class); IReactionSet reactSetProd = getRelevantReactionsAsProduct(reactSet, molecule); for (IReaction reaction : reactSetProd.reactions()) newReactSet.addReaction(reaction); IReactionSet reactSetReact = getRelevantReactionsAsReactant(reactSet, molecule); for (IReaction reaction : reactSetReact.reactions()) newReactSet.addReaction(reaction); return newReactSet; }
if (found) break; if (reactant.equals(origenMol)) { IAtomContainerSet allSet = reactionSet.getBuilder().newInstance(IAtomContainerSet.class);
@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 testClone_Reaction() throws Exception { 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 IReactionSet clone = (IReactionSet) reactionSet.clone(); Assert.assertEquals(reactionSet.getReactionCount(), clone.getReactionCount()); for (int f = 0; f < reactionSet.getReactionCount(); f++) { for (int g = 0; g < clone.getReactionCount(); g++) { Assert.assertNotNull(reactionSet.getReaction(f)); Assert.assertNotNull(clone.getReaction(g)); Assert.assertNotSame(reactionSet.getReaction(f), clone.getReaction(g)); } } }
@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); }
@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 public void testRemoveReaction_IReaction() { IReactionSet reactionSet = (IReactionSet) newChemObject(); IReaction reaction = reactionSet.getBuilder().newInstance(IReaction.class); reaction.setID("1"); reactionSet.addReaction(reaction); IReaction relevantReaction = reactionSet.getBuilder().newInstance(IReaction.class); relevantReaction.setID("2"); reactionSet.addReaction(relevantReaction); Assert.assertEquals(2, reactionSet.getReactionCount()); reactionSet.removeReaction(relevantReaction); Assert.assertEquals(1, reactionSet.getReactionCount()); Assert.assertEquals("1", reactionSet.getReaction(0).getID()); reactionSet.addReaction(relevantReaction); reactionSet.addReaction(relevantReaction); Assert.assertEquals(3, reactionSet.getReactionCount()); reactionSet.removeReaction(relevantReaction); Assert.assertEquals(1, reactionSet.getReactionCount()); Assert.assertEquals("1", reactionSet.getReaction(0).getID()); }