Abstract
This article introduces the main characteristics of PyMossFit, a software for Mössbauer spectra fitting. It is explained how each aspect of the code works. Based on the Lmfit Python package, it is a robust data fitting tool. Designed to run through Jupyter Notebook in the Google Colab cloud, it also allows one to work via multiple devices and operating systems. In addition, it allows the fitting procedure to be performed collaboratively among researchers. The software performs the folding of raw data with a discrete Fourier transform. Data smoothing is available with the use of a Savitzky–Golay algorithm. Moreover, a K-nearest neighbor algorithm enables users to determine the present phases by matching the correlations of hyperfine parameters from a local database.
1. Introduction
Mössbauer effect spectroscopy [,] is a highly specialized technique that uses the resonant absorption of rays by atomic nuclei to determine the short-range ordering in the neighborhood around the probe. The Mössbauer effect, observed primarily in isotopes such as iron-57 (), provides information about hyperfine interactions, including isomer shifts, quadrupole splittings, and magnetic hyperfine fields. These parameters offer detailed information about the electronic, magnetic, and structural environment of the sample, making the technique invaluable in materials science, condensed matter physics, chemistry, biology [], planetary science [], and cosmology []. The gamma ray of resonant absorption in nuclei amounts to 14.4 keV, and hyperfine interactions promote the breakage of degeneracy at ground and excited nuclear levels. The above-cited parameters are described in the following subsections.
1.1. Isomer Shift, or
This phenomenon corresponds to the probability that electrons are present inside the nucleus []—an exclusive quantum event. The following equation describes this parameter:
where , are the s-wavefunctions at the origin of the absorbent (A) and the -ray source (S) nucleus, while is the relative nuclear radius R change during recoilless resonant absorption.
1.2. Quadrupole Splitting, or
This quantum effect accounts for the interaction of a nucleus having a quadrupole moment with an electric field gradient (EFG) originating in an asymmetric electronic orbital distribution. The analytical expression is
with being Q the quadrupolar moment, the principal component of the EFG, and the asymmetric factor.
1.3. Magnetic Hyperfine Field,
When the nuclear spin is coupled with the quantum orbital moment, a total moment can interact with the local magnetic field induced by the electronic orbitals, giving rise to more complex splitting (Zeeman effect) and, according to the nuclear selection rules, some forbidden transitions. Consequently, certain decays by -ray emission are not physically possible.
Figure 1 shows the energy level schemes of all these hyperfine interactions for the isotope. As can be observed, IS is associated with shifts in the excited and ground energy levels, the energy of which differs between the source nucleus and the sample; meanwhile, QS arises due to the splitting of the excited level, while is the same in both the ground and the excited levels. The and transitions correspond to zero-intensity ones. The selection rules for gamma transitions ( magnetic dipole transition) are . In the case mentioned, and correspond to , which are forbidden transitions.
Figure 1.
Energy level schemes for corresponding to (i) isomer shift (IS, in blue), (ii) quadrupole splitting (QS, in red), and (iii) hyperfine field splitting, with all allowed transitions (magnetic Zeeman effect field, , in green).
In a typical Mössbauer experiment, a radioactive source emits gamma rays, which are absorbed by the nuclei in the sample (see Figure 2). Resonant absorption occurs when rays hit the probe in a recoilless manner. The detector measures the intensity of the transmitted radiation as a function of the velocity of the gamma ray source (with additional energy added by the Doppler effect). This results in a Mössbauer spectrum, typically characterized by sharp peaks or dips at resonance frequencies corresponding to different hyperfine interactions within the sample. The most common experimental setup corresponds to transmission geometry (in this case, the observed lines come from a reduction of 14.4 keV gamma counting in the detector, as compared to the background signal). Another possible option is backscattering Mössbauer spectroscopy (BMS), which corresponds to the detection of the backward gamma resonance scattering of gamma rays and is recorded as in the case of the Mössbauer spectrometer onboard the Mars Opportunity Rover. In recent years, the use of synchrotron radiation has been extended, helping to collect Mössbauer spectra with greater detail and in a short period of time [].
Figure 2.
Scheme of a typical Mössbauer experiment in transmission geometry.
1.4. Statement of Need
Recently, in a review by Grandjean et al. [], the authors provided a series of suggestions about how successful measurements should be taken, which could be beneficial for Mössbauer data treatment and the presentation of the corresponding fitting. Usually, scientists working with Mössbauer spectroscopy manage their data and fit them with non-open-source software that is run on a Windows OS with poor upgrade services [,]. The need for an open-source option with reduced OS or package dependency motivated this work.
In this context, Google Colab is a useful tool for a collaborative team working in data analysis, with the advantage of no additional packages being locally installed. It also allows the user to run their codes from multiple devices.
2. Mössbauer Spectra and Curve Shapes
The shape of a Mössbauer spectrum varies depending on the nature of the hyperfine interactions in the sample. For example, a simple paramagnetic material might produce a single absorption peak (Lorentzian or Gaussian) due to the isomer shift. Materials with quadrupole splitting generate a doublet (two peaks), while materials experiencing magnetic hyperfine interactions often exhibit more complex sextet patterns. These spectral features often overlap, making it difficult to isolate and quantify each individual component.
Curve Fitting and Least Squares Method
Curve fitting plays a crucial role in Mössbauer spectral analysis, as it allows for the decomposition of these complex spectra into individual contributions, each associated with specific hyperfine parameters. The challenge lies in accurately reproducing the spectral shapes using mathematical models and adjusting the parameters until a satisfactory fit is achieved.
To accurately extract physical parameters from Mössbauer spectra, fitting procedures are applied to the experimental data. One of the most common approaches is the least squares method, which minimizes the difference between the experimental data points and the theoretical model curve. The objective is to adjust the parameters of the theoretical model (such as isomer shift, quadrupole splitting, and line broadening) so that the calculated spectrum fits the experimental data as closely as possible. Then, the minimization of is defined as
with being a set of selected parameters for fitting that minimize the distance between the experimental data and the modeled data points .
In Python 3, this process can be implemented using libraries like Lmfit [], SciPy [], or NumPy [], which provide robust tools for data processing, graphics, and least squares curve fitting. The general approach involves defining a model function that represents the expected shape of the Mössbauer spectrum, which could be a sum of multiple Lorentzian or Gaussian functions, depending on the number and types of spectral components. Lorentzian functions are preferred with crystalline samples, whereas PseudoVoigts (the sum of Lorentzian and Gaussian functions) are appropriate for Fe sites in disordered materials.
The least squares fitting algorithm iteratively adjusts the model parameters until the sum of squared residuals between the experimental and calculated spectra is minimized. An example of a Lorentzian function definition for Python is shown below.
from scipy.optimize import curve_fit
import numpy as np
# Define the model function (e.g., a sum of Lorentzian components)
def lorentzian(x, amplitude, center, width):
return amplitude * (width**2 / ((x - center)**2 + width**2))
# Generate synthetic data for fitting
x_data = np.linspace(-10, 10, 500) # Example velocity range
y_data = lorentzian(x_data, 1, 0, 1) + np.random.normal(0, 0.02,
size=len(x_data))
# Perform least-squares curve fitting
initial_guess = [1, 0, 1] # Initial guess for parameters
params, covariance = curve_fit(lorentzian, x_data, y_data,
p0 = initial_guess)
# params contains the optimized parameters: amplitude, center,
and width
This example demonstrates the fitting of a single Lorentzian function to synthetic data, although more complex models involving sums of Lorentzians or other spectral shapes can be implemented to represent real Mössbauer spectra.
3. Description of the Python Code for Google Colab (PyMossFit)
The Python code is available in Jupyter Notebook together with a user manual []. Selected parts of the code are described in this section.
The code is structured in three cells. The first includes installation in the Google Colab environment of Lmfit, the core environment for data fitting. Moreover, it imports some packages from Scipy, Pandas, Matplotlib, and Numpy, among others. The next step includes a Drive connection that asks the user for permission.
The second cell reads the datafile (the format should be inspected in advance to define the “delimiter”, “columns”, and “skiprows” parameters). The required inputs are the date (in YYYYMMDD format) and the maximum velocity associated with the extreme channels in order to define the velocity scale.
In this cell, spectrum folding is performed with a discrete Fourier transform (DFT) routine, namely Numpy fft. The theory of this procedure corresponds to the Nyquist–Shannon sampling theorem, which helps to determine a folding channel from the symmetry of discrete Fourier spectra [].
Data can also be smoothed using a Savitzky–Golay package (we use savgol from Scipy). After folding, a new datafile is saved for fitting with the use of the next cell.
The following figures illustrate partial examples of data management with this procedure. This spectrum corresponds to zinc ferrite nanoparticles obtained by a wet chemical method [], which present a spinel structure with a tetrahedral site for and a octahedral site for both and cations.
When raw data are plotted, they appear as shown in Figure 3 because of the collection of absorption resonances converted to signals in a single-channel analyzer output, while the source moves back and forth. Figure 4 and Figure 5 show the DFT plot and the final folded spectrum, respectively. In the final folded spectrum, the horizontal sequence of channels was transformed to the scale based on calibration with a metallic thin foil sample.
Figure 3.
Unfolded plot of raw Mössbauer experimental data.
Figure 4.
Discrete Fourier transform of the raw Mössbauer experimental data plotted in the previous figure.
Figure 5.
Final folded spectrum.
The fitting procedure starts when we run the third cell. The dynamic model is built by adding the number of needed singlets, doublets, and/or sextets. The set of physical parameters, such as the linewidth (), isomer shift (IS), quadrupole splitting (QS), and magnetic hyperfine field (), is also requested and calculated after adjusting the amplitude (a), full width at half maximum (b), centroid (m), line shift (d), and line separation (q). The initial set of these parameters can be fitted or fixed by selecting the “True” or “False” options, respectively.
A typical fit report for the output of this cell is in Figure 6.
Figure 6.
An example of a fit report output from Jupyter Notebook v.7 in Google Colab.
Finally, the code saves the fitted parameters and the experimental and modeled sub-spectra in CSV-formatted output files.
3.1. Some Examples
The following figures illustrate the fit results obtained from the Mössbauer spectra of different samples. Each exhibits several characteristics corresponding to the short-range-order neighborhood of probes. Figure 7 corresponds to the fitted spectrum of an aged cathodic material (LFP), where iron-rich secondary phases can clearly be identified. These undesired phases, which are responsible for the lowering of the storage capacity, were precipitated after extended thermal and environmental degradation. The fitting procedure took less than 40 s after the appropriate selection of the parameters.
Figure 7.
Mössbauer spectrum of a degraded commercial active material for batteries. Residual phases were detected, such as and . The latter phase shows the presence of in two different oxidation states, and , respectively. Black crosses correspond to experimental data, red line to fitted model. Rest of coloured lines, model’s sub components (singlet, doublet or sextet, as appropriate).
In contrast, Figure 8 shows the spectrum of a pure LFP sample that was synthesized by a solid-state reaction from analytical-grade precursors.
Figure 8.
Mössbauer spectrum of active material for batteries after synthesis at lab scale. In this case, only was detected, as well as showing the extraordinary sensitivity of the characterization technique. Black crosses correspond to experimental data, red line to fitted model. Rest of coloured lines, model’s sub components (singlet, doublet or sextet, as appropriate).
Figure 9 corresponds to the fitted spectrum obtained with PyMossFit for a soil sample taken by the Mössbauer spectrometer onboard the Mars Opportunity Rover. The data are available in [], and this set is named the “Bounce Rock Case” (B0RR067). The iron-rich detected phase was identified with the code and corresponds to the pyroxene phase (), with two different octahedral Fe sites, M1 and M2, respectively [,].
Figure 9.
BMS spectrum of pyroxene in Mars soil (Opportunity Mission, September 2004, T = 240–260 K). The sub-spectra correspond to two different sites, M1 and M2, typically found in pyroxene. Black crosses correspond to experimental data, red line to fitted model. Rest of coloured lines, model’s sub components (singlet, doublet or sextet, as appropriate).
The final example of the use of the PyMossFit notebook can be observed in Figure 10, which shows the spectrum of an Iguazú Falls soil sample. It corresponds to a complex spectrum where the use of a combination of sextets, doublets, and a singlet was required. All these sub-spectra correspond to different characteristics of iron oxides and hydroxides present in this type of soil, originating from the erosion of basalt rocks.
Figure 10.
Mössbauer spectra of an Iguazú Falls soil sample (Argentina–Brazil border). Black crosses correspond to experimental data, red line to fitted model. Rest of coloured lines, model’s sub components (singlet, doublet or sextet, as appropriate).
3.2. Matching of Fitted Parameters with a Local Database
A final cell allows the identification of the phases from the user’s own database or a public one []. This procedure is based on the minimization of the Euclidean distances of the set of parameters with the bibliographic collection, which can be updated or extended by the user. Some lines that reflect ranges of hyperfine parameters from the database are also included. The phases cited in the examples above were identified or verified using this code section.
The machine learning algorithm used to estimate the present phases is based on a K-nearest neighbors algorithm (sklearn.neighbors) []. The output is a recommendation with the ranking of suggested phases that exhibit the best match. Figure 11 is a match report.
Figure 11.
A match report obtained with a KNN algorithm for phase identification.
4. Conclusions
PyMossFit is a tool for Mössbauer spectroscopy analysis that extends cloud computing. It was coded in Python and run on Jupyter Notebook. The code requires the installation of the Lmfit package as the core component for model fitting. PyMossFit was designed to work in the Python environment within cloud computing services such as Google Colab, being a good choice for user updates, free from OS and device dependencies. Moreover, it simplifies collaborative work during spectra analysis, with the addition of a code section for phase identification based on a KNN algorithm.
Funding
This research received no external funding.
Institutional Review Board Statement
Not applicable.
Informed Consent Statement
Not applicable.
Data Availability Statement
The original contributions presented in this study are included in the article. Further inquiries can be directed to the corresponding author.
Acknowledgments
The author thanks C.P. Ramos from the Mössbauer group of CNEA and the INTECIN (UBA-CONICET) team for sample measurement.
Conflicts of Interest
The authors declare no conflicts of interest.
References
- Gütlich, P. Fifty Years of Mössbauer Spectroscopy in Solid State Research—Remarkable Achievements, Future Perspectives. Z. Anorg. Allg. Chem. 2012, 638, 15–43. [Google Scholar] [CrossRef]
- Zhang, T.; Wang, J. The Mössbauer Effect Data Center. Available online: https://medc.dicp.ac.cn/ (accessed on 25 October 2025).
- Martinho, M.; Münck, E. 57Fe Mössbauer Spectroscopy in Chemistry and Biology. In Physical Inorganic Chemistry; John Wiley and Sons, Ltd.: Hoboken, NJ, USA, 2010; Chapter 2; pp. 39–67. [Google Scholar] [CrossRef]
- Dyar, M.D.; Agresti, D.G.; Schaefer, M.W.; Grant, C.A.; Sklute, E.C. Mössbauer spectroscopy of earth and planetary materials. Annu. Rev. Earth Planet. Sci. 2006, 34, 83–125. [Google Scholar] [CrossRef]
- Gao, Y.; Xu, W.; Zhang, H. A Mössbauer scheme to probe gravitational waves. Sci. Bull. 2024, 69, 2795–2798. [Google Scholar] [CrossRef] [PubMed]
- Walker, L.R.; Wertheim, G.K.; Jaccarino, V. Interpretation of the Fe57 Isomer Shift. Phys. Rev. Lett. 1961, 6, 98–101. [Google Scholar] [CrossRef]
- Chen, Y.-L.; Yang, D.-P. Synchrotron Mössbauer Spectroscopy. In Mössbauer Effect in Lattice Dynamics; John Wiley and Sons, Ltd.: Hoboken, NJ, USA, 2007; Chapter 7; pp. 253–304. [Google Scholar] [CrossRef]
- Grandjean, F.; Long, G.J. Best Practices and Protocols in Mössbauer Spectroscopy. Chem. Mater. 2021, 33, 3878–3904. [Google Scholar] [CrossRef]
- Lagarec, K.; Rancourt, D.G. RECOIL, Mössbauer Spectral Analysis Software for Windows, Version 1.0; University of Ottawa: Ottawa, ON, Canada, 1998. [Google Scholar]
- Klencsár, Z.; Kuzmann, E.; Vértes, A. User-friendly software for Mössbauer spectrum analysis. J. Radioanal. Nucl. Chem. 1996, 210, 105–118. [Google Scholar] [CrossRef]
- Newville, M.E.A. LMFIT: Non-Linear Least-Squares Minimization and Curve-Fitting for Python, version 1.3.4; Zenodo: Geneva, Switzerland, 2025. [Google Scholar] [CrossRef]
- Virtanen, P.; Gommers, R.; Oliphant, T.E.; Haberland, M.; Reddy, T.; Cournapeau, D.; Burovski, E.; Peterson, P.; Weckesser, W.; Bright, J.; et al. SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python. Nat. Methods 2020, 17, 261–272. [Google Scholar] [CrossRef] [PubMed]
- Harris, C.R.; Millman, K.J.; van der Walt, S.J.; Gommers, R.; Virtanen, P.; Cournapeau, D.; Wieser, E.; Taylor, J.; Berg, S.; Smith, N.J.; et al. Array programming with NumPy. Nature 2020, 585, 357–362. [Google Scholar] [CrossRef] [PubMed]
- Saccone, F.D. Fitting Code for Mössbauer Spectroscopy Running in Jupyter Colab; Zenodo: Geneva, Switzerland, 2025. [Google Scholar] [CrossRef]
- Kong, Q.; Siauw, T.; Bayen, A. Discrete Fourier Transform (DFT). 2020. Available online: https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter24.02-Discrete-Fourier-Transform.html (accessed on 25 October 2025).
- Ferrari, S.; Apehesteguy, J.C.; Saccone, F.D. Structural and magnetic properties of Zn doped magnetite nanoparticles obtained by wet chemical method. IEEE Trans. Magn. 2015, 51, 2900206. Available online: https://ieeexplore.ieee.org/document/6975229/ (accessed on 25 October 2025). [CrossRef]
- Opportunity (MERB) Analyst’s Notebook. 2025. Available online: https://an.rsl.wustl.edu/merb/AN/an3.aspx (accessed on 25 October 2025).
- Corke, P.; Haviland, J. Mössbauer mineralogy of rock, soil, and dust at Meridiani Planum, Mars: Opportunity’s journey across sulfate-rich outcrop, basaltic sand and dust, and hematite lag deposits. J. Geophys. Res. Planets 2006, 111. [Google Scholar] [CrossRef]
- Oshtrakh, M.I.; Petrova, E.; Grokhovsky, V. Determination of quadrupole splitting for 57Fe in M1 and M2 sites of both olivine and pyroxene in ordinary chondrites using Mössbauer spectroscopy with high velocity resolution. Hyperfine Interact. 2007, 177, 65–71. [Google Scholar] [CrossRef]
- Tao, W.; Junhu, Z. Mössbauer Effect Data Reference Journal. Available online: https://merdj.dicp.ac.cn/indexen.htm (accessed on 25 October 2025).
- Cover, T.; Hart, P. Nearest neighbor pattern classification. IEEE Trans. Inf. Theory 1967, 13, 21–27. [Google Scholar] [CrossRef]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).