/** * Create a pattern which can be used to find molecules which are the same * as the {@code query} structure. The default structure search * implementation is {@link VentoFoggia}. * * @param query the substructure to find * @return a pattern for finding the {@code query} * @see VentoFoggia */ public static Pattern findIdentical(IAtomContainer query) { return VentoFoggia.findIdentical(query); } }
public IAtomContainer removeMolecule(IAtomContainer molecule) throws CDKException { for (int i = 0; i < templates.size(); i++) { if (VentoFoggia.findIdentical(templates.get(i), anonAtomMatcher, anonBondMatcher) .matches(molecule)) { elemPatterns.remove(i); anonPatterns.remove(i); return templates.remove(i); } } return null; }
public IAtomContainer removeMolecule(IAtomContainer molecule) throws CDKException { for (int i = 0; i < templates.size(); i++) { if (VentoFoggia.findIdentical(templates.get(i), anonAtomMatcher, anonBondMatcher) .matches(molecule)) { elemPatterns.remove(i); anonPatterns.remove(i); return templates.remove(i); } } return null; }
/** * Checks if one of the loaded templates is isomorph to the given * Molecule. If so, it assigns the coordinates from the template to the * respective atoms in the Molecule, and marks the atoms as ISPLACED. * * @param molecule The molecule to be check for potential templates * @return True if there was a possible mapping */ public boolean mapTemplateExact(IAtomContainer molecule) throws CDKException { for (IAtomContainer template : templates) { Mappings mappings = VentoFoggia.findIdentical(template, anonAtomMatcher, anonBondMatcher) .matchAll(molecule); for (Map<IAtom, IAtom> atoms : mappings.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; }
/** * Checks if one of the loaded templates is isomorph to the given * Molecule. If so, it assigns the coordinates from the template to the * respective atoms in the Molecule, and marks the atoms as ISPLACED. * * @param molecule The molecule to be check for potential templates * @return True if there was a possible mapping */ public boolean mapTemplateExact(IAtomContainer molecule) throws CDKException { for (IAtomContainer template : templates) { Mappings mappings = VentoFoggia.findIdentical(template, anonAtomMatcher, anonBondMatcher) .matchAll(molecule); for (Map<IAtom, IAtom> atoms : mappings.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; }
/** * Create a pattern which can be used to find molecules which are the same * as the {@code query} structure. * * @param query the substructure to find * @return a pattern for finding the {@code query} */ public static Pattern findIdentical(IAtomContainer query) { boolean isQuery = query instanceof IQueryAtomContainer; return findIdentical(query, isQuery ? AtomMatcher.forQuery() : AtomMatcher.forElement(), isQuery ? BondMatcher.forQuery() : BondMatcher.forOrder()); }
@Test public void benzeneIdentical() throws Exception { int[] match = VentoFoggia.findIdentical(TestMoleculeFactory.makeBenzene()).match( TestMoleculeFactory.makeBenzene()); assertThat(match, is(new int[]{0, 1, 2, 3, 4, 5})); int count = FluentIterable.from( VentoFoggia.findIdentical(TestMoleculeFactory.makeBenzene()) .matchAll(TestMoleculeFactory.makeBenzene())).size(); assertThat(count, is(6)); // note: aromatic one would be 12 }
@Test public void benzeneNonIdentical() throws Exception { int[] match = VentoFoggia.findIdentical(TestMoleculeFactory.makeBenzene()).match( TestMoleculeFactory.makeNaphthalene()); assertThat(match, is(new int[0])); int count = FluentIterable.from( VentoFoggia.findIdentical(TestMoleculeFactory.makeBenzene()).matchAll( TestMoleculeFactory.makeNaphthalene())).size(); assertThat(count, is(0)); }
/** * Atom-atom mapping of the input molecule to the bare container constructed from the InChI connection table. * This makes it possible to map the positions of the mobile hydrogens in the InChI back to the input molecule. * @param inchiMolGraph molecule (bare) as defined in InChI * @param mol user input molecule * @throws CDKException */ private void mapInputMoleculeToInchiMolgraph(IAtomContainer inchiMolGraph, IAtomContainer mol) throws CDKException { Iterator<Map<IAtom, IAtom>> iter = org.openscience.cdk.isomorphism.VentoFoggia.findIdentical(inchiMolGraph, AtomMatcher.forElement(), BondMatcher.forAny()) .matchAll(mol) .limit(1) .toAtomMap() .iterator(); if (iter.hasNext()) { for (Map.Entry<IAtom,IAtom> e : iter.next().entrySet()) { IAtom src = e.getKey(); IAtom dst = e.getValue(); String position = src.getID(); dst.setID(position); LOGGER.debug("Mapped InChI ", src.getSymbol(), " ", src.getID(), " to ", dst.getSymbol(), " " + dst.getID()); } } else { throw new IllegalArgumentException(CANSMI.create(inchiMolGraph) + " " + CANSMI.create(mol)); } }