Skip to main content

FragFit

A Python library for handling chemical formulas and mass spectrometry MS2 fragments.

Features

  • Calculate charged and uncharged masses
  • Handle different adducts and their effects on formulas and masses
  • Find best-fitting formulas for fragments
  • Generate all possible subformulas from a parent formula
  • Convert between formula strings and element count vectors
  • Command-line interface for common operations

Installation

pip install fragfit

Usage

Basic Mass Calculations

from fragfit import charged_mass, uncharged_mass, form_to_mz

# Calculate the mass of a charged ion
mass = charged_mass("H2O", 1)  # Water with +1 charge
print(f"Charged mass: {mass}")

# Calculate m/z value
mz = form_to_mz("C6H12O6", 1)  # Glucose with +1 charge
print(f"m/z: {mz}")

Working with Adducts

from fragfit import adduct_mass, to_adduct, from_adduct

# Calculate mass with sodium adduct
sodium_adduct_mass = adduct_mass("C6H12O6", "[M+Na]+")
print(f"Glucose with sodium adduct: {sodium_adduct_mass}")

# Get formula with adduct
sodium_adduct_formula = to_adduct("C6H12O6", "[M+Na]+")
print(f"Glucose with sodium adduct formula: {sodium_adduct_formula}")

Finding Best-Fit Fragment Formulas

from fragfit import find_best_form

# Find the best formula for a fragment
formula, mass, error = find_best_form(
    mass=180.063,
    parent_form="C10H20O10", 
    tolerance_da=0.01
)

print(f"Best formula: {formula}, Mass: {mass}, Error: {error}")

Generating All Possible Subformulas

from fragfit import generate_all_forms

# Generate all possible subformulas of glucose
all_forms = generate_all_forms("C6H12O6")
print(f"Found {len(all_forms)} possible subformulas")

Command-Line Interface

FragFit includes a command-line interface for common operations:

Finding the Best Formula for a Mass

fragfit find-formula 180.063 C10H20O10 --tolerance 0.01

Calculating Mass or m/z

# Calculate mass with adduct
fragfit calculate-mass C6H12O6 --adduct "[M+Na]+"

# Calculate m/z with charge
fragfit calculate-mass C6H12O6 --charge 1

Working with Adducts

# Add adduct to formula
fragfit adduct C6H12O6 "[M+Na]+"

# Remove adduct from formula
fragfit adduct C6H12NaO6 "[M+Na]+" --reverse

Listing All Possible Fragments

# List to stdout
fragfit list-fragments C6H12O6

# Output to CSV
fragfit list-fragments C6H12O6 --csv fragments.csv

Analyzing Mass Spec Data from a CSV File

fragfit analyze-file spec_data.csv --parent C5H11N --output results.csv

License

MIT

Author

Gabe Reder gk@reder.io

Metadata

Release files for fragfit 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fragfit 0.1.2
File Size Uploaded Provenance
fragfit-0.1.2.tar.gz 14.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fragfit 0.1.2
File Interpreter ABI Platform
fragfit-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / fragfit-0.1.2.tar.gz

Download URL fragfit-0.1.2.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
05c72b95f6b2ff6f7002a44c1e868572a7442955214904d5a6d36cb8e19d9778
BLAKE2b-256 checksum
How to use checksums
f59451b723c1c5d4d8930aebe7d8d51969d131536bfb73c39bbc74d8f6be83a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 22, 2025.

Transparency log

Release files / fragfit-0.1.2-py3-none-any.whl

Download URL fragfit-0.1.2-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29bdae219f1a54de4c6a94c645e3a0ea819d9aaa61a35b596611f3eeee4f6382
BLAKE2b-256 checksum
How to use checksums
bfdf77bdc488578bd9829d951a0d4ddbb8fccd4b75af3a13c61d7fcff6c9338c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 22, 2025.

Transparency log

Security for fragfit 0.1.2

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fragfit-0.1.2.tar.gz

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 22, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page