static boolean matches(IAtomContainer a, IAtomContainer b) throws CDKException { IQueryAtomContainer query = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(b); return new UniversalIsomorphismTester().isIsomorph(a, query); }
private static int getUITSolutionCount(IAtomContainer query, IAtomContainer target) throws CDKException { UniversalIsomorphismTester uti = new UniversalIsomorphismTester(); if (uti.isSubgraph(target, query)) { return 1; } else { return 0; } }
UniversalIsomorphismTester universalIsomorphismTester = new UniversalIsomorphismTester(); List<List<Integer>> uniqueSubgraphs = new ArrayList<List<Integer>>(); for (QueryAtomContainer query : queries) { try { subgraphMaps = universalIsomorphismTester.getSubgraphMaps(atomContainer, query); } catch (CDKException e) { e.printStackTrace();
/** * Returns the first subgraph 'atom mapping' found for g2 in g1, where g2 must be a substructure * of g1. If it is not a substructure, null will be returned. * * @param g1 first molecule. Must not be an {@link IQueryAtomContainer}. * @param g2 substructure to be mapped. May be an {@link IQueryAtomContainer}. * @return the first subgraph atom mapping found projected on g1. * This is a {@link List} of {@link RMap} objects containing Ids of matching atoms. */ public List<RMap> getSubgraphAtomsMap(IAtomContainer g1, IAtomContainer g2) throws CDKException { List<RMap> list = checkSingleAtomCases(g1, g2); if (list == null) { return makeAtomsMapOfBondsMap(getSubgraphMap(g1, g2), g1, g2); } else if (list.isEmpty()) { return null; } else { return list; } }
/** * Returns all subgraph 'atom mappings' found for g2 in g1, where g2 must be a substructure * of g1. If it is not a substructure, null will be returned. * This is an {@link List} of {@link List}s of {@link RMap} objects. * * @param g1 first molecule. Must not be an {@link IQueryAtomContainer}. * @param g2 substructure to be mapped. May be an {@link IQueryAtomContainer}. * @return all subgraph atom mappings found projected on g1. This is a * {@link List} of {@link RMap} objects containing Ids of matching atoms. */ public List<List<RMap>> getSubgraphAtomsMaps(IAtomContainer g1, IAtomContainer g2) throws CDKException { List<RMap> list = checkSingleAtomCases(g1, g2); if (list == null) { return makeAtomsMapsOfBondsMaps(getSubgraphMaps(g1, g2), g1, g2); } else { List<List<RMap>> atomsMap = new ArrayList<List<RMap>>(); atomsMap.add(list); return atomsMap; } }
UniversalIsomorphismTester universalIsomorphismTester = new UniversalIsomorphismTester(); if (checkAminoAcid > 1) { if (universalIsomorphismTester.isSubgraph(ac, aminoAcid)) { List list = universalIsomorphismTester.getSubgraphAtomsMap(ac, aminoAcid); RMap map = null; IAtom atom1 = null; if (universalIsomorphismTester.isSubgraph(ac, paba)) { xlogP -= 0.501; IAtomContainer salicilic = createSalicylicAcid(ac.getBuilder()); try { if (universalIsomorphismTester.isSubgraph(ac, salicilic)) { xlogP += 0.554;
@Before public void setUpUITester() { uiTester = new UniversalIsomorphismTester(); }
/** * A unit test suite for JUnit for acetaldehyde. * Reaction: O=C-C-H => O(H)-C=C. * Automatically looks for the active centre. * * @cdk.inchi InChI=1/C2H4O/c1-2-3/h2H,1H3 * * @return The test suite */ @Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new AdductionProtonLPReaction(); /* 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(getExampleReactants(), null); Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(uiTester.isIsomorph(molecule2, queryAtom)); }
UniversalIsomorphismTester universalIsomorphismTester = new UniversalIsomorphismTester(); while ((l = universalIsomorphismTester.getSubgraphMap(ac, replaceStructure)) != null) { List<RMap> l2 = universalIsomorphismTester.makeAtomsMapOfBondsMap(l, ac, replaceStructure); Iterator<RMap> bondit = l.iterator(); while (bondit.hasNext()) {
/** * Removes all redundant solution. * * @param graphList the list of structure to clean * @return the list cleaned * @throws CDKException if there is a problem in obtaining subgraphs */ private List<IAtomContainer> getMaximum(List<IAtomContainer> graphList) throws CDKException { List<IAtomContainer> reducedGraphList = new ArrayList<IAtomContainer>(); reducedGraphList.addAll(graphList); for (int i = 0; i < graphList.size(); i++) { IAtomContainer gi = graphList.get(i); for (int j = i + 1; j < graphList.size(); j++) { IAtomContainer gj = graphList.get(j); // Gi included in Gj or Gj included in Gi then // reduce the irrelevant solution if (isSubgraph(gj, gi)) { reducedGraphList.remove(gi); } else if (isSubgraph(gi, gj)) { reducedGraphList.remove(gj); } } } return reducedGraphList; }
List<RMap> list; try { list = new UniversalIsomorphismTester().getSubgraphAtomsMap(firstAtomContainer, secondAtomContainer);
@Test public void testAnyAtomAnyBondCase() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer target = sp.parseSmiles("O1C=CC=C1"); IAtomContainer queryac = sp.parseSmiles("C1CCCC1"); QueryAtomContainer query = QueryAtomContainerCreator.createAnyAtomAnyBondContainer(queryac, false); Assert.assertTrue("C1CCCC1 should be a subgraph of O1C=CC=C1", uiTester.isSubgraph(target, query)); Assert.assertTrue("C1CCCC1 should be a isomorph of O1C=CC=C1", uiTester.isIsomorph(target, query)); }
if (!testSubgraphHeuristics(g1, g2)) return false; return (getSubgraphMap(g1, g2) != null);
@Test public void testGetSubgraphAtomsMap_Butane() throws Exception { IAtomContainer mol1 = TestMoleculeFactory.makeAlkane(4); IAtomContainer mol2 = TestMoleculeFactory.makeAlkane(4); // Test for atom mapping between the mols List<RMap> maplist = uiTester.getSubgraphAtomsMap(mol2, mol1); Assert.assertNotNull(maplist); Assert.assertEquals(4, maplist.size()); maplist = uiTester.getSubgraphAtomsMap(mol1, mol2); Assert.assertNotNull(maplist); Assert.assertEquals(4, maplist.size()); }
@Test public void testGetSubgraphMap_IAtomContainer_IAtomContainer() throws Exception { String molfile = "data/mdl/decalin.mol"; String queryfile = "data/mdl/decalin.mol"; IAtomContainer mol = new AtomContainer(); IAtomContainer temp = new AtomContainer(); QueryAtomContainer query1 = null; QueryAtomContainer query2 = null; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(molfile); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); reader.read(mol); ins = this.getClass().getClassLoader().getResourceAsStream(queryfile); reader = new MDLV2000Reader(ins, Mode.STRICT); reader.read(temp); query1 = QueryAtomContainerCreator.createBasicQueryContainer(temp); SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer atomContainer = sp.parseSmiles("C1CCCCC1"); query2 = QueryAtomContainerCreator.createBasicQueryContainer(atomContainer); List<RMap> list = uiTester.getSubgraphMap(mol, query1); Assert.assertEquals(11, list.size()); list = uiTester.getSubgraphMap(mol, query2); Assert.assertEquals(6, list.size()); }
/** * @cdk.bug 1708336 */ @Test public void testSFBug1708336() throws Exception { IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance(); IAtomContainer atomContainer = builder.newInstance(IAtomContainer.class); atomContainer.addAtom(builder.newInstance(IAtom.class, "C")); atomContainer.addAtom(builder.newInstance(IAtom.class, "C")); atomContainer.addAtom(builder.newInstance(IAtom.class, "N")); atomContainer.addBond(0, 1, IBond.Order.SINGLE); atomContainer.addBond(1, 2, IBond.Order.SINGLE); IQueryAtomContainer query = new QueryAtomContainer(DefaultChemObjectBuilder.getInstance()); if (!Smarts.parse(query, "C*C")) Assert.fail(Smarts.getLastErrorMesg()); List<List<RMap>> list = uiTester.getSubgraphMaps(atomContainer, query); Assert.assertTrue(list.isEmpty()); }
UniversalIsomorphismTester universalIsomorphismTester = new UniversalIsomorphismTester(); if (checkAminoAcid > 1) { if (universalIsomorphismTester.isSubgraph(ac, aminoAcid)) { List list = universalIsomorphismTester.getSubgraphAtomsMap(ac, aminoAcid); RMap map = null; IAtom atom1 = null; if (universalIsomorphismTester.isSubgraph(ac, paba)) { xlogP -= 0.501; IAtomContainer salicilic = createSalicylicAcid(ac.getBuilder()); try { if (universalIsomorphismTester.isSubgraph(ac, salicilic)) { xlogP += 0.554;
@Before public void setUpUITester() { uiTester = new UniversalIsomorphismTester(); }
/** * A unit test suite for JUnit. Reaction: * C(H)(H)=O => [C+](H)(H)-[O-] + [C+](H)=O + * Automatic search of the reactive atoms and bonds. * * @cdk.inchi InChI=1/CH2O/c1-2/h1H2 * * @return The test suite */ @Test public void testBB_AutomaticSearchCentreActiveFormaldehyde() throws Exception { IReactionProcess type = new HeterolyticCleavagePBReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); /* automatic search of the reactive atoms and bonds */ List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); /* initiate */ AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); makeSureAtomTypesAreRecognized(molecule); 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); Assert.assertTrue(uiTester.isIsomorph(getExpectedProducts().getAtomContainer(0), product)); }
@Test public void testIsSubgraph_IAtomContainer_IAtomContainer() throws java.lang.Exception { IAtomContainer mol = TestMoleculeFactory.makeAlphaPinene(); IAtomContainer frag1 = TestMoleculeFactory.makeCyclohexene(); //one double bond in ring AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(frag1); Aromaticity.cdkLegacy().apply(mol); Aromaticity.cdkLegacy().apply(frag1); if (standAlone) { System.out.println("Cyclohexene is a subgraph of alpha-Pinen: " + uiTester.isSubgraph(mol, frag1)); } else { Assert.assertTrue(uiTester.isSubgraph(mol, frag1)); } }