This repository contains the code for the analysis of chemical reaction kinetics using nuclear magnetic resonance (NMR) spectra and the Magnetstein algorithm.
Magnetstein is available here. To be able to use all the functionalities dedicated for the analysis of chemical reactions, make sure that you set branch to initial_proportions.
The method should be used when:
- peaks move throughout the reaction,
- peaks from different reagents overlap,
- lineshapes are distorted,
- there are contaminations and/or noise.
In such circumstances, the Magnetstein algorithm gains an advantage over the traditional integration methods due to the special properties of the Wasserstein metric that is the core concept of the method. The metric makes the algorithm robust to changes in peaks' locations and shapes, and to ambiguity in assigning signal to particular reagents due to overlap. The additional refinements make it possible for the algorithm to remove noise from the data.
The input should consist of the two crucial parts:
- mixture, i.e. a series of NMR spectra of reaction mixture measured in the consecutive moments of time,
- library, i.e. a set of spectra of individual reagents expected to be present in the mixture (no need for a series here, just a single spectrum for each reagent).
The user needs to define the values of two parameters:
If you are unsure about how to set the parameters, we recommend using the default values, i.e.
The main output of the algorithm is the series of vectors indexed by time:
where
In order to make the results reproducible, one needs to provide: 1) input data, i.e. series of spectra of the reaction mixture indexed by time, and the library; 2) information about the parameters settings, i.e. chosen values of
To be able to run the code from this repository, set your environment as in requirements.txt file. We also strongly recommend installing Gurobi and using it as a solver in the analysis.
Due to the large size of the input data, they are not stored in this repository. The data are available here. The data folder should be stored as magnetstein_x_chemical_reactions/data to ensure that all the paths are correct.
The code used for preprocessing, analysis and visualisations is available in notebooks/. To reproduce the analysis (without warm-start), use notebooks/estimation.ipynb. To run the analysis with warm-start, use notebooks/estimation_with_warm_start.ipynb.
The numerical results as well as figures are available in results/. Additional figures showing the comparison of results for different settings of parameters are available in kappa_panels/.
To compare the results from Magnetstein with other tools (Mnova and manual integration in Python), we use the data stored in mnova_integrals/ and python_integrals/.
If you use tools from this package, please cite:
Domżał, B., Nawrocka, E.K., Gołowicz, D., Ciach, M.A., Miasojedow, B., Kazimierczuk, K., & Gambin, A. (2023). Magnetstein: An Open-Source Tool for Quantitative NMR Mixture Analysis Robust to Low Resolution, Distorted Lineshapes, and Peak Shifts. Analytical Chemistry. DOI: 10.1021/acs.analchem.3c03594.