Пример #1
0
        public virtual void TestInstance_IIsotope()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            IIsotope carb = Builder.NewIsotope("C");
            IIsotope flu  = Builder.NewIsotope("F");
            IIsotope h1   = Builder.NewIsotope("H");

            mf.Add(carb);
            mf.Add(flu);
            mf.Add(h1, 3);

            IEnumerator <IIsotope> istoIter = mf.Isotopes.GetEnumerator();

            Assert.IsNotNull(istoIter);
            Assert.IsTrue(istoIter.MoveNext());
            IIsotope next = istoIter.Current;

            Assert.IsTrue(next is IIsotope);
            //        Assert.AreEqual(carb, next);

            Assert.IsTrue(istoIter.MoveNext());
            next = istoIter.Current;
            Assert.IsTrue(next is IIsotope);
            //        Assert.AreEqual(flu, next);

            Assert.IsTrue(istoIter.MoveNext());
            next = istoIter.Current;
            Assert.IsTrue(next is IIsotope);
            //        Assert.AreEqual(h1, next);

            Assert.IsFalse(istoIter.MoveNext());
        }
Пример #2
0
        public virtual void TestGetIsotope_Number_Clone()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            IIsotope carb = Builder.NewIsotope("C");
            IIsotope flu  = Builder.NewIsotope("F");
            IIsotope h1   = Builder.NewIsotope("H");

            mf.Add(carb);
            mf.Add(flu);
            mf.Add(h1, 3);

            object clone = mf.Clone();

            Assert.IsTrue(clone is IMolecularFormula);

            IMolecularFormula cloneFormula = (IMolecularFormula)clone;

            Assert.AreEqual(1, cloneFormula.GetCount(carb));
            Assert.AreEqual(1, cloneFormula.GetCount(flu));
            Assert.AreEqual(3, cloneFormula.GetCount(h1));
            // In a List the objects are not stored in the same order than called
            //        Assert.AreEqual("C", cloneFormula.Isotopes[0].Symbol);
            //        Assert.AreEqual("F", cloneFormula.Isotopes[1].Symbol);
            //        Assert.AreEqual("H", cloneFormula.Isotopes[2].Symbol);
        }
Пример #3
0
        public virtual void TestClone_IMolecualrFormula()
        {
            IMolecularFormulaSet mfS  = Builder.NewMolecularFormulaSet();
            IMolecularFormula    mf1  = Builder.NewMolecularFormula();
            IIsotope             carb = Builder.NewIsotope("C");
            IIsotope             flu  = Builder.NewIsotope("F");
            IIsotope             h1   = Builder.NewIsotope("H");

            mf1.Add(carb);
            mf1.Add(flu);
            mf1.Add(h1, 3);
            mfS.Add(mf1);

            IMolecularFormula mf2   = Builder.NewMolecularFormula();
            IIsotope          carb2 = Builder.NewIsotope("C");
            IIsotope          iode  = Builder.NewIsotope("I");
            IIsotope          h2    = Builder.NewIsotope("H");

            mf2.Add(carb2);
            mf2.Add(iode, 2);
            mf2.Add(h2, 2);
            mfS.Add(mf2);

            object clone = mfS.Clone();

            Assert.IsTrue(clone is IMolecularFormulaSet);
            Assert.AreNotSame(mfS, clone);
            Assert.AreEqual(mfS.Count(), ((IMolecularFormulaSet)clone).Count());
            Assert.AreEqual(mfS[0].IsotopesCount, ((IMolecularFormulaSet)clone)
                            [0].IsotopesCount);
            Assert.AreEqual(mfS[1].IsotopesCount, ((IMolecularFormulaSet)clone)
                            [1].IsotopesCount);
        }
Пример #4
0
        public virtual void TestSetCharge_Integer()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            mf.Charge = 1;
            mf.Add(Builder.NewAtom("C"));
            mf.Add(Builder.NewAtom("F"));
            mf.Add(Builder.NewAtom("H"), 3);

            Assert.AreEqual(1.0, mf.Charge.Value, 0.001);
        }
Пример #5
0
        public virtual void TestGetCharge()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            mf.Charge = 1;
            mf.Add(Builder.NewAtom("C"));
            mf.Add(Builder.NewAtom("F"));
            mf.Add(Builder.NewAtom("H"), 3);

            Assert.AreEqual(3, mf.IsotopesCount);
            Assert.AreEqual(1.0, mf.Charge.Value, 0.001);
        }
Пример #6
0
        public virtual void TestGetIsotopeCount()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            mf.Add(Builder.NewIsotope("C"));
            mf.Add(Builder.NewIsotope("H"));
            mf.Add(Builder.NewIsotope("H"));
            mf.Add(Builder.NewIsotope("H"));
            mf.Add(Builder.NewIsotope("H"));

            Assert.AreEqual(2, mf.IsotopesCount);
        }
Пример #7
0
        public virtual void TestAddIsotope_IIsotope()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            mf.Add(Builder.NewIsotope("C"));
            mf.Add(Builder.NewIsotope("H"));

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

            hy.Abundance = 2.00342342;
            mf.Add(hy);

            Assert.AreEqual(3, mf.IsotopesCount);
        }
Пример #8
0
        public virtual void TestRemoveAllIsotopes()
        {
            IMolecularFormula mf   = Builder.NewMolecularFormula();
            IIsotope          carb = Builder.NewIsotope("C");
            IIsotope          flu  = Builder.NewIsotope("F");
            IIsotope          h1   = Builder.NewIsotope("H");

            mf.Add(carb);
            mf.Add(flu);
            mf.Add(h1, 3);

            // remove the Fluorine
            mf.Clear();

            Assert.AreEqual(0, mf.IsotopesCount);
        }
Пример #9
0
        /// <summary>
        /// Clear the isotope information from isotopes that are major (e.g.
        /// <sup>12</sup>C, <sup>1</sup>H, etc).
        /// </summary>
        /// <param name="formula">the formula</param>
        public static void ClearMajorIsotopes(IMolecularFormula formula)
        {
            var isotopesToRemove = new List <IIsotope>();
            var isotopesToAdd    = new List <Tuple <IIsotope, int> >();

            foreach (var iso in formula.Isotopes.Where(n => IsMajor(n)))
            {
                var count = formula.GetCount(iso);
                isotopesToRemove.Add(iso);
                iso.MassNumber = null;
                // may be immutable
                var iso_ = iso;
                if (iso_.MassNumber != null)
                {
                    iso_ = formula.Builder.NewIsotope(iso_.Symbol);
                }
                iso_.ExactMass = null;
                iso_.Abundance = null;
                isotopesToAdd.Add(new Tuple <IIsotope, int>(iso_, count));
            }
            foreach (var isotope in isotopesToRemove)
            {
                formula.Remove(isotope);
            }
            foreach (var t in isotopesToAdd)
            {
                formula.Add(t.Item1, t.Item2);
            }
        }
Пример #10
0
        public virtual void TestGetIsotopeCount_IIsotope_Occurr()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            IIsotope carb = Builder.NewIsotope("C");
            IIsotope flu  = Builder.NewIsotope("F");
            IIsotope h1   = Builder.NewIsotope("H");

            mf.Add(carb);
            mf.Add(flu);
            mf.Add(h1, 3);

            Assert.AreEqual(3, mf.IsotopesCount);
            Assert.AreEqual(1, mf.GetCount(carb));
            Assert.AreEqual(1, mf.GetCount(flu));
            Assert.AreEqual(3, mf.GetCount(h1));
        }
Пример #11
0
        public virtual void TestMolecularFormula_NullCharge()
        {
            IMolecularFormula mf  = Builder.NewMolecularFormula();
            IMolecularFormula mf2 = Builder.NewMolecularFormula();

            mf2.Charge = 0;
            mf.Add(mf2);
        }
Пример #12
0
        public virtual void TestContains_IIsotope()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

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

            h2.ExactMass = 2.0004;

            mf.Add(carb);
            mf.Add(h1);

            Assert.IsTrue(mf.Contains(carb));
            Assert.IsTrue(mf.Contains(h1));
            Assert.IsFalse(mf.Contains(h2));
        }
Пример #13
0
        public virtual void TestIsotopes()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            mf.Add(Builder.NewIsotope("C"));
            mf.Add(Builder.NewIsotope("F"));
            mf.Add(Builder.NewIsotope("H"), 3);

            IEnumerator <IIsotope> istoIter = mf.Isotopes.GetEnumerator();
            int counter = 0;

            while (istoIter.MoveNext())
            {
                counter++;
            }
            Assert.AreEqual(3, counter);
        }
Пример #14
0
        public virtual void TestContains_IMolecularFormula()
        {
            IMolecularFormulaSet mfS = Builder.NewMolecularFormulaSet();

            IMolecularFormula mf   = Builder.NewMolecularFormula();
            IIsotope          carb = Builder.NewIsotope("C");
            IIsotope          h1   = Builder.NewIsotope("H");
            IIsotope          h2   = Builder.NewIsotope("H");

            h2.ExactMass = 2.00055;

            mf.Add(carb);
            mf.Add(h1);

            mfS.Add(mf);

            Assert.IsTrue(mfS.Contains(mf));
        }
Пример #15
0
        public virtual void TestAdd_IMolecularFormula()
        {
            IMolecularFormula acetone = Builder.NewMolecularFormula();

            acetone.Add(Builder.NewIsotope("C"), 3);
            IIsotope oxig = Builder.NewIsotope("O");

            acetone.Add(oxig);

            Assert.AreEqual(2, acetone.IsotopesCount);

            IMolecularFormula water = Builder.NewMolecularFormula();

            water.Add(Builder.NewIsotope("H"), 2);
            water.Add(oxig);
            acetone.Add(water);

            Assert.AreEqual(3, acetone.IsotopesCount);
        }
Пример #16
0
        /// <summary>
        /// Returns the maximal occurrence of the IIsotope into IMolecularFormula
        /// from this MolelecularFormulaRange.
        /// </summary>
        /// <param name="mfRange">The MolecularFormulaRange to analyze</param>
        /// <returns>A IMolecularFormula containing the maximal occurrence of each isotope</returns>
        public static IMolecularFormula GetMaximalFormula(MolecularFormulaRange mfRange, IChemObjectBuilder builder)
        {
            IMolecularFormula formula = builder.NewMolecularFormula();

            foreach (var isotope in mfRange.GetIsotopes())
            {
                formula.Add(isotope, mfRange.GetIsotopeCountMax(isotope));
            }

            return(formula);
        }
Пример #17
0
        public virtual void TestSetCharge_Double()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            Assert.AreEqual(null, mf.Charge);

            mf.Charge = 1;
            Assert.AreEqual(1.0, mf.Charge.Value, 0.001);

            mf.Add(mf);
            Assert.AreEqual(2.0, mf.Charge.Value, 0.001);
        }
Пример #18
0
        public virtual void TestAddIsotope_IIsotope_int()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            IIsotope carb = Builder.NewIsotope("C");
            IIsotope flu  = Builder.NewIsotope("F");
            IIsotope h1   = Builder.NewIsotope("H");

            mf.Add(carb);
            mf.Add(flu);
            mf.Add(h1, 3);

            Assert.AreEqual(3, mf.IsotopesCount);
            Assert.AreEqual(1, mf.GetCount(carb));
            Assert.AreEqual(1, mf.GetCount(flu));
            Assert.AreEqual(3, mf.GetCount(h1));
            // In a List the objects are not stored in the same order than called
            //        Assert.AreEqual("C", mf.Isotopes[0].Symbol);
            //        Assert.AreEqual("F", mf.Isotopes[1].Symbol);
            //        Assert.AreEqual("H", mf.Isotopes[2].Symbol);
        }
Пример #19
0
                internal IMolecularFormula GenerateCurrentMolecularFormula(IChemObjectBuilder builder)
                {
                    IMolecularFormula formula = builder.NewMolecularFormula();

                    for (int k = 0; k < buffer.Length; ++k)
                    {
                        if (buffer[k] > 0)
                        {
                            formula.Add(GetCharacterAt(k), buffer[k]);
                        }
                    }
                    return(formula);
                }
        /// <summary>
        /// Generates a MolecularFormula object that contains the isotopes in the
        /// isotopes[] array with counts in the currentCounts[] array. In other
        /// words, generates a proper CDK representation of the currently examined
        /// formula.
        /// </summary>
        private IMolecularFormula GenerateFormulaObject()
        {
            IMolecularFormula formulaObject = builder.NewMolecularFormula();

            for (int i = 0; i < isotopes.Length; i++)
            {
                if (currentCounts[i] == 0)
                {
                    continue;
                }
                formulaObject.Add(isotopes[i], currentCounts[i]);
            }
            return(formulaObject);
        }
Пример #21
0
        public virtual void TestClone_Isotopes()
        {
            IMolecularFormula mf   = Builder.NewMolecularFormula();
            IIsotope          carb = Builder.NewIsotope("C");
            IIsotope          flu  = Builder.NewIsotope("F");
            IIsotope          h1   = Builder.NewIsotope("H");

            mf.Add(carb);
            mf.Add(flu);
            mf.Add(h1, 3);

            Assert.AreEqual(3, mf.IsotopesCount);
            Assert.AreEqual(1, mf.GetCount(carb));
            Assert.AreEqual(1, mf.GetCount(flu));
            Assert.AreEqual(3, mf.GetCount(h1));

            object clone = mf.Clone();

            Assert.IsTrue(clone is IMolecularFormula);
            Assert.AreEqual(mf.IsotopesCount, ((IMolecularFormula)clone).IsotopesCount);

            Assert.AreEqual(3, ((IMolecularFormula)clone).IsotopesCount);
        }
Пример #22
0
        public virtual void TestCharge_rest()
        {
            IMolecularFormula mf = Builder.NewMolecularFormula();

            Assert.AreEqual(null, mf.Charge);

            mf.Charge = 1;
            Assert.AreEqual(1.0, mf.Charge.Value, 0.001);

            IMolecularFormula mf2 = Builder.NewMolecularFormula();

            mf2.Charge = -1;
            mf.Add(mf2);
            Assert.AreEqual(0.0, mf.Charge.Value, 0.001);
        }
Пример #23
0
        public virtual void TestGetIsotopeCount_Sum_Isotope()
        {
            var add = Builder.NewAdductFormula();

            Assert.AreEqual(0, add.GetIsotopes().Count());

            var adduct1 = Builder.NewMolecularFormula();
            var C       = Builder.NewIsotope("C");

            adduct1.Add(C);
            var h = Builder.NewIsotope("H");

            adduct1.Add(h, 4);
            add.Add(adduct1);

            IMolecularFormula adduct2 = Builder.NewMolecularFormula();

            adduct2.Add(h);
            add.Add(adduct2);

            Assert.AreEqual(1, add.GetCount(C));
            Assert.AreEqual(5, add.GetCount(h));
        }