Exemple #1
0
 /// <summary>
 /// Constructor of the <see cref="IsotopeContainer"/> object setting a <see cref="IMolecularFormula"/> object and intensity value.
 /// </summary>
 /// <param name="formula">The formula of this container</param>
 /// <param name="intensity">The intensity of this container</param>
 public IsotopeContainer(IMolecularFormula formula, double intensity)
 {
     forms.Add(formula);
     if (formula != null)
     {
         Mass = MolecularFormulaManipulator.GetTotalExactMass(formula);
     }
     Intensity = intensity;
 }
Exemple #2
0
        /// <summary>
        /// Validate the Tolerance Range of this IMolecularFormula.
        /// </summary>
        /// <param name="formula">Parameter is the IMolecularFormula</param>
        /// <returns>A double value meaning 1.0 True, 0.0 False</returns>
        public double Validate(IMolecularFormula formula)
        {
            Trace.TraceInformation("Start validation of ", formula);

            double totalExactMass = MolecularFormulaManipulator.GetTotalExactMass(formula);

            if (Math.Abs(totalExactMass - mass) > tolerance)
            {
                return(0.0);
            }
            else
            {
                return(1.0);
            }
        }
        /// <summary>
        /// Calculates the 3 MI's, 3 ration and the R_gyr value.
        /// The molecule should have hydrogens.
        /// </summary>
        /// <returns>An <see cref="Result"/> containing 7 elements in the order described above</returns>
        public Result Calculate(IAtomContainer container)
        {
            container = (IAtomContainer)container.Clone();

            var factory = CDK.IsotopeFactory;

            factory.ConfigureAtoms(container);

            if (!GeometryUtil.Has3DCoordinates(container))
            {
                throw new ThreeDRequiredException("Molecule must have 3D coordinates");
            }

            var retval = new List <double>(7);

            double ccf = 1.000138;
            double eps = 1e-5;

            var imat         = Arrays.CreateJagged <double>(3, 3);
            var centerOfMass = GeometryUtil.Get3DCentreOfMass(container).Value;

            double xdif;
            double ydif;
            double zdif;
            double xsq;
            double ysq;
            double zsq;

            for (int i = 0; i < container.Atoms.Count; i++)
            {
                var currentAtom = container.Atoms[i];

                var _mass = factory.GetMajorIsotope(currentAtom.Symbol).ExactMass;
                var mass  = _mass == null?factory.GetNaturalMass(currentAtom.Element) : _mass.Value;

                var p = currentAtom.Point3D.Value;
                xdif = p.X - centerOfMass.X;
                ydif = p.Y - centerOfMass.Y;
                zdif = p.Z - centerOfMass.Z;
                xsq  = xdif * xdif;
                ysq  = ydif * ydif;
                zsq  = zdif * zdif;

                imat[0][0] += mass * (ysq + zsq);
                imat[1][1] += mass * (xsq + zsq);
                imat[2][2] += mass * (xsq + ysq);

                imat[1][0] += -1 * mass * ydif * xdif;
                imat[0][1]  = imat[1][0];

                imat[2][0] += -1 * mass * xdif * zdif;
                imat[0][2]  = imat[2][0];

                imat[2][1] += -1 * mass * ydif * zdif;
                imat[1][2]  = imat[2][1];
            }

            // diagonalize the MI tensor
            var tmp = Matrix <double> .Build.DenseOfColumnArrays(imat);

            var eigenDecomp = tmp.Evd();
            var eval        = eigenDecomp.EigenValues.Select(n => n.Real).ToArray();

            retval.Add(eval[2]);
            retval.Add(eval[1]);
            retval.Add(eval[0]);

            var etmp = eval[0];

            eval[0] = eval[2];
            eval[2] = etmp;

            if (Math.Abs(eval[1]) > 1e-3)
            {
                retval.Add(eval[0] / eval[1]);
            }
            else
            {
                retval.Add(1000);
            }

            if (Math.Abs(eval[2]) > 1e-3)
            {
                retval.Add(eval[0] / eval[2]);
                retval.Add(eval[1] / eval[2]);
            }
            else
            {
                retval.Add(1000);
                retval.Add(1000);
            }

            // finally get the radius of gyration
            var formula = MolecularFormulaManipulator.GetMolecularFormula(container);
            var pri     = Math.Abs(eval[2]) > eps
                    ? Math.Pow(eval[0] *eval[1] *eval[2], 1.0 / 3.0)
                    : Math.Sqrt(eval[0] * ccf / MolecularFormulaManipulator.GetTotalExactMass(formula));

            retval.Add(Math.Sqrt(Math.PI * 2 * pri * ccf / MolecularFormulaManipulator.GetTotalExactMass(formula)));

            return(new Result(retval));
        }