epyr.physics module
The epyr.physics package collects CODATA 2022 physical constants, EPR/NMR
unit conversions, and a general-purpose unitconvert() interface.
It replaces the legacy flat epyr.constants module. For backwards
compatibility, epyr.constants is still importable and resolves to
epyr.physics.constants.
Overview
epyr.physics.constants– fundamental constants in SI and CGS (GFREE,BMAGN,PLANCK,HBAR,CLIGHT,BOLTZM,NMAGN,ECHARGE,EVOLT, plus*_CGSvariants and callable accessors for backwards compatibility).epyr.physics.conversions– direct frequency/field conversions (mhz_to_mt,mt_to_mhz,cm_inv_to_mhz,mhz_to_cm_inv) and pre-formatted lookup tables.epyr.physics.units– a generalunitconvert(value, from, to)interface backed by the conversion functions.
Constants
Physical constants for EPR/NMR spectroscopy All values from 2022 CODATA recommendations with proper units and uncertainties Constants available in both SI and CGS units.
- epyr.physics.constants.gfree(return_uncertainty=False)[source]
Free electron g-factor (dimensionless).
Parameters:
- return_uncertaintybool
If True, return (value, standard_uncertainty)
Returns:
- float or tuple
Free electron g-factor (dimensionless)
References:
2022 CODATA recommended values
- epyr.physics.constants.bmagn(return_uncertainty=False)[source]
Bohr magneton in SI units (J T⁻¹).
Parameters:
- return_uncertaintybool
If True, return (value, standard_uncertainty)
Returns:
- float or tuple
Bohr magneton in J T⁻¹
References:
2022 CODATA recommended values
- epyr.physics.constants.planck()[source]
Planck constant in SI units (J⋅s = J⋅Hz⁻¹).
Returns:
- float
Planck constant in J⋅s
References:
2019 SI redefinition, exact value
- Return type:
- epyr.physics.constants.hbar()[source]
Reduced Planck constant ℏ = h/(2π) in SI units (J⋅s).
Returns:
- float
Reduced Planck constant in J⋅s
- Return type:
- epyr.physics.constants.clight()[source]
Speed of light in vacuum in SI units (m⋅s⁻¹).
Returns:
- float
Speed of light in m⋅s⁻¹
References:
1983 SI redefinition, exact value
- Return type:
- epyr.physics.constants.boltzm(return_uncertainty=False)[source]
Boltzmann constant in SI units (J⋅K⁻¹).
Parameters:
- return_uncertaintybool
If True, return (value, standard_uncertainty)
Returns:
- float or tuple
Boltzmann constant in J⋅K⁻¹
References:
2019 SI redefinition, exact value
- epyr.physics.constants.avogadro(return_uncertainty=False)[source]
Avogadro constant in SI units (mol⁻¹).
Parameters:
- return_uncertaintybool
If True, return (value, standard_uncertainty)
Returns:
- float or tuple
Avogadro constant in mol⁻¹
References:
2019 SI redefinition, exact value
- epyr.physics.constants.nmagn(return_uncertainty=False)[source]
Nuclear magneton in SI units (J⋅T⁻¹).
Parameters:
- return_uncertaintybool
If True, return (value, standard_uncertainty)
Returns:
- float or tuple
Nuclear magneton in J⋅T⁻¹
References:
2022 CODATA recommended values
- epyr.physics.constants.echarge(return_uncertainty=False)[source]
Elementary charge in SI units (C).
Parameters:
- return_uncertaintybool
If True, return (value, standard_uncertainty)
Returns:
- float or tuple
Elementary charge in C
References:
2019 SI redefinition, exact value
- epyr.physics.constants.evolt(return_uncertainty=False)[source]
Electron volt in SI units (J).
Parameters:
- return_uncertaintybool
If True, return (value, standard_uncertainty)
Returns:
- float or tuple
Electron volt in J
References:
2019 SI redefinition, exact value (e × 1V)
- epyr.physics.constants.gamma_hz(g_factor=None)[source]
Calculate gyromagnetic ratio in Hz/T for any g-factor.
The gyromagnetic ratio relates frequency to magnetic field: ν = γ B where γ = g μ_B / h
Parameters:
- g_factorfloat, optional
g-factor (defaults to free electron g-factor)
Returns:
- float
Gyromagnetic ratio in Hz/T
Examples:
>>> # Free electron gyromagnetic ratio >>> gamma_e = gamma_hz() >>> print(f"Free electron: {gamma_e:.3e} Hz/T")
>>> # Custom g-factor >>> gamma_custom = gamma_hz(2.005) >>> print(f"g=2.005: {gamma_custom:.3e} Hz/T")
>>> # Calculate resonance frequency >>> B = 0.34 # Tesla (X-band field) >>> freq = gamma_hz() * B >>> print(f"X-band frequency: {freq/1e9:.2f} GHz")
- epyr.physics.constants.magnetic_field_to_frequency(B_tesla, g_factor=None)[source]
Convert magnetic field to resonance frequency.
Uses the fundamental EPR/NMR relation: ν = γB = gμ_B B/h
Parameters:
- B_teslafloat
Magnetic field in Tesla
- g_factorfloat, optional
g-factor (defaults to free electron g-factor)
Returns:
- float
Resonance frequency in Hz
Examples:
>>> # X-band EPR at ~9.5 GHz >>> B = 0.34 # Tesla >>> freq = magnetic_field_to_frequency(B) # Hz >>> print(f"Frequency: {freq/1e9:.2f} GHz")
- epyr.physics.constants.frequency_to_magnetic_field(freq_hz, g_factor=None)[source]
Convert frequency to magnetic field.
Parameters:
- freq_hzfloat
Frequency in Hz
- g_factorfloat, optional
g-factor (defaults to free electron g-factor)
Returns:
- float
Magnetic field in Tesla
Examples:
>>> # What field for 9.5 GHz EPR? >>> freq = 9.5e9 # Hz >>> B = frequency_to_magnetic_field(freq) >>> print(f"Magnetic field: {B*1000:.1f} mT")
- epyr.physics.constants.thermal_energy(temperature_k)[source]
Thermal energy k_B T at given temperature.
Parameters:
- temperature_kfloat
Temperature in Kelvin
Returns:
- float
Thermal energy in J
Examples:
>>> # Room temperature thermal energy >>> E_thermal = thermal_energy(295) # K >>> print(f"kT = {E_thermal/(1.602176634e-19):.3f} meV")
- epyr.physics.constants.wavelength_to_frequency(wavelength_m)[source]
Convert wavelength to frequency.
Parameters:
- wavelength_mfloat
Wavelength in meters
Returns:
- float
Frequency in Hz
Examples:
>>> # 3 cm microwave wavelength >>> freq = wavelength_to_frequency(0.03) # m >>> print(f"Frequency: {freq/1e9:.1f} GHz")
Conversions
Direct conversion functions for EPR spectroscopy
Provides simple, direct conversion functions between common EPR units: MHz, mT, cm-1, and related energy/field conversions.
- epyr.physics.conversions.mhz_to_mt(frequency_mhz, g_factor=None)[source]
Convert frequency in MHz to magnetic field in mT.
Uses the fundamental EPR relation: B = h*nu / (g*mu_B)
Parameters:
- frequency_mhzfloat or array
Frequency in MHz
- g_factorfloat or array, optional
g-factor (defaults to free electron g-factor = 2.002319…)
Returns:
- float or array
Magnetic field in mT
Examples:
>>> # X-band EPR frequency >>> field = mhz_to_mt(9500) # 9.5 GHz >>> print(f"Field: {field:.1f} mT")
>>> # Different g-factors >>> fields = mhz_to_mt(9500, g_factor=[2.000, 2.005, 2.010]) >>> print(f"Fields: {fields}")
- epyr.physics.conversions.mt_to_mhz(field_mt, g_factor=None)[source]
Convert magnetic field in mT to frequency in MHz.
Uses the fundamental EPR relation: nu = g*mu_B*B / h
Parameters:
- field_mtfloat or array
Magnetic field in mT
- g_factorfloat or array, optional
g-factor (defaults to free electron g-factor = 2.002319…)
Returns:
- float or array
Frequency in MHz
Examples:
>>> # What frequency for 340 mT field? >>> freq = mt_to_mhz(340) >>> print(f"Frequency: {freq:.1f} MHz")
>>> # Array of fields >>> freqs = mt_to_mhz([100, 200, 300, 400]) >>> print(f"Frequencies: {freqs}")
- epyr.physics.conversions.cm_inv_to_mhz(wavenumber_cm_inv)[source]
Convert wavenumber in cm^-1 to frequency in MHz.
Uses the relation: nu = c * wavenumber where c is the speed of light.
Parameters:
- wavenumber_cm_invfloat or array
Wavenumber in cm^-1
Returns:
- float or array
Frequency in MHz
Examples:
>>> # Convert 1000 cm^-1 to MHz >>> freq = cm_inv_to_mhz(1000) >>> print(f"Frequency: {freq:.3e} MHz")
>>> # Array conversion >>> freqs = cm_inv_to_mhz([100, 500, 1000, 2000]) >>> print(f"Frequencies: {freqs}")
- epyr.physics.conversions.mhz_to_cm_inv(frequency_mhz)[source]
Convert frequency in MHz to wavenumber in cm^-1.
Uses the relation: wavenumber = nu / c where c is the speed of light.
Parameters:
- frequency_mhzfloat or array
Frequency in MHz
Returns:
- float or array
Wavenumber in cm^-1
Examples:
>>> # Convert 30000 MHz (30 GHz) to cm^-1 >>> wn = mhz_to_cm_inv(30000) >>> print(f"Wavenumber: {wn:.3f} cm^-1")
>>> # Array conversion >>> wns = mhz_to_cm_inv([1000, 5000, 10000, 30000]) >>> print(f"Wavenumbers: {wns}")
- epyr.physics.conversions.frequency_field_conversion_table(frequencies_ghz=None, g_factors=None)[source]
Log a frequency-vs-field conversion table for common EPR bands.
- Parameters:
- Returns:
Output goes through the module logger; nothing is returned.
- Return type:
None
Examples
>>> from epyr.physics import frequency_field_conversion_table >>> frequency_field_conversion_table(frequencies_ghz=[9.5]) # X-band only
- epyr.physics.conversions.energy_conversion_table(energies_cm_inv=None)[source]
Log an energy conversion table covering cm⁻¹, MHz, GHz, eV, K, meV.
- Parameters:
energies_cm_inv (list of float, optional) – Wavenumbers in cm⁻¹. Default
[1, 10, 100, 1000, 5000, 10000], covering the typical EPR / zero-field-splitting range.- Return type:
None
Examples
>>> from epyr.physics import energy_conversion_table >>> energy_conversion_table(energies_cm_inv=[1, 1000])
Units
Unit conversion utilities for EPR/NMR spectroscopy
Converts between common spectroscopic units: cm⁻¹, eV, K, mT, MHz All conversions use 2022 CODATA physical constants for accuracy.
- epyr.physics.units.unitconvert(value, units, g_factor=None)[source]
Convert between spectroscopic units.
Supported conversions: - cm⁻¹ ↔ eV, K, mT, MHz - eV ↔ cm⁻¹, K, mT, MHz - K ↔ cm⁻¹, eV, mT, MHz - mT ↔ cm⁻¹, eV, K, MHz - MHz ↔ cm⁻¹, eV, K, mT
- Parameters:
- Returns:
Converted value(s)
- Return type:
float or array
Examples
>>> # Convert wavenumbers to frequency >>> freq = unitconvert(1000, 'cm^-1->MHz') # 1000 cm⁻¹ to MHz >>> print(f"{freq:.3f} MHz")
>>> # Convert with custom g-factor >>> field = unitconvert(100, 'cm^-1->mT', g_factor=2.005) >>> print(f"{field:.2f} mT")
>>> # Vector conversion >>> energies = np.array([100, 200, 300]) # cm⁻¹ >>> temps = unitconvert(energies, 'cm^-1->K') >>> print(f"Temperatures: {temps}")
Usage Examples
Constants
from epyr.physics import PLANCK, BMAGN, GFREE
# Compute the resonance frequency at B = 0.335 T with g = g_e
B = 0.335 # Tesla
nu = GFREE * BMAGN * B / PLANCK
print(f"EPR frequency: {nu / 1e9:.3f} GHz") # ~9.4 GHz
Field/frequency conversion
from epyr.physics import mhz_to_mt, mt_to_mhz
# X-band
B_mT = mhz_to_mt(9500, g_factor=2.0023)
print(f"X-band field for g=g_e: {B_mT:.1f} mT") # ~339 mT
# Reverse direction
nu_MHz = mt_to_mhz(339.0, g_factor=2.0023)
print(f"{nu_MHz / 1000:.2f} GHz")
Energy unit cheat-sheet
from epyr.physics import energy_conversion_table
# Print cm^-1 / MHz / GHz / eV / K / meV mapping for typical ZFS values
energy_conversion_table(energies_cm_inv=[1, 10, 100])
g-factor from EPR parameters
from epyr.physics import PLANCK, BMAGN
nu_Hz = 9.4e9 # X-band microwave frequency
B_T = 3350e-4 # resonance field, Tesla (3350 G)
g = PLANCK * nu_Hz / (BMAGN * B_T)
print(f"g = {g:.6f}") # ~2.003
Nuclear isotope data
Nuclear properties (spin, abundance, magnetogyric ratio) are not stored in
epyr.physics. They live in epyr/sub/isotopedata.txt (EasySpin
format) and are surfaced by the interactive GUI documented at
epyr.isotope_gui module.