Skill Tracer
Skills › Scientific Agent Skills › matchms › migration.md

migration.md

389 lines · skills/matchms/references/migration.md at 5f2bc03

Open on GitHub
1# Migration to matchms 0.33.1
2
3Use this guide when adapting code written for older matchms releases or the
4official tutorial notebooks last revised in 2024. The stable release and
5public symbols were rechecked on 2026-10-01; development-branch changes are
6not automatically supported by the pinned release.
7

Migration to matchms 0.33.1

Use this guide when adapting code written for older matchms releases or the official tutorial notebooks last revised in 2024. The stable release and public symbols were rechecked on 2026-10-01; development-branch changes are not automatically supported by the pinned release.

Raw lines 1 to 7
8## Release Timeline That Affects This Skill
9

Release Timeline That Affects This Skill

Raw lines 8 to 9
10### 0.27.0 (2024-07-10)
12- `add_losses()` was removed.
13- Neutral losses moved to on-demand computation through `spectrum.losses` and
14 `spectrum.compute_losses(...)`.
15- public names and parameters began changing from `spectrums` to `spectra`;
16 compatibility spellings were deprecated.
17- Python support moved to 3.9-3.12 at that release.

0.27.0 (2024-07-10)

  • add_losses() was removed.
  • Neutral losses moved to on-demand computation through spectrum.losses and spectrum.compute_losses(...).
  • public names and parameters began changing from spectrums to spectra; compatibility spellings were deprecated.
  • Python support moved to 3.9-3.12 at that release.
Raw lines 10 to 18
19### 0.29.x-0.30.x (2025)
21- importers gained broader `pathlib.Path`/MGF file-like support and writer
22 behavior was revised.
23- NumPy 2 became the supported baseline.
24- Python 3.13 support was added.

0.29.x-0.30.x (2025)

  • importers gained broader pathlib.Path/MGF file-like support and writer behavior was revised.
  • NumPy 2 became the supported baseline.
  • Python 3.13 support was added.
Raw lines 19 to 25
26### 0.31.0 (2025-10-06)
28- `FlashSimilarity` and `BlinkCosine` were added.
29- `normalize_intensities(..., scaling=(low, high))` gained min-max scaling.
30- `add_precursor_formula` and
31 `remove_peaks_relative_to_precursor_mz` were added.

0.31.0 (2025-10-06)

  • FlashSimilarity and BlinkCosine were added.
  • normalize_intensities(..., scaling=(low, high)) gained min-max scaling.
  • add_precursor_formula and remove_peaks_relative_to_precursor_mz were added.
Raw lines 26 to 32
33### 0.32.0 (2026-03-04)
35- `ModifiedCosine` was renamed to `ModifiedCosineGreedy`.
36- `ModifiedCosineHungarian` was added for exact assignment.

0.32.0 (2026-03-04)

  • ModifiedCosine was renamed to ModifiedCosineGreedy.
  • ModifiedCosineHungarian was added for exact assignment.
Raw lines 33 to 37
38### 0.33.0-0.33.1 (2026-05-12 to 2026-06-08)
40- `CosineLinear` was added.
41- v1 cleanup/deprecation work began, including migration away from
42 `add_fingerprint()`.
43- Python 3.14 support was added.

0.33.0-0.33.1 (2026-05-12 to 2026-06-08)

  • CosineLinear was added.
  • v1 cleanup/deprecation work began, including migration away from add_fingerprint().
  • Python 3.14 support was added.
Raw lines 38 to 44
45## Required Code Changes

Required Code Changes

Raw lines 45 to 46
47### Modified cosine class
49Old:
51```python
52from matchms.similarity import ModifiedCosine
54metric = ModifiedCosine(tolerance=0.02)
55```
57Current greedy behavior:
59```python
60from matchms.similarity import ModifiedCosineGreedy
62metric = ModifiedCosineGreedy(tolerance=0.02)
63```
65Current exact assignment:
67```python
68from matchms.similarity import ModifiedCosineHungarian
70metric = ModifiedCosineHungarian(tolerance=0.02)
71```
73Update score field names too:
75```text
76ModifiedCosine_score -> ModifiedCosineGreedy_score
77ModifiedCosine_matches -> ModifiedCosineGreedy_matches
78```

Modified cosine class

Old:

from matchms.similarity import ModifiedCosine

metric = ModifiedCosine(tolerance=0.02)

Current greedy behavior:

from matchms.similarity import ModifiedCosineGreedy

metric = ModifiedCosineGreedy(tolerance=0.02)

Current exact assignment:

from matchms.similarity import ModifiedCosineHungarian

metric = ModifiedCosineHungarian(tolerance=0.02)

Update score field names too:

ModifiedCosine_score   -> ModifiedCosineGreedy_score
ModifiedCosine_matches -> ModifiedCosineGreedy_matches
Raw lines 47 to 79
80### Neutral losses
82Old:
84```python
85from matchms.filtering import add_losses
87spectrum = add_losses(spectrum)
88```
90Current:
92```python
93losses = spectrum.losses
94custom_losses = spectrum.compute_losses(
95 loss_mz_from=5.0,
96 loss_mz_to=200.0,
98```
100`NeutralLossesCosine` computes the needed losses directly; do not pre-add them.

Neutral losses

Old:

from matchms.filtering import add_losses

spectrum = add_losses(spectrum)

Current:

losses = spectrum.losses
custom_losses = spectrum.compute_losses(
    loss_mz_from=5.0,
    loss_mz_to=200.0,
)

NeutralLossesCosine computes the needed losses directly; do not pre-add them.

Raw lines 80 to 101
102### `SpectrumProcessor`
104Old:
106```python
107processor = SpectrumProcessor(
108 [
109 normalize_intensities,
110 lambda spectrum: select_by_relative_intensity(
111 spectrum,
112 intensity_from=0.01,
113 ),
114 ]
116processed = [processor(spectrum) for spectrum in spectra]
117```
119Current:
121```python
122processor = SpectrumProcessor(
123 [
124 normalize_intensities,
125 (select_by_relative_intensity, {"intensity_from": 0.01}),
126 ]
128processed, report = processor.process_spectra(
129 spectra,
130 progress_bar=False,
131 create_report=False,
133```
135For one spectrum, call `processor.process_spectrum(spectrum)`.
137The aggregate `default_filters` callable is not registered in
138`SpectrumProcessor`'s built-in filter order. Run it before the processor or
139expand its nine component filters; otherwise it is treated as custom and moved
140after registered filters.

SpectrumProcessor

Old:

processor = SpectrumProcessor(
    [
        normalize_intensities,
        lambda spectrum: select_by_relative_intensity(
            spectrum,
            intensity_from=0.01,
        ),
    ]
)
processed = [processor(spectrum) for spectrum in spectra]

Current:

processor = SpectrumProcessor(
    [
        normalize_intensities,
        (select_by_relative_intensity, {"intensity_from": 0.01}),
    ]
)
processed, report = processor.process_spectra(
    spectra,
    progress_bar=False,
    create_report=False,
)

For one spectrum, call processor.process_spectrum(spectrum).

The aggregate default_filters callable is not registered in SpectrumProcessor's built-in filter order. Run it before the processor or expand its nine component filters; otherwise it is treated as custom and moved after registered filters.

Raw lines 102 to 141
142### Score access
144Old assumptions:
146```python
147reference_index, score = scores.scores_by_query(query, sort=True)[0]
148reference = references[reference_index]
149numeric = scores.scores[j, i]
150```
152Current:
154```python
155score_name = "CosineGreedy_score"
156reference, value = scores.scores_by_query(
157 query,
158 name=score_name,
159 sort=True,
160)[0]
162numeric = float(value[score_name])
163matches = int(value["CosineGreedy_matches"])
164matrix = scores.to_array(score_name)
165```
167`Scores.scores` is a layered sparse container. Always inspect
168`scores.score_names`.

Score access

Old assumptions:

reference_index, score = scores.scores_by_query(query, sort=True)[0]
reference = references[reference_index]
numeric = scores.scores[j, i]

Current:

score_name = "CosineGreedy_score"
reference, value = scores.scores_by_query(
    query,
    name=score_name,
    sort=True,
)[0]

numeric = float(value[score_name])
matches = int(value["CosineGreedy_matches"])
matrix = scores.to_array(score_name)

Scores.scores is a layered sparse container. Always inspect scores.score_names.

Raw lines 142 to 169
170### Metadata matching
172Old:
174```python
175MetadataMatch(field="ionmode", matching_type="exact")
176```
178Current:
180```python
181MetadataMatch(field="ionmode", matching_type="equal_match")
182```
184Current matching types are `equal_match` and `difference`.

Metadata matching

Old:

MetadataMatch(field="ionmode", matching_type="exact")

Current:

MetadataMatch(field="ionmode", matching_type="equal_match")

Current matching types are equal_match and difference.

Raw lines 170 to 185
186### High-peak requirement
188Old:
190```python
191require_minimum_number_of_high_peaks(
192 spectrum,
193 n_required=5,
194 intensity_threshold=0.05,
196```
198Current:
200```python
201require_minimum_number_of_high_peaks(
202 spectrum,
203 no_peaks=5,
204 intensity_percent=5.0,
206```
208`intensity_percent` is expressed as a percentage.

High-peak requirement

Old:

require_minimum_number_of_high_peaks(
    spectrum,
    n_required=5,
    intensity_threshold=0.05,
)

Current:

require_minimum_number_of_high_peaks(
    spectrum,
    no_peaks=5,
    intensity_percent=5.0,
)

intensity_percent is expressed as a percentage.

Raw lines 186 to 209
210### Top-k peak filter
212Old examples may use a `ratio_desired` argument. Current:
214```python
215remove_peaks_outside_top_k(
216 spectrum,
217 k=6,
218 mz_window=50,
220```
222For global peak-count reduction, use
223`reduce_to_number_of_peaks(n_required=..., n_max=..., ratio_desired=...)`.

Top-k peak filter

Old examples may use a ratio_desired argument. Current:

remove_peaks_outside_top_k(
    spectrum,
    k=6,
    mz_window=50,
)

For global peak-count reduction, use reduce_to_number_of_peaks(n_required=..., n_max=..., ratio_desired=...).

Raw lines 210 to 224
225### Precursor upper bound
227Old:
229```python
230require_precursor_below_mz(spectrum, max_mz=1000)
231```
233Current:
235```python
236require_precursor_mz(
237 spectrum,
238 minimum_accepted_mz=10.0,
239 maximum_mz=1000.0,
241```
243`require_precursor_below_mz()` is deprecated.

Precursor upper bound

Old:

require_precursor_below_mz(spectrum, max_mz=1000)

Current:

require_precursor_mz(
    spectrum,
    minimum_accepted_mz=10.0,
    maximum_mz=1000.0,
)

require_precursor_below_mz() is deprecated.

Raw lines 225 to 244
245### Parent-mass repair names
247Older examples may refer to:
249```text
250repair_parent_mass_is_mol_wt
251repair_adduct_based_on_smiles
252```
254Current public helpers include:
256```text
257repair_parent_mass_is_molar_mass
258repair_adduct_and_parent_mass_based_on_smiles
259repair_adduct_based_on_parent_mass
260repair_parent_mass_from_smiles
261```
263Review semantics and supply required `mass_tolerance` arguments rather than
264performing a mechanical rename.

Parent-mass repair names

Older examples may refer to:

repair_parent_mass_is_mol_wt
repair_adduct_based_on_smiles

Current public helpers include:

repair_parent_mass_is_molar_mass
repair_adduct_and_parent_mass_based_on_smiles
repair_adduct_based_on_parent_mass
repair_parent_mass_from_smiles

Review semantics and supply required mass_tolerance arguments rather than performing a mechanical rename.

Raw lines 245 to 265
266### Fingerprints
268Old:
270```python
271spectra = [add_fingerprint(spectrum, fingerprint_type="morgan2")
272 for spectrum in spectra]
273```
275`add_fingerprint()` still works in 0.33.1 but is marked for removal in matchms
2761.0. Forward-oriented preparation:
278```python
279from matchms import Fingerprints
281fp_store = Fingerprints(
282 fingerprint_algorithm="morgan2",
283 fingerprint_method="bit",
284 nbits=2048,
286fp_store.compute_fingerprints(spectra)
287```
289Current `FingerprintSimilarity` still reads a `"fingerprint"` spectrum field.
290When that class is needed in 0.33.1, bridge the store explicitly:
292```python
293for spectrum in spectra:
294 fingerprint = fp_store.get_fingerprint_by_spectrum(spectrum)
295 if fingerprint is not None:
296 spectrum.set("fingerprint", fingerprint)
297```

Fingerprints

Old:

spectra = [add_fingerprint(spectrum, fingerprint_type="morgan2")
           for spectrum in spectra]

add_fingerprint() still works in 0.33.1 but is marked for removal in matchms 1.0. Forward-oriented preparation:

from matchms import Fingerprints

fp_store = Fingerprints(
    fingerprint_algorithm="morgan2",
    fingerprint_method="bit",
    nbits=2048,
)
fp_store.compute_fingerprints(spectra)

Current FingerprintSimilarity still reads a "fingerprint" spectrum field. When that class is needed in 0.33.1, bridge the store explicitly:

for spectrum in spectra:
    fingerprint = fp_store.get_fingerprint_by_spectrum(spectrum)
    if fingerprint is not None:
        spectrum.set("fingerprint", fingerprint)
Raw lines 266 to 298
299### Installation
301Old:
303```bash
304uv pip install matchms[chemistry]
305```
307Current:
309```bash
310uv pip install "matchms==0.33.1"
311```
313The 0.33.1 package metadata has no `chemistry` extra and includes RDKit as a
314regular dependency.

Installation

Old:

uv pip install matchms[chemistry]

Current:

uv pip install "matchms==0.33.1"

The 0.33.1 package metadata has no chemistry extra and includes RDKit as a regular dependency.

Raw lines 299 to 315
316### Spectrum serialization
318Old:
320```python
321from matchms.exporting import save_as_pickle
323save_as_pickle(spectra, "spectra.pkl")
324```
326Current public pattern:
328```python
329from matchms.exporting import save_spectra
331save_spectra(spectra, "trusted-cache.pickle")
332```
334`save_as_pickle` is not exported in 0.33.1. The generic writer recognizes
335`.pickle`, not `.pkl`. Prefer portable MGF/MSP/JSON for exchanged data, and
336never load untrusted pickle.

Spectrum serialization

Old:

from matchms.exporting import save_as_pickle

save_as_pickle(spectra, "spectra.pkl")

Current public pattern:

from matchms.exporting import save_spectra

save_spectra(spectra, "trusted-cache.pickle")

save_as_pickle is not exported in 0.33.1. The generic writer recognizes .pickle, not .pkl. Prefer portable MGF/MSP/JSON for exchanged data, and never load untrusted pickle.

Raw lines 316 to 337
338### Generic I/O and overwrite behavior
340Prefer:
342```python
343from matchms.exporting import save_spectra
344from matchms.importing import load_spectra
346spectra = list(load_spectra("input.mgf"))
347save_spectra(spectra, "output.msp")
348```
350`save_spectra()` refuses an existing output unless appending MGF/MSP data.
351Direct `save_as_mgf()` and `save_as_msp()` default to append mode, so specify
352write mode explicitly when bypassing the generic writer.

Generic I/O and overwrite behavior

Prefer:

from matchms.exporting import save_spectra
from matchms.importing import load_spectra

spectra = list(load_spectra("input.mgf"))
save_spectra(spectra, "output.msp")

save_spectra() refuses an existing output unless appending MGF/MSP data. Direct save_as_mgf() and save_as_msp() default to append mode, so specify write mode explicitly when bypassing the generic writer.

Raw lines 338 to 353
354## Deprecated Compatibility Names
356Replace these even if 0.33.1 still accepts some of them:
358```text
359spectrums -> spectra
360process_spectrums() -> process_spectra()
361import_spectrums() -> import_spectra()
362spectrums_queries -> spectra_queries
363spectrums_references -> spectra_references
364```
366Do not suppress deprecation warnings globally; they are migration signals for
367the forthcoming 1.0 API.

Deprecated Compatibility Names

Replace these even if 0.33.1 still accepts some of them:

spectrums             -> spectra
process_spectrums()   -> process_spectra()
import_spectrums()    -> import_spectra()
spectrums_queries     -> spectra_queries
spectrums_references  -> spectra_references

Do not suppress deprecation warnings globally; they are migration signals for the forthcoming 1.0 API.

Raw lines 354 to 368
369## Tutorial Caveat
371The separate `matchms-docs` user-guide repository was last revised on
3722024-06-13. Its pipeline/filtering explanations remain useful, but the tutorial
373still contains examples using `ModifiedCosine` and older spelling. Prefer the
374current Read the Docs API and release notes for symbol names and signatures.

Tutorial Caveat

The separate matchms-docs user-guide repository was last revised on 2024-06-13. Its pipeline/filtering explanations remain useful, but the tutorial still contains examples using ModifiedCosine and older spelling. Prefer the current Read the Docs API and release notes for symbol names and signatures.

Raw lines 369 to 375
376## Migration Verification
378After migration:
3801. print `matchms.__version__` and confirm 0.33.1;
3812. run imports with deprecation warnings visible;
3823. inspect `processor.processing_steps`;
3834. compare spectrum counts before/after processing;
3845. print `scores.score_names`;
3856. test one known spectrum pair and one query/library search;
3867. compare old and new result rankings on a representative subset;
3878. verify serialized outputs by reopening them; and
3889. document any score changes caused by algorithm renaming, filtering, or
389 dependency updates.

Migration Verification

After migration:

  1. print matchms.__version__ and confirm 0.33.1;
  2. run imports with deprecation warnings visible;
  3. inspect processor.processing_steps;
  4. compare spectrum counts before/after processing;
  5. print scores.score_names;
  6. test one known spectrum pair and one query/library search;
  7. compare old and new result rankings on a representative subset;
  8. verify serialized outputs by reopening them; and
  9. document any score changes caused by algorithm renaming, filtering, or dependency updates.
Raw lines 376 to 389