private static SuperAtom parse(int[] element_num) { SuperAtom origin; SuperAtom newSuperAtom = new SuperAtom(); newSuperAtom.type = 1; newSuperAtom.mass[0] = 0; newSuperAtom.prop[0] = 1; newSuperAtom.mono_mass = newSuperAtom.mass[0]; int numAtom = 0; for (int i = 0; i < element_num.Length; ++i) { origin = super[i]; numAtom = element_num[i]; while (numAtom > 0) { if (numAtom % 2 == 1) { newSuperAtom = CalculateMass(newSuperAtom, origin); } origin = CalculateMass(origin, origin); numAtom /= 2; } } return(newSuperAtom); }
public static SuperAtom[] super = new SuperAtom[150]; //每个元素的质量及丰度 public static SuperAtom CalculateMass(SuperAtom a, SuperAtom b) { SuperAtom newSuperAtom = new SuperAtom(); int length_f = a.type; int length_g = b.type; int new_type = 0; for (int k = 0; k < length_f + length_g; ++k) { double sumweight = 0, summass = 0; int start = k < (length_f - 1) ? 0 : k - length_f + 1; int end = k < (length_g - 1) ? k : length_g - 1; if (start > end) { break; } for (int i = start; i <= end; ++i) //start==end==0,单同位素峰 { double weight = b.prop[i] * a.prop[k - i]; double ma = b.mass[i] + a.mass[k - i]; sumweight += weight; summass += weight * ma; } if (sumweight >= low_scale && sumweight <= high_scale && sumweight != 0) { new_type++; } else { break; } if (new_type > newSuperAtom.mass.Length) { break; } newSuperAtom.mass[new_type - 1] = summass / sumweight; newSuperAtom.prop[new_type - 1] = sumweight; } if (new_type > newSuperAtom.mass.Length) { new_type = newSuperAtom.mass.Length; } newSuperAtom.type = new_type; double new_mono_mass = a.mono_mass + b.mono_mass; double new_min_me = double.MaxValue; int min_index = -1; for (int i = 0; i < new_type; ++i) { double me = Math.Abs(new_mono_mass - newSuperAtom.mass[i]); if (me < new_min_me) { min_index = i; new_min_me = me; } } newSuperAtom.mass[min_index] = new_mono_mass; newSuperAtom.mono_mass = new_mono_mass; return(newSuperAtom); }