public void TestSetFormula_IMolecularFormula() { IsotopeContainer isoC = new IsotopeContainer(); IMolecularFormula formula = builder.NewMolecularFormula(); isoC.Formula = formula; Assert.IsNotNull(isoC); }
public void TestGetMonoIsotope() { var isoP = new IsotopePattern(); var isoC = new IsotopeContainer(); isoP.MonoIsotope = isoC; Assert.AreEqual(isoC, isoP.MonoIsotope); }
public void TestGetFormula() { IsotopeContainer isoC = new IsotopeContainer(); IMolecularFormula formula = builder.NewMolecularFormula(); isoC.Formula = formula; Assert.AreEqual(formula, isoC.Formula); }
public void TestGetMass() { IsotopeContainer isoC = new IsotopeContainer(); double mass = 130.00; isoC.Mass = mass; Assert.AreEqual(mass, isoC.Mass, 0.001); }
public void TestGetIntensity() { IsotopeContainer isoC = new IsotopeContainer(); double intensity = 130.00; isoC.Intensity = intensity; Assert.AreEqual(intensity, isoC.Intensity, 0.001); }
public void TestSetIntensity_Double() { IsotopeContainer isoC = new IsotopeContainer { Intensity = 5000000.0 }; Assert.IsNotNull(isoC); }
public void TestSetMass_Double() { IsotopeContainer isoC = new IsotopeContainer { Mass = 130.00 }; Assert.IsNotNull(isoC); }
/// <summary> /// Get all combinatorial chemical isotopes given a structure. /// </summary> /// <param name="molFor">The IMolecularFormula to start</param> /// <returns>A IsotopePattern object containing the different combinations</returns> public IsotopePattern GetIsotopes(IMolecularFormula molFor) { if (builder == null) { try { isoFactory = CDK.IsotopeFactory; builder = molFor.Builder; } catch (Exception e) { Console.WriteLine(e.StackTrace); } } var mf = MolecularFormulaManipulator.GetString(molFor, true); var molecularFormula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula(mf, builder); IsotopePattern abundance_Mass = null; foreach (var isos in molecularFormula.Isotopes) { var elementSymbol = isos.Symbol; var atomCount = molecularFormula.GetCount(isos); // Generate possible isotope containers for the current atom's // these will then me 'multiplied' with the existing patten var additional = new List <IsotopeContainer>(); foreach (var isotope in isoFactory.GetIsotopes(elementSymbol)) { double mass = isotope.ExactMass.Value; double abundance = isotope.Abundance.Value; if (abundance <= 0.000000001) { continue; } IsotopeContainer container = new IsotopeContainer(mass, abundance); if (storeFormula) { container.Formula = AsFormula(isotope); } additional.Add(container); } for (int i = 0; i < atomCount; i++) { abundance_Mass = CalculateAbundanceAndMass(abundance_Mass, additional); } } var isoP = IsotopePatternManipulator.SortAndNormalizedByIntensity(abundance_Mass); isoP = CleanAbundance(isoP, minIntensity); var isoPattern = IsotopePatternManipulator.SortByMass(isoP); return(isoPattern); }
public void TestIsotopeContainer_Double_double() { double mass = 130.00; double intensity = 500000.00; IsotopeContainer isoC = new IsotopeContainer(mass, intensity); Assert.IsNotNull(isoC); Assert.AreEqual(mass, isoC.Mass, 0.001); Assert.AreEqual(intensity, isoC.Intensity, 0.001); }
public void TestIsotopeContainer_IMolecularFormula_Double() { IMolecularFormula formula = builder.NewMolecularFormula(); double intensity = 130.00; IsotopeContainer isoC = new IsotopeContainer(formula, intensity); Assert.IsNotNull(isoC); Assert.AreEqual(formula, isoC.Formula); Assert.AreEqual(intensity, isoC.Intensity, 0.001); }
public void TestGetNumberOfIsotopes() { var iso1 = new IsotopeContainer(); var iso2 = new IsotopeContainer(); var isoP = new IsotopePattern(new[] { iso1, iso2 }) { MonoIsotope = iso1 }; Assert.AreEqual(2, isoP.Isotopes.Count); }
private void AddDistinctFormula(IsotopeContainer container, IMolecularFormula mf) { foreach (var curr in container.Formulas) { if (MolecularFormulaManipulator.Compare(curr, mf)) { return; } } container.AddFormula(mf); }
public void TestGetIsotopes() { var iso1 = new IsotopeContainer(); var iso2 = new IsotopeContainer(); var isoP = new IsotopePattern(new[] { iso1, iso2 }) { MonoIsotope = iso1 }; Assert.AreEqual(iso1, isoP.Isotopes[0]); Assert.AreEqual(iso2, isoP.Isotopes[1]); }
/// <summary> /// Search and find the closest difference in an array in terms of mass and /// intensity. Always return the position in this List. /// </summary> /// <param name="isoContainer"></param> /// <param name="pattern"></param> /// <returns></returns> private int GetClosestDataDiff(IsotopeContainer isoContainer, IsotopePattern pattern) { double diff = 100; int posi = -1; for (int i = 0; i < pattern.Isotopes.Count; i++) { double tempDiff = Math.Abs((isoContainer.Mass) - pattern.Isotopes[i].Mass); if (tempDiff <= (Tolerance / isoContainer.Mass) && tempDiff < diff) { diff = tempDiff; posi = i; } } return(posi); }
/// <summary> /// Return the isotope pattern normalized to the highest abundance. /// </summary> /// <param name="isotopeP">The IsotopePattern object to normalize</param> /// <returns>The IsotopePattern normalized</returns> public static IsotopePattern Normalize(IsotopePattern isotopeP) { IsotopeContainer isoHighest = null; double biggestAbundance = 0; /* Extraction of the isoContainer with the highest abundance */ foreach (var isoContainer in isotopeP.Isotopes) { double abundance = isoContainer.Intensity; if (biggestAbundance < abundance) { biggestAbundance = abundance; isoHighest = isoContainer; } } IsotopePattern isoNormalized; { /* Normalize */ var newIsotopes = new List <IsotopeContainer>(); IsotopeContainer monoIsotope = null; foreach (var isoContainer in isotopeP.Isotopes) { var inten = isoContainer.Intensity / isoHighest.Intensity; var icClone = (IsotopeContainer)isoContainer.Clone(); icClone.Intensity = inten; if (isoHighest.Equals(isoContainer)) { monoIsotope = icClone; } newIsotopes.Add(icClone); } isoNormalized = new IsotopePattern(newIsotopes); if (monoIsotope != null) { isoNormalized.MonoIsotope = monoIsotope; } isoNormalized.Charge = isotopeP.Charge; } return(isoNormalized); }
public void TestClone() { IsotopeContainer isoC = new IsotopeContainer(); IMolecularFormula formula = builder.NewMolecularFormula(); isoC.Formula = formula; double mass = 130.00; isoC.Mass = mass; double intensity = 130.00; isoC.Intensity = intensity; IsotopeContainer clone = (IsotopeContainer)isoC.Clone(); Assert.AreEqual(mass, clone.Mass, 0.001); Assert.AreEqual(intensity, clone.Intensity, 0.001); Assert.AreEqual(formula, clone.Formula); }
/// <summary> /// Normalize the intensity (relative abundance) of all isotopes in relation /// of the most abundant isotope. /// </summary> /// <param name="isopattern">The IsotopePattern object</param> /// <param name="minIntensity">The minimum abundance</param> /// <returns>The IsotopePattern cleaned</returns> private static IsotopePattern CleanAbundance(IsotopePattern isopattern, double minIntensity) { double intensity; double biggestIntensity = 0; foreach (var sc in isopattern.Isotopes) { intensity = sc.Intensity; if (intensity > biggestIntensity) { biggestIntensity = intensity; } } foreach (var sc in isopattern.Isotopes) { intensity = sc.Intensity; intensity /= biggestIntensity; if (intensity < 0) { intensity = 0; } sc.Intensity = intensity; } var sortedIsoPattern = new IsotopePattern { MonoIsotope = new IsotopeContainer(isopattern.Isotopes[0]) }; for (int i = 1; i < isopattern.Isotopes.Count; i++) { if (isopattern.Isotopes[i].Intensity >= (minIntensity)) { var container = new IsotopeContainer(isopattern.Isotopes[i]); sortedIsoPattern.isotopes.Add(container); } } return(sortedIsoPattern); }
/// <summary> /// Calculates the mass and abundance of all isotopes generated by adding one /// atom. Receives the periodic table element and calculate the isotopes, if /// there exist a previous calculation, add these new isotopes. In the /// process of adding the new isotopes, remove those that has an abundance /// less than setup parameter minIntensity, and remove duplicated masses. /// </summary> /// <param name="additional">additional isotopes to 'multiple' the current pattern by</param> /// <returns>the calculation was successful</returns> private IsotopePattern CalculateAbundanceAndMass(IsotopePattern current, List <IsotopeContainer> additional) { if (additional == null || additional.Count == 0) { return(current); } var containers = new List <IsotopeContainer>(); // Verify if there is a previous calculation. If it exists, add the new // isotopes if (current == null) { current = new IsotopePattern(); foreach (var container in additional) { current.isotopes.Add(container); } } else { foreach (var container in current.Isotopes) { foreach (IsotopeContainer other in additional) { var abundance = container.Intensity * other.Intensity * 0.01; var mass = container.Mass + other.Mass; // merge duplicates with some resolution var existing = FindExisting(containers, mass, resolution); if (existing != null) { var newIntensity = existing.Intensity + abundance; // moving weighted avg existing.Mass = (existing.Mass * existing.Intensity + mass * abundance) / newIntensity; existing.Intensity = newIntensity; if (storeFormula) { foreach (var mf in container.Formulas) { AddDistinctFormula(existing, Union(mf, other.Formula)); } } continue; } // Filter isotopes too small if (abundance > minAbundance) { var newcontainer = new IsotopeContainer(mass, abundance); if (storeFormula) { foreach (var mf in container.Formulas) { newcontainer.AddFormula(Union(mf, other.Formula)); } } containers.Add(newcontainer); } } } current = new IsotopePattern(); foreach (var container in containers) { current.isotopes.Add(container); } } return(current); }
public IsotopeContainer(IsotopeContainer container) { mass = container.mass; intensity = container.intensity; forms = new List <IMolecularFormula>(container.forms); }
public void TestIsotopeContainer() { IsotopeContainer isoC = new IsotopeContainer(); Assert.IsNotNull(isoC); }