示例#1
0
        public void TestDefaultValidFalse()
        {
            IRule rule = new MMElementRule();

            var formula = new MolecularFormula();

            formula.Add(builder.NewIsotope("C"), 2);
            formula.Add(builder.NewIsotope("H"), 200);

            Assert.AreEqual(0.0, rule.Validate(formula), 0.0001);
        }
示例#2
0
        public void TestNewIsotope_String_int()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IIsotope           isotope = builder.NewIsotope("C", 13);

            Assert.IsNotNull(isotope);
        }
示例#3
0
        public void TestNewIsotope_IElement()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IIsotope           isotope = builder.NewIsotope(ChemicalElement.R);

            Assert.IsNotNull(isotope);
        }
示例#4
0
        public void TestNewIsotope_int_String_int_Double_double()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IIsotope           isotope = builder.NewIsotope("C", 13, 1.0, 1.0);

            Assert.IsNotNull(isotope);
        }
示例#5
0
        public void TestSetParameters()
        {
            IRule rule = new ElementRule();

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

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

            rule.Parameters = new object[] { mfRange };

            var objects = rule.Parameters;

            Assert.AreEqual(1, objects.Count);

            MolecularFormulaRange mfRange2 = (MolecularFormulaRange)objects[0];

            Assert.AreEqual(mfRange.Count, mfRange2.Count);
            Assert.AreEqual(mfRange.GetIsotopeCountMin(new Isotope("C")), mfRange2.GetIsotopeCountMin(new Isotope("C")));
            Assert.AreEqual(mfRange.GetIsotopeCountMax(new Isotope("C")), mfRange2.GetIsotopeCountMax(new Isotope("C")));
        }
示例#6
0
        /// <summary>
        /// Initiate the MolecularFormulaExpand with the maximum and minimum occurrence of the Elements.
        /// In this case all elements of the periodic table are loaded.
        /// </summary>
        /// <param name="builder"></param>
        private void EnsureDefaultOccurElements(IChemObjectBuilder builder)
        {
            if (mfRange == null)
            {
                string[] elements = new string[] { "C", "H", "O", "N", "Si", "P", "S", "F", "Cl", "Br", "I", "Sn", "B", "Pb",
                                                   "Tl", "Ba", "In", "Pd", "Pt", "Os", "Ag", "Zr", "Se", "Zn", "Cu", "Ni", "Co", "Fe", "Cr", "Ti",
                                                   "Ca", "K", "Al", "Mg", "Na", "Ce", "Hg", "Au", "Ir", "Re", "W", "Ta", "Hf", "Lu", "Yb", "Tm", "Er",
                                                   "Ho", "Dy", "Tb", "Gd", "Eu", "Sm", "Pm", "Nd", "Pr", "La", "Cs", "Xe", "Te", "Sb", "Cd", "Rh",
                                                   "Ru", "Tc", "Mo", "Nb", "Y", "Sr", "Rb", "Kr", "As", "Ge", "Ga", "Mn", "V", "Sc", "Ar", "Ne", "Be",
                                                   "Li", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu" };

                mfRange = new MolecularFormulaRange();
                foreach (var element in elements)
                {
                    mfRange.AddIsotope(builder.NewIsotope(element), 0, 50);
                }
            }
        }
示例#7
0
        public void TestDefaultValidFalse()
        {
            IRule rule = new ToleranceRangeRule();

            var      formula = new MolecularFormula();
            IIsotope carb    = builder.NewIsotope("C");

            carb.ExactMass = 12.00;
            IIsotope cl = builder.NewIsotope("Cl");

            cl.ExactMass = 34.96885268;
            formula.Add(carb);
            formula.Add(cl);

            Assert.AreEqual(0.0, rule.Validate(formula), 0.0001);
        }
示例#8
0
        private IIsotope CreateIsotopeOfElement(string currentElement, XElement element)
        {
            var isotope = builder.NewIsotope(currentElement);

            XAttribute att = null;

            try
            {
                att = element.Attribute("id");
                if (att != null)
                {
                    isotope.Id = att.Value;
                }
                att = element.Attribute("number");
                if (att != null)
                {
                    isotope.MassNumber = int.Parse(att.Value, NumberFormatInfo.InvariantInfo);
                }
                att = element.Attribute("elementType");
                if (att != null)
                {
                    isotope.Symbol = att.Value;
                }
            }
            catch (FormatException exception)
            {
                Trace.TraceError($"Value of isotope {att.Name} is not as expected.");
                Debug.WriteLine(exception);
            }

            // we set the natural abundance to 0, since the default is -1, but
            // some isotope entries have no entry for this field, so the values
            // stays at -1
            isotope.Abundance = 0;

            return(isotope);
        }
        public void TestGetIsotopes1()
        {
            var molFor = new MolecularFormula();

            molFor.Add(builder.NewIsotope("Br"));
            molFor.Add(builder.NewIsotope("Br"));

            var isotopeGe  = new IsotopePatternGenerator(0.1);
            var isoPattern = isotopeGe.GetIsotopes(molFor);

            Assert.AreEqual(3, isoPattern.Isotopes.Count);
        }
示例#10
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);
        }
        public void TestGetMaxOccurrenceElements_IMolecularFormulaSet()
        {
            var mf1 = new MolecularFormula(); /* C4H12NO4 */

            mf1.Add(builder.NewIsotope("C"), 4);
            mf1.Add(builder.NewIsotope("H"), 12);
            mf1.Add(builder.NewIsotope("N"), 1);
            mf1.Add(builder.NewIsotope("O"), 4);

            var mf2 = new MolecularFormula(); /* C7H20N4O2 */

            mf2.Add(builder.NewIsotope("C"), 7);
            mf2.Add(builder.NewIsotope("H"), 20);
            mf2.Add(builder.NewIsotope("N"), 4);
            mf2.Add(builder.NewIsotope("O"), 2);

            var mf3 = new MolecularFormula(); /* C9H5O7 */

            mf3.Add(builder.NewIsotope("C"), 9);
            mf3.Add(builder.NewIsotope("H"), 5);
            mf3.Add(builder.NewIsotope("O"), 7);

            IMolecularFormulaSet mfSet = new MolecularFormulaSet
            {
                mf1,
                mf2,
                mf3
            };

            var molecularFormula = MolecularFormulaSetManipulator.GetMaxOccurrenceElements(mfSet);

            /* Result: C9H20N4O7 */

            Assert.AreEqual(40, MolecularFormulaManipulator.GetAtomCount(molecularFormula));
            Assert.AreEqual(4, molecularFormula.Isotopes.Count());
            Assert.AreEqual(9, molecularFormula.GetCount(builder.NewIsotope("C")));
            Assert.AreEqual(20, molecularFormula.GetCount(builder.NewIsotope("H")));
            Assert.AreEqual(4, molecularFormula.GetCount(builder.NewIsotope("N")));
            Assert.AreEqual(7, molecularFormula.GetCount(builder.NewIsotope("O")));
        }
        public void TestGetRange_IMolecularFormulaSet()
        {
            var mf1 = new MolecularFormula(); /* C4H12NO4 */

            mf1.Add(builder.NewIsotope("C"), 4);
            mf1.Add(builder.NewIsotope("H"), 12);
            mf1.Add(builder.NewIsotope("N"), 1);
            mf1.Add(builder.NewIsotope("O"), 4);

            var mf2 = new MolecularFormula(); /* C7H20N4O2 */

            mf2.Add(builder.NewIsotope("C"), 7);
            mf2.Add(builder.NewIsotope("H"), 20);
            mf2.Add(builder.NewIsotope("N"), 4);
            mf2.Add(builder.NewIsotope("O"), 2);

            var mf3 = new MolecularFormula(); /* C9H5O7 */

            mf3.Add(builder.NewIsotope("C"), 9);
            mf3.Add(builder.NewIsotope("H"), 5);
            mf3.Add(builder.NewIsotope("O"), 7);

            var mfSet = new MolecularFormulaSet
            {
                mf1,
                mf2,
                mf3
            };

            MolecularFormulaRange mfRange = MolecularFormulaRangeManipulator.GetRange(mfSet);

            /* Result: C4-9H5-20N0-4O2-7 */

            Assert.AreEqual(4, mfRange.GetIsotopes().Count());
            Assert.AreEqual(4, mfRange.GetIsotopeCountMin(builder.NewIsotope("C")));
            Assert.AreEqual(9, mfRange.GetIsotopeCountMax(builder.NewIsotope("C")));
            Assert.AreEqual(5, mfRange.GetIsotopeCountMin(builder.NewIsotope("H")));
            Assert.AreEqual(20, mfRange.GetIsotopeCountMax(builder.NewIsotope("H")));
            Assert.AreEqual(0, mfRange.GetIsotopeCountMin(builder.NewIsotope("N")));
            Assert.AreEqual(4, mfRange.GetIsotopeCountMax(builder.NewIsotope("N")));
            Assert.AreEqual(2, mfRange.GetIsotopeCountMin(builder.NewIsotope("O")));
            Assert.AreEqual(7, mfRange.GetIsotopeCountMax(builder.NewIsotope("O")));
        }