@Override Pattern create(IAtomContainer container) { return DfPattern.findSubstructure(container); }
/** * Create a pattern which can be used to find molecules which contain the * {@code query} structure. If a 'real' molecule is provided is is converted * with {@link QueryAtomContainer#create(IAtomContainer, Expr.Type...)} * matching elements, aromaticity status, and bond orders. * * @param query the substructure to find * @return a pattern for finding the {@code query} * @see QueryAtomContainer#create(IAtomContainer, Expr.Type...) */ public static DfPattern findSubstructure(IAtomContainer query) { if (query instanceof IQueryAtomContainer) return new DfPattern((IQueryAtomContainer) query); else return new DfPattern(QueryAtomContainer.create(query, ALIPHATIC_ELEMENT, AROMATIC_ELEMENT, SINGLE_OR_AROMATIC, ALIPHATIC_ORDER, STEREOCHEMISTRY)); }
private DfPattern(IQueryAtomContainer query) { this.query = query; determineFilters(query); state = new DfState(query); }
@Test public void matchRoot() throws Exception { IAtomContainer mol = smi("OC(=O)C(=O)O"); IAtomContainer qry = sma("O=*"); DfPattern ptrn = DfPattern.findSubstructure(qry); assertFalse(ptrn.matchesRoot(mol.getAtom(0))); assertTrue(ptrn.matchesRoot(mol.getAtom(2))); assertTrue(ptrn.matchesRoot(mol.getAtom(4))); assertFalse(ptrn.matchesRoot(mol.getAtom(5))); } }
/** * {@inheritDoc} */ @Override public Mappings matchAll(IAtomContainer mol) { if (mol.getAtomCount() < query.getAtomCount()) return new Mappings(query, mol, Collections.<int[]>emptySet()); if (mol.getAtomCount() > 0) checkCompatibleAPI(mol.getAtom(0)); DfState local = new DfState(state); local.setMol(mol); return filter(new Mappings(query, mol, local), query, mol); }
/** * {@inheritDoc} */ @Override public int[] match(IAtomContainer target) { return matchAll(target).first(); }
/** * Test whether the pattern matches at the provided atom. * * @param root the root atom of the molecule * @return the pattern matches */ public boolean matchesRoot(IAtom root) { return matchRoot(root).atLeast(1); }
case RECURSIVE: if (ptrn == null) ptrn = DfPattern.findSubstructure(query); return ptrn.matchesRoot(atom); default: throw new IllegalArgumentException("Cannot match AtomExpr, type=" + type);
/** * Match the pattern at the provided root. * * @param root the root atom of the molecule * @return mappings * @see Mappings */ Mappings matchRoot(IAtom root) { checkCompatibleAPI(root); IAtomContainer mol = root.getContainer(); if (query.getAtomCount() > 0 && ((IQueryAtom) query.getAtom(0)).matches(root)) { DfState local = new DfState(state); local.setRoot(root); return filter(new Mappings(query, mol, local), query, mol); } else { return new Mappings(query, mol, Collections.<int[]>emptySet()); } }
/** * {@inheritDoc} */ @Override public boolean matches(IAtomContainer target) { return matchAll(target).atLeast(1); }