@Override public boolean matches(IAtom atom) { return qatom.matches(atom); } }
@Override public boolean matches(IAtom atom) { return qatom.matches(atom); } }
@Override public boolean matches(IAtom atom) { return qatom.matches(atom); } }
@Override public boolean matches(IAtom atom) { return qatom.matches(atom); } }
/**{@inheritDoc} */ @Override public boolean matches(IAtom atom1, IAtom atom2) { return ((IQueryAtom) atom1).matches(atom2); } }
/** * {@inheritDoc} */ @Override public boolean matches(IAtom atom1, IAtom atom2) { return ((IQueryAtom) atom1).matches(atom2); }
@Override public boolean matches(IAtom atom) { return this.atom.matches(atom); }
@Override public boolean matches(IAtom atom) { boolean val = false; boolean matchesLeft = left.matches(atom); if (right != null) { if ("and".equals(operator) && matchesLeft) { boolean matchesRight = right.matches(atom); val = matchesLeft && matchesRight; } else if ("or".equals(operator)) { boolean matchesRight = right.matches(atom); val = matchesLeft || matchesRight; } } else { if ("not".equals(operator)) { val = (!matchesLeft); } else { val = matchesLeft; } } return val; }
/** {@inheritDoc} */ @Override public boolean matches(IAtomContainer targetContainer, IAtom targetAtom) { if (qAtom instanceof IQueryAtom) { if (!((IQueryAtom) qAtom).matches(targetAtom)) { return false; } } else if (!matchSymbol(targetAtom)) { return false; } if (!matchMaximumNeighbors(targetContainer, targetAtom)) { return false; } return true; }
/** {@inheritDoc} */ @Override public boolean matches(TargetProperties targetContainer, IAtom targetAtom) { if (smartQueryAtom != null && qAtom == null) { if (!smartQueryAtom.matches(targetAtom)) { return false; } } else { if (!matchSymbol(targetAtom)) { return false; } if (!matchMaximumNeighbors(targetContainer, targetAtom)) { return false; } } return true; } }
/** {@inheritDoc} */ @Override public boolean matches(IAtomContainer targetContainer, IAtom targetAtom) { if (smartQueryAtom != null && qAtom == null) { if (!smartQueryAtom.matches(targetAtom)) { return false; } } else { if (!matchSymbol(targetAtom)) { return false; } if (!matchMaximumNeighbors(targetContainer, targetAtom)) { return false; } } return true; } }
@Override public boolean matches(IAtom atom) { if (!((IQueryAtom) query.getAtom(0)).matches(atom)) return false; if (query.getAtomCount() == 1) return true; IAtomContainer target = invariants(atom).target(); return cache.getUnchecked(target).get(target.indexOf(atom)); } }
/** * * @param bondA1 * @param bondA2 * @param shouldMatchBonds * @param shouldMatchRings * @param matchAtomType * @return */ protected static boolean isMatchFeasible( IBond bondA1, IBond bondA2, boolean shouldMatchBonds, boolean shouldMatchRings, boolean matchAtomType) { if (bondA1 instanceof IQueryBond) { if (((IQueryBond) bondA1).matches(bondA2)) { IQueryAtom atom1 = (IQueryAtom) (bondA1.getAtom(0)); IQueryAtom atom2 = (IQueryAtom) (bondA1.getAtom(1)); return atom1.matches(bondA2.getAtom(0)) && atom2.matches(bondA2.getAtom(1)) || atom1.matches(bondA2.getAtom(1)) && atom2.matches(bondA2.getAtom(0)); } return false; } else { return DefaultMatcher.matches(bondA1, bondA2, shouldMatchBonds, shouldMatchRings, matchAtomType); } }
/** * * @param bondA1 * @param bondA2 * @param shouldMatchBonds * @param shouldMatchRings * @param matchAtomType * @return true if condition meet else false */ protected static boolean isMatchFeasible( IBond bondA1, IBond bondA2, boolean shouldMatchBonds, boolean shouldMatchRings, boolean matchAtomType) { if (bondA1 instanceof IQueryBond) { if (((IQueryBond) bondA1).matches(bondA2)) { IQueryAtom atom1 = (IQueryAtom) (bondA1.getAtom(0)); IQueryAtom atom2 = (IQueryAtom) (bondA1.getAtom(1)); return atom1.matches(bondA2.getAtom(0)) && atom2.matches(bondA2.getAtom(1)) || atom1.matches(bondA2.getAtom(1)) && atom2.matches(bondA2.getAtom(0)); } return false; } else { return DefaultMatcher.matches(bondA1, bondA2, shouldMatchBonds, shouldMatchRings, matchAtomType); } }
/** * * @param bondA1 * @param bondA2 * @param shouldMatchBonds * @param shouldMatchRings * @return */ private boolean isMatchFeasible( IBond bondA1, IBond bondA2, boolean shouldMatchBonds, boolean shouldMatchRings, boolean matchAtomType) { if (bondA1 instanceof IQueryBond) { if (((IQueryBond) bondA1).matches(bondA2)) { IQueryAtom atom1 = (IQueryAtom) (bondA1.getAtom(0)); IQueryAtom atom2 = (IQueryAtom) (bondA1.getAtom(1)); return atom1.matches(bondA2.getAtom(0)) && atom2.matches(bondA2.getAtom(1)) || atom1.matches(bondA2.getAtom(1)) && atom2.matches(bondA2.getAtom(0)); } return false; } else { /* This one also matches atom type, not just symbols */ return DefaultMatcher.matches(bondA1, bondA2, shouldMatchBonds, shouldMatchRings, matchAtomType); } }
/** * Determine if a atom from the molecule is unvisited and if it is matched * by the query atom. If the match is feasible the provided query bond index * stored on the stack. * * @param qatom atom from the query * @param atom atom from the molecule * @return the match was feasible and the state was stored */ private boolean feasible(int bidx, IQueryAtom qatom, IAtom atom) { int aidx = atom.getIndex(); if (avisit[aidx] || !qatom.matches(atom)) return false; ++numMapped; amap[qatom.getIndex()] = aidx; avisit[aidx] = true; store(bidx, qatom); return true; }
@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)); } }
/** * Checks that {@link IQueryAtom}'s correctly match consistently. * * @param bondmap bond mapping * @param g1 target graph * @param g2 query graph * @return the atom matches are consistent */ private boolean checkQueryAtoms(List<RMap> bondmap, IAtomContainer g1, IAtomContainer g2) { if (!(g2 instanceof IQueryAtomContainer)) return true; List<RMap> atommap = makeAtomsMapOfBondsMap(bondmap, g1, g2); for (RMap rmap : atommap) { IAtom a1 = g1.getAtom(rmap.getId1()); IAtom a2 = g2.getAtom(rmap.getId2()); if (a2 instanceof IQueryAtom) { if (!((IQueryAtom) a2).matches(a1)) return false; } } return true; }
/** * 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()); } }
/** * Determines if 2 bond have 1 atom in common if second is a query AtomContainer. * * @param a1 first bond * @param b1 second bond * @return the symbol of the common atom or "" if * the 2 bonds have no common atom */ private static boolean queryAdjacency(IBond a1, IBond b1, IBond a2, IBond b2) { IAtom atom1 = null; IAtom atom2 = null; if (a1.contains(b1.getBegin())) { atom1 = b1.getBegin(); } else if (a1.contains(b1.getEnd())) { atom1 = b1.getEnd(); } if (a2.contains(b2.getBegin())) { atom2 = b2.getBegin(); } else if (a2.contains(b2.getEnd())) { atom2 = b2.getEnd(); } if (atom1 != null && atom2 != null) { // well, this looks fishy: the atom2 is not always a IQueryAtom ! return ((IQueryAtom) atom2).matches(atom1); } else return atom1 == null && atom2 == null; }