Esempio n. 1
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]));
        }
Esempio n. 2
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]));
        }
Esempio n. 3
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));
        }
Esempio n. 4
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]));
        }
Esempio n. 5
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");
        }
Esempio n. 6
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));
        }
Esempio n. 7
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]));
        }
        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
        }
Esempio n. 9
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);
                }
            }
        }
Esempio n. 10
0
        public void TestNewIsotope_String_int()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IIsotope           isotope = builder.NewIsotope("C", 13);

            Assert.IsNotNull(isotope);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public void TestNewIsotope_IElement()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IIsotope           isotope = builder.NewIsotope(ChemicalElement.R);

            Assert.IsNotNull(isotope);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        public virtual void TestNonclonable()
        {
            var      isotope = new BODRIsotope("C", 6, 12, 12.0, 99.0);
            IIsotope clone   = (IIsotope)isotope.Clone();

            Assert.AreEqual(isotope, clone);
        }
Esempio n. 15
0
        public virtual void TestSetMassNumber_Integer()
        {
            IIsotope i = (IIsotope)NewChemObject();

            i.MassNumber = 2;
            Assert.AreEqual(2, i.MassNumber.Value);
        }
Esempio n. 16
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);
                }
            }
        }
Esempio n. 17
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));
        }
Esempio n. 18
0
        public void TestMatchAgainstItself()
        {
            var    m_element1 = new Mock <IIsotope>(); IIsotope element1 = m_element1.Object;
            string result = IsotopeDiff.Diff(element1, element1);

            AssertZeroLength(result);
        }
Esempio n. 19
0
        private IIsotope createIsotopeOfElement(System.String currentElement, SaxAttributesSupport atts)
        {
            IIsotope isotope = builder.newIsotope(currentElement);

            for (int i = 0; i < atts.GetLength(); i++)
            {
                try
                {
                    if ("id".Equals(atts.GetFullName(i)))
                    {
                        isotope.ID = atts.GetValue(i);
                    }
                    else if ("isotopeNumber".Equals(atts.GetFullName(i)))
                    {
                        isotope.MassNumber = System.Int32.Parse(atts.GetValue(i));
                    }
                    else if ("elementType".Equals(atts.GetFullName(i)))
                    {
                        isotope.Symbol = atts.GetValue(i);
                    }
                }
                catch (System.FormatException exception)
                {
                    //logger.error("Value of isotope@", atts.GetFullName(i), " is not as expected.");
                    //logger.debug(exception);
                }
            }
            return(isotope);
        }
Esempio n. 20
0
        public virtual void TestSetExactMass_Double()
        {
            IIsotope i = (IIsotope)NewChemObject();

            i.ExactMass = 12.03;
            Assert.AreEqual(12.03, i.ExactMass.Value, 0.001);
        }
Esempio n. 21
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());
        }
Esempio n. 22
0
 public override void startElement(System.String uri, System.String local, System.String raw, SaxAttributesSupport atts)
 {
     currentChars = "";
     dictRef      = "";
     //logger.debug("startElement: ", raw);
     //logger.debug("uri: ", uri);
     //logger.debug("local: ", local);
     //logger.debug("raw: ", raw);
     if ("isotope".Equals(local))
     {
         workingIsotope = createIsotopeOfElement(currentElement, atts);
     }
     else if ("isotopeList".Equals(local))
     {
         currentElement = getElementSymbol(atts);
     }
     else if ("abundance".Equals(local))
     {
         //logger.warn("Disregarding dictRef for now...");
     }
     else if ("scalar".Equals(local))
     {
         for (int i = 0; i < atts.GetLength(); i++)
         {
             if ("dictRef".Equals(atts.GetFullName(i)))
             {
                 dictRef = atts.GetValue(i);
             }
         }
     }
 }
Esempio n. 23
0
        public void TestGetMajorIsotopeInt()
        {
            var      isofac  = BODRIsotopeFactory.Instance;
            IIsotope isotope = isofac.GetMajorIsotope(17);

            Assert.AreEqual("Cl", isotope.Symbol);
        }
Esempio n. 24
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);
        }
Esempio n. 25
0
        public void TestGetMajorIsotopeNonelement()
        {
            var      isofac  = BODRIsotopeFactory.Instance;
            IIsotope isotope = isofac.GetMajorIsotope("E");

            Assert.IsNull(isotope);
        }
Esempio n. 26
0
        public void TestGetMajorIsotopeString()
        {
            var      isofac  = BODRIsotopeFactory.Instance;
            IIsotope isotope = isofac.GetMajorIsotope("Te");

            Assert.AreEqual(129.9062244, isotope.ExactMass.Value, 0.0001);
        }
Esempio n. 27
0
        /// <summary>
        /// Returns the molecular weight (exact mass) of the major isotopes
        /// of all heavy atoms of the given IAtomContainer.
        /// </summary>
        /// <param name="atomContainer">an IAtomContainer to calculate the mocular weight for</param>
        /// <exception cref="CDKException">if an error occurs with the IsotopeFactory</exception>
        /// <returns>the molecularweight (exact mass) of the major isotopes
        ///         of all heavy atoms of the given IAtomContainer</returns>
        private static double GetMolecularWeight(T atomContainer)
        {
            double mw = 0.0;

            try
            {
                var isotopeFactory = CDK.IsotopeFactory;

                foreach (var atom in atomContainer.Atoms)
                {
                    if (!atom.AtomicNumber.Equals(AtomicNumbers.H))
                    {
                        IIsotope majorIsotope = isotopeFactory.GetMajorIsotope(atom.Symbol);

                        if (majorIsotope != null && majorIsotope.ExactMass != null)
                        {
                            mw += majorIsotope.ExactMass.Value;
                        }
                    }
                }
            }
            catch (IOException e)
            {
                throw new CDKException(e.Message, e);
            }
            return(mw);
        }
Esempio n. 28
0
        /// <summary>
        /// Adds an Isotope to this MolecularFormulaExpand in a number of
        /// maximum and minimum occurrences allowed.
        /// </summary>
        /// <param name="isotope">The isotope to be added to this MolecularFormulaExpand</param>
        /// <param name="countMax">The maximal number of occurrences to add</param>
        /// <param name="countMin">The minimal number of occurrences to add</param>
        public void AddIsotope(IIsotope isotope, int countMin, int countMax)
        {
            if (isotope == null)
            {
                throw new ArgumentNullException(nameof(isotope), "Isotope must not be null");
            }

            bool flag = false;

            foreach (var thisIsotope in GetIsotopes())
            {
                if (IsTheSame(thisIsotope, isotope))
                {
                    isotopesMax[thisIsotope] = countMax;
                    isotopesMin[thisIsotope] = countMin;
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                isotopesMax[isotope] = countMax;
                isotopesMin[isotope] = countMin;
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Returns the most abundant (major) isotope with a given atomic number.
        /// </summary>
        /// <remarks>
        /// The isotope's abundance is for atoms with atomic number 60 and smaller
        /// defined as a number that is proportional to the 100 of the most abundant
        /// isotope. For atoms with higher atomic numbers, the abundance is defined
        /// as a percentage.
        /// </remarks>
        /// <param name="elem">The atomicNumber for which an isotope is to be returned</param>
        /// <returns>The isotope corresponding to the given atomic number</returns>
        /// <seealso cref="GetMajorIsotope(string)"/>
        public IIsotope GetMajorIsotope(int elem)
        {
            IIsotope major = null;

            if (this.majorIsotope[elem] != null)
            {
                return(Clone(this.majorIsotope[elem]));
            }
            var isotopes = this.isotopes[elem];

            if (isotopes != null)
            {
                foreach (var isotope in isotopes)
                {
                    if (isotope.Abundance <= 0)
                    {
                        continue;
                    }
                    if (major == null ||
                        isotope.Abundance > major.Abundance)
                    {
                        major = isotope;
                    }
                }
                if (major != null)
                {
                    this.majorIsotope[elem] = major;
                }
                else
                {
                    Trace.TraceError($"Could not find major isotope for: {elem}");
                }
            }
            return(Clone(major));
        }
Esempio n. 30
0
        private IMolecularFormula AsFormula(IIsotope isotope)
        {
            var mf = builder.NewMolecularFormula();

            mf.Add(isotope);
            return(mf);
        }
Esempio n. 31
0
 public override void endElement(System.String uri, System.String local, System.String raw)
 {
     //logger.debug("end element: ", raw);
     if ("isotope".Equals(local))
     {
         if (workingIsotope != null)
             isotopes.Add(workingIsotope);
         workingIsotope = null;
     }
     else if ("isotopeList".Equals(local))
     {
         currentElement = null;
     }
     else if ("abundance".Equals(local))
     {
         try
         {
             workingIsotope.NaturalAbundance = System.Double.Parse(currentChars);
         }
         catch (System.FormatException exception)
         {
             //logger.error("The abundance value is incorrect: ", currentChars);
             //logger.debug(exception);
         }
     }
     else if ("scalar".Equals(local))
     {
         try
         {
             if ("cdk:exactMass".Equals(dictRef))
             {
                 workingIsotope.setExactMass(System.Double.Parse(currentChars));
             }
             else if ("cdk:atomicNumber".Equals(dictRef))
             {
                 workingIsotope.AtomicNumber = System.Int32.Parse(currentChars);
             }
         }
         catch (System.FormatException exception)
         {
             //logger.error("The ", dictRef, " value is incorrect: ", currentChars);
             //logger.debug(exception);
         }
     }
 }
Esempio n. 32
0
 public override void startElement(System.String uri, System.String local, System.String raw, SaxAttributesSupport atts)
 {
     currentChars = "";
     dictRef = "";
     //logger.debug("startElement: ", raw);
     //logger.debug("uri: ", uri);
     //logger.debug("local: ", local);
     //logger.debug("raw: ", raw);
     if ("isotope".Equals(local))
     {
         workingIsotope = createIsotopeOfElement(currentElement, atts);
     }
     else if ("isotopeList".Equals(local))
     {
         currentElement = getElementSymbol(atts);
     }
     else if ("abundance".Equals(local))
     {
         //logger.warn("Disregarding dictRef for now...");
     }
     else if ("scalar".Equals(local))
     {
         for (int i = 0; i < atts.GetLength(); i++)
         {
             if ("dictRef".Equals(atts.GetFullName(i)))
             {
                 dictRef = atts.GetValue(i);
             }
         }
     }
 }
Esempio n. 33
0
 /// <summary>  Configures an atom to have all the data of the
 /// given isotope.
 /// 
 /// </summary>
 /// <param name="atom">    The atom to be configure
 /// </param>
 /// <param name="isotope"> The isotope to read the data from
 /// </param>
 /// <returns>          The configured atom
 /// </returns>
 public virtual IAtom configure(IAtom atom, IIsotope isotope)
 {
     atom.MassNumber = isotope.MassNumber;
     atom.Symbol = isotope.Symbol;
     atom.setExactMass(isotope.getExactMass());
     atom.AtomicNumber = isotope.AtomicNumber;
     atom.NaturalAbundance = isotope.NaturalAbundance;
     return atom;
 }