matchms.exporting.save_as_mgf module

matchms.exporting.save_as_mgf.save_as_mgf(spectrums: List[Spectrum] | Spectrum, filename: str, export_style: str = 'matchms')[source]

Save spectrum(s) as mgf file.

losses of spectrum will not be saved.

Example:

import numpy as np
from matchms import Spectrum
from matchms.exporting import save_as_mgf

# Create dummy spectrum
spectrum = Spectrum(mz=np.array([100, 200, 300], dtype="float"),
                    intensities=np.array([10, 10, 500], dtype="float"),
                    metadata={"charge": -1,
                              "inchi": '"InChI=1S/C6H12"',
                              "precursor_mz": 222.2})

# Write spectrum to test file
save_as_mgf(spectrum, "test.mgf")
Parameters:
  • spectrums – Expected input are match.Spectrum.Spectrum() objects.

  • filename – Provide filename to save spectrum(s).

  • export_style – Converts the keys to the required export style. One of [“matchms”, “massbank”, “nist”, “riken”, “gnps”]. Default is “matchms”