Exemple #1
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]));
        }
Exemple #2
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]));
        }
Exemple #3
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]));
        }
Exemple #4
0
        public void TestGetIsotopeCountMin_IIsotope4()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            IIsotope carb1 = builder.NewIsotope("C");
            IIsotope h1    = builder.NewIsotope("H");

            IIsotope carb2 = builder.NewIsotope("C");

            carb2.Abundance = 13.0876689;
            IIsotope h2 = builder.NewIsotope("H");

            h2.Abundance = 2.0968768;

            mfRange.AddIsotope(carb1, 0, 10);
            mfRange.AddIsotope(h1, 0, 10);

            mfRange.AddIsotope(carb2, 5, 10);
            mfRange.AddIsotope(h2, 5, 10);

            Assert.AreEqual(4, mfRange.Count);
            Assert.AreEqual(0, mfRange.GetIsotopeCountMin(carb1));
            Assert.AreEqual(0, mfRange.GetIsotopeCountMin(h1));
            Assert.AreEqual(5, mfRange.GetIsotopeCountMin(carb2));
            Assert.AreEqual(5, mfRange.GetIsotopeCountMin(h2));
        }
Exemple #5
0
        public void TestMaxCounts()
        {
            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, 3, 7);
            mfRange.AddIsotope(h, 3, 7);
            mfRange.AddIsotope(o, 3, 7);
            mfRange.AddIsotope(n, 3, 7);

            // The maximal formula MF=C7H7O7N7 MW=301.0406955954
            double minMass = 250;
            double maxMass = 400;

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

            // Check that all element counts in the formula are <= 7
            foreach (var f in mfSet)
            {
                foreach (var i in f.Isotopes)
                {
                    int count = f.GetCount(i);
                    Assert.IsTrue(count <= 7);
                }
            }
        }
Exemple #6
0
        public void TestMinCounts()
        {
            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, 5, 20);
            mfRange.AddIsotope(h, 5, 20);
            mfRange.AddIsotope(o, 5, 20);
            mfRange.AddIsotope(n, 5, 20);

            // The minimal formula MF=C5H5O5N5 MW=215.0290682825
            double minMass = 100;
            double maxMass = 250;

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

            // Check that all element counts in the formula are >= 5
            foreach (var f in mfSet)
            {
                foreach (var i in f.Isotopes)
                {
                    int count = f.GetCount(i);
                    Assert.IsTrue(count >= 5);
                }
            }
        }
Exemple #7
0
        public void TestClone_Isotopes()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();
            IIsotope carb = builder.NewIsotope("C");
            IIsotope flu  = builder.NewIsotope("F");
            IIsotope h1   = builder.NewIsotope("H");

            mfRange.AddIsotope(carb, 0, 5);
            mfRange.AddIsotope(flu, 2, 8);
            mfRange.AddIsotope(h1, 4, 10);

            Assert.AreEqual(3, mfRange.Count);
            Assert.AreEqual(0, mfRange.GetIsotopeCountMin(carb));
            Assert.AreEqual(2, mfRange.GetIsotopeCountMin(flu));
            Assert.AreEqual(4, mfRange.GetIsotopeCountMin(h1));
            Assert.AreEqual(5, mfRange.GetIsotopeCountMax(carb));
            Assert.AreEqual(8, mfRange.GetIsotopeCountMax(flu));
            Assert.AreEqual(10, mfRange.GetIsotopeCountMax(h1));

            object clone = mfRange.Clone();

            Assert.IsTrue(clone is MolecularFormulaRange);
            Assert.AreEqual(mfRange.Count, ((MolecularFormulaRange)clone).Count);

            Assert.AreEqual(3, ((MolecularFormulaRange)clone).Count);

            Assert.AreEqual(3, ((MolecularFormulaRange)clone).Count);
            Assert.AreEqual(0, ((MolecularFormulaRange)clone).GetIsotopeCountMin(carb));
            Assert.AreEqual(2, ((MolecularFormulaRange)clone).GetIsotopeCountMin(flu));
            Assert.AreEqual(4, ((MolecularFormulaRange)clone).GetIsotopeCountMin(h1));
            Assert.AreEqual(5, ((MolecularFormulaRange)clone).GetIsotopeCountMax(carb));
            Assert.AreEqual(8, ((MolecularFormulaRange)clone).GetIsotopeCountMax(flu));
            Assert.AreEqual(10, ((MolecularFormulaRange)clone).GetIsotopeCountMax(h1));
        }
Exemple #8
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");
        }
Exemple #9
0
        public void TestDifferentIsotopes()
        {
            var      ifac    = BODRIsotopeFactory.Instance;
            IIsotope c       = ifac.GetMajorIsotope("C");
            var      carbons = ifac.GetIsotopes("C");
            IIsotope c13     = carbons.ElementAt(5); // 13
            IIsotope h       = ifac.GetMajorIsotope("H");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 11);
            mfRange.AddIsotope(c13, 0, 10);
            mfRange.AddIsotope(h, 0, 10);

            double minMass = 54.04193 - 0.001;
            double maxMass = 54.04193 + 0.001;

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

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);

            IMolecularFormula trueFormula = new MolecularFormula(); // C3CH5

            trueFormula.Add(c, 3);
            trueFormula.Add(c13, 1);
            trueFormula.Add(h, 5);

            Assert.AreEqual(trueFormula.IsotopesCount, mfSet[0].IsotopesCount);
            Assert.AreEqual(trueFormula.GetCount(c), mfSet[0].GetCount(c));
            Assert.AreEqual(trueFormula.GetCount(c13), mfSet[0].GetCount(c13));
        }
Exemple #10
0
        public void TestNull()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();
            IIsotope carb = builder.NewIsotope("C");
            IIsotope nul  = null;

            mfRange.AddIsotope(carb, 2, 5);
            mfRange.AddIsotope(nul, 3, 7);
        }
Exemple #11
0
        public void TestAddIsotope_IIsotope_int_int()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(builder.NewIsotope("C"), 0, 10);
            mfRange.AddIsotope(builder.NewIsotope("H"), 0, 10);

            Assert.AreEqual(2, mfRange.Count);
        }
Exemple #12
0
        public void TestAddIsotope2()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(builder.NewIsotope("C"), 0, 10);
            mfRange.AddIsotope(builder.NewIsotope("H"), 0, 10);

            IIsotope hy = builder.NewIsotope("C");

            hy.Abundance = 2.00342342;
            mfRange.AddIsotope(hy, 0, 10);

            Assert.AreEqual(3, mfRange.Count);
        }
Exemple #13
0
        public void TestGetIsotopeCountMax_IIsotope()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            IIsotope carb = builder.NewIsotope("C");
            IIsotope h1   = builder.NewIsotope("H");

            mfRange.AddIsotope(carb, 0, 10);
            mfRange.AddIsotope(h1, 0, 10);

            Assert.AreEqual(2, mfRange.Count);
            Assert.AreEqual(10, mfRange.GetIsotopeCountMax(carb));
            Assert.AreEqual(10, mfRange.GetIsotopeCountMax(h1));
        }
Exemple #14
0
        public void TestIsotopes()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(builder.NewIsotope("C"), 0, 10);
            mfRange.AddIsotope(builder.NewIsotope("F"), 0, 10);

            IEnumerator <IIsotope> istoIter = mfRange.GetIsotopes().GetEnumerator();
            int counter = 0;

            while (istoIter.MoveNext())
            {
                counter++;
            }
            Assert.AreEqual(2, counter);
        }
Exemple #15
0
        public void TestUseFullEnumerationWhenNoHydrogen()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

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

            MolecularFormulaGenerator generator = new MolecularFormulaGenerator(builder, 1023.000, 1023.002, mfRange);

            Assert.IsTrue(generator.formulaGenerator is FullEnumerationFormulaGenerator, "generator implementation should be instance of FullEnumerationFormulaGenerator");
        }
Exemple #16
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]));
        }
Exemple #17
0
        public void TestRemoveIsotope_IIsotope()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();
            IIsotope carb = builder.NewIsotope("C");
            IIsotope flu  = builder.NewIsotope("F");
            IIsotope h1   = builder.NewIsotope("H");

            mfRange.AddIsotope(carb, 0, 10);
            mfRange.AddIsotope(flu, 0, 10);
            mfRange.AddIsotope(h1, 0, 10);

            // remove the Fluorine
            mfRange.Remove(flu);

            Assert.AreEqual(2, mfRange.Count);
            Assert.AreEqual(0, mfRange.GetIsotopeCountMin(carb));
            Assert.AreEqual(-1, mfRange.GetIsotopeCountMin(flu));
        }
Exemple #18
0
        public void TestUseRoundRobinWheneverPossible()
        {
            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, 20);
            mfRange.AddIsotope(h, 0, 30);
            mfRange.AddIsotope(o, 0, 15);
            mfRange.AddIsotope(n, 0, 10);

            MolecularFormulaGenerator generator = new MolecularFormulaGenerator(builder, 230.002, 230.004, mfRange);

            Assert.IsTrue(generator.formulaGenerator is RoundRobinFormulaGenerator, "generator implementation should be instance of RoundRobinFormulaGenerator");
        }
Exemple #19
0
        public void TestNegativeMass()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 100);
            new MolecularFormulaGenerator(builder, -20, -10, new MolecularFormulaRange());
        }
Exemple #20
0
        public void TestUseFullEnumerationWhenExceedIntegerSpace()
        {
            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, 20);
            mfRange.AddIsotope(h, 0, 30);
            mfRange.AddIsotope(o, 0, 15);
            mfRange.AddIsotope(n, 0, 10);

            MolecularFormulaGenerator generator = new MolecularFormulaGenerator(builder, 1300000, 1300000.1, mfRange);

            Assert.IsTrue(generator.formulaGenerator is FullEnumerationFormulaGenerator, "generator implementation should be instance of FullEnumerationFormulaGenerator");
        }
        /// <summary>
        /// Clones this MolecularFormulaExpand object and its content. I should
        /// integrate into ChemObject.
        /// </summary>
        /// <returns>The cloned object</returns>
        public virtual object Clone()
        {
            MolecularFormulaRange clone = new MolecularFormulaRange();

            foreach (var isotope in GetIsotopes())
            {
                clone.AddIsotope((IIsotope)isotope.Clone(), GetIsotopeCountMin(isotope), GetIsotopeCountMax(isotope));
            }
            return(clone);
        }
Exemple #22
0
        public void TestContains_IIsotope()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            IIsotope carb = builder.NewIsotope("C");
            IIsotope cl   = builder.NewIsotope("Cl");
            IIsotope h1   = builder.NewIsotope("H");
            IIsotope h2   = builder.NewIsotope("H");

            h2.ExactMass = 2.0004;

            mfRange.AddIsotope(carb, 0, 10);
            mfRange.AddIsotope(h1, 0, 10);

            Assert.IsTrue(mfRange.Contains(carb));
            Assert.IsFalse(mfRange.Contains(cl));
            Assert.IsTrue(mfRange.Contains(h1));
            Assert.IsFalse(mfRange.Contains(h2));
        }
        public void Main()
        {
            #region
            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 p    = ifac.GetMajorIsotope("P");
            IIsotope s    = ifac.GetMajorIsotope("S");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();
            mfRange.AddIsotope(c, 0, 50);
            mfRange.AddIsotope(h, 0, 100);
            mfRange.AddIsotope(o, 0, 50);
            mfRange.AddIsotope(n, 0, 50);
            mfRange.AddIsotope(p, 0, 10);
            mfRange.AddIsotope(s, 0, 10);

            var    builder = Silent.ChemObjectBuilder.Instance;
            double minMass = 133.003;
            double maxMass = 133.005;
            MolecularFormulaGenerator mfg   = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormulaSet      mfSet = mfg.GetAllFormulas();
            #endregion
        }
Exemple #24
0
        public void TestGetIsotopeCountMin_IIsotope3()
        {
            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            IIsotope carb1 = builder.NewIsotope("C");
            IIsotope h1    = builder.NewIsotope("H");

            IIsotope carb2 = builder.NewIsotope("C");
            IIsotope h2    = builder.NewIsotope("H");

            mfRange.AddIsotope(carb1, 0, 10);
            mfRange.AddIsotope(h1, 0, 10);

            mfRange.AddIsotope(carb2, 5, 10);
            mfRange.AddIsotope(h2, 5, 10);

            Assert.AreEqual(2, mfRange.Count);
            Assert.AreEqual(5, mfRange.GetIsotopeCountMin(carb1));
            Assert.AreEqual(5, mfRange.GetIsotopeCountMin(h1));
            Assert.AreEqual(5, mfRange.GetIsotopeCountMin(carb2));
            Assert.AreEqual(5, mfRange.GetIsotopeCountMin(h2));
        }
Exemple #25
0
        public void TestGetFinishedPercentage()
        {
            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, 10);
            mfRange.AddIsotope(h, 0, 10);
            mfRange.AddIsotope(o, 0, 10);
            mfRange.AddIsotope(n, 0, 10);

            double minMass = 100.0;
            double maxMass = 100.05;

            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);

            double finishedPerc, lastFinishedPerc = 0d;

            // The initial value must be 0
            finishedPerc = gen.GetFinishedPercentage();
            Assert.AreEqual(0d, finishedPerc, 0.0001);

            // The value must increase after each generated formula
            while (gen.GetNextFormula() != null)
            {
                finishedPerc = gen.GetFinishedPercentage();
                Assert.IsTrue(finishedPerc > lastFinishedPerc);
                lastFinishedPerc = finishedPerc;
            }

            // The final value must be 1
            finishedPerc = gen.GetFinishedPercentage();
            Assert.AreEqual(1d, finishedPerc, 0.0001);
        }
Exemple #26
0
        public void TestGetNextFormula()
        {
            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, 10);
            mfRange.AddIsotope(h, 0, 10);
            mfRange.AddIsotope(o, 0, 10);
            mfRange.AddIsotope(n, 0, 10);

            double minMass = 100.0;
            double maxMass = 100.05;

            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormula         f   = gen.GetNextFormula();

            Assert.IsNotNull(f);
        }
Exemple #27
0
        public void TestMassRangeTooLow()
        {
            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, 100, 200);
            mfRange.AddIsotope(h, 100, 200);
            mfRange.AddIsotope(o, 100, 200);
            mfRange.AddIsotope(n, 100, 200);

            double massMin = 50d;
            double massMax = 100d;
            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, massMin, massMax, mfRange);

            IMolecularFormulaSet mfSet = gen.GetAllFormulas();

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(0, mfSet.Count);
        }
Exemple #28
0
        public void TestCarbons()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 100000);

            double minMass = 120000.0 - 1;
            double maxMass = 120000.0 + 1;

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

            Assert.IsNotNull(mfSet);
            Assert.AreEqual(1, mfSet.Count);
            Assert.AreEqual("C10000", MolecularFormulaManipulator.GetString(mfSet[0]));
        }
Exemple #29
0
        public void TestCancel()
        {
            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 p    = ifac.GetMajorIsotope("P");
            IIsotope s    = ifac.GetMajorIsotope("S");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 1000);
            mfRange.AddIsotope(h, 0, 1000);
            mfRange.AddIsotope(o, 0, 1000);
            mfRange.AddIsotope(n, 0, 1000);
            mfRange.AddIsotope(p, 0, 1000);
            mfRange.AddIsotope(s, 0, 1000);

            double minMass = 100000.0;
            double maxMass = 100000.001;

            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);

            var cancelThread = new ThreadStart(() => {
                Thread.Sleep(5);
                gen.Cancel();
            });

            new Thread(cancelThread).Start();

            Thread.Sleep(10);
            // We will get stuck in the next method call until the cancel thread
            // calls the Cancel() method
            gen.GetAllFormulas();

            // Next GetNextFormula() call should return null
            IMolecularFormula f = gen.GetNextFormula();

            Assert.IsNull(f);
        }
Exemple #30
0
        public void TestWater()
        {
            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 p    = ifac.GetMajorIsotope("P");
            IIsotope s    = ifac.GetMajorIsotope("S");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 10);
            mfRange.AddIsotope(h, 0, 10);
            mfRange.AddIsotope(o, 0, 10);
            mfRange.AddIsotope(n, 0, 10);
            mfRange.AddIsotope(p, 0, 10);
            mfRange.AddIsotope(s, 0, 10);

            double minMass = 1;
            double maxMass = 20;

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

            Assert.IsNotNull(mfSet);

            bool found = false;

            foreach (IMolecularFormula formula in mfSet)
            {
                string mf = MolecularFormulaManipulator.GetString(formula);
                if (mf.Equals("H2O"))
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found, "The molecular formula H2O should be found");
        }