Ejemplo n.º 1
0
        /// <summary>
        /// Returns a <see cref="string"/> representation for this <see cref="IDifference"/>.
        /// </summary>
        /// <returns>a <see cref="string"/></returns>
        public override string ToString()
        {
            var p1 = first.IsUnset() ? "NA" : first.ToString();
            var p2 = second.IsUnset() ? "NA" : second.ToString();

            return($"{name}:{p1}/{p2}");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the single bond equivalent (SBE) of a list of bonds, given an iterator to the list.
        /// </summary>
        /// <param name="bonds">An iterator to the list of bonds</param>
        /// <returns>The SBE sum</returns>
        public static int GetSingleBondEquivalentSum(IEnumerable <IBond> bonds)
        {
            int sum = 0;

            foreach (var bond in bonds)
            {
                BondOrder order = bond.Order;
                if (!order.IsUnset())
                {
                    sum += order.Numeric();
                }
            }
            return(sum);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Calculate the number of bonds of a given type in an atomContainer
 /// </summary>
 /// <param name="order">The bond order. Default is <see cref="BondOrder.Unset"/>, which means count all bonds.</param>
 /// <returns>The number of bonds of a certain type.</returns>
 public Result Calculate(IAtomContainer container, BondOrder order = BondOrder.Unset)
 {
     if (order.IsUnset())
     {
         var count = container.Bonds
                     .Select(bond => bond.Atoms
                             .Count(atom => atom.AtomicNumber.Equals(AtomicNumbers.H)))
                     .Sum();
         return(new Result(count, order));
     }
     else
     {
         var count = container.Bonds.Count(bond => bond.Order.Equals(order));
         return(new Result(count, order));
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Method that tests if the matched <see cref="IAtomType"/> and the <see cref="IAtom"/> are
        /// consistent. For example, it tests if hybridization states and formal charges are equal.
        ///
        // @cdk.bug 1897589
        /// </summary>
        private void AssertConsistentProperties(IAtomContainer mol, IAtom atom, IAtomType matched)
        {
            // X has no properties; nothing to match
            if (string.Equals("X", matched.AtomTypeName, StringComparison.Ordinal))
            {
                return;
            }

            if (!atom.Hybridization.IsUnset() && !matched.Hybridization.IsUnset())
            {
                Assert.AreEqual(atom.Hybridization, matched.Hybridization, "Hybridization does not match");
            }
            if (atom.FormalCharge != null && matched.FormalCharge != null)
            {
                Assert.AreEqual(atom.FormalCharge, matched.FormalCharge, "Formal charge does not match");
            }
            var connections     = mol.GetConnectedBonds(atom);
            int connectionCount = connections.Count();

            if (matched.FormalNeighbourCount != null)
            {
                Assert.IsFalse(connectionCount > matched.FormalNeighbourCount, "Number of neighbors is too high");
            }
            if (!matched.MaxBondOrder.IsUnset())
            {
                BondOrder expectedMax = matched.MaxBondOrder;
                foreach (var bond in connections)
                {
                    BondOrder order = bond.Order;
                    if (!order.IsUnset())
                    {
                        if (BondManipulator.IsHigherOrder(order, expectedMax))
                        {
                            Assert.Fail("At least one bond order exceeds the maximum for the atom type");
                        }
                    }
                    else if (bond.IsSingleOrDouble)
                    {
                        if (expectedMax != BondOrder.Single && expectedMax != BondOrder.Double)
                        {
                            Assert.Fail("A single or double flagged bond does not match the bond order of the atom type");
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static double[] GetAtomWeights(IAtomContainer atomContainer)
        {
            IAtom atom, headAtom, endAtom;
            int   headAtomPosition, endAtomPosition;

            //int k = 0;
            double[]   weightArray = new double[atomContainer.Atoms.Count];
            double[][] adjaMatrix  = ConnectionMatrix.GetMatrix(atomContainer);

            int[][] apspMatrix = PathTools.ComputeFloydAPSP(adjaMatrix);
            int[]   atomLayers = GetAtomLayers(apspMatrix);

            int[] valenceSum;
            int[] interLayerBondSum;

            Debug.WriteLine("adjacency matrix: ");
            DisplayMatrix(adjaMatrix);
            Debug.WriteLine("all-pairs-shortest-path matrix: ");
            DisplayMatrix(apspMatrix);
            Debug.WriteLine("atom layers: ");
            DisplayArray(atomLayers);

            for (int i = 0; i < atomContainer.Atoms.Count; i++)
            {
                atom = atomContainer.Atoms[i];

                valenceSum = new int[atomLayers[i]];
                for (int v = 0; v < valenceSum.Length; v++)
                {
                    valenceSum[v] = 0;
                }

                interLayerBondSum = new int[atomLayers[i] - 1];
                for (int v = 0; v < interLayerBondSum.Length; v++)
                {
                    interLayerBondSum[v] = 0;
                }

                //weightArray[k] = atom.GetValenceElectronsCount() - atom.GetHydrogenCount(); // method unfinished
                if (AtomicNumbers.O.Equals(atom.AtomicNumber))
                {
                    weightArray[i] = 6 - atom.ImplicitHydrogenCount.Value;
                }
                else
                {
                    weightArray[i] = 4 - atom.ImplicitHydrogenCount.Value;
                }

                for (int j = 0; j < apspMatrix.Length; j++)
                {
                    if (string.Equals("O", atomContainer.Atoms[j].Symbol, StringComparison.Ordinal))
                    {
                        valenceSum[apspMatrix[j][i]] += 6 - atomContainer.Atoms[j].ImplicitHydrogenCount.Value;
                    }
                    else
                    {
                        valenceSum[apspMatrix[j][i]] += 4 - atomContainer.Atoms[j].ImplicitHydrogenCount.Value;
                    }
                }

                var bonds = atomContainer.Bonds;
                foreach (var bond in bonds)
                {
                    headAtom = bond.Begin;
                    endAtom  = bond.End;

                    headAtomPosition = atomContainer.Atoms.IndexOf(headAtom);
                    endAtomPosition  = atomContainer.Atoms.IndexOf(endAtom);

                    if (Math.Abs(apspMatrix[i][headAtomPosition] - apspMatrix[i][endAtomPosition]) == 1)
                    {
                        int       min   = Math.Min(apspMatrix[i][headAtomPosition], apspMatrix[i][endAtomPosition]);
                        BondOrder order = bond.Order;
                        interLayerBondSum[min] += order.IsUnset() ? 0 : order.Numeric();
                    }
                }

                for (int j = 0; j < interLayerBondSum.Length; j++)
                {
                    weightArray[i] += interLayerBondSum[j] * valenceSum[j + 1] * Math.Pow(10, -(j + 1));
                }

                Debug.WriteLine("valence sum: ");
                DisplayArray(valenceSum);
                Debug.WriteLine("inter-layer bond sum: ");
                DisplayArray(interLayerBondSum);
            }

            Debug.WriteLine("weight array: ");
            DisplayArray(weightArray);

            return(weightArray);
        }