Ejemplo n.º 1
0
        /// <summary>
        /// Completely removes a particular isotope from this chemical formula.
        /// </summary>
        /// <param name="isotope">The isotope to remove</param>
        /// <returns>Number of removed isotopes</returns>
        public int Remove(Isotope isotope)
        {
            int count = Isotopes[isotope];

            Add(isotope, -count);
            return(count);
        }
Ejemplo n.º 2
0
        public int CountSpecificIsotopes(Element element, int massNumber)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element", "Cannot count null elements in formula");
            }
            Isotope isotope = element[massNumber];

            return(CountSpecificIsotopes(isotope));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add the principal isotope of the element to this chemical formula
        /// given its chemical symbol
        /// </summary>
        /// <param name="symbol">The chemical symbol of the element to add</param>
        /// <param name="count">The number of the element to add</param>
        public void AddPrincipalIsotopesOf(Element element, int count)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element", "Cannot add null element to formula");
            }
            Isotope isotope = element.PrincipalIsotope;

            Add(isotope, count);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Добавление <see cref="Isotope"/>
        /// </summary>
        /// <param name="massNumber">Массовое число</param>
        /// <param name="atomicWeight">Атомная масса</param>
        /// <param name="abundance">Частота обнаружения</param>
        /// <exception cref="ArgumentException"></exception>
        public void AddIsotope(int massNumber, double atomicWeight, double abundance)
        {
            if (_isotopesByMassNumber.ContainsKey(massNumber))
            {
                throw new ArgumentException("Изотоп с таким массовым числом уже существует");
            }
            var isotope = new Isotope(this, massNumber, atomicWeight, abundance);

            _isotopesByMassNumber.Add(massNumber, isotope);
            Isotopes.Add(isotope);
            if (PrincipalIsotope == null || abundance > PrincipalIsotope.RelativeAbundance)
            {
                PrincipalIsotope = isotope;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Add an isotope to this chemical formula
 /// </summary>
 /// <param name="isotope">The isotope to add</param>
 /// <param name="count">The number of the isotope to add</param>
 public void Add(Isotope isotope, int count)
 {
     if (count == 0)
     {
         return;
     }
     if (!Isotopes.ContainsKey(isotope))
     {
         Isotopes.Add(isotope, count);
     }
     else
     {
         Isotopes[isotope] += count;
         if (Isotopes[isotope] <= 0)
         {
             Isotopes.Remove(isotope);
         }
     }
     formulaString = null;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Add an isotope to this chemical formula
 /// </summary>
 /// <param name="isotope">The isotope to add</param>
 /// <param name="count">The number of the isotope to add</param>
 public void Add(Isotope isotope, int count)
 {
     if (count == 0)
     {
         return;
     }
     if (!isotopes.ContainsKey(isotope))
     {
         isotopes.Add(isotope, count);
     }
     else
     {
         isotopes[isotope] += count;
         if (isotopes[isotope] == 0)
         {
             isotopes.Remove(isotope);
         }
     }
     _formula = null;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Add an isotope to this element
        /// </summary>
        /// <param name="massNumber">The mass number of the isotope</param>
        /// <param name="atomicMass">The atomic mass of the isotope </param>
        /// <param name="abundance">The natural relative abundance of the isotope</param>
        /// <returns>The created isotopes that is added to this element</returns>
        public void AddIsotope(int massNumber, double atomicMass, double abundance)
        {
            if (IsotopesByMassNumber[massNumber] != null)
            {
                throw new MzLibException("Isotope with mass number " + massNumber + " already exists!");
            }
            var isotope = new Isotope(this, massNumber, atomicMass, abundance);

            IsotopesByMassNumber[massNumber] = isotope;
            int ok = 0;

            while (IsotopesInOrderTheyWereAdded[ok] != null)
            {
                ok++;
            }
            IsotopesInOrderTheyWereAdded[ok] = isotope;
            if (PrincipalIsotope == null || (abundance > PrincipalIsotope.RelativeAbundance))
            {
                PrincipalIsotope = isotope;
            }
        }
Ejemplo n.º 8
0
        public int CountSpecificIsotopes(Element element, int massNumber)
        {
            Isotope isotope = element[massNumber];

            return(CountSpecificIsotopes(isotope));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Return the number of given isotopes in this chemical fomrula
 /// </summary>
 /// <param name="isotope"></param>
 /// <returns></returns>
 public int CountSpecificIsotopes(Isotope isotope)
 {
     return(Isotopes.TryGetValue(isotope, out int isotopeCount) ? isotopeCount : 0);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Checks if the isotope is present in this chemical formula
 /// </summary>
 /// <param name="isotope">The isotope to look for</param>
 /// <returns>True if there is a non-negative number of the isotope in this formula</returns>
 public bool ContainsSpecificIsotope(Isotope isotope)
 {
     return(CountSpecificIsotopes(isotope) != 0);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Remove a isotope from this chemical formula
 /// </summary>
 /// <param name="isotope">The isotope to remove</param>
 /// <param name="count">The number of isotopes to remove</param>
 public void Remove(Isotope isotope, int count)
 {
     Add(isotope, -count);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Add the principal isotope of the element to this chemical formula
        /// given its chemical symbol
        /// </summary>
        /// <param name="element">The chemical element to add</param>
        /// <param name="count">The number of the element to add</param>
        public void AddPrincipalIsotopesOf(Element element, int count)
        {
            Isotope isotope = element.PrincipalIsotope;

            Add(isotope, count);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Replaces one isotope with another.
        /// Replacement happens on a 1 to 1 basis, i.e., if you remove 5 you will add 5
        /// </summary>
        /// <param name="isotopeToRemove">The isotope to remove</param>
        /// <param name="isotopeToAdd">The isotope to add</param>
        public void Replace(Isotope isotopeToRemove, Isotope isotopeToAdd)
        {
            int numberRemoved = Remove(isotopeToRemove);

            Add(isotopeToAdd, numberRemoved);
        }