/** * Create a pattern which can be used to find molecules which contain the * {@code query} structure. * * @param query the substructure to find * @return a pattern for finding the {@code query} */ public static Pattern findSubstructure(IAtomContainer query) { boolean isQuery = query instanceof IQueryAtomContainer; return findSubstructure(query, isQuery ? AtomMatcher.forQuery() : AtomMatcher.forElement(), isQuery ? BondMatcher.forQuery() : BondMatcher.forOrder()); }
/** * Create a pattern which can be used to find molecules which contain the * {@code query} structure. * * @param query the substructure to find * @return a pattern for finding the {@code query} */ public static Pattern findSubstructure(IAtomContainer query) { boolean isQuery = query instanceof IQueryAtomContainer; return new Ullmann(query, isQuery ? AtomMatcher.forQuery() : AtomMatcher.forElement(), isQuery ? BondMatcher.forQuery() : BondMatcher.forOrder()); }
@Test(expected = NullPointerException.class) public void elementError() throws Exception { AtomMatcher matcher = AtomMatcher.forElement(); IAtom atom1 = mock(IAtom.class); IAtom atom2 = mock(IAtom.class); when(atom1.getAtomicNumber()).thenReturn(null); when(atom2.getAtomicNumber()).thenReturn(null); matcher.matches(atom1, atom2); }
/** * 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 elementMismatch() throws Exception { AtomMatcher matcher = AtomMatcher.forElement(); IAtom atom1 = mock(IAtom.class); IAtom atom2 = mock(IAtom.class); when(atom1.getAtomicNumber()).thenReturn(6); when(atom2.getAtomicNumber()).thenReturn(8); assertFalse(matcher.matches(atom1, atom2)); assertFalse(matcher.matches(atom2, atom1)); }
/** * 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)); } }
@Test public void elementMatch() throws Exception { AtomMatcher matcher = AtomMatcher.forElement(); IAtom atom1 = mock(IAtom.class); IAtom atom2 = mock(IAtom.class); when(atom1.getAtomicNumber()).thenReturn(6); when(atom2.getAtomicNumber()).thenReturn(6); assertTrue(matcher.matches(atom1, atom2)); assertTrue(matcher.matches(atom2, atom1)); }
@Test public void elementPseudo() throws Exception { AtomMatcher matcher = AtomMatcher.forElement(); IAtom atom1 = mock(IPseudoAtom.class); IAtom atom2 = mock(IPseudoAtom.class); assertTrue(matcher.matches(atom1, atom2)); assertTrue(matcher.matches(atom2, atom1)); }