Esempio n. 1
0
 /// <summary>
 /// Add the given multiple of mf into to.
 /// </summary>
 /// <param name="to"></param>
 /// <param name="mf"></param>
 /// <param name="multiple"></param>
 private void Add(MolecularFormula to, MolecularFormula mf, int multiple)
 {
     foreach (String s in mf.elementCounts.Keys)
     {
         to.Add(s, ((int)mf.elementCounts[s]) * multiple);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Add the given multiple of formulaToAdd into targetFormula
 /// </summary>
 /// <param name="targetFormula"></param>
 /// <param name="formulaToAdd"></param>
 /// <param name="multiple"></param>
 private void Add(MolecularFormula targetFormula, MolecularFormula formulaToAdd, int multiple)
 {
     foreach (var item in formulaToAdd.elementCounts)
     {
         targetFormula.Add(item.Key, item.Value * multiple);
     }
 }
Esempio n. 3
0
        public MolecularFormula GetAveragineFormula(double mz, int chargeState)
        {
            var monoIsotopicMass = mz * chargeState - chargeState * decon2LSMercuryDistribution.ChargeCarrierMass;
            var empiricalFormula = averagineFormulaCreator.GenerateAveragineFormula(monoIsotopicMass);

            return(MolecularFormula.Parse(empiricalFormula));
        }
Esempio n. 4
0
        public MolecularFormula GetAveragineFormula(double mz, int chargeState)
        {
            double monoIsotopicMass = mz * chargeState - chargeState * hornParameters.CCMass;
            string empiricalFormula = avergineFormulaCreator.GenerateAveragineFormula(monoIsotopicMass, hornParameters.AveragineFormula, hornParameters.TagFormula);

            return(MolecularFormula.Parse(empiricalFormula));
        }
Esempio n. 5
0
        public void CreateDistribution(double mass, int chargeState, double resolution)
        {
            string empiricalFormula = avergineFormulaCreator.GenerateAveragineFormula(mass, hornParameters.AveragineFormula, hornParameters.TagFormula);

            this.molecularFormula = MolecularFormula.Parse(empiricalFormula);
            this.resolution       = resolution;
            this.chargeState      = chargeState;
            CreateDistribution(this.molecularFormula);
        }
Esempio n. 6
0
        public void CreateDistribution(double mass, int chargeState, double resolution)
        {
            var empiricalFormula = averagineFormulaCreator.GenerateAveragineFormula(mass);

            MolecularFormula = MolecularFormula.Parse(empiricalFormula);
            Resolution       = resolution;
            ChargeState      = chargeState;
            CreateDistribution(MolecularFormula);
        }
Esempio n. 7
0
 public void Add(String part, MolecularFormula mf)
 {
     if (part == null)
     {
         throw new ArgumentNullException("part");
     }
     if (mf == null)
     {
         throw new ArgumentNullException("mf");
     }
     partFormulas.Add(part, mf);
 }
Esempio n. 8
0
 public void Set(String part, MolecularFormula mf)
 {
     if (part == null)
     {
         throw new ArgumentNullException("part");
     }
     if (mf == null)
     {
         throw new ArgumentNullException("mf");
     }
     this.partFormulas.Remove(part);
     this.Add(part, mf);
 }
Esempio n. 9
0
        public MolecularFormula Add(MolecularFormula mf, int multiple, bool permitNegativeMultiple)
        {
            if (multiple < 0 && !permitNegativeMultiple)
            {
                throw new ArgumentOutOfRangeException("multiple", multiple, "Multiple must be >= 0");
            }
            var newFormula = new MolecularFormula(this);

            newFormula.name          = null;
            newFormula.formulaString = null;
            Add(newFormula, mf, multiple);
            return(newFormula);
        }
Esempio n. 10
0
        public static MolecularFormula Parse(string formula, string name, bool allowNegatives)
        {
            if (formula == null)
            {
                throw new ArgumentNullException(nameof(formula));
            }
            var match = parsingRegex.Match(formula);

            if (!match.Success)
            {
                throw new ApplicationException("Formula can not be parsed");
            }

            var mf      = new MolecularFormula();
            var matched = match.Groups["element"].Captures.Count;

            //Console.WriteLine("Num Groups {0}", matched);
            // Iterate through the matched groups, updating element counts
            for (var i = 0; i < matched; i++)
            {
                var element = match.Groups["element"].Captures[i].Value;
                var count   = match.Groups["count"].Captures[i].Value;

                //Console.WriteLine("Element {0}, Count {1}", element, count);
                // If the symbol is unknown, throw an exception.
                // The multiple defaults to 1 if not found.  So CHHCHH is C2 H4.
                var multiple = 1;
                if (count != "")
                {
                    try
                    {
                        multiple = int.Parse(count);
                        if (multiple < 0 && !allowNegatives)
                        {
                            throw new ApplicationException("Negative multiple " + multiple + " for element " +
                                                           element + " is not allowed.");
                        }
                    }
                    // This can never actually happen, because the regex makes sure that
                    // only integer values which can be parsed make it to this stage
                    catch (Exception ex)
                    {
                        throw new ApplicationException("The multiple for element " + element + ", " + count + ", was not parseable", ex);
                    }
                }
                mf.Add(element, multiple);
            }
            mf.formulaString = formula;
            mf.name          = name;
            return(mf);
        }
Esempio n. 11
0
        public void Add(string part, MolecularFormula mf)
        {
            if (part == null)
            {
                throw new ArgumentNullException(nameof(part));
            }
            if (mf == null)
            {
                throw new ArgumentNullException(nameof(mf));
            }

            // This will raise an exception if partFormulas already contains the part string
            partFormulas.Add(part, mf);
        }
Esempio n. 12
0
        public void CreateDistribution(MolecularFormula molecularFormula)
        {
            Check.Require(molecularFormula != null, "Molecular formula has not been defined.");

            this.molecularFormula = molecularFormula;
            this.data             = new XYData(); //clears any old data

            this.elementTable = molecularFormula.ToElementTable();
            this.decon2LSMercuryDistribution             = new DeconToolsV2.clsMercuryIsotopeDistribution();
            this.decon2LSMercuryDistribution.Resolution  = this.resolution;
            this.decon2LSMercuryDistribution.ChargeState = (short)this.chargeState;
            System.Drawing.PointF[] drawingpoints = this.decon2LSMercuryDistribution.CalculateDistribution(this.elementTable);

            this.data = XYData.ConvertDrawingPoints(drawingpoints);
        }
Esempio n. 13
0
        public void CreateDistribution(MolecularFormula molecularFormula)
        {
            Check.Require(molecularFormula != null, "Molecular formula has not been defined.");

            MolecularFormula = molecularFormula;
            Data             = new XYData(); //clears any old data

            var deconToolsMolFormula = ProcessingTasks.Deconvoluters.HornDeconvolutor.ThrashV1.ElementalFormulas.MolecularFormula.ConvertFromString(molecularFormula.ToFormulaString());

            decon2LSMercuryDistribution = new ProcessingTasks.Deconvoluters.HornDeconvolutor.ThrashV1.Mercury.MercuryIsotopeDistribution();

            decon2LSMercuryDistribution.CalculateDistribution(ChargeState, Resolution, deconToolsMolFormula, out var x, out var y, 0, out _, out _);

            Data = new XYData()
            {
                Xvalues = x.ToArray(), Yvalues = y.ToArray()
            };
        }
Esempio n. 14
0
        public void Set(string part, MolecularFormula mf)
        {
            if (part == null)
            {
                throw new ArgumentNullException(nameof(part));
            }

            if (mf == null)
            {
                throw new ArgumentNullException(nameof(mf));
            }

            if (partFormulas.ContainsKey(part))
            {
                partFormulas.Remove(part);
            }

            Add(part, mf);
        }
Esempio n. 15
0
 public MolecularFormula Translate(string input, string partRegex)
 {
     try
     {
         var regex   = new Regex(partRegex);
         var formula = new MolecularFormula();
         var matches = regex.Matches(input);
         foreach (Match match in matches)
         {
             if (!partFormulas.TryGetValue(match.Value, out var partFormula))
             {
                 throw new ApplicationException("Formula for part " + match.Value + " is unknown.");
             }
             formula = formula.Add(partFormula, 1);
         }
         return(formula);
     }
     catch (Exception e)
     {
         throw new ApplicationException("Translation of " + input + " failed.  " + e.Message, e);
     }
 }
Esempio n. 16
0
 public MolecularFormula Translate(String input, String partRegex)
 {
     try
     {
         var regex   = new Regex(partRegex);
         var formula = new MolecularFormula();
         var matches = regex.Matches(input);
         foreach (Match match in matches)
         {
             var partFormula = (MolecularFormula)this.partFormulas[match.Value];
             if (partFormula == null)
             {
                 throw new ApplicationException("Formula for part " + match.Value + " is unknown.");
             }
             formula = formula.Add(partFormula, 1);
         }
         return(formula);
     }
     catch (Exception e)
     {
         throw new ApplicationException("Translation of " + input + " failed.  " + e.Message, e);
     }
 }
Esempio n. 17
0
 /// <summary>
 /// Clones the formula.
 /// </summary>
 /// <param name="formula"></param>
 private MolecularFormula(MolecularFormula formula)
 {
     this.name          = formula.name;
     this.formulaString = formula.formulaString;
     this.elementCounts = new Hashtable(formula.elementCounts);
 }
Esempio n. 18
0
 /// <summary>
 /// Create a new MolecularFormula by adding the given formula (times the given multiple)
 /// to this formula.
 /// </summary>
 /// <param name="mf"></param>
 /// <param name="multiple"></param>
 /// <returns></returns>
 public MolecularFormula Add(MolecularFormula mf, int multiple)
 {
     return(Add(mf, multiple, false));
 }
Esempio n. 19
0
 /// <summary>
 /// Clones the formula.
 /// </summary>
 /// <param name="formula"></param>
 private MolecularFormula(MolecularFormula formula)
 {
     name          = formula.name;
     formulaString = formula.formulaString;
     elementCounts = new Dictionary <string, int>(formula.elementCounts);
 }