Skip to main content

RGA mass spectrum decomposition and library fitting

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rgakit-0.1.1.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rgakit-0.1.1-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file rgakit-0.1.1.tar.gz.

File metadata

  • Download URL: rgakit-0.1.1.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rgakit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e1ac2e6f8dc95e93f959befee61ed5b2bf82977e77cbfd02db7c0eb76f5f6e13
MD5 8529b5916b3e9d1e166c931050eada20
BLAKE2b-256 b1c4002af953df72f1c014a2d722330ed29afdbeb3bcfa96ccff3a78002a5150

See more details on using hashes here.

Provenance

The following attestation bundles were made for rgakit-0.1.1.tar.gz:

Publisher: publish.yml on roncofaber/rgakit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rgakit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: rgakit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rgakit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1048aa9009675764e2d42b6008704206d29a4b1754a7fcffc313ab41f5c121b9
MD5 72c5911fe793d397060ae2db4617ca5e
BLAKE2b-256 7c66be2eaf5070ff1f10d2d4229feb719bce74892b2feaacbd014bd631aa46f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rgakit-0.1.1-py3-none-any.whl:

Publisher: publish.yml on roncofaber/rgakit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page