TemplateHandler { public boolean mapTemplates(IAtomContainer molecule) throws CDKException { for (Pattern anonPattern : elemPatterns) { for (Map<IAtom, IAtom> atoms : anonPattern.matchAll(molecule).toAtomMap()) { for (Map.Entry<IAtom, IAtom> e : atoms.entrySet()) { e.getValue().setPoint2d(new Point2d(e.getKey().getPoint2d())); e.getValue().setFlag(CDKConstants.ISPLACED, true); } if (!atoms.isEmpty()) return true; } } for (Pattern anonPattern : anonPatterns) { for (Map<IAtom, IAtom> atoms : anonPattern.matchAll(molecule).toAtomMap()) { for (Map.Entry<IAtom, IAtom> e : atoms.entrySet()) { e.getValue().setPoint2d(new Point2d(e.getKey().getPoint2d())); e.getValue().setFlag(CDKConstants.ISPLACED, true); } if (!atoms.isEmpty()) return true; } } return false; } TemplateHandler(IChemObjectBuilder builder);  TemplateHandler(); void loadTemplates(IChemObjectBuilder builder); void addMolecule(IAtomContainer molecule); IAtomContainer removeMolecule(IAtomContainer molecule); boolean mapTemplateExact(IAtomContainer molecule); boolean mapTemplates(IAtomContainer molecule); int getTemplateCount(); IAtomContainer getTemplateAt(int position); IAtomContainerSet getMappedSubstructures(IAtomContainer molecule); static TemplateHandler createSingleton(IAtomContainer template); static TemplateHandler createFromSubstructure(Pattern ptrn, Iterable<IAtomContainer> mols); static TemplateHandler createFromSubstructure(Pattern ptrn, IAtomContainer mol);  }
@Test public void testDetection() throws Exception { TemplateHandler th = new TemplateHandler(DefaultChemObjectBuilder.getInstance()); String smiles = "CC12C3(C6CC6)C4(C)C1C5(C(CC)C)C(C(CC)C)2C(C)3C45CC(C)C"; IAtomContainer mol = sp.parseSmiles(smiles); Assert.assertTrue(th.mapTemplates(mol)); }
@Test public void testOtherElements() throws Exception { boolean itIsInThere = false; TemplateHandler th = new TemplateHandler(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = TestMoleculeFactory.makeSteran(); itIsInThere = th.mapTemplates(mol); Assert.assertTrue(itIsInThere); mol.getAtom(0).setSymbol("N"); itIsInThere = th.mapTemplates(mol); Assert.assertTrue(itIsInThere); }
@Test public void testOtherBondOrder() throws Exception { boolean itIsInThere = false; TemplateHandler th = new TemplateHandler(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = TestMoleculeFactory.makeSteran(); itIsInThere = th.mapTemplates(mol); Assert.assertTrue(itIsInThere); mol.getBond(0).setOrder(IBond.Order.DOUBLE); itIsInThere = th.mapTemplates(mol); Assert.assertTrue(itIsInThere); }