/** * 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()); }
/** * 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 queryMatch() throws Exception { AtomMatcher matcher = AtomMatcher.forQuery(); IQueryAtom atom1 = mock(IQueryAtom.class); IAtom atom2 = mock(IAtom.class); IAtom atom3 = mock(IAtom.class); when(atom1.matches(atom2)).thenReturn(true); when(atom1.matches(atom3)).thenReturn(false); assertTrue(matcher.matches(atom1, atom2)); assertFalse(matcher.matches(atom1, atom3)); } }