private List <Fragment> recursiveFragGeneration(IndigoObject prefrag, List <fragmentationRule> _copyRules, string currName = "") { List <fragmentationRule> copyRules = new List <fragmentationRule>(); copyRules.AddRange(_copyRules); List <Fragment> _frags = new List <Fragment>(); foreach (IndigoObject structure in prefrag.iterateComponents()) { foreach (fragmentationRule rule in _copyRules) { IndigoObject temp = structure.clone(); try { temp.getBond(rule._bondId).remove(); if (rule._bondId2 != -1) { temp.getBond(rule._bondId2).remove(); } currName = currName + "+" + rule.fragmentName; if (_copyRules.Count == _rules.Count) { currName = rule.fragmentName; } Console.Out.WriteLine("RULE NAME " + currName); for (int i = 0; i < temp.countComponents(); i++) { IndigoObject currFragment = temp.component(i).clone(); double totalMassShift = 0.00; totalMassShift = calculateRgrpMassShift(rule, currFragment); Fragment currFragAdd = new Fragment(rule); Console.Out.WriteLine("MASS BEFORE " + totalMassShift); foreach (IndigoObject atoms in temp.component(i).iterateAtoms()) { if (atoms.componentIndex() == i) { if (atoms.index() == rule._atomId1) { totalMassShift = totalMassShift + rule._MassShift1; } if (atoms.index() == rule._atomId2) { totalMassShift = totalMassShift + rule._MassShift2; } } } currFragAdd.mass = (currFragment.monoisotopicMass() + totalMassShift); currFragAdd.fragmentName = currName; _frags.Add(currFragAdd); copyRules.Remove(rule); } _frags.AddRange(recursiveFragGeneration(temp, copyRules, currName)); } catch (Exception e) { Console.Out.WriteLine("That Atom doesn't exist in thsi structure!" + e); } } } // renderMolecule2(prefrag, prefrag.monoisotopicMass().ToString()); return(_frags); }