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) - modifications - (z * sign * e_mass)) / n_mer)

where:
- z = number of charges
- m/z = observed mass-to-charge ratio
- iso = isotope shift (mass units)
- modifications = total mass change from adduct modifications
- sign = charge polarity (+1 or -1)
- 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.4489
# Expected: ~122.45 Da

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

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

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

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