Пример #1
0
        public override bool Matches(IBond bond)
        {
            bool matchesLeft = left.Matches(bond);

            if (right != null)
            {
                bool matchesRight = right.Matches(bond);
                if (string.Equals("and", operator_, StringComparison.Ordinal))
                {
                    return(matchesLeft && matchesRight);
                }
                else if (string.Equals("or", operator_, StringComparison.Ordinal))
                {
                    return(matchesLeft || matchesRight);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (string.Equals("not", operator_, StringComparison.Ordinal))
                {
                    return(!matchesLeft);
                }
                else
                {
                    return(matchesLeft);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// 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.
 /// </summary>
 ///     /// <param name="qbond">bond from the query</param>
 /// <param name="bond">bond from the molecule</param>
 /// <returns>the match was feasible and the state was stored</returns>
 private bool Feasible(IQueryBond qbond, IBond bond)
 {
     if (bond == null || !qbond.Matches(bond))
     {
         return(false);
     }
     Store(CurrBondIdx() + 1, null);
     return(true);
 }
Пример #3
0
 /// <inheritdoc/>
 /// <param name="targetConatiner">target container</param>
 /// <param name="targetBond">target bond</param>
 /// <returns>true if bonds match</returns>
 public bool 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);
 }
Пример #4
0
        private static double GetBondTypeMatches(IBond queryBond, IBond targetBond)
        {
            double score = 0;

            if (targetBond is IQueryBond && queryBond is IBond)
            {
                IQueryBond bond  = (IQueryBond)targetBond;
                IQueryAtom atom1 = (IQueryAtom)(targetBond.Atoms[0]);
                IQueryAtom atom2 = (IQueryAtom)(targetBond.Atoms[1]);
                if (bond.Matches(queryBond))
                {
                    // ok, bonds match
                    if (atom1.Matches(queryBond.Atoms[0]) && atom2.Matches(queryBond.Atoms[1]) ||
                        atom1.Matches(queryBond.Atoms[1]) && atom2.Matches(queryBond.Atoms[0]))
                    {
                        // ok, atoms match in either order
                        score += 4;
                    }
                }
                else
                {
                    score -= 4;
                }
            }
            else if (queryBond is IQueryBond && targetBond is IBond)
            {
                IQueryBond bond  = (IQueryBond)queryBond;
                IQueryAtom atom1 = (IQueryAtom)(queryBond.Atoms[0]);
                IQueryAtom atom2 = (IQueryAtom)(queryBond.Atoms[1]);
                if (bond.Matches(targetBond))
                {
                    // ok, bonds match
                    if (atom1.Matches(targetBond.Atoms[0]) && atom2.Matches(targetBond.Atoms[1]) ||
                        atom1.Matches(targetBond.Atoms[1]) && atom2.Matches(targetBond.Atoms[0]))
                    {
                        // ok, atoms match in either order
                        score += 4;
                    }
                }
                else
                {
                    score -= 4;
                }
            }
            else
            {
                int reactantBondType = ConvertBondOrder(queryBond);
                int productBondType  = ConvertBondOrder(targetBond);
                int rStereo          = ConvertBondStereo(queryBond);
                int pStereo          = ConvertBondStereo(targetBond);
                if ((queryBond.IsAromatic == targetBond.IsAromatic) &&
                    (reactantBondType == productBondType))
                {
                    score += 8;
                }
                else if (queryBond.IsAromatic && targetBond.IsAromatic)
                {
                    score += 4;
                }

                if (reactantBondType == productBondType)
                {
                    score += productBondType;
                }
                else
                {
                    score -= 4 * Math.Abs(reactantBondType - productBondType);
                }

                if (rStereo != 4 || pStereo != 4 || rStereo != 3 || pStereo != 3)
                {
                    if (rStereo == pStereo)
                    {
                        score += 1;
                    }
                    else
                    {
                        score -= 1;
                    }
                }
            }
            return(score);
        }