Beispiel #1
0
        private static double[] Listpolarizability(IAtomContainer container, int[][] dmat)
        {
            int natom = container.Atoms.Count;

            double[] polars = new double[natom];

            for (int i = 0; i < natom; i++)
            {
                IAtom atom = container.Atoms[i];
                try
                {
                    polars[i] = Polarizability.CalculateGHEffectiveAtomPolarizability(container, atom, false, dmat);
                }
                catch (Exception ex1)
                {
                    throw new CDKException("Problems with assign Polarizability due to " + ex1.ToString(), ex1);
                }
            }

            return(polars);
        }
        /// <summary>
        /// The method calculates the Effective Atom Polarizability of a given atom
        /// It is needed to call the addExplicitHydrogensToSatisfyValency method from the class tools.HydrogenAdder.
        /// </summary>
        /// <param name="atom">The <see cref="IAtom"/> for which the <see cref="Result"/> is requested</param>
        /// <returns>return the effective polarizability</returns>
        public Result Calculate(IAtom atom)
        {
            // FIXME: for now I'll cache a few modified atomic properties, and restore them at the end of this method
            var originalAtomtypeName  = atom.AtomTypeName;
            var originalNeighborCount = atom.FormalNeighbourCount;
            var originalHCount        = atom.ImplicitHydrogenCount;
            var originalValency       = atom.Valency;
            var originalHybridization = atom.Hybridization;
            var originalFlag          = atom.IsVisited;
            var originalBondOrderSum  = atom.BondOrderSum;
            var originalMaxBondOrder  = atom.MaxBondOrder;
            var polarizability        = Polarizability.CalculateGHEffectiveAtomPolarizability(container, atom, 100, true);

            // restore original props
            atom.AtomTypeName         = originalAtomtypeName;
            atom.FormalNeighbourCount = originalNeighborCount;
            atom.Valency = originalValency;
            atom.ImplicitHydrogenCount = originalHCount;
            atom.IsVisited             = originalFlag;
            atom.Hybridization         = originalHybridization;
            atom.MaxBondOrder          = originalMaxBondOrder;
            atom.BondOrderSum          = originalBondOrderSum;
            return(new Result(polarizability));
        }
Beispiel #3
0
        private static Result CalculateMain(IAtomContainer container, int nhigh, int nlow)
        {
            var iso    = CDK.IsotopeFactory;
            int nheavy = 0;

            // find number of heavy atoms
            nheavy += container.Atoms.Count(atom => !atom.AtomicNumber.Equals(AtomicNumbers.H));
            if (nheavy == 0)
            {
                throw new CDKException("No heavy atoms in the container");
            }

            var diagvalue = new double[nheavy];

            // get atomic mass weighted BCUT
            try
            {
                var counter = 0;
                foreach (var atom in container.Atoms.Where(atom => !atom.AtomicNumber.Equals(AtomicNumbers.H)))
                {
                    diagvalue[counter] = iso.GetMajorIsotope(atom.AtomicNumber).ExactMass.Value;
                    counter++;
                }
            }
            catch (Exception e)
            {
                throw new CDKException($"Could not calculate weight: {e.Message}", e);
            }

            double[] eval1, eval2, eval3;
            {
                var burdenMatrix = BurdenMatrix.EvalMatrix(container, diagvalue);
                if (HasUndefined(burdenMatrix))
                {
                    throw new CDKException("Burden matrix has undefined values");
                }
                var matrix = Matrix <double> .Build.DenseOfColumnArrays(burdenMatrix);

                var eigenDecomposition = matrix.Evd().EigenValues;
                eval1 = eigenDecomposition.Select(n => n.Real).ToArray();
            }
            try
            {
                // get charge weighted BCUT
                CDK.LonePairElectronChecker.Saturate(container);
                var charges = new double[container.Atoms.Count];
                var peoe    = new GasteigerMarsiliPartialCharges();
                peoe.AssignGasteigerMarsiliSigmaPartialCharges(container, true);
                for (int i = 0; i < container.Atoms.Count; i++)
                {
                    charges[i] += container.Atoms[i].Charge.Value;
                }
                for (int i = 0; i < container.Atoms.Count; i++)
                {
                    container.Atoms[i].Charge = charges[i];
                }
            }
            catch (Exception e)
            {
                throw new CDKException("Could not calculate partial charges: " + e.Message, e);
            }
            {
                var counter = 0;
                foreach (var atom in container.Atoms.Where(atom => !atom.AtomicNumber.Equals(AtomicNumbers.H)))
                {
                    diagvalue[counter++] = atom.Charge.Value;
                }
            }
            {
                var burdenMatrix = BurdenMatrix.EvalMatrix(container, diagvalue);
                if (HasUndefined(burdenMatrix))
                {
                    throw new CDKException("Burden matrix has undefined values");
                }
                var matrix = Matrix <double> .Build.DenseOfColumnArrays(burdenMatrix);

                var eigenDecomposition = matrix.Evd().EigenValues;
                eval2 = eigenDecomposition.Select(n => n.Real).ToArray();
            }

            var topoDistance = PathTools.ComputeFloydAPSP(AdjacencyMatrix.GetMatrix(container));

            // get polarizability weighted BCUT
            {
                var counter = 0;
                foreach (var atom in container.Atoms.Where(atom => !atom.AtomicNumber.Equals(AtomicNumbers.H)))
                {
                    diagvalue[counter++] = Polarizability.CalculateGHEffectiveAtomPolarizability(container, atom, false, topoDistance);
                }
            }
            {
                var burdenMatrix = BurdenMatrix.EvalMatrix(container, diagvalue);
                if (HasUndefined(burdenMatrix))
                {
                    throw new CDKException("Burden matrix has undefined values");
                }
                var matrix = Matrix <double> .Build.DenseOfColumnArrays(burdenMatrix);

                var eigenDecomposition = matrix.Evd().EigenValues;
                eval3 = eigenDecomposition.Select(n => n.Real).ToArray();
            }

            // return only the n highest & lowest eigenvalues
            int lnlow, lnhigh, enlow, enhigh;

            if (nlow > nheavy)
            {
                lnlow = nheavy;
                enlow = nlow - nheavy;
            }
            else
            {
                lnlow = nlow;
                enlow = 0;
            }

            if (nhigh > nheavy)
            {
                lnhigh = nheavy;
                enhigh = nhigh - nheavy;
            }
            else
            {
                lnhigh = nhigh;
                enhigh = 0;
            }

            var retval = new List <double>((lnlow + enlow + lnhigh + enhigh) * 3);

            for (int i = 0; i < lnlow; i++)
            {
                retval.Add(eval1[i]);
            }
            for (int i = 0; i < enlow; i++)
            {
                retval.Add(double.NaN);
            }
            for (int i = 0; i < lnhigh; i++)
            {
                retval.Add(eval1[eval1.Length - i - 1]);
            }
            for (int i = 0; i < enhigh; i++)
            {
                retval.Add(double.NaN);
            }

            for (int i = 0; i < lnlow; i++)
            {
                retval.Add(eval2[i]);
            }
            for (int i = 0; i < enlow; i++)
            {
                retval.Add(double.NaN);
            }
            for (int i = 0; i < lnhigh; i++)
            {
                retval.Add(eval2[eval2.Length - i - 1]);
            }
            for (int i = 0; i < enhigh; i++)
            {
                retval.Add(double.NaN);
            }

            for (int i = 0; i < lnlow; i++)
            {
                retval.Add(eval3[i]);
            }
            for (int i = 0; i < enlow; i++)
            {
                retval.Add(double.NaN);
            }
            for (int i = 0; i < lnhigh; i++)
            {
                retval.Add(eval3[eval3.Length - i - 1]);
            }
            for (int i = 0; i < enhigh; i++)
            {
                retval.Add(double.NaN);
            }

            return(new Result(retval, nhigh, nlow));
        }