public IEnumerable <Peptide> GenerateAllModificationCombinations() { // Get all the modifications that are isotopologues var isotopologues = GetUniqueModifications <ModificationWithMultiplePossibilitiesCollection>().ToArray(); // Base condition, no more isotopologues to make, so just return if (isotopologues.Length < 1) { yield break; } // Grab the the first isotopologue ModificationWithMultiplePossibilitiesCollection isotopologue = isotopologues[0]; // Loop over each modification in the isotopologue foreach (OldSchoolModification mod in isotopologue) { // Create a clone of the peptide, cloning modifications as well. Peptide peptide = new Peptide(this); // Replace the base isotopologue mod with the specific version peptide.ReplaceModification(isotopologue, mod); // There were more than one isotopologue, so we must go deeper if (isotopologues.Length > 1) { // Call the same rotuine on the newly generate peptide that has one less isotopologue foreach (var subpeptide in peptide.GenerateAllModificationCombinations()) { yield return(subpeptide); } } else { // Return this peptide yield return(peptide); } } }