rgakit
Python toolkit for decomposing RGA (Residual Gas Analyzer) electron-ionisation mass spectra into known compound contributions.
Developed for synchrotron beamline ALS BL12.0.1.2 to analyse gas desorption from X-ray irradiated perovskite thin films.
Features
- NNLS fitting — non-negative least-squares decomposition against a reference library
- Similarity metrics — cosine, Jaccard, Pearson, spectral entropy; pairwise matrix for clustering
- Library search — rank candidates by any similarity metric before NNLS fitting
- NIST library access — fetch and cache spectra from NIST WebBook by name or CAS
- JDX & MSP I/O — JCAMP-DX (round-trip with metadata) and NIST MSP (multi-entry files)
- Background correction — linear subtraction using beam-off windows (via
clabs) - Interactive HTML report — observed vs fitted, residual, contributions, stacked breakdown
- Smart naming — common trivial names (Water, Methane, …) with IUPAC fallback via NCI Cactus
Install
pip install rgakit
Quick start
from rgakit import MassSpectrum, SpectraLibrary, pairwise
# Build library from a folder of .jdx or .msp files
lib = SpectraLibrary.from_dir("data/jdx/")
# Load an experimental spectrum
ms = MassSpectrum.from_jdx_file("sample.jdx")
# Candidate search (cosine, jaccard, pearson, or entropy)
print(lib.search(ms, top_n=5, method="entropy"))
# NNLS fit
result = lib.fit(ms)
result.summary()
# HTML report
from rgakit import generate_report
generate_report(result, library=lib, spectrum=ms, output_path="report.html")
# Pairwise similarity matrix (for clustering / classification)
mat, names = pairwise(lib, method="cosine")
# mat is a symmetric (N, N) ndarray; use with seaborn.heatmap or UMAP
MSP format
# Load all spectra from a single NIST MSP file (multi-entry)
lib = SpectraLibrary.from_msp("nist_library.msp")
# Load one entry by index
ms = MassSpectrum.from_msp_file("nist_library.msp", index=3)
# Save a spectrum as MSP
ms.save_msp("output/water.msp")
Workflow with clabs
# Background-correct the raw RGA measurement in clabs, then extract spectrum
rga.background_correct()
ms = MassSpectrum.from_rga(rga)
ms.save_jdx("sample.jdx")
File structure
rgakit/
spectrum.py — MassSpectrum (JDX, MSP, txt I/O; compare; from_rga)
library.py — SpectraLibrary (NNLS fit, search, from_dir/from_msp)
result.py — FitResult (summary table, plot)
similarity.py — cosine / jaccard / pearson / entropy; pairwise matrix
background.py — standalone linear background correction
nomenclature.py — name resolution (common names → Cactus IUPAC → NIST)
report.py — interactive HTML report generation
Metadata
Release files for rgakit 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rgakit-0.1.1.tar.gz | 26.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rgakit-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.1 kB
Release files / rgakit-0.1.1.tar.gz
| Download URL | rgakit-0.1.1.tar.gz |
|---|---|
| Size | 26.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1ac2e6f8dc95e93f959befee61ed5b2bf82977e77cbfd02db7c0eb76f5f6e13
|
|
BLAKE2b-256 checksum How to use checksums |
b1c4002af953df72f1c014a2d722330ed29afdbeb3bcfa96ccff3a78002a5150
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.
Transparency logRelease files / rgakit-0.1.1-py3-none-any.whl
| Download URL | rgakit-0.1.1-py3-none-any.whl |
|---|---|
| Size | 28.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1048aa9009675764e2d42b6008704206d29a4b1754a7fcffc313ab41f5c121b9
|
|
BLAKE2b-256 checksum How to use checksums |
7c66be2eaf5070ff1f10d2d4229feb719bce74892b2feaacbd014bd631aa46f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.
Transparency log