Calculate mass of M

Description

This function calculates the neutral mass (M) from an observed m/z value and adduct notation. It accounts for charge, multimers, isotopes, and adduct modifications.

The calculation follows the formula:
M = (|z| * (m/z - iso_shift) - modifications + z * e_mass) / n_mer

where:
- |z| = absolute number of charges
- z = signed charge (`|z| * polarity`)
- m/z = observed mass-to-charge ratio
- iso_shift = `n_iso * ISOTOPE_MASS_SHIFT_DALTONS`
- modifications = total neutral mass change from adduct modifications
- e_mass = electron mass
- n_mer = multimer count

Usage

calculate_mass_of_m(mz, adduct_string, electron_mass = ELECTRON_MASS_DALTONS)

Arguments

mz numeric Observed m/z value in Daltons. Must be positive.
adduct_string character Adduct notation string (e.g., [M+H]+, [2M+Na]+, [M-H2O+H]+)
electron_mass numeric Electron mass in Daltons (default: ELECTRON_MASS_DALTONS from constants.R - CODATA 2018 value)

Value

Numeric neutral mass (M) in Daltons. Returns 0 if: - Adduct parsing fails - Invalid input parameters - Division by zero would occur (n_mer = 0 or n_charges = 0) Returns NA if calculated mass is negative (physically impossible)

See Also

Other mass-spectrometry: calculate_mz_from_mass(), calculate_similarity(), harmonize_adducts(), import_spectra(), parse_adduct()

Examples

library("tima")

# Simple protonated molecule
calculate_mass_of_m(mz = 123.4567, adduct_string = "[M+H]+")
[1] 122.4494
# Expected: ~122.45 Da

# Sodium adduct
calculate_mass_of_m(mz = 145.4421, adduct_string = "[M+Na]+")
[1] 122.4529
# Expected: ~122.45 Da

# Complex adduct with water loss
calculate_mass_of_m(mz = 105.4467, adduct_string = "[M-H2O+H]+")
[1] 122.45
# Expected: ~122.45 Da

# Dimer
calculate_mass_of_m(mz = 245.9053, adduct_string = "[2M+H]+")
[1] 122.449
# Expected: ~122.45 Da

# Doubly charged
calculate_mass_of_m(mz = 62.2311, adduct_string = "[M+2H]2+")
[1] 122.4476
# Expected: ~122.45 Da