/** * A unit test suite for JUnit for Ethene. Reaction: O=C-C-H => O(H)-C=C. Automatic looking for * active center. * * @cdk.inchi InChI=1/C2H4/c1-2/h1-2H2 * @return The test suite */ @Test public void testInitiate_IMoleculeSet_IMoleculeSet() throws Exception { IReactionProcess type = new AdductionProtonPBReaction(); IMolecule molecule = getEthene(); IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet(); setOfReactants.addMolecule(molecule); /* 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(2, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0); IMolecule molecule2 = getExpected(); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2, queryAtom)); }
/** * Checks if the given structures are isomorph. * * @param candidate1 the candidate1 * @param candidate2 the candidate2 * @return true, if is isomorph * @throws CDKException the CDK exception */ public boolean isIsomorph(String candidate1, String candidate2) throws CDKException { IAtomContainer cand1 = null; IAtomContainer cand2 = null; if (hasAtomContainer) { cand1 = this.candidateToStructure.get(candidate1); cand2 = this.candidateToStructure.get(candidate2); } else { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); cand1 = sp.parseSmiles(candidatesToSmiles.get(candidate1)); cand2 = sp.parseSmiles(candidatesToSmiles.get(candidate2)); } return UniversalIsomorphismTester.isIsomorph(cand1, cand2); }
/** * Search if the setOfAtomContainer contains the atomContainer * * @param set ISetOfAtomContainer object where to search * @param atomContainer IAtomContainer to search * @return True, if the atomContainer is contained */ private boolean existAC(IAtomContainerSet set, IAtomContainer atomContainer) { IAtomContainer acClone = null; try { acClone = (IMolecule) atomContainer.clone(); if (!lookingSymmetry) { /*remove all aromatic flags*/ for (IAtom atom : acClone.atoms()) atom.setFlag(CDKConstants.ISAROMATIC, false); for (IBond bond : acClone.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false); } } catch (CloneNotSupportedException e1) { e1.printStackTrace(); } for (int i = 0; i < acClone.getAtomCount(); i++) // if(acClone.getAtom(i).getID() == null) acClone.getAtom(i).setID("" + acClone.getAtomNumber(acClone.getAtom(i))); if (lookingSymmetry) { try { CDKHueckelAromaticityDetector.detectAromaticity(acClone); } catch (CDKException e) { e.printStackTrace(); } } else { if (!lookingSymmetry) { /*remove all aromatic flags*/ for (IAtom atom : acClone.atoms()) atom.setFlag(CDKConstants.ISAROMATIC, false); for (IBond bond : acClone.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false); } } for (int i = 0; i < set.getAtomContainerCount(); i++) { IAtomContainer ss = set.getAtomContainer(i); for (int j = 0; j < ss.getAtomCount(); j++) // if(ss.getAtom(j).getID() == null) ss.getAtom(j).setID("" + ss.getAtomNumber(ss.getAtom(j))); try { if (!lookingSymmetry) { QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolChargeIDQueryContainer(acClone); if (UniversalIsomorphismTester.isIsomorph(ss, qAC)) { QueryAtomContainer qAC2 = QueryAtomContainerCreator.createSymbolAndBondOrderQueryContainer(acClone); if (UniversalIsomorphismTester.isIsomorph(ss, qAC2)) return true; } } else { QueryAtomContainer qAC = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(acClone); CDKHueckelAromaticityDetector.detectAromaticity(ss); if (UniversalIsomorphismTester.isIsomorph(ss, qAC)) return true; } } catch (CDKException e1) { System.err.println(e1); logger.error(e1.getMessage()); logger.debug(e1); } } return false; }