Skip to content

Fix Kendrick base consistency between MSPeak and MolecularFormula#28

Open
robertyoung3 wants to merge 1 commit intoEMSL-Computing:masterfrom
robertyoung3:fix/kendrick-base-consistency
Open

Fix Kendrick base consistency between MSPeak and MolecularFormula#28
robertyoung3 wants to merge 1 commit intoEMSL-Computing:masterfrom
robertyoung3:fix/kendrick-base-consistency

Conversation

@robertyoung3
Copy link

Summary

Two related fixes for Kendrick base handling:

  1. Inconsistent default in MolecularFormulaBase: When a molecular formula has no parent peak, __init__ used a hardcoded {"C": 1, "H": 2} fallback instead of reading from MSParameters.ms_peak.kendrick_base. This meant user-configured Kendrick bases were ignored for orphan formulas.

  2. Stale formula KMD after base change: MSPeak.change_kendrick_base() recalculated KMD for the peak but not for its associated molecular formulas. When change_kendrick_base_all_mspeaks() is called after formula assignment (as in priorityAssignment.py and findOxygenPeaks.py), formulas retained stale KMD values.

Changes

MolecularFormulaFactory.py

# Before: hardcoded fallback
kendrick_dict_base = {"C": 1, "H": 2}

# After: reads from MSParameters
from corems.encapsulation.factory.parameters import MSParameters
kendrick_dict_base = MSParameters.ms_peak.kendrick_base

MSPeakClasses.py — added to change_kendrick_base():

# Also update all associated molecular formulas
for mf in self.molecular_formulas:
    mf._kmd, mf._kendrick_mass, mf._nominal_km = mf._calc_kmd(kendrick_dict_base)

Test plan

  • Verified change_kendrick_base_all_mspeaks() is the canonical entry point (called in priorityAssignment.py:273 and findOxygenPeaks.py:92)
  • That method iterates all peaks calling mspeak.change_kendrick_base(), which now also updates formulas
  • Existing test in tests/test_mspeak.py:32 exercises change_kendrick_base

@robertyoung3 robertyoung3 force-pushed the fix/kendrick-base-consistency branch from 55e812f to 6168b5f Compare March 3, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant