API Reference

Complete index of the exported symbols, followed by the internal types they refer to.

Species type and constructor

AtomicAndPhysicalConstants.Species — Type
Species(speciesname::String)
Species()

Construct a particle species by name, or a null placeholder with no arguments.

The string format encodes particle identity, isotope (for atoms), and charge state in one expression: [mass_number] symbol [charge].

Subatomic particles

Pass the openPMD name exactly:

NameParticle
"electron" / "positron"electron / positron
"proton" / "anti-proton"proton / antiproton
"neutron" / "anti-neutron"neutron / antineutron
"muon" / "anti-muon"muon / antimuon
"pion0" / "pion+" / "pion-"pions
"deuteron" / "anti-deuteron"deuteron / antideuteron
"triton" / "anti-triton"triton / antitriton
"helion" / "anti-helion"helion / antihelion
"photon"photon

Atomic species

Atomic symbols "H" (Z=1) through "Og" (Z=118) are supported.

Mass number — give it before the atomic symbol, either as ASCII digits prefixed with # or as Unicode superscript digits: "#4He" or "⁴He". A bare ASCII mass number such as "4He" is not accepted. Without a mass number the abundance-averaged mass is used; an element with no stable isotopes has no standard atomic weight, so for those (Tc, Pm, and Po onward, apart from Th, Pa, and U) a mass number is required and "Po" alone is an error.

Charge state — append after the symbol. Repeated signs ("++", "---") or "+n" / "-n" notation are both accepted.

Species("#4He")     # helium-4, neutral (# prefix required for ASCII digits)
Species("⁴He")      # same, Unicode superscript
Species("Li+3")     # lithium, charge +3
Species("Li+++")    # same
Species("K-2")      # potassium, charge −2

Anti-atoms: prepend "anti-" to any atomic symbol.

Species("anti-H")   # antihydrogen

Null species: Species(), or names "Null", "null", "".

Fields

FieldTypeDescription
nameStringParticle name or atomic symbol
chargeFloat64Net charge in units of e
massFloat64Rest mass in eV/c²
spinFloat64Spin in ħ; for an atom the nuclear spin, NaN if undefined
gspinFloat64Signed spin g-factor (0 for atoms); g_spin returns its absolute value by default
momentFloat64Magnetic dipole moment in eV/T (0 for atoms)
isoIntMass number; −1 for abundance average; 0 for subatomic particles
kindKind.TLEPTON, HADRON, PHOTON, ATOM, or NULL

Direct field access is disabled. Use chargeof, massof, spinof, g_spin, momentof, iso_of, atomicnumberof, kindof, isnullspecies, Base.nameof.

source

Accessor functions

The Species page describes the unit conventions these follow and what each one returns for a species that does not carry the property.

Base.nameof — Method
nameof(species::Species) -> String

Return the canonical name of species.

For subatomic particles the openPMD name is returned unchanged. For atomic species the name is assembled from the atomic symbol, mass number (if a specific isotope was requested), and charge state, using the #mAS±c convention:

julia> nameof(Species("electron"))
"electron"

julia> nameof(Species("#4He+2"))
"#4He+2"

julia> nameof(Species("Li+"))      # the charge is always spelled out
"Li+1"

julia> nameof(Species("anti-#4He"))
"anti-#4He"
source
AtomicAndPhysicalConstants.chargeof — Function
chargeof(species::Species; C::Bool = false) -> Float64

Return the net charge of species.

By default the charge is returned as a (whole-numbered) multiple of the elementary charge e. Pass C = true to convert to coulombs using the active E_CHARGE constant.

Examples

julia> chargeof(Species("proton"))
1.0

julia> chargeof(Species("electron"))
-1.0

julia> chargeof(Species("Li+3"))
3.0

julia> chargeof(Species("proton"), C = true)   # coulombs
1.602176634e-19
source
AtomicAndPhysicalConstants.massof — Function
massof(species::Species; AMU::Bool = false) -> Float64

Return the rest mass of species.

By default the mass is returned in eV/c². Pass AMU = true to return the mass in atomic mass units (daltons), which is particularly convenient for atomic species.

Examples

julia> massof(Species("electron"))          # eV/c²
510998.95069

julia> massof(Species("proton"))
9.3827208943e8

julia> massof(Species("H"), AMU = true)     # daltons
1.0079407540557772

julia> massof(Species("#4He"), AMU = true)
4.00260325413
source
AtomicAndPhysicalConstants.spinof — Function
spinof(species::Species) -> Float64

Return the spin of species in units of the reduced Planck constant ħ.

For an atomic species this is the nuclear spin, taken from the tabulated NUBASE2020 ground-state values. Electron spin is not included: the total angular momentum of an atom depends on its electronic state, which Species does not model. Ionisation therefore does not change the result, and an anti-nucleus has the same spin as its mirror.

Returns NaN when no spin is defined:

  • for an atom given without a mass number (e.g. Species("He")), because the abundance average runs over isotopes with differing spins;
  • for the handful of exotic isotopes to which NUBASE assigns no unambiguous ground-state spin.

Note that spin is not a function of the mass number — nucleons pair off with opposite spins, so every even-even nucleus has spin 0.

Examples

julia> spinof(Species("electron"))
0.5

julia> spinof(Species("photon"))
1.0

julia> spinof(Species("#4He"))     # even-even nucleus
0.0

julia> spinof(Species("#3He+2"))   # ionisation does not change the nucleus
0.5

julia> spinof(Species("He"))       # abundance average, no single value
NaN
source
AtomicAndPhysicalConstants.momentof — Function
momentof(species::Species) -> Float64

Return the magnetic dipole moment of species in eV/T.

Returns 0 for atomic species and the null species (no moment is stored for these types).

Examples

julia> momentof(Species("electron"))   # eV/T
-5.795094307747843e-5

julia> momentof(Species("proton"))
8.804315114297192e-8

julia> momentof(Species("H"))          # atoms carry no moment
0.0
source
AtomicAndPhysicalConstants.g_spin — Function
g_spin(species::Species; signed::Bool = false) -> Float64

Return the spin g-factor of species.

By default the absolute value is returned. Pass signed = true to get the signed g-factor in the convention mu = g * (e / 2m) * S with e > 0, so the sign is that of the magnetic moment relative to the spin: negative for the electron, muon, neutron, and helion, and positive for their antiparticles.

Returns 0 for atomic species, for which no g-factor is stored.

Examples

julia> g_spin(Species("electron"))
2.00231930436092

julia> g_spin(Species("electron"), signed = true)
-2.00231930436092

julia> g_spin(Species("positron"), signed = true)
2.00231930436092

julia> g_spin(Species("proton"))
5.5856946893

julia> g_spin(Species("H"))        # atoms carry no g-factor
0.0
source
AtomicAndPhysicalConstants.gyromagnetic_anomaly — Function
gyromagnetic_anomaly(species::Species) -> Float64

Compute and return the gyromagnetic anomaly

\[a = \frac{g_q - 2}{2}, \qquad g_q = g \, \frac{e}{q}\]

for charged leptons and hadrons, where $g$ is the signed g-factor (g_spin with signed = true) and $q$ the particle's charge. $g_q$ is the g-factor normalized to the particle's own charge, $\boldsymbol{\mu} = g_q \frac{q}{2m} \mathbf{S}$, which is the anomaly that enters the Thomas–BMT spin-precession equation. Returns NaN for neutral particles (neutron, anti-neutron, neutral pion), for which $g_q$ is undefined, and for photons, atoms, and null species.

Dividing by the charge takes care of the sign: the electron ($g < 0$, $q = -e$) gets the conventional +0.00115965…, the same as the positron ($g > 0$, $q = +e$). It also takes care of the doubly charged helion, whose anomaly is -4.1841537… rather than the value (|g| - 2)/2 would give.

The stored g-factors are all in the convention mu = g * (e / 2m) * S, where the particle's own mass sets the magneton. For the deuteron, helion, and triton this required renormalizing the NIST values, which are tabulated against the nuclear magneton e*hbar/(2*M_PROTON); G_DEUTERON, G_HELION, and G_TRITON carry the renormalized values (see the Physical Constants manual page).

Examples

julia> gyromagnetic_anomaly(Species("electron"))
0.0011596521804599913

julia> gyromagnetic_anomaly(Species("muon"))
0.0011659206150000934

julia> gyromagnetic_anomaly(Species("deuteron"))
-0.14298726968020148

julia> gyromagnetic_anomaly(Species("helion"))    # doubly charged
-4.184153749832893

julia> gyromagnetic_anomaly(Species("neutron"))   # neutral
NaN
source
AtomicAndPhysicalConstants.iso_of — Function
iso_of(species::Species) -> Int

Return the mass number (isotope) of species.

  • For atomic species: the mass number of the requested isotope, or −1 if the abundance-averaged atomic mass was used.
  • For subatomic particles: always 0.

Examples

julia> iso_of(Species("#3He"))
3

julia> iso_of(Species("He"))        # abundance average
-1

julia> iso_of(Species("electron"))  # not an atom
0
source
AtomicAndPhysicalConstants.atomicnumberof — Function
atomicnumberof(species::Species) -> Int

Return the atomic number (number of protons) of species.

For an anti-atom, returns the negative of the atomic number (-Z), to distinguish it from the matter atom of the same symbol.

Throws an error if species is not of kind ATOM.

Examples

julia> atomicnumberof(Species("Fe"))
26

julia> atomicnumberof(Species("H+"))     # ionisation does not change Z
1

julia> atomicnumberof(Species("anti-H"))
-1
source
AtomicAndPhysicalConstants.kindof — Function
kindof(species::Species) -> Kind.T

Return the particle classification of species as a Kind.T enum value.

Possible values: Kind.LEPTON, Kind.HADRON, Kind.PHOTON, Kind.ATOM, Kind.NULL.

Examples

julia> kindof(Species("electron"))
Kind.LEPTON = 2

julia> kindof(Species("H"))
Kind.ATOM = 0

julia> kindof(Species())
Kind.NULL = 4
source
AtomicAndPhysicalConstants.isnullspecies — Function
isnullspecies(species::Species) -> Bool

Return true if species is a null (placeholder) species, false otherwise.

julia> isnullspecies(Species())
true

julia> isnullspecies(Species("null"))
true

julia> isnullspecies(Species("proton"))
false
source

Configuration

AtomicAndPhysicalConstants.set_release — Function
set_release(; year::Union{String,Nothing} = nothing)

Persistently set the CODATA release year used by AtomicAndPhysicalConstants.jl.

The setting is stored via Preferences.jl in the active Julia environment and survives across sessions. A Julia restart is required for the new constants to take effect.

Valid values for year are the keys of CODATA_MAP, currently 2002, 2006, 2010, 2014, 2018, 2022, each given as a string. Calling with no arguments removes the setting, so the package uses its default: the most recent release it ships, which moves forward when a newer release is added.

Examples

set_release(year = "2014")
# [ Info: The default CODATA release is now 2014.
#         Restart your Julia session for this change to take effect.

set_release()   # follow the most recent release again

See also: RELEASE_YEAR.

source

Particle kind enum

AtomicAndPhysicalConstants.Kind — Module
Kind

Classification of a particle species.

ValueMeaning
Kind.LEPTONleptons: electron, positron, muon, anti-muon
Kind.HADRONhadrons: proton, neutron, pions, deuteron, …
Kind.PHOTONphoton
Kind.ATOMany atomic or ionic species
Kind.NULLnull placeholder species

The kind of a species is queried with kindof.

source

Particle data dictionaries

AtomicAndPhysicalConstants.SUBATOMIC_SPECIES — Constant
SUBATOMIC_SPECIES :: Dict{String, SubatomicSpecies}

Dictionary of all supported subatomic particles, keyed by openPMD name.

Supported keys: "electron", "positron", "proton", "anti-proton", "neutron", "anti-neutron", "muon", "anti-muon", "pion0", "pion+", "pion-", "deuteron", "anti-deuteron", "triton", "anti-triton", "helion", "anti-helion", "photon".

source
AtomicAndPhysicalConstants.ATOMIC_SPECIES — Constant
ATOMIC_SPECIES :: Dict{String, AtomicSpecies}

Dictionary of all supported atomic elements (Z = 1 … 118), keyed by atomic symbol (e.g. "H", "Fe", "Og"). Each value is an AtomicSpecies struct containing the atomic number, symbol, a dictionary of isotope masses in atomic mass units, and a dictionary of ground-state nuclear spins in units of ħ.

Isotope masses come from NIST; nuclear spins come from NUBASE2020. Regenerate them with update/update_isos.jl and update/update_spins.jl respectively.

source

CODATA release structs

Physical constants

AtomicAndPhysicalConstants.G_NEUTRON — Constant
G_NEUTRON::Float64

The neutron spin g-factor renormalized to the neutron magneton e*hbar/(2*M_NEUTRON), the convention in which the gyromagnetic anomaly a = (|g|-2)/2 holds.

source
AtomicAndPhysicalConstants.G_DEUTERON — Constant
G_DEUTERON::Float64

The deuteron spin g-factor renormalized to the deuteron magneton e*hbar/(2*M_DEUTERON), the convention in which the gyromagnetic anomaly a = (|g|-2)/2 holds.

source
AtomicAndPhysicalConstants.G_HELION — Constant
G_HELION::Float64

The helion spin g-factor renormalized to the helion magneton e*hbar/(2*M_HELION), the convention in which the gyromagnetic anomaly a = (|g|-2)/2 holds.

source
AtomicAndPhysicalConstants.G_TRITON — Constant
G_TRITON::Float64

The triton spin g-factor renormalized to the triton magneton e*hbar/(2*M_TRITON), the convention in which the gyromagnetic anomaly a = (|g|-2)/2 holds.

source
AtomicAndPhysicalConstants.CLASSICAL_RADIUS_FACTOR — Constant
CLASSICAL_RADIUS_FACTOR::Float64

Classical radius factor $e^2/(4 \pi \varepsilon_0) = r_e m_e c^2$ in eV·m.

Not a tabulated CODATA value: it is derived from the selected release as R_ELECTRON * M_ELECTRON, and so is not a field of CODATA_release. It is the same for all particles of charge ±1.

source

Internal types

Not exported, and documented here only because the exported dictionaries and release structs are built from them. Unlike Species, these are plain structs with ordinary dot access.

AtomicAndPhysicalConstants.SubatomicSpecies — Type
SubatomicSpecies

Internal struct storing intrinsic data for a single subatomic particle. Instances are stored in SUBATOMIC_SPECIES.

Fields

  • speciesname::String — openPMD particle identifier.
  • charge::Float64 — charge in units of e.
  • mass::Float64 — mass in eV/c².
  • moment::Float64 — magnetic dipole moment in eV/T.
  • spin::Float64 — spin in ħ.
  • gspin::Float64 — spin g-factor.
source
AtomicAndPhysicalConstants.AtomicSpecies — Type
AtomicSpecies

Internal struct storing isotope data for a chemical element. Instances are stored in ATOMIC_SPECIES.

Fields

  • Z::Int — atomic number (number of protons).
  • speciesname::String — standard atomic symbol (e.g. "Fe").
  • mass::Dict{Int,Float64} — isotope masses in atomic mass units (u), keyed by mass number. The special key −1 holds the abundance-averaged atomic mass.
  • spin::Dict{Int,Float64} — ground-state nuclear spins in units of ħ, keyed by mass number, taken from NUBASE2020. NaN marks an isotope to which NUBASE assigns no unambiguous spin. There is deliberately no −1 key: the abundance average has no meaningful spin, because different isotopes of an element have different ones.
source
AtomicAndPhysicalConstants.CODATA_release — Type
CODATA_release

Keyword-argument struct holding all fundamental constants from one CODATA release year. Fields mirror the exported scalar constants (M_ELECTRON, C_LIGHT, etc.) but are grouped together so that multiple release years can coexist in memory simultaneously.

Pre-built instances are exported as CODATA2002, CODATA2006, CODATA2010, CODATA2014, CODATA2018, and CODATA2022.

CODATA2018.M_ELECTRON   # electron mass from the 2018 release
CODATA2014.C_LIGHT      # speed of light from the 2014 release
source