예제 #1
0
        public string MolFormula => GetMolecularFormula(NativeMol);            // get mol formula

        /// <summary>
        /// GetMolecularFormula
        /// </summary>
        /// <param name="mol"></param>
        /// <returns></returns>

        public static string GetMolecularFormula(IAtomContainer mol)
        {
            IMolecularFormula moleculeFormula = MolecularFormulaManipulator.getMolecularFormula(mol);
            String            formula         = MolecularFormulaManipulator.getString(moleculeFormula);

            return(formula);
        }
예제 #2
0
        public void TestFormulaFoundInRange2()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 1, 50);
            mfRange.AddIsotope(h, 1, 100);
            mfRange.AddIsotope(o, 1, 50);
            mfRange.AddIsotope(n, 1, 50);

            double minMass = 187;
            double maxMass = 189;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.AreEqual(528, mfSet.Count);
            bool found = false;

            foreach (var formula in mfSet)
            {
                string mf = MolecularFormulaManipulator.GetString(formula);
                if (mf.Equals("C11H10NO2"))
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found, "The molecular formula C11H10NO2 should be found");
        }
예제 #3
0
        public void TestHighMass()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");
            IIsotope s    = ifac.GetMajorIsotope("S");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 350, 400);
            mfRange.AddIsotope(h, 620, 650);
            mfRange.AddIsotope(o, 100, 150);
            mfRange.AddIsotope(n, 100, 150);
            mfRange.AddIsotope(s, 0, 10);

            double minMass = 8445.573784 - 0.00001;
            double maxMass = 8445.573784 + 0.00001;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C374H623N103O116S", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
예제 #4
0
        public void TestCompoundWith7Elements()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");
            IIsotope s    = ifac.GetMajorIsotope("S");
            IIsotope p    = ifac.GetMajorIsotope("P");
            IIsotope cl   = ifac.GetMajorIsotope("Cl");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 7, 9);
            mfRange.AddIsotope(h, 8, 10);
            mfRange.AddIsotope(o, 1, 3);
            mfRange.AddIsotope(n, 0, 2);
            mfRange.AddIsotope(s, 0, 2);
            mfRange.AddIsotope(p, 0, 2);
            mfRange.AddIsotope(cl, 2, 4);

            double minMass = 318.915719 - 0.0001;
            double maxMass = 318.915719 + 0.0001;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C8H9Cl3NO2PS", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
예제 #5
0
        public void TestFixedElementCounts()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 7, 7);
            mfRange.AddIsotope(h, 15, 15);
            mfRange.AddIsotope(o, 4, 4);
            mfRange.AddIsotope(n, 2, 2);

            double massMin = 10d;
            double massMax = 1000d;
            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, massMin, massMax, mfRange);

            IMolecularFormulaSet mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C7H15N2O4", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
예제 #6
0
        public void TestDefaultValidFalse()
        {
            IRule             rule    = new NitrogenRule();
            IMolecularFormula formula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C2H4", builder);

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
        /// <summary>
        /// Extract from a set of MolecularFormula the minimal occurrence of each element found and
        /// put the element and occurrence in a new IMolecularFormula.
        /// </summary>
        /// <param name="mfSet">The set of molecularFormules to inspect</param>
        /// <returns>A IMolecularFormula containing the minimal occurrence of the elements</returns>
        /// <seealso cref="GetMaxOccurrenceElements(IMolecularFormulaSet)"/>
        public static IMolecularFormula GetMinOccurrenceElements(IMolecularFormulaSet mfSet)
        {
            var molecularFormula = mfSet.Builder.NewMolecularFormula();

            foreach (var mf in mfSet)
            {
                foreach (var isotope in mf.Isotopes)
                {
                    var element   = isotope.Element;
                    int occur_new = MolecularFormulaManipulator.GetElementCount(mf, element);
                    if (!MolecularFormulaManipulator.ContainsElement(molecularFormula, element))
                    {
                        molecularFormula.Add(mfSet.Builder.NewIsotope(element), occur_new);
                    }
                    else
                    {
                        int occur_old = MolecularFormulaManipulator.GetElementCount(molecularFormula, element);
                        if (occur_new < occur_old)
                        {
                            MolecularFormulaManipulator.RemoveElement(molecularFormula, element);
                            molecularFormula.Add(mfSet.Builder.NewIsotope(element), occur_new);
                        }
                    }
                }
            }
            return(molecularFormula);
        }
예제 #8
0
        public void TestMiddleMass()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 50);
            mfRange.AddIsotope(h, 0, 100);
            mfRange.AddIsotope(o, 0, 30);
            mfRange.AddIsotope(n, 0, 10);

            double minMass = 698.25879 - 0.0001;
            double maxMass = 698.25879 + 0.0001;

            MolecularFormulaGenerator gen   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C37H38N4O10", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
        [TestMethod(), Ignore()] //Non-deterministic test value is bad! This likely depends on our current isotope data which is also bad.
        public void TestCalculateIsotopesC20H30Fe2P2S4Cl4()
        {
            IMolecularFormula       molFor    = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C20H30Fe2P2S4Cl4", builder);
            IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(.01);
            IsotopePattern          isos      = isotopeGe.GetIsotopes(molFor);

            Assert.IsTrue(isos.Isotopes.Count == 34 || isos.Isotopes.Count == 35);
        }
        public void TestGetIsotopesIMolecularFormulaWithoutONE()
        {
            IMolecularFormula       molFor    = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C41H79N8O3P", builder);
            IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(.01);
            IsotopePattern          isos      = isotopeGe.GetIsotopes(molFor);

            Assert.AreEqual(6, isos.Isotopes.Count, 0.001);
        }
예제 #11
0
        public void Test2()
        {
            RDBERule rule = new RDBERule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C4H8O3S1", builder);

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
예제 #12
0
        public void TestValidate_IMolecularFormula_Double()
        {
            RDBERule rule = new RDBERule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C2H4", builder);

            Assert.IsTrue(rule.Validate(formula, 2.0));
        }
예제 #13
0
        public void TestAnticipatedIonState_2()
        {
            RDBERule rule = new RDBERule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("NH4", builder);

            Assert.AreEqual(0.0, rule.Validate(formula), 0.0001);
        }
예제 #14
0
        public void TestGetRDBEValue_IMolecularFormula()
        {
            RDBERule rule = new RDBERule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C2H4", builder);

            Assert.AreEqual(1.0, rule.GetRDBEValue(formula)[0], 0.0001);
        }
        public void TestRemove_1()
        {
            var formulaMin = new MolecularFormula();

            formulaMin.Add(builder.NewIsotope("C"), 1);
            formulaMin.Add(builder.NewIsotope("H"), 1);
            formulaMin.Add(builder.NewIsotope("N"), 1);

            var formulaMax = new MolecularFormula();

            formulaMax.Add(builder.NewIsotope("C"), 4);
            formulaMax.Add(builder.NewIsotope("H"), 12);
            formulaMax.Add(builder.NewIsotope("N"), 2);

            var mf1 = new MolecularFormula();

            mf1.Add(builder.NewIsotope("C"), 3);
            mf1.Add(builder.NewIsotope("H"), 10);
            mf1.Add(builder.NewIsotope("N"), 1);

            var mf2 = new MolecularFormula();

            mf2.Add(builder.NewIsotope("C"), 1);
            mf2.Add(builder.NewIsotope("H"), 1);
            mf2.Add(builder.NewIsotope("N"), 1);

            var mf3 = new MolecularFormula();

            mf3.Add(builder.NewIsotope("C"), 4);
            mf3.Add(builder.NewIsotope("H"), 12);
            mf3.Add(builder.NewIsotope("N"), 2);

            var mf4 = new MolecularFormula();

            mf4.Add(builder.NewIsotope("C"), 7);
            mf4.Add(builder.NewIsotope("H"), 10);
            mf4.Add(builder.NewIsotope("N"), 1);

            var formulaSet = new MolecularFormulaSet
            {
                mf1,
                mf2,
                mf3,
                mf4
            };

            var newMFSet = MolecularFormulaSetManipulator.Remove(formulaSet, formulaMin, formulaMax);

            /* the mf4 is excluded from the limits */

            Assert.AreEqual(3, newMFSet.Count());
            Assert.AreEqual(MolecularFormulaManipulator.GetString(mf1),
                            MolecularFormulaManipulator.GetString(newMFSet[0]));
            Assert.AreEqual(MolecularFormulaManipulator.GetString(mf2),
                            MolecularFormulaManipulator.GetString(newMFSet[1]));
            Assert.AreEqual(MolecularFormulaManipulator.GetString(mf3),
                            MolecularFormulaManipulator.GetString(newMFSet[2]));
        }
예제 #16
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;
 }
예제 #17
0
        /// <summary>
        /// Get all combinatorial chemical isotopes given a structure.
        /// </summary>
        /// <param name="molFor">The IMolecularFormula to start</param>
        /// <returns>A IsotopePattern object containing the different combinations</returns>
        public IsotopePattern GetIsotopes(IMolecularFormula molFor)
        {
            if (builder == null)
            {
                try
                {
                    isoFactory = CDK.IsotopeFactory;
                    builder    = molFor.Builder;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
            var mf = MolecularFormulaManipulator.GetString(molFor, true);

            var molecularFormula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula(mf, builder);

            IsotopePattern abundance_Mass = null;

            foreach (var isos in molecularFormula.Isotopes)
            {
                var elementSymbol = isos.Symbol;
                var atomCount     = molecularFormula.GetCount(isos);

                // Generate possible isotope containers for the current atom's
                // these will then me 'multiplied' with the existing patten
                var additional = new List <IsotopeContainer>();
                foreach (var isotope in isoFactory.GetIsotopes(elementSymbol))
                {
                    double mass      = isotope.ExactMass.Value;
                    double abundance = isotope.Abundance.Value;
                    if (abundance <= 0.000000001)
                    {
                        continue;
                    }
                    IsotopeContainer container = new IsotopeContainer(mass, abundance);
                    if (storeFormula)
                    {
                        container.Formula = AsFormula(isotope);
                    }
                    additional.Add(container);
                }
                for (int i = 0; i < atomCount; i++)
                {
                    abundance_Mass = CalculateAbundanceAndMass(abundance_Mass, additional);
                }
            }

            var isoP = IsotopePatternManipulator.SortAndNormalizedByIntensity(abundance_Mass);

            isoP = CleanAbundance(isoP, minIntensity);
            var isoPattern = IsotopePatternManipulator.SortByMass(isoP);

            return(isoPattern);
        }
예제 #18
0
        public void TestCalculate_IronOxide()
        {
            var material = CDK.Builder.NewSubstance();

            material.Add(MolecularFormulaManipulator.GetAtomContainer("Fe3O4", material.Builder));
            var value = Descriptor.Calculate(material);

            Assert.IsNotNull(value);
            Assert.AreEqual(4, value.Value);
        }
예제 #19
0
        public void TestDefaultValidTrue()
        {
            IRule rule = new RDBERule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C1H4", builder);

            formula.Charge = 0;

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
예제 #20
0
        public void TestC45H75NO15()
        {
            IRule rule = new NitrogenRule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C45H75NO15", builder);

            formula.Charge = 0;

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
예제 #21
0
        public void TestDoubleCharge()
        {
            IRule rule = new NitrogenRule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMolecularFormula("C22H34N2S2", builder);

            formula.Charge = 2;

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
예제 #22
0
        public void TestWithCo()
        {
            IRule rule = new NitrogenRule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMolecularFormula("C43H50CoN4O16", builder);

            formula.Charge = 0;

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
예제 #23
0
        public void TestB()
        {
            RDBERule rule = new RDBERule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C6H9BNO2", builder);

            formula.Charge = 1;

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
예제 #24
0
        public void TestWithFe()
        {
            IRule rule = new NitrogenRule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMolecularFormula("C40H46FeN6O8S2", builder);

            formula.Charge = 2;

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
예제 #25
0
        public void TestNominalMass()
        {
            IRule rule = new NitrogenRule();

            IMolecularFormula formula = MolecularFormulaManipulator.GetMolecularFormula("C25H53NO7P", builder);

            formula.Charge = 1;

            Assert.AreEqual(1.0, rule.Validate(formula), 0.0001);
        }
예제 #26
0
        static void Main(string[] args)
        {
            IAtomContainer    mol1  = Chem.MolFromSmiles("[C:1]([C:5]1[CH:10]=[CH:9][C:8]([OH:11])=[CH:7][CH:6]=1)([CH3:4])([CH3:3])[CH3:2]");
            IMolecularFormula form1 = MolecularFormulaManipulator.GetMolecularFormula(mol1);

            Console.WriteLine(MolecularFormulaManipulator.GetString(form1));
            IAtomContainer mol2  = Chem.MolFromFile("/Users/john/My Documents/1,3-diisopropenylbenzene.mol");
            var            form2 = MolecularFormulaManipulator.GetMolecularFormula(mol2);

            Console.WriteLine(MolecularFormulaManipulator.GetString(form2));
        }
예제 #27
0
        public string MolFormula => GetMolecularFormula(NativeMol);            // get mol formula

        /// <summary>
        /// GetMolecularFormula
        /// </summary>
        /// <param name="mol"></param>
        /// <returns></returns>

        public static string GetMolecularFormula(IAtomContainer mol)
        {
            if (mol == null)
            {
                return("");
            }
            IMolecularFormula moleculeFormula = MolecularFormulaManipulator.GetMolecularFormula(mol);
            String            formula         = MolecularFormulaManipulator.GetString(moleculeFormula);

            return(formula);
        }
예제 #28
0
 private void AddDistinctFormula(IsotopeContainer container, IMolecularFormula mf)
 {
     foreach (var curr in container.Formulas)
     {
         if (MolecularFormulaManipulator.Compare(curr, mf))
         {
             return;
         }
     }
     container.AddFormula(mf);
 }
 /// <summary>
 /// In the minimal IMolecularFormula must contain all those IElement found in the
 /// minimal IMolecularFormula.
 /// </summary>
 /// <param name="formulaMax">A IMolecularFormula which contains the maximal representation of the Elements</param>
 /// <param name="formulaMin">A IMolecularFormula which contains the minimal representation of the Elements</param>
 /// <returns>True, if the correlation is valid</returns>
 private static bool ValidCorrelation(IMolecularFormula formulaMin, IMolecularFormula formulaMax)
 {
     foreach (var element in MolecularFormulaManipulator.Elements(formulaMin))
     {
         if (!MolecularFormulaManipulator.ContainsElement(formulaMax, element))
         {
             return(false);
         }
     }
     return(true);
 }
 /// <summary>
 ///  True, if the IMolecularFormulaSet contains the given IMolecularFormula but not
 ///  as object. It compare according contains the same number and type of Isotopes.
 ///  It is not based on compare objects.
 /// </summary>
 /// <param name="formulaSet">The IMolecularFormulaSet</param>
 /// <param name="formula">The IMolecularFormula this IMolecularFormulaSet is searched for</param>
 /// <returns>True, if the IMolecularFormulaSet contains the given formula</returns>
 /// <seealso cref="System.Collections.Generic.ICollection{T}.Contains(T)"/>
 public static bool Contains(IMolecularFormulaSet formulaSet, IMolecularFormula formula)
 {
     foreach (var fm in formulaSet)
     {
         if (MolecularFormulaManipulator.Compare(fm, formula))
         {
             return(true);
         }
     }
     return(false);
 }