CDKMCS { public static boolean isSubgraph(IAtomContainer sourceGraph, IAtomContainer targetGraph, boolean shouldMatchBonds) throws CDKException { if (sourceGraph instanceof IQueryAtomContainer) { throw new CDKException("The first IAtomContainer must not be an IQueryAtomContainer"); } if (targetGraph.getAtomCount() > sourceGraph.getAtomCount()) { return false; } if (targetGraph.getAtomCount() == 1) { IAtom atom = targetGraph.getAtom(0); for (int i = 0; i < sourceGraph.getAtomCount(); i++) { IAtom atom2 = sourceGraph.getAtom(i); if (atom instanceof IQueryAtom) { IQueryAtom qAtom = (IQueryAtom) atom; if (qAtom.matches(atom2)) { return true; } } else if (atom2 instanceof IQueryAtom) { IQueryAtom qAtom = (IQueryAtom) atom2; if (qAtom.matches(atom)) { return true; } } else { if (atom2.getSymbol().equals(atom.getSymbol())) { return true; } } } return false; } if (!testSubgraphHeuristics(sourceGraph, targetGraph)) { return false; } return (getSubgraphMap(sourceGraph, targetGraph, shouldMatchBonds) != null); }  static boolean isIsomorph(IAtomContainer sourceGraph, IAtomContainer targetGraph, boolean shouldMatchBonds); static List<CDKRMap> getIsomorphMap(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            boolean shouldMatchBonds); static List<CDKRMap> getIsomorphAtomsMap(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            boolean shouldMatchBonds); static List<List<CDKRMap>> getIsomorphMaps(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            boolean shouldMatchBonds); static List<List<CDKRMap>> getSubgraphMaps(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            boolean shouldMatchBonds); static List<CDKRMap> getSubgraphMap(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            boolean shouldMatchBonds); static List<List<CDKRMap>> getSubgraphAtomsMaps(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            boolean shouldMatchBonds); static List<CDKRMap> getSubgraphAtomsMap(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            boolean shouldMatchBonds); static boolean isSubgraph(IAtomContainer sourceGraph, IAtomContainer targetGraph, boolean shouldMatchBonds); static List<IAtomContainer> getOverlaps(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            boolean shouldMatchBonds); static BitSet getBitSet(IAtomContainer atomContainer); static CDKRGraph buildRGraph(IAtomContainer sourceGraph, IAtomContainer targetGraph, boolean shouldMatchBonds); static List<List<CDKRMap>> search(IAtomContainer sourceGraph, IAtomContainer targetGraph,
            BitSet sourceBitSet, BitSet targetBitSet, boolean findAllStructure, boolean findAllMap,
            boolean shouldMatchBonds); static IAtomContainer project(List<CDKRMap> rMapList, IAtomContainer graph, int key); static ArrayList<IAtomContainer> projectList(List<List<CDKRMap>> rMapsList, IAtomContainer graph, int key); static List<CDKRMap> checkSingleAtomCases(IAtomContainer sourceGraph, IAtomContainer targetGraph); static List<List<CDKRMap>> makeAtomsMapsOfBondsMaps(List<List<CDKRMap>> list, IAtomContainer sourceGraph,
            IAtomContainer targetGraph); static List<CDKRMap> makeAtomsMapOfBondsMap(List<CDKRMap> list, IAtomContainer sourceGraph,
            IAtomContainer targetGraph); synchronized static boolean isTimeOut();  }
@Test public void testIsSubgraph_IAtomContainer_IAtomContainer() throws java.lang.Exception { IAtomContainer mol = TestMoleculeFactory.makeAlphaPinene(); IAtomContainer frag1 = TestMoleculeFactory.makeCyclohexene(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(frag1); CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(mol.getBuilder()); adder.addImplicitHydrogens(mol); adder = CDKHydrogenAdder.getInstance(frag1.getBuilder()); adder.addImplicitHydrogens(frag1); Aromaticity.cdkLegacy().apply(mol); Aromaticity.cdkLegacy().apply(frag1); if (standAlone) { System.out.println("Cyclohexene is a subgraph of alpha-Pinen: " + CDKMCS.isSubgraph(mol, frag1, true)); } else { Assert.assertTrue(CDKMCS.isSubgraph(mol, frag1, true)); } }
@Test public void test2() throws java.lang.Exception { IAtomContainer mol = TestMoleculeFactory.makeAlphaPinene(); IAtomContainer frag1 = TestMoleculeFactory.makeCyclohexane(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(frag1); Aromaticity.cdkLegacy().apply(mol); Aromaticity.cdkLegacy().apply(frag1); if (standAlone) { System.out.println("Cyclohexane is a subgraph of alpha-Pinen: " + CDKMCS.isSubgraph(mol, frag1, true)); } else { Assert.assertTrue(!CDKMCS.isSubgraph(mol, frag1, true)); } }
@Test public void test3() throws java.lang.Exception { IAtomContainer mol = TestMoleculeFactory.makeIndole(); IAtomContainer frag1 = TestMoleculeFactory.makePyrrole(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(frag1); CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(mol.getBuilder()); adder.addImplicitHydrogens(mol); adder = CDKHydrogenAdder.getInstance(frag1.getBuilder()); adder.addImplicitHydrogens(frag1); Aromaticity.cdkLegacy().apply(mol); Aromaticity.cdkLegacy().apply(frag1); if (standAlone) { System.out.println("Pyrrole is a subgraph of Indole: " + CDKMCS.isSubgraph(mol, frag1, true)); } else { Assert.assertTrue(CDKMCS.isSubgraph(mol, frag1, true)); } }
@Test public void testBasicQueryAtomContainer() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer atomContainer = sp.parseSmiles("CC(=O)OC(=O)C"); IAtomContainer SMILESquery = sp.parseSmiles("CC"); QueryAtomContainer query = QueryAtomContainerCreator.createBasicQueryContainer(SMILESquery); Assert.assertTrue(CDKMCS.isSubgraph(atomContainer, query, true)); }
@Test public void testItself() throws Exception { String smiles = "C1CCCCCCC1CC"; QueryAtomContainer query = QueryAtomContainerCreator.createAnyAtomContainer(new SmilesParser( DefaultChemObjectBuilder.getInstance()).parseSmiles(smiles), true); IAtomContainer ac = new SmilesParser(DefaultChemObjectBuilder.getInstance()).parseSmiles(smiles); if (standAlone) { System.out.println("AtomCount of query: " + query.getAtomCount()); System.out.println("AtomCount of target: " + ac.getAtomCount()); } boolean matched = CDKMCS.isSubgraph(ac, query, true); if (standAlone) { System.out.println("QueryAtomContainer matched: " + matched); } if (!standAlone) { Assert.assertTrue(matched); } }
@Test public void testFirstArgumentMustNotBeAnQueryAtomContainer() 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); try { CDKMCS.isSubgraph(query, target, true); Assert.fail("The UniversalIsomorphism should check when the first arguments is a QueryAtomContainer"); } catch (Exception e) { } }