Beispiel #1
0
        public static double[][] Convolute(double[][] distrib1, double[][] distrib2, double massPrecision, double weightCutoff)
        {
            double[] masses1  = distrib1[0];
            double[] masses2  = distrib2[0];
            double[] weights1 = distrib1[1];
            double[] weights2 = distrib2[1];
            double[] masses   = new double[masses1.Length * masses2.Length];
            double[] weights  = new double[masses1.Length * masses2.Length];
            int      count    = 0;

            for (int i = 0; i < masses1.Length; i++)
            {
                for (int j = 0; j < masses2.Length; j++)
                {
                    masses[count]  = masses1[i] + masses2[j];
                    weights[count] = weights1[i] * weights2[j];
                    count++;
                }
            }
            int[] o = ArrayUtils.Order(masses);
            masses  = ArrayUtils.SubArray(masses, o);
            weights = ArrayUtils.SubArray(weights, o);
            double[][] x = ChemElement.FilterMasses(masses, weights, massPrecision);
            masses  = x[0];
            weights = x[1];
            if (!double.IsNaN(weightCutoff))
            {
                x       = ChemElement.FilterWeights(masses, weights, weightCutoff);
                masses  = x[0];
                weights = x[1];
            }
            return(new[] { masses, weights });
        }
Beispiel #2
0
        public Molecule GetUnlabeledVersion()
        {
            Dictionary <int, int> w = new Dictionary <int, int>();

            for (int i = 0; i < AtomType.Length; i++)
            {
                w.Add(AtomType[i], AtomCount[i]);
            }
            foreach (int t in AtomType)
            {
                ChemElement el = ChemElements.Elements[t];
                if (el.IsIsotopicLabel)
                {
                    int c = w[t];
                    w.Remove(t);
                    int n = el.NaturalVersion;
                    if (!w.ContainsKey(n))
                    {
                        w.Add(n, 0);
                    }
                    w[n] += c;
                }
            }
            int[] newTypes = w.Keys.ToArray();
            Array.Sort(newTypes);
            int[] newCounts = new int[newTypes.Length];
            for (int i = 0; i < newCounts.Length; i++)
            {
                newCounts[i] = w[newTypes[i]];
            }
            return(new Molecule(newTypes, newCounts));
        }
Beispiel #3
0
        public double[][] GetIsotopeDistribution(double massPrecision)
        {
            if (AtomType.Length == 0)
            {
                return(new[] { new double[] { 0 }, new double[] { 1 } });
            }
            ChemElement element = ChemElements.Elements[AtomType[0]];

            double[][] distrib = element.GetIsotopeDistribution(AtomCount[0]);
            for (int i = 1; i < AtomType.Length; i++)
            {
                element = ChemElements.Elements[AtomType[i]];
                distrib = Convolute(distrib, element.GetIsotopeDistribution(AtomCount[i]), massPrecision, 1e-6);
            }
            return(distrib);
        }
Beispiel #4
0
        public double[][] GetIsotopeDistributionAlteredDeuterium(double deltaDeuterium, double massPrecision)
        {
            if (AtomType.Length == 0)
            {
                return(new[] { new double[] { 0 }, new double[] { 1 } });
            }
            ChemElement element = ChemElements.Elements[AtomType[0]];

            double[][] distrib = element.IsHydrogen()
                                ? element.GetIsotopeDistributionAlteredIsotopeContribution(AtomCount[0], 1, deltaDeuterium)
                                : element.GetIsotopeDistribution(AtomCount[0]);
            for (int i = 1; i < AtomType.Length; i++)
            {
                element = ChemElements.Elements[AtomType[i]];
                distrib = Convolute(distrib, element.GetIsotopeDistribution(AtomCount[i]), massPrecision, 1e-6);
            }
            return(distrib);
        }
Beispiel #5
0
 private static void SetNaturalVersion(ChemElement ce, IList<ChemElement> chemElements)
 {
     string label = ce.Symbol;
     if (label.Equals("D")){
         ce.NaturalVersion = GetElementIndexByName("H", chemElements);
         return;
     }
     if (label.Equals("T")){
         ce.NaturalVersion = GetElementIndexByName("H", chemElements);
         return;
     }
     if (label.Equals("Fey")){
         ce.NaturalVersion = GetElementIndexByName("Fe", chemElements);
         return;
     }
     if (label.Equals("Oy")){
         ce.NaturalVersion = GetElementIndexByName("O", chemElements);
         return;
     }
     if (label.Equals("Sy")){
         ce.NaturalVersion = GetElementIndexByName("S", chemElements);
         return;
     }
     if (!label.EndsWith("x")){
         throw new Exception("Never get here.");
     }
     label = label.Substring(0, label.Length - 1);
     ce.NaturalVersion = GetElementIndexByName(label, chemElements);
 }