/// <summary> /// Creates a Unimod composition from a composition string. /// </summary> /// <param name="composition">The composition.</param> /// <param name="atomProvider">The atom provider.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">formula</exception> public static UnimodComposition CreateFromFormula(string composition, IUnimodCompositionAtomProvider atomProvider) { if (string.IsNullOrEmpty(composition)) { throw new ArgumentNullException(nameof(composition)); } if (atomProvider == null) { throw new ArgumentNullException(nameof(atomProvider)); } var unimodComposition = new UnimodComposition(); string[] atoms = composition.Split(' '); for (int i = 0; i < atoms.Length; i++) { string symbol = atoms[i]; int count = 1; if (symbol.Contains("(")) { int startIndex = atoms[i].IndexOf("("); symbol = atoms[i].Substring(0, startIndex); count = Convert.ToInt32(atoms[i].Substring(startIndex + 1, atoms[i].Length - startIndex - 2)); } unimodComposition.AddAtom(atomProvider.GetUnimodCompositionAtom(symbol), count); } return(unimodComposition); }
/// <summary> /// Initializes the <see cref="ResidModificationLookup" /> class. /// </summary> /// <param name="modifications">The modifications.</param> /// <param name="atomProvider">The atom provider.</param> /// <returns></returns> public static IProteoformModificationLookup CreateFromModifications(IEnumerable <UnimodModification> modifications, IUnimodCompositionAtomProvider atomProvider) { var lookup = new UnimodModificationLookup(atomProvider); lookup.SetupModificationArray(modifications); return(lookup); }
private UnimodModificationLookup(IUnimodCompositionAtomProvider atomProvider) { _atomProvider = atomProvider; }