Ejemplo n.º 1
0
 public Molecule(string empiricalFormula)
 {
     if (empiricalFormula.Contains(".")){
         string[] q = empiricalFormula.Split('.');
         Molecule[] m = new Molecule[q.Length];
         int[] w = new int[q.Length];
         for (int i = 0; i < q.Length; i++){
             m[i] = new Molecule(q[i]);
             w[i] = 1;
         }
         Molecule x = Sum(m, w);
         AtomType = x.AtomType;
         AtomCount = x.AtomCount;
         CalcMasses();
     } else{
         int[][] tc = ProcessEmpiricalFormula(empiricalFormula);
         AtomType = tc[0];
         AtomCount = tc[1];
         CalcMasses();
     }
 }
 public Molecule GetMolecule()
 {
     Molecule[] x = new Molecule[ModificationTypes.Length];
     for (int i = 0; i < x.Length; i++){
         Modification mod = Tables.ModificationList[ModificationTypes[i]];
         x[i] = mod.GetMolecule();
     }
     return Molecule.Sum(x, ModificationCounts);
 }
Ejemplo n.º 3
0
 protected bool Equals(Molecule other)
 {
     return ArrayUtils.EqualArrays(AtomType, other.AtomType) && ArrayUtils.EqualArrays(AtomCount, other.AtomCount);
 }
Ejemplo n.º 4
0
 public static Molecule Sum(Molecule molecule1, Molecule molecule2)
 {
     return Sum(new[]{molecule1, molecule2});
 }
Ejemplo n.º 5
0
 //TODO: can probably be optimized. (not necessary to produce the full counts arrays.)
 public bool Contains(Molecule other)
 {
     int[] counts = ToCountArray();
     int[] otherCounts = other.ToCountArray();
     for (int i = 0; i < counts.Length; i++){
         if (otherCounts[i] > counts[i]){
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 6
0
 public static Molecule Subtract(Molecule molecule1, Molecule molecule2)
 {
     int[] counts = new int[ChemElements.Elements.Length];
     for (int j = 0; j < molecule1.AtomType.Length; j++){
         counts[molecule1.AtomType[j]] += molecule1.AtomCount[j];
     }
     for (int j = 0; j < molecule2.AtomType.Length; j++){
         counts[molecule2.AtomType[j]] -= molecule2.AtomCount[j];
     }
     int[] types = new int[counts.Length];
     int count = 0;
     for (int i = 0; i < counts.Length; i++){
         if (counts[i] > 0){
             types[count++] = i;
         }
     }
     Array.Resize(ref types, count);
     return new Molecule(types, ArrayUtils.SubArray(counts, types));
 }
Ejemplo n.º 7
0
 public static Molecule Max(Molecule x, Molecule y)
 {
     int[] counts1 = new int[ChemElements.Elements.Length];
     for (int j = 0; j < x.AtomType.Length; j++){
         counts1[x.AtomType[j]] = x.AtomCount[j];
     }
     int[] counts2 = new int[ChemElements.Elements.Length];
     for (int j = 0; j < y.AtomType.Length; j++){
         counts2[y.AtomType[j]] = y.AtomCount[j];
     }
     int[] counts = new int[ChemElements.Elements.Length];
     for (int i = 0; i < ChemElements.Elements.Length; i++){
         counts[i] = Math.Max(counts1[i], counts2[i]);
     }
     int[] types = new int[counts.Length];
     int count = 0;
     for (int i = 0; i < counts.Length; i++){
         if (counts[i] > 0){
             types[count++] = i;
         }
     }
     Array.Resize(ref types, count);
     return new Molecule(types, ArrayUtils.SubArray(counts, types));
 }
Ejemplo n.º 8
0
 public static Tuple<Molecule, Molecule> GetDifferences(Molecule molecule1, Molecule molecule2)
 {
     int[] counts1 = new int[ChemElements.Elements.Length];
     for (int j = 0; j < molecule1.AtomType.Length; j++){
         counts1[molecule1.AtomType[j]] = molecule1.AtomCount[j];
     }
     int[] counts2 = new int[ChemElements.Elements.Length];
     for (int j = 0; j < molecule2.AtomType.Length; j++){
         counts2[molecule2.AtomType[j]] = molecule2.AtomCount[j];
     }
     for (int i = 0; i < counts1.Length; i++){
         if (counts1[i] > counts2[i]){
             counts1[i] -= counts2[i];
             counts2[i] = 0;
         } else{
             counts2[i] -= counts1[i];
             counts1[i] = 0;
         }
     }
     int[] types1 = new int[counts1.Length];
     int count1 = 0;
     for (int i = 0; i < counts1.Length; i++){
         if (counts1[i] > 0){
             types1[count1++] = i;
         }
     }
     Array.Resize(ref types1, count1);
     Molecule diff1 = new Molecule(types1, ArrayUtils.SubArray(counts1, types1));
     int[] types2 = new int[counts2.Length];
     int count2 = 0;
     for (int i = 0; i < counts2.Length; i++){
         if (counts2[i] > 0){
             types2[count2++] = i;
         }
     }
     Array.Resize(ref types2, count2);
     Molecule diff2 = new Molecule(types2, ArrayUtils.SubArray(counts2, types2));
     return new Tuple<Molecule, Molecule>(diff1, diff2);
 }
Ejemplo n.º 9
0
 protected bool Equals(Molecule other)
 {
     return(ArrayUtils.EqualArrays(AtomType, other.AtomType) && ArrayUtils.EqualArrays(AtomCount, other.AtomCount));
 }
Ejemplo n.º 10
0
 public static Molecule Sum(Molecule molecule1, Molecule molecule2)
 {
     return(Sum(new[] { molecule1, molecule2 }));
 }