Improve adduct/isotope generation - #319
Merged
Merged
Conversation
This was referenced Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves simulated isotope envelopes, adduct generation, and deisotoping/deadducting support.
The main scientific change is replacing the previous carbon-only isotope approximation with a multi-element isotope envelope approximation based on natural isotope abundances. The PR also adds configurable adduct priors/profiles and concentration controls, removes adducts we cannot currently simulate correctly, and adds OpenMS / ms-deisotope helpers plus tests to validate generated patterns.
Scientific fixes and behavior changes
Isotope generation
Isotope generation now approximates the full-formula isotope envelope by convolving per-element natural isotope distributions (
NATURAL_ISOTOPES).mass_precision,min_prob, andmax_statesto keep runtime bounded.total_proportionis reached.max_peaksnow defaults to unlimited; if explicitly set too low to reachtotal_proportion, a warning is emitted.isotopes[0], because downstream code assumes that invariant.Implementation lives in
vimms/IsotopeDistribution.py, withvimms/Chemicals.py::Isotopeskept as the public wrapper.Adduct generation
Adduct metadata now has one shared definition table in
vimms/Common.py, from which names, priors, and mass terms are derived.M+2K+Hwas replaced withM+2K-H.M+Cl,M+FA-H, andM+Ac-H;M+Cluses the chloride ion mass.2M+H,2M+NH4) were removed because the old mass-term approach applies isotope envelopes incorrectly for multimer species. It is better not to simulate them than to produce scientifically wrong isotope/adduct peaks.Deisotoping and deadducting
vimms/Deisotoping.pyis added with utilities for validating and processing generated isotope/adduct patterns.pyopenmsandms-deisotopeare added as required dependencies for this PR's functionality and tests.Validation
Added
tests/test_deisotoping.pyto cover:max_peakstruncates the requested envelope,Local validation run in the
vimmsconda environment:pytest tests/test_deisotoping.py -q-> 30 passedpytest tests/test_chemical_generation.py tests/test_controllers_TopN.py -q-> 31 passedpytest -q-> 144 passed, 2 existing warningsCI is currently green on the PR.
Limitations