Ejemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 public DefaultBondMatcher()
 {
     this.queryBond      = null;
     this.smartQueryBond = null;
     this.unsaturation   = -1;
     IsBondMatchFlag     = false;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
        public void QueryMatch()
        {
            BondMatcher matcher = BondMatcher.CreateQueryMatcher();
            var         m_bond1 = new Mock <IQueryBond>(); IQueryBond bond1 = m_bond1.Object;
            var         m_bond2 = new Mock <IBond>(); IBond bond2 = m_bond2.Object;
            var         m_bond3 = new Mock <IBond>(); IBond bond3 = m_bond3.Object;

            m_bond1.Setup(n => n.Matches(bond2)).Returns(true);
            m_bond1.Setup(n => n.Matches(bond3)).Returns(false);
            Assert.IsTrue(matcher.Matches(bond1, bond2));
            Assert.IsFalse(matcher.Matches(bond1, bond3));
        }
Ejemplo n.º 4
0
        /// <summary>  Builds  the nodes of the RGraph ( resolution graph ), from
        /// two atom containers (description of the two molecules to compare)
        ///
        /// </summary>
        /// <param name="gr">  the target RGraph
        /// </param>
        /// <param name="ac1"> description of the first molecule
        /// </param>
        /// <param name="ac2"> description of the second molecule
        /// </param>
        private static void nodeConstructor(RGraph gr, IAtomContainer ac1, IAtomContainer ac2)
        {
            // resets the target graph.
            gr.clear();
            IBond[] bondsA1 = ac1.Bonds;
            IBond[] bondsA2 = ac2.Bonds;

            // compares each bond of G1 to each bond of G2
            for (int i = 0; i < bondsA1.Length; i++)
            {
                for (int j = 0; j < bondsA2.Length; j++)
                {
                    if (timeout > -1 && ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start) > timeout)
                    {
                        throw new CDKException("Timeout exceeded in getOverlaps");
                    }
                    IBond bondA2 = bondsA2[j];
                    if (bondA2 is IQueryBond)
                    {
                        IQueryBond queryBond = (IQueryBond)bondA2;
                        IQueryAtom atom1     = (IQueryAtom)(bondA2.getAtomAt(0));
                        IQueryAtom atom2     = (IQueryAtom)(bondA2.getAtomAt(1));
                        IBond      bond      = bondsA1[i];
                        if (queryBond.matches(bond))
                        {
                            // ok, bonds match
                            if (atom1.matches(bond.getAtomAt(0)) && atom2.matches(bond.getAtomAt(1)) || atom1.matches(bond.getAtomAt(1)) && atom2.matches(bond.getAtomAt(0)))
                            {
                                // ok, atoms match in either order
                                gr.addNode(new RNode(i, j));
                            }
                        }
                    }
                    else
                    {
                        // if both bonds are compatible then create an association node
                        // in the resolution graph
                        if (((bondsA1[i].Order == bondsA2[j].Order && bondsA1[i].getFlag(CDKConstants.ISAROMATIC) == bondsA2[j].getFlag(CDKConstants.ISAROMATIC)) || (bondsA1[i].getFlag(CDKConstants.ISAROMATIC) && bondsA2[j].getFlag(CDKConstants.ISAROMATIC))) && ((bondsA1[i].getAtomAt(0).Symbol.Equals(bondsA2[j].getAtomAt(0).Symbol) && bondsA1[i].getAtomAt(1).Symbol.Equals(bondsA2[j].getAtomAt(1).Symbol)) || (bondsA1[i].getAtomAt(0).Symbol.Equals(bondsA2[j].getAtomAt(1).Symbol) && bondsA1[i].getAtomAt(1).Symbol.Equals(bondsA2[j].getAtomAt(0).Symbol))))
                        {
                            gr.addNode(new RNode(i, j));
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public object Visit(ASTExplicitHighAndBond node, object data)
        {
            object left = node.JjtGetChild(0).JjtAccept(this, data);

            if (node.JjtGetNumChildren() == 1)
            {
                return(left);
            }
            LogicalOperatorBond bond = new LogicalOperatorBond(builder)
            {
                Operator = "and",
                Left     = (IQueryBond)left
            };
            IQueryBond right = (IQueryBond)node.JjtGetChild(1).JjtAccept(this, data);

            bond.Right = right;
            return(bond);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor
        /// <param name="queryBond">query Molecule</param>
        /// </summary>
        public DefaultVFBondMatcher(IQueryBond queryBond)
            : base()

        {
            this.smartQueryBond = queryBond;
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 private static IVFBondMatcher CreateBondMatcher(IQueryBond bond)
 {
     return(new DefaultVFBondMatcher(bond));
 }