Example #1
0
            /// <summary>
            /// Returns an iterator over all decompositons of this mass range
            /// </summary>
            /// <param name="from">lowest mass to decompose</param>
            /// <param name="to">(inclusive) largest mass to decompose</param>
            /// <param name="boundaries">defines lowerbounds and upperbounds for the number of elements</param>
            internal DecompIterator DecomposeIterator(double from, double to, MolecularFormulaRange boundaries)
            {
                Init();
                if (to < 0d || from < 0d)
                {
                    throw new ArgumentException("Expect positive mass for decomposition: [" + from + ", " + to + "]");
                }
                if (to < from)
                {
                    throw new ArgumentException("Negative range given: [" + from + ", " + to + "]");
                }
                int[]  minValues = new int[weights.Count];
                int[]  boundsarray = new int[weights.Count];
                double cfrom = from, cto = to;

                Arrays.Fill(boundsarray, int.MaxValue);
                if (boundaries != null)
                {
                    for (int i = 0; i < boundsarray.Length; i++)
                    {
                        IIsotope el  = weights[i].GetOwner();
                        int      max = boundaries.GetIsotopeCountMax(el);
                        int      min = boundaries.GetIsotopeCountMin(el);
                        if (min >= 0 || max >= 0)
                        {
                            boundsarray[i] = max - min;
                            minValues[i]   = min;
                            if (minValues[i] > 0)
                            {
                                double reduceWeightBy = weights[i].GetMass() * min;
                                cfrom -= reduceWeightBy;
                                cto   -= reduceWeightBy;
                            }
                        }
                    }
                }
                int[] minmax = new int[2];
                IntegerBound(cfrom, cto, minmax);
                int deviation = minmax[1] - minmax[0];

                //calculate the required ERTs
                if ((1 << (ERTs.Length - 1)) <= deviation)
                {
                    CalcERT(deviation);
                }
                {
                    int[][][] ERTs = this.ERTs;

                    //take ERT with required deviation
                    int[][] currentERT;
                    if (deviation == 0)
                    {
                        currentERT = ERTs[0];
                    }
                    else
                    {
                        currentERT = ERTs[32 - Ints.NumberOfLeadingZeros(deviation)];
                    }

                    return(new DecompIterator(currentERT, minmax[0], minmax[1], from, to, minValues, boundsarray, weights));
                }
            }