/** * Gets the reactionIDs attribute of the CreateReactionAction object * *@param reactionSet Description of the Parameter *@return The reactionIDs value */ private Object[] getReactionIDs(IReactionSet reactionSet) { if (reactionSet != null) { String[] ids = new String[reactionSet.getReactionCount()]; for (int i = 0; i < reactionSet.getReactionCount(); i++) { ids[i] = reactionSet.getReaction(i).getID(); } return ids; } else { return new String[0]; } } }
/** * Tells the position of an atom in a reaction. Format is "reaction/product:numberofreaction/product_atomnumber". * * @param reactionSet The reactionSet in which to search. * @param chemObject The atom to search for. * @return The position in the said format. * @throws CDKException Atom not found in reactionSet. */ private String getAtomNumber(IReactionSet reactionSet, IChemObject chemObject) throws CDKException { for (int i = 0; i < reactionSet.getReaction(0).getReactantCount(); i++) { for (int k = 0; k < reactionSet.getReaction(0).getReactants().getAtomContainer(i).getAtomCount(); k++) { if (reactionSet.getReaction(0).getReactants().getAtomContainer(i).getAtom(k).equals(chemObject)) return "reactant:" + i + "_" + k; } } for (int i = 0; i < reactionSet.getReaction(0).getProductCount(); i++) { for (int k = 0; k < reactionSet.getReaction(0).getProducts().getAtomContainer(i).getAtomCount(); k++) { if (reactionSet.getReaction(0).getProducts().getAtomContainer(i).getAtom(k).equals(chemObject)) return "product:" + i + "_" + k; } } throw new CDKException("not found"); } }
@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)); } } }
/** * This test checks of different numbering for the same mapping gives the same result. */ @Test public void testAsadExamples() throws Exception { String filename = "data/mdl/output.rxn"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLRXNReader reader = new MDLRXNReader(ins); IReactionSet reactionSet = (IReactionSet) reader.read(new ReactionSet()); reader.close(); filename = "data/mdl/output_Cleaned.rxn"; logger.info("Testing: " + filename); ins = this.getClass().getClassLoader().getResourceAsStream(filename); reader = new MDLRXNReader(ins); IReactionSet reactionSet2 = (IReactionSet) reader.read(new ReactionSet()); reader.close(); Assert.assertEquals(reactionSet.getReaction(0).getMappingCount(), reactionSet2.getReaction(0).getMappingCount()); for (int i = 0; i < reactionSet.getReaction(0).getMappingCount(); i++) { Assert.assertEquals(getAtomNumber(reactionSet, reactionSet.getReaction(0).getMapping(i).getChemObject(0)), getAtomNumber(reactionSet2, reactionSet2.getReaction(0).getMapping(i).getChemObject(0))); Assert.assertEquals(getAtomNumber(reactionSet, reactionSet.getReaction(0).getMapping(i).getChemObject(1)), getAtomNumber(reactionSet2, reactionSet2.getReaction(0).getMapping(i).getChemObject(1))); } }
@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 testReactionProperties() throws Exception { String filename = "data/cml/reaction.2.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); IReaction reaction = chemFile.getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0); Assert.assertEquals("3", (String) reaction.getProperty("Ka")); } }
/** * */ @Test public void testRDFReactioniSet() throws Exception { String filename = "data/mdl/qsar-reaction-test.rdf"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLRXNReader reader = new MDLRXNReader(ins); IReactionSet reactionSet = (IReactionSet) reader.read(new ReactionSet()); reader.close(); Assert.assertNotNull(reactionSet); Assert.assertEquals(2, reactionSet.getReactionCount()); Assert.assertEquals(2, reactionSet.getReaction(0).getReactantCount()); Assert.assertEquals(3, reactionSet.getReaction(0).getReactants().getAtomContainer(0).getAtomCount()); Assert.assertEquals(2, reactionSet.getReaction(0).getReactants().getAtomContainer(1).getAtomCount()); Assert.assertEquals(2, reactionSet.getReaction(0).getProductCount()); Assert.assertEquals(2, reactionSet.getReaction(0).getProducts().getAtomContainer(0).getAtomCount()); Assert.assertEquals(2, reactionSet.getReaction(0).getProducts().getAtomContainer(1).getAtomCount()); Assert.assertEquals(1, reactionSet.getReaction(1).getReactantCount()); Assert.assertEquals(3, reactionSet.getReaction(1).getReactants().getAtomContainer(0).getAtomCount()); Assert.assertEquals(1, reactionSet.getReaction(1).getProductCount()); Assert.assertEquals(2, reactionSet.getReaction(1).getProducts().getAtomContainer(0).getAtomCount()); }
/** * A unit test suite for JUnit. * * @cdk.inchi InChI=1/C2H4O/c1-2-3/h2H,1H3 * * @return The test suite */ @Test public void testMapping() throws Exception { IReactionProcess type = new AdductionSodiumLPReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); /* automatic looking for active center */ List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); /* initiate */ IReactionSet setOfReactions = type.initiate(setOfReactants, null); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(8, setOfReactions.getReaction(0).getMappingCount()); IAtom mappedProductA0 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(0)); Assert.assertEquals(mappedProductA0, product.getAtom(0)); }
@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()); }
/** * A unit test suite for JUnit. * * @cdk.inchi InChI=1/C2H4O/c1-2-3/h2H,1H3 * * @return The test suite */ @Test public void testMapping() throws Exception { IReactionProcess type = new AdductionProtonLPReaction(); /* automatic looking for active center */ List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); /* initiate */ IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); IReactionSet setOfReactions = type.initiate(setOfReactants, null); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(8, setOfReactions.getReaction(0).getMappingCount()); IAtom mappedProductA0 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(0)); Assert.assertEquals(mappedProductA0, product.getAtom(0)); }
/** * A unit test suite for JUnit. Reaction: * * @return The test suite */ @Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new RadicalSiteHrBetaReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); /* initiate */ List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); IReactionSet setOfReactions = type.initiate(setOfReactants, null); Assert.assertEquals(3, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); assertEquals(molecule2, product); }
/** * @cdk.bug 2697568 */ @Test public void testReadReactionWithPointersToMoleculeSet() throws Exception { String filename = "data/cml/AlanineTree.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); Assert.assertSame(chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0), chemFile .getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0).getReactants().getAtomContainer(0)); }
/** * A unit test suite for JUnit. Reaction: [C*]-C=C-C => C=C-[C*]-C * Automatic search of the center active. * * @return The test suite */ @Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new RearrangementRadicalReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); /* initiate */ List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); IReactionSet setOfReactions = type.initiate(setOfReactants, null); Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); /* C=C-[C*]-C */ IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); assertEquals(molecule2, product); }
/** * @cdk.bug 2697568 */ @Test public void testBug2697568() throws Exception { String filename = "data/cml/AlanineTreeReverse.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); Assert.assertSame(chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0), chemFile .getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0).getReactants().getAtomContainer(0)); }
/** * A unit test suite for JUnit. Reaction: [C+]-O => C=[O+] * Automatic search of the center active. * * @return The test suite */ @Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new SharingLonePairReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); /* initiate */ List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); IReactionSet setOfReactions = type.initiate(setOfReactants, null); Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); /* C=[O+] */ IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule2, queryAtom)); }
@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 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 IReaction checkForXReactionFile(IChemFile chemFile, int numberOfReactions) { Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); IReactionSet reactionSet = model.getReactionSet(); Assert.assertNotNull(reactionSet); Assert.assertEquals(reactionSet.getReactionCount(), numberOfReactions); IReaction reaction = null; for (int i = 0; i < numberOfReactions; i++) { reaction = reactionSet.getReaction(i); Assert.assertNotNull(reaction); } return reaction; }
public static IReaction roundTripReaction(Convertor convertor, IReaction reaction) throws Exception { String cmlString = "<!-- failed -->"; Element cmlDOM = convertor.cdkReactionToCMLReaction(reaction); cmlString = cmlDOM.toXML(); IReaction roundTrippedReaction = null; logger.debug("CML string: ", cmlString); CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); IChemFile file = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); Assert.assertNotNull(file); Assert.assertEquals(1, file.getChemSequenceCount()); IChemSequence sequence = file.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(1, sequence.getChemModelCount()); IChemModel chemModel = sequence.getChemModel(0); Assert.assertNotNull(chemModel); IReactionSet reactionSet = chemModel.getReactionSet(); Assert.assertNotNull(reactionSet); Assert.assertEquals(1, reactionSet.getReactionCount()); roundTrippedReaction = reactionSet.getReaction(0); Assert.assertNotNull(roundTrippedReaction); return roundTrippedReaction; }
@Test public void testGetRelevantReactionsAsProduct_IReactionSet_IAtomContainer() { IReactionSet set = builder.newInstance(IReactionSet.class); IReaction reaction1 = builder.newInstance(IReaction.class); set.addReaction(reaction1); IAtomContainer mol1a = builder.newInstance(IAtomContainer.class); IAtomContainer mol1b = builder.newInstance(IAtomContainer.class); reaction1.addReactant(mol1a); reaction1.addReactant(mol1b); reaction1.addProduct(builder.newInstance(IAtomContainer.class)); reaction1.addProduct(builder.newInstance(IAtomContainer.class)); IReaction reaction2 = builder.newInstance(IReaction.class); reaction2.addReactant(mol1b); reaction2.addProduct(builder.newInstance(IAtomContainer.class)); set.addReaction(reaction2); IReaction reaction3 = builder.newInstance(IReaction.class); reaction3.addReactant(builder.newInstance(IAtomContainer.class)); reaction3.addProduct(mol1a); set.addReaction(reaction3); Assert.assertEquals(3, set.getReactionCount()); IReactionSet reactionSet2 = ReactionSetManipulator.getRelevantReactionsAsProduct(set, mol1b); Assert.assertEquals(0, reactionSet2.getReactionCount()); IReactionSet reactionSet1 = ReactionSetManipulator.getRelevantReactionsAsProduct(set, mol1a); Assert.assertEquals(1, reactionSet1.getReactionCount()); Assert.assertEquals(reaction3, reactionSet1.getReaction(0)); }