Repository navigation
[FIX] EmpiricalFormula: order the elements by atomic number, not by address - #10605
Conversation
…ddress
EmpiricalFormula kept its elements in a std::map<const Element*, SignedSize>,
i.e. in the order of the addresses of the Element objects, and summed weights
and isotope distributions in that order. ElementDB allocates every element on
its own, so the order depends on the heap: on Linux it follows the atomic
numbers, on Windows (randomized heap) it changes from run to run. Theoretical
masses then differed in the last bits between two identical runs; Percolator
rescoring in ProSE (Test 12, one decoy among 896 PSMs) turned that into
percolator_score differences of about 1% and failed
TOPP_ProSE_12_pin_rescore_idXML_out on Windows.
The map now orders the elements by atomic number, then by the length and the
text of the symbol: an element before its isotopes ("C", "(12)C", "(13)C"),
the isotopes by mass number. This is the order the elements have in memory on
Linux, so Linux results do not change. operator< compared the map keys by
address as well and now uses the same order.
ProSE Test 12 with -rescore again diffs the idXML of the two runs (reverts the
hit-count comparison of 055f6a0).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
…#10301, #10611, #10606, #10608, #10609, #10617, #10610, #10578 ProSE Percolator rescoring, #10628) Only CHANGELOG conflicted; both entries are kept. Develop's changes to FalseDiscoveryRate, IDScoreGetterSetter, ConsensusMapMergerAlgorithm, FileInfo and ProSE work on the established classes, which this branch keeps as they are. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
…ddress (OpenMS#10605) EmpiricalFormula kept its elements in a std::map<const Element*, SignedSize>, i.e. in the order of the addresses of the Element objects, and summed weights and isotope distributions in that order. ElementDB allocates every element on its own, so the order depends on the heap: on Linux it follows the atomic numbers, on Windows (randomized heap) it changes from run to run. Theoretical masses then differed in the last bits between two identical runs; Percolator rescoring in ProSE (Test 12, one decoy among 896 PSMs) turned that into percolator_score differences of about 1% and failed TOPP_ProSE_12_pin_rescore_idXML_out on Windows. The map now orders the elements by atomic number, then by the length and the text of the symbol: an element before its isotopes ("C", "(12)C", "(13)C"), the isotopes by mass number. This is the order the elements have in memory on Linux, so Linux results do not change. operator< compared the map keys by address as well and now uses the same order. ProSE Test 12 with -rescore again diffs the idXML of the two runs (reverts the hit-count comparison of 055f6a0). Claude-Session: https://claude.ai/code/session_014w9WfnJVb61NA9tyTwNbZ6 Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit d67b262)
Description
TOPP_ProSE_12_pin_rescore_idXML_outfailed on Windows in many PRs: thepercolator_scoreof two identical-rescoreruns differed by about 1%. 055f6a0 worked around it by comparing only hit counts. This PR fixes the cause and restores the full comparison.Cause
EmpiricalFormulakeeps its elements in astd::map<const Element*, SignedSize>, i.e. in the order of the addresses of theElementobjects.getMonoWeight(),getAverageWeight(),getLightestIsotopeWeight(), the isotope distributions andoperator<follow that order.ElementDBallocates each element on its own, so the order depends on the heap:A different order of the additions changes the last bits of the masses, e.g.
CalcMass768.9445477617209 vs …211. In ProSE Test 12, Percolator trains on 896 PSMs with a single decoy, so one cross-validation fold has none. That ill-conditioned training turned last-bit differences in the featuresCalcMass,dm,absdm,fragment_mz_error_median_ppmandchance_match_surpriseinto ~1% differences inpercolator_score. Thread races are ruled out, because the test runs withthreads 1.Fix
EmpiricalFormula::MapType_gets a comparator: atomic number, then length and text of the symbol. An element comes before its isotopes (C,(12)C,(13)C), and the isotopes come in order of mass number. Only distinct elements with the same atomic number and symbol fall back to their address.operator<compared the keys by address (std::map::operator<uses<on the pointers); it now uses the same order.-rescoreagain diffs the full idXML of the two runs. The test part of 055f6a0 is reverted; the block is identical to the one before it.How this was validated
There was no full build in this environment. The changed
EmpiricalFormula.cppwas compiled against the 2026-10-14 nightly libraries, whoseEmpiricalFormulais identical todevelop, and took precedence over libOpenMS's copy.EmpiricalFormula_testpasses. Its new checks fail with the old code: the iteration order with isotopes, and Element objects whose address order is opposite to their atomic numbers (checked for iteration, weight andoperator<).-rescoreruns gave 6 different idXMLs.Not changed:
ResidueDB::getResidues()returns astd::set<const Residue*>, which is also ordered by address. It is used by MassDecompositionAlgorithm, Tagger and OpenNuXL, and is not in the ProSE path.Checklist
EmpiricalFormula_testand the TOPP tests above pass against the nightly libraries; full suite not run, see above)Generated by Claude Code
Summary by CodeRabbit