A lightweight version of AtomicAndPhysicalConstants.jl that provides atomic and physical constants as plain Float64 values in fixed units.
- Latest CODATA 2022 data: All physical constants from the most recent CODATA release
- No dependencies: Pure Julia with no external dependencies
- Fast compilation: Simple static constants for optimal performance
- Simple API: Easy-to-use Species struct with direct field access
- Comprehensive coverage: Subatomic particles, atoms, ions, and isotopes
- Robust parsing: Efficient atomic name parser with comprehensive error handling
| Feature | APClite | AtomicAndPhysicalConstants |
|---|---|---|
| Dependencies | None | Unitful, DynamicQuantities, etc. |
| Performance | Fast | Slower |
| Units | Plain Float64 | Unitful quantities |
| Data sources | CODATA 2022 only | Multiple years available |
| API | Direct field access | Macro-based API |
julia> using Pkg
julia> Pkg.add(url="https://github.com/ndwang/APClite")using APClite
# Access physical constants directly
C_LIGHT # 2.99792458e8 [m/s]
H_PLANCK # 6.62607015e-34 [J⋅s]
M_ELECTRON # 510998.95069 [eV/c²]
FINE_STRUCTURE # 0.0072973525643
# Create species objects
e = Species("electron")
p = Species("proton")
h = Species("H")
h_ion = Species("H+")
anti_p = Species("anti-proton")
# Access species properties (direct fields)
e.mass # 510998.95069 [eV/c²]
p.charge # 1.0 [e]
e.spin # 0.5 [ħ]
e.g_factor # g-factor (dimensionless)"electron","positron""proton","anti-proton""neutron","anti-neutron""muon","anti-muon""pion0","pion+","pion-""deuteron","anti-deuteron""photon"
- Supported elements from
"H"to"Og"
- Mass number before the atomic symbol
- Optional "#" symbol at the beginning
- If not specified, uses the average of the mass in naturally occurring samples.
julia> Species("12C")
julia> Species("#12C")- Charge number after the atomic symbol
"+"- Single positive charge (e.g.,"C+")"++"- Double positive charge (e.g.,"C++")"+n"- n positive charges (e.g.,"C+3")"n+"- n positive charges (e.g.,"C3+")"-"- Single negative charge (e.g.,"C-")"--"- Double negative charge (e.g.,"C--")"-n"- n negative charges (e.g.,"C-2")"n-"- n negative charges (e.g.,"C2-")
All constants are available as module-level constants, grouped by type:
-
Fundamental constants
C_LIGHT: Speed of light [m/s]H_PLANCK: Planck constant [J⋅s]H_BAR: Reduced Planck constant [J⋅s]E_CHARGE: Elementary charge [C]FINE_STRUCTURE: Fine structure constant (dimensionless)AVOGADRO: Avogadro constant [mol⁻¹]R_ELECTRON: Classical electron radius [m]R_PROTON: Classical proton radius [m]EPS_0: Permittivity of free space [F/m]MU_0: Permeability of free space [N/A²]
-
Particle masses [eV/c²]
M_ELECTRON: ElectronM_PROTON: ProtonM_NEUTRON: NeutronM_MUON: MuonM_PION_0: Neutral pionM_PION_CHARGED: Charged pionM_DEUTERON: DeuteronM_HELION: Helion (³He nucleus)
-
Magnetic moments [J/T]
MU_ELECTRON: ElectronMU_PROTON: ProtonMU_NEUTRON: NeutronMU_MUON: MuonMU_DEUTERON: DeuteronMU_HELION: HelionMU_TRITON: Triton
-
g-factors (dimensionless)
G_ELECTRON: ElectronG_PROTON: ProtonG_NEUTRON: NeutronG_MUON: MuonG_DEUTERON: DeuteronG_HELION: HelionG_TRITON: Triton
-
Magnetic moment anomalies (dimensionless)
ANOMALY_ELECTRON: ElectronANOMALY_MUON: Muon
-
Unit conversions
KG_PER_AMU: Kilograms per atomic mass unit [kg/amu]EV_PER_AMU: Electronvolts per atomic mass unit [eV/amu]J_PER_EV: Joules per electronvolt [J/eV]C_PER_E: Coulombs per elementary charge [C/e]
-
Release info
RELEASE_YEAR: Data release year
Species(name::String): Create a species from name- Access fields directly:
species.mass(eV/c²)species.charge(units of e)species.spin(ħ)species.moment(J/T)species.g_factor(dimensionless)species.iso(mass number)species.kind(ATOM, HADRON, LEPTON, PHOTON, NULL)species.nameornameof(species)for isotope and charge information
using APClite
# Physical constants
println("Speed of light: ", C_LIGHT, " m/s")
println("Electron mass: ", M_ELECTRON, " eV/c²")
# Create particles
electron = Species("electron")
proton = Species("proton")
hydrogen = Species("H")
carbon12 = Species("12C")
# Access properties
println("Electron charge: ", electron.charge, " e")
println("Proton mass: ", proton.mass, " eV/c²")
println("Hydrogen mass: ", hydrogen.mass, " eV/c²")
# Display species
println(electron)
println(proton)using APClite
# 1) Direct construction (no registry entry needed)
# name, charge [e], mass [eV/c^2], spin [ħ], moment [J/T], g_factor, iso, kind
custom = Species("my-hadron", 1.0, 2.5e9, 0.5, 0.0, 2.0, 0.0, HADRON)
println(custom)
# 2) Register a custom subatomic species for name-based construction
APClite.SUBATOMIC_SPECIES["X-"] = (
charge=-1.0,
mass=1e9.0,
spin=0.5,
moment=0.0,
kind=HADRON,
)
xminus = Species("X-")
println(xminus)
# 3) Register a custom atomic element (with isotopes) for name/ion/isotope parsing
APClite.ATOMIC_SPECIES["Xe"] = (
Z=54,
isotopes=Dict(129 => 120000.0, 132 => 122000.0, -1 => 121000.0),
)
xe129pp = Species("129Xe++")
println(xe129pp)