/**{@inheritDoc} */ @Override public boolean matches(IBond bond1, IBond bond2) { return ((IQueryBond) bond1).matches(bond2); } }
/** * {@inheritDoc} */ @Override public boolean matches(IBond bond1, IBond bond2) { return ((IQueryBond) bond1).matches(bond2); }
@Override public boolean matches(IBond bond) { boolean matchesLeft = left.matches(bond); if (right != null) { boolean matchesRight = right.matches(bond); if ("and".equals(operator)) { return matchesLeft && matchesRight; } else if ("or".equals(operator)) { return matchesLeft || matchesRight; } else { return false; } } else { if ("not".equals(operator)) { return (!matchesLeft); } else { return matchesLeft; } } }
@Override public boolean matches(IBond bond) { return ((IQueryBond) deref()).matches(bond); } }
@Override public boolean matches(IBond bond) { return ((IQueryBond) deref()).matches(bond); } }
@Override public boolean matches(IBond bond) { return ((IQueryBond) deref()).matches(bond); } }
@Override public boolean matches(IBond bond) { return ((IQueryBond) deref()).matches(bond); } }
/** * Determine if a bond from the molecule exists and if it is matched * by the query bond. If the match is feasible the current query bond index * is increment and stored on the stack. * * @param qbond bond from the query * @param bond bond from the molecule * @return the match was feasible and the state was stored */ private boolean feasible(IQueryBond qbond, IBond bond) { if (bond == null || !qbond.matches(bond)) return false; store(currBondIdx() + 1, null); return true; }
@Test public void queryMatch() { BondMatcher matcher = BondMatcher.forQuery(); IQueryBond bond1 = mock(IQueryBond.class); IBond bond2 = mock(IBond.class); IBond bond3 = mock(IBond.class); when(bond1.matches(bond2)).thenReturn(true); when(bond1.matches(bond3)).thenReturn(false); assertTrue(matcher.matches(bond1, bond2)); assertFalse(matcher.matches(bond1, bond3)); } }
/** {@inheritDoc} * * @param targetConatiner target container * @param targetBond target bond * @return true if bonds match */ @Override public boolean matches(TargetProperties targetConatiner, IBond targetBond) { if (this.smartQueryBond != null) { return smartQueryBond.matches(targetBond); } else { if (!isBondMatchFlag()) { return true; } if (isBondMatchFlag() && isBondTypeMatch(targetBond)) { return true; } if (isBondMatchFlag() && this.unsaturation == getUnsaturation(targetConatiner, targetBond)) { return true; } } return false; }
/** {@inheritDoc} * * @param targetContainer target container * @param targetBond target bond * @return true if bonds match */ @Override public boolean matches(IAtomContainer targetContainer, IBond targetBond) { if (this.smartQueryBond != null && queryBond == null) { return smartQueryBond.matches(targetBond); } else { if (!isBondMatchFlag()) { return true; } if (isBondMatchFlag() && isBondTypeMatch(targetBond)) { return true; } if (isBondMatchFlag() && this.unsaturation == getUnsaturation(targetContainer, targetBond)) { return true; } } return false; }
/** * {@inheritDoc} * * @param targetBond target bond * @return true if bonds match */ @Override public boolean matches(IBond targetBond) { if (this.queryBond != null && queryBond instanceof IQueryBond) { return ((IQueryBond) queryBond).matches(targetBond); } else if ((queryBond != null && targetBond != null) && isBondMatchFlag() && isBondTypeMatch(targetBond)) { return true; } else if ((queryBond != null && targetBond != null) && !isBondMatchFlag() && isShouldMatchRings()) { if (queryBond.getFlag(CDKConstants.ISAROMATIC) && targetBond.getFlag(CDKConstants.ISAROMATIC)) { return true; } else if (!queryBond.getFlag(CDKConstants.ISAROMATIC) && !targetBond.getFlag(CDKConstants.ISAROMATIC)) { return true; } } else if ((queryBond != null && targetBond != null) && !isBondMatchFlag() && !isShouldMatchRings()) { return true; } return false; }
/** * {@inheritDoc} * * @param targetBond target bond * @return true if bonds match */ @Override public boolean matches(IBond targetBond) { if (this.queryBond != null && queryBond instanceof IQueryBond) { return ((IQueryBond) queryBond).matches(targetBond); } else if ((queryBond != null && targetBond != null) && isBondMatchFlag() && isBondTypeMatch(targetBond)) { return true; } else if ((queryBond != null && targetBond != null) && !isBondMatchFlag() && isShouldMatchRings()) { if (queryBond.getFlag(CDKConstants.ISAROMATIC) && targetBond.getFlag(CDKConstants.ISAROMATIC)) { return true; } else if (!queryBond.getFlag(CDKConstants.ISAROMATIC) && !targetBond.getFlag(CDKConstants.ISAROMATIC)) { return true; } } else if ((queryBond != null && targetBond != null) && !isBondMatchFlag() && !isShouldMatchRings()) { return true; } return false; }
/** * * @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 * @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 * @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 */ 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); } }
/** * * @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); } }
protected static boolean isMatchFeasible(IAtomContainer ac1, IBond bondA1, IAtomContainer ac2, IBond bondA2, boolean shouldMatchBonds) { if (ac1 instanceof IQueryAtomContainer) { if (((IQueryBond) bondA1).matches(bondA2)) { IQueryAtom atom1 = (IQueryAtom) (bondA1.getBegin()); IQueryAtom atom2 = (IQueryAtom) (bondA1.getEnd()); // ok, bonds match if (atom1.matches(bondA2.getBegin()) && atom2.matches(bondA2.getEnd()) || atom1.matches(bondA2.getEnd()) && atom2.matches(bondA2.getBegin())) { // ok, atoms match in either order return true; } return false; } return false; } else { //Bond Matcher BondMatcher bondMatcher = new DefaultBondMatcher(ac1, bondA1, shouldMatchBonds); //Atom Matcher AtomMatcher atomMatcher1 = new DefaultMCSPlusAtomMatcher(ac1, bondA1.getBegin(), shouldMatchBonds); //Atom Matcher AtomMatcher atomMatcher2 = new DefaultMCSPlusAtomMatcher(ac1, bondA1.getEnd(), shouldMatchBonds); if (DefaultMatcher.isBondMatch(bondMatcher, ac2, bondA2, shouldMatchBonds) && DefaultMatcher.isAtomMatch(atomMatcher1, atomMatcher2, ac2, bondA2, shouldMatchBonds)) { return true; } return false; } }