private synchronized void BondCollection() { for (int i = 0; i < reactionWithUniqueSTOICHIOMETRY.getReactantCount(); i++) { IAtomContainer mol = reactionWithUniqueSTOICHIOMETRY.getReactants().getAtomContainer(i); for (int j = 0; j < mol.getBondCount(); j++) { IBond bond = mol.getBond(j); rBonds.add(bond); } } for (int i = 0; i < reactionWithUniqueSTOICHIOMETRY.getProductCount(); i++) { IAtomContainer mol = reactionWithUniqueSTOICHIOMETRY.getProducts().getAtomContainer(i); for (int j = 0; j < mol.getBondCount(); j++) { IBond bond = mol.getBond(j); pBonds.add(bond); } } }
@Test public void testGetProductCount() { IReaction reaction = (IReaction) newChemObject(); Assert.assertEquals(0, reaction.getProductCount()); reaction.addProduct(reaction.getBuilder().newInstance(IAtomContainer.class)); Assert.assertEquals(1, reaction.getProductCount()); }
@Test public void fragmentGroupingInvalid() throws InvalidSmilesException { IReaction reaction = smipar.parseReactionSmiles("CC1=NC2=C(O)C=CC=C2C=C1.CC(Cl)=O.[Al+3].[Cl-].[Cl-].[Cl-]>[O-][N+](=O)C1=CC=CC=C1>CC(=O)C1=C2C=CC(C)=NC2=C(O)C=C1 |f:2.3.4.5,4.6|"); assertThat(reaction.getReactantCount(), is(6)); assertThat(reaction.getAgents().getAtomContainerCount(), is(1)); assertThat(reaction.getProductCount(), is(1)); assertThat(reaction.getProperty(CDKConstants.TITLE, String.class), is("")); }
@Test public void fragmentGroupingProducts() throws InvalidSmilesException { IReaction reaction = smipar.parseReactionSmiles("CC1=NC2=C(O)C=CC=C2C=C1.CC(Cl)=O>[O-][N+](=O)C1=CC=CC=C1>CC(=O)C1=C2C=CC(C)=NC2=C(O)C=C1.[Al+3].[Cl-].[Cl-].[Cl-] |f:3.4.5.6|"); assertThat(reaction.getReactantCount(), is(2)); assertThat(reaction.getAgents().getAtomContainerCount(), is(1)); assertThat(reaction.getProductCount(), is(2)); assertThat(reaction.getProperty(CDKConstants.TITLE, String.class), is("")); }
@Test public void fragmentGroupingReactants() throws InvalidSmilesException { IReaction reaction = smipar.parseReactionSmiles("CC1=NC2=C(O)C=CC=C2C=C1.CC(Cl)=O.[Al+3].[Cl-].[Cl-].[Cl-]>[O-][N+](=O)C1=CC=CC=C1>CC(=O)C1=C2C=CC(C)=NC2=C(O)C=C1 |f:2.3.4.5|"); assertThat(reaction.getReactantCount(), is(3)); assertThat(reaction.getAgents().getAtomContainerCount(), is(1)); assertThat(reaction.getProductCount(), is(1)); assertThat(reaction.getProperty(CDKConstants.TITLE, String.class), is("")); }
@Test public void fragmentGroupingAgents() throws InvalidSmilesException { IReaction reaction = smipar.parseReactionSmiles("CC1=NC2=C(O)C=CC=C2C=C1.CC(Cl)=O>[Al+3].[Cl-].[Cl-].[Cl-].[O-][N+](=O)C1=CC=CC=C1>CC(=O)C1=C2C=CC(C)=NC2=C(O)C=C1 |f:2.3.4.5|"); assertThat(reaction.getReactantCount(), is(2)); assertThat(reaction.getAgents().getAtomContainerCount(), is(2)); assertThat(reaction.getProductCount(), is(1)); assertThat(reaction.getProperty(CDKConstants.TITLE, String.class), is("")); }
@Test public void noProducts() throws Exception { IReaction reaction = sp.parseReactionSmiles("C>>"); Assert.assertEquals(1, reaction.getReactantCount()); Assert.assertEquals(0, reaction.getProductCount()); }
@Test public void testReadReactions2() throws Exception { String filename2 = "data/mdl/reaction-2.rxn"; logger.info("Testing: " + filename2); InputStream ins2 = this.getClass().getClassLoader().getResourceAsStream(filename2); MDLRXNReader reader2 = new MDLRXNReader(ins2); IReaction reaction2 = new Reaction(); reaction2 = (IReaction) reader2.read(reaction2); reader2.close(); Assert.assertNotNull(reaction2); Assert.assertEquals(2, reaction2.getReactantCount()); Assert.assertEquals(2, reaction2.getProductCount()); }
@Test public void noReaction() throws Exception { IReaction reaction = sp.parseReactionSmiles(">>"); Assert.assertEquals(0, reaction.getReactantCount()); Assert.assertEquals(0, reaction.getProductCount()); }
/** * Example taken from 'Handbook of Chemoinformatics', Gasteiger, 2003, page 89 * (Part I). */ @org.junit.Test(timeout = 1000) public void testReaction() throws Exception { String reactionSmiles = "O>>[H+].[OH-]"; IReaction reaction = sp.parseReactionSmiles(reactionSmiles); Assert.assertEquals(1, reaction.getReactantCount()); Assert.assertEquals(2, reaction.getProductCount()); }
@Test public void noReactants() throws Exception { IReaction reaction = sp.parseReactionSmiles(">>C"); Assert.assertEquals(0, reaction.getReactantCount()); Assert.assertEquals(1, reaction.getProductCount()); }
@Test public void testReaction() { IReaction reaction = new Reaction(); Assert.assertNotNull(reaction); Assert.assertEquals(0, reaction.getReactantCount()); Assert.assertEquals(0, reaction.getProductCount()); Assert.assertEquals(IReaction.Direction.FORWARD, reaction.getDirection()); }
@Test public void onlyAgents() throws Exception { IReaction reaction = sp.parseReactionSmiles(">C>"); Assert.assertEquals(0, reaction.getReactantCount()); Assert.assertEquals(1, reaction.getAgents().getAtomContainerCount()); Assert.assertEquals(0, reaction.getProductCount()); }
@Test public void testAddProduct_IAtomContainer() { IReaction reaction = (IReaction) newChemObject(); IAtomContainer sodiumhydroxide = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer aceticAcid = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer water = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer acetate = reaction.getBuilder().newInstance(IAtomContainer.class); reaction.addProduct(sodiumhydroxide); reaction.addProduct(aceticAcid); reaction.addProduct(water); Assert.assertEquals(3, reaction.getProductCount()); // next one should trigger a growArray, if the grow // size is still 3. reaction.addProduct(acetate); Assert.assertEquals(4, reaction.getProductCount()); Assert.assertEquals(1.0, reaction.getProductCoefficient(aceticAcid), 0.00001); }
protected IReaction convertRoundTripRXNSMILES(IReaction r) throws CDKException { final SmilesGenerator sg = new SmilesGenerator( SmiFlavor.AtomAtomMap | SmiFlavor.UseAromaticSymbols | SmiFlavor.Stereo); String createSmilesFromReaction = sg.create(r); final SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IReaction parseReactionSmiles = smilesParser.parseReactionSmiles(createSmilesFromReaction); parseReactionSmiles.setID(r.getID()); for (int i = 0; i < r.getReactantCount(); i++) { parseReactionSmiles.getReactants().getAtomContainer(i).setID(r.getReactants().getAtomContainer(i).getID()); } for (int i = 0; i < r.getProductCount(); i++) { parseReactionSmiles.getProducts().getAtomContainer(i).setID(r.getProducts().getAtomContainer(i).getID()); } return parseReactionSmiles; }
/** * 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); }
/** * Example taken from 'Handbook of Chemoinformatics', Gasteiger, 2003, page 90 * (Part I). */ @org.junit.Test(timeout = 1000) public void testReactionWithAgents() throws Exception { String reactionSmiles = "CCO.CC(=O)O>[H+]>CC(=O)OCC.O"; IReaction reaction = sp.parseReactionSmiles(reactionSmiles); Assert.assertEquals(2, reaction.getReactantCount()); Assert.assertEquals(2, reaction.getProductCount()); Assert.assertEquals(1, reaction.getAgents().getAtomContainerCount()); Assert.assertEquals(1, reaction.getAgents().getAtomContainer(0).getAtomCount()); }
/** * 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 testSetProducts_IAtomContainerSet() { IReaction reaction = (IReaction) newChemObject(); IAtomContainer sodiumhydroxide = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer aceticAcid = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainer water = reaction.getBuilder().newInstance(IAtomContainer.class); IAtomContainerSet products = reaction.getBuilder().newInstance(IAtomContainerSet.class); products.addAtomContainer(sodiumhydroxide); products.addAtomContainer(aceticAcid); products.addAtomContainer(water); reaction.setProducts(products); Assert.assertEquals(3, reaction.getProductCount()); Assert.assertEquals(1.0, reaction.getProductCoefficient(aceticAcid), 0.00001); }
@Test public void testReaction() throws Exception { String cmlString = "<reaction>" + "<reactantList><reactant><molecule id='react'/></reactant></reactantList>" + "<productList><product><molecule id='product'/></product></productList>" + "<substanceList><substance><molecule id='water'/></substance></substanceList>" + "</reaction>"; IChemFile chemFile = parseCMLString(cmlString); IReaction reaction = checkForSingleReactionFile(chemFile); Assert.assertEquals(1, reaction.getReactantCount()); Assert.assertEquals(1, reaction.getProductCount()); Assert.assertEquals(1, reaction.getAgents().getAtomContainerCount()); Assert.assertEquals("react", reaction.getReactants().getAtomContainer(0).getID()); Assert.assertEquals("product", reaction.getProducts().getAtomContainer(0).getID()); Assert.assertEquals("water", reaction.getAgents().getAtomContainer(0).getID()); }