Chemistry Basics¶
Use the chemistry helpers for molecular formulas, exact masses, isotope abundances, and predefined adduct tables.
"""Chemistry basics: formulas, isotopes, adducts, and abundances."""
import emzed
print()
# --- formula + mass basics ---
glucose = emzed.mf("C6H12O6")
glucose_mass = glucose.mass()
water = emzed.mf("H2O")
water_mass = emzed.mass.of("H2O")
dehydrated = glucose - water
dehydrated_mass = dehydrated.mass()
protonated_composition = glucose + emzed.mf("H")
protonated_mz = glucose_mass + emzed.mass.H1 - emzed.mass.e
sodium_adduct = glucose + emzed.mf("Na")
sodium_adduct_mass = sodium_adduct.mass()
c13_glucose = emzed.mf("[13]CC5H12O6")
c13_glucose_mass = c13_glucose.mass()
print("formula + mass basics:\n")
print(f"glucose: {glucose} m0={glucose_mass:.6f}")
print(f"glucose monoisotopic mass: {glucose_mass:.6f}")
print(f"water mass: {water_mass:.6f}")
print(f"glucose - water: {dehydrated} m0={dehydrated_mass:.6f}")
print(
f"[M+H]+ composition: {protonated_composition} "
f"m/z={protonated_mz:.6f} (mass uses H - electron)"
)
print(f"[M+Na]+ composition: {sodium_adduct} m0={sodium_adduct_mass:.6f}")
print(f"13C-labeled glucose: {c13_glucose} m0={c13_glucose_mass:.6f}")
print()
# --- elements + abundance basics ---
print("elements + abundance basics:\n")
print(f"carbon-12 mass: {emzed.mass.C12:.6f}")
print(f"carbon-13 abundance: {emzed.abundance.C13:.6f}")
carbon_isotopes = emzed.elements.filter(
emzed.elements.symbol == "C",
keep_view=True,
).sort_by("mass_number")
print(carbon_isotopes)
print()
print(f"O18 abundance: {emzed.abundance.O18:.6f}")
print(f"N15 abundance: {emzed.abundance.N15:.6f}")
print()
# --- adduct tables ---
print("adduct tables:")
print(emzed.adducts.positive[:5])
print()
print(emzed.adducts.single_charged[:8])
print()
# --- isotope centroids ---
print("isotope centroids of C6H12O6 (99% explained abundance):")
isotopes = emzed.chemistry.compute_centroids("C6H12O6", 0.99)
print(isotopes)
formula + mass basics:
glucose: C6H12O6 m0=180.063390
glucose monoisotopic mass: 180.063390
water mass: 18.010565
glucose - water: C6H10O5 m0=162.052825
[M+H]+ composition: C6H13O6 m/z=181.070667 (mass uses H - electron)
[M+Na]+ composition: C6H12O6Na m0=203.053160
13C-labeled glucose: [13]CC5H12O6 m0=181.066745
elements + abundance basics:
carbon-12 mass: 12.000000
carbon-13 abundance: 0.010700
atomic_number symbol name average_mass mass_number mass abundance
int str str float int float float
------------- ------ ------ ------------- ----------- ------------- ---------
6 C Carbon 12.0107358985 12 12.0000000000 0.989
6 C Carbon 12.0107358985 13 13.0033550000 0.011
O18 abundance: 0.002050
N15 abundance: 0.003680
adduct tables:
id adduct_name m_multiplier adduct_add adduct_sub z sign_z
int str int str str int int
--- ----------- ------------ ---------- ---------- --- ------
19 M+ 1 1 1
20 M+H 1 H 1 1
21 M+NH4 1 NH4 1 1
22 M+Na 1 Na 1 1
23 M+H-2H2O 1 H (H2O)2 1 1
id adduct_name m_multiplier adduct_add adduct_sub z sign_z
int str int str str int int
--- ----------- ------------ ---------- ---------- --- ------
2 M- 1 1 -1
3 M-H 1 H 1 -1
4 M-H2O-H 1 H2OH 1 -1
5 M+Na-2H 1 Na H2 1 -1
6 M+Cl 1 Cl 1 -1
7 M+K-2H 1 K H2 1 -1
8 M+KCl-H 1 KCl H 1 -1
9 M+FA-H 1 H2CO2 H 1 -1
isotope centroids of C6H12O6 (99% explained abundance):
id mf m0 abundance
int str MzType float
--- -------------------------- ----------- ---------
0 [12]C6 [1]H12 [16]O6 180.063390 0.923
1 [12]C5 [13]C [1]H12 [16]O6 181.066745 0.060
2 [12]C6 [1]H12 [16]O5 [18]O 182.067644 0.011
3 [12]C6 [1]H11 [2]H [16]O6 181.069667 0.001