matchms.similarity.ParentMassMatch module

class matchms.similarity.ParentMassMatch.ParentMassMatch(tolerance: float = 0.1)[source]

Bases: MetadataMatch

Return True if spectra match in parent mass, and False otherwise.

__init__(tolerance: float = 0.1)[source]
Parameters:

tolerance – Specify tolerance below which two parent masses are counted as match.

property is_structured_score: bool

Return True if this similarity uses a structured score dtype.

keep_score(score) bool

Return whether a score should be retained in sparse outputs.

This defines the default sparse retention behavior. Users can override it per call via score_filter=....

Default behavior: - scalar score: keep if score != 0 - structured score: keep if all fields are non-zero

matrix(spectra_1: Sequence[Spectrum], spectra_2: Sequence[Spectrum] | None = None, score_fields: Sequence[str] | None = None, progress_bar: bool = True) Scores

Compare metadata entries between all spectra in spectra_1 and spectra_2.

Parameters:
  • spectra_1 – First collection of input spectra.

  • spectra_2 – Second collection of input spectra. If None, compare spectra_1 against itself.

  • score_fields – Requested score fields. Only ("score",) is supported.

  • progress_bar – Included for API compatibility. Not used here because this optimized implementation does not iterate pairwise in Python.

pair(spectrum_1: Spectrum, spectrum_2: Spectrum)

Compare metadata entries between two spectra.

Parameters:
  • spectrum_1 – First spectrum.

  • spectrum_2 – Second spectrum.

score_datatype

alias of bool

sparse_matrix(spectra_1: Sequence[Spectrum], spectra_2: Sequence[Spectrum] | None = None, idx_row=None, idx_col=None, score_fields: Sequence[str] | None = None, score_filter: Callable[[ndarray], bool] | None = None, progress_bar: bool = True) Scores

Compare metadata entries and return sparse scores.

This method uses optimized metadata matching when no explicit indices are provided. If explicit idx_row and idx_col are given, it falls back to the generic sparse implementation from BaseSimilarityWithSparse.

to_dict() dict

Return a dictionary representation of the similarity function.