Skip to content

Commit 55e812f

Browse files
robertyoung3claude
andcommitted
Fix Kendrick base consistency between MSPeak and MolecularFormula
Two related fixes for Kendrick base handling: 1. MolecularFormulaBase.__init__ fallback used hardcoded {"C":1,"H":2} instead of MSParameters.ms_peak.kendrick_base, so molecular formulas without a parent peak ignored user-configured Kendrick base. 2. MSPeak.change_kendrick_base() now recalculates KMD on all associated molecular formulas, so they stay consistent when change_kendrick_base_all_mspeaks() is called after formula assignment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0176770 commit 55e812f

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

corems/molecular_formula/factory/MolecularFormulaFactory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ def __init__(
136136
self._mspeak_parent._ms_parent.mspeaks_settings.kendrick_base
137137
)
138138
else:
139-
kendrick_dict_base = {"C": 1, "H": 2}
139+
from corems.encapsulation.factory.parameters import MSParameters
140+
141+
kendrick_dict_base = MSParameters.ms_peak.kendrick_base
140142
self._kmd, self._kendrick_mass, self._nominal_km = self._calc_kmd(
141143
kendrick_dict_base
142144
)

corems/ms_peak/factory/MSPeakClasses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ def change_kendrick_base(self, kendrick_dict_base):
139139
kendrick_dict_base
140140
)
141141

142+
# Also update all associated molecular formulas
143+
for mf in self.molecular_formulas:
144+
mf._kmd, mf._kendrick_mass, mf._nominal_km = mf._calc_kmd(kendrick_dict_base)
145+
142146
def add_molecular_formula(self, molecular_formula_obj):
143147
"""Adds a molecular formula to the peak.
144148

0 commit comments

Comments
 (0)