/// <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); } }
public virtual void TestRemoveIsotope_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); // remove the Fluorine mf.Remove(flu); Assert.AreEqual(2, mf.IsotopesCount); }