Skip to content

Commit

Permalink
Use CODATA 2022 for physical constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kienzle committed Oct 8, 2024
1 parent 25d0085 commit 48135c6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 50 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Modified:
* Fix typos in uncertainties in the neutron table (Zr-90, Te-124, Ba-138, Sm-147)
* Use correctactivation for Pb-208 which was entered as barns rather than mbarns
* Use Aug 2023 update to CXRO scattering factors (Pt, Cr, Nb, Y, Er)
* Update physical constants to CODATA 2022. Relative change up to 1e-7 in
Avogadro number, Planck constant, J/eV, electron radius, electron mass,
neutron mass and atomic mass constant. `planck_constant` is now in J/Hz rather
than eV s.

2024-07-08 R1.7.1
-----------------
Expand Down
40 changes: 21 additions & 19 deletions periodictable/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
Various fundamental constants.
"""

#: Avogadro's number (mol^-1)
avogadro_number = 6.02214179e23 #(30) mol^-1
#: Planck's constant (eV s)
plancks_constant = 4.13566733e-15 #(10) eV s
#: Electron volt (J/eV)
electron_volt = 1.602176487e-19 #(40) J / eV
#: speed of light c (m/s)
speed_of_light = 299792458 # m/s (exact)
#: electron radius r_e (m)
electron_radius = 2.8179402894e-15 #(58) m
#: Avogadro's number (mol^-1) [CODATA 2022]
avogadro_number = 6.02214076e23 #(exact) 1/mol [CODATA 2022]
#: Planck constant (eV s) [CODATA 2022]
planck_constant = 6.62607015e-34 #(exact) J/Hz [CODATA 2022]
#: Electron volt (J/eV) [CODATA 2022]
electron_volt = 1.602176634e-19 #(exact) J / eV [CODATA 2022]
#planck_constant_eV = planck_constant / electron_volt
#: speed of light c (m/s) [CODATA 2022]
speed_of_light = 299792458 #(exact) m/s [CODATA 2022]
#: electron radius r_e (m) [CODATA 2022]
electron_radius = 2.8179403205e-15 #(13) m [CODATA 2022]

# [CODATA] From NIST Reference on Constants, Units, and Uncertainty
# http://physics.nist.gov/cuu/index.html
# [AME2020] "The Ame2020 atomic mass evaluation (II)"
# by M.Wang, W.J.Huang, F.G.Kondev, G.Audi and S.Naimi
# Chinese Physics C45, 030003, March 2021.
#: neutron mass (u)
neutron_mass = 1.00866491590 #(47) u [AME 2020]
neutron_mass_unc = 0.00000000047
#neutron_mass = 1.00866491597 #(43) u [CODATA 2010?]
#neutron_mass = 1.00866491595 #(49) u [CODATA 2018]
#: atomic mass constant (kg / u)
atomic_mass_constant = 1.660538782e-27 #(83) kg / u
#: electron mass (u)
electron_mass = 5.48577990946e-4 #(22) u
#: neutron mass (u) [CODATA 2022]
neutron_mass = 1.00866491606 #(40) u [CODATA 2022]
neutron_mass_unc = 0.00000000040
#neutron_mass = 1.00866491590 #(47) u [AME 2020]
#neutron_mass = 1.00866491597 #(43) u [CODATA 2006]
#neutron_mass = 1.00866491595 #(49) u [CODATA 2018]
#: atomic mass constant (kg / u) [CODATA 2022]
atomic_mass_constant = 1.66053906892e-27 #(52) kg / u [CODATA 2022]
#: electron mass (u) [CODATA 2022]
electron_mass = 5.485799090441e-4 #(97) u [CODATA 2022]
42 changes: 21 additions & 21 deletions periodictable/nsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
import numpy as np
from numpy import sqrt, pi, asarray, inf
from .core import Element, Isotope, default_table
from .constants import (avogadro_number, plancks_constant, electron_volt,
from .constants import (avogadro_number, planck_constant, electron_volt,
neutron_mass, atomic_mass_constant)
from .util import require_keywords, parse_uncertainty

Expand All @@ -173,24 +173,24 @@
#'scattering_potential',
]

ABSORPTION_WAVELENGTH = 1.798
#: Wavelength [Å] for which neutron scattering cross sections are tabulated.
ABSORPTION_WAVELENGTH = 1.798 # [Å]


# Velocity (m/s) <=> wavelength (A)
# lambda = h / p = h (eV) (J/eV) / ( m_n (kg) v (m/s) ) (10^10 A/m)
#
# Since plancks constant is in eV
# lambda = (1e10 * h*electron_volt/(neutron_mass/N_A)) / velocity

# Energy (eV) <=> wavelength (A)
# h^2/(2 m_n kg lambda A) (10^20 A/m) (1000 meV/eV) / (electron_volt J/eV)
# Since plancks constant is in eV
# (h J)^2/electron_volt = ((h eV)(electron_volt J/eV))^2/electron_volt
# = (h eV)^2 * electron_volt
ENERGY_FACTOR = (plancks_constant**2*electron_volt
/ (2 * neutron_mass * atomic_mass_constant)) * 1e23
VELOCITY_FACTOR = (plancks_constant*electron_volt
/ (neutron_mass * atomic_mass_constant)) * 1e10
#: Energy [eV] <=> wavelength [Å]:
#: E = 1/2 m v² = h² / (2 m λ²)
#: E[meV s] = h[J s]²/(2 m_n[u] m_u[kg/u] λ[Å]²/10^20[Å/m])
#: * 1000[meV/eV] / electron_volt[J/eV]
ENERGY_FACTOR = (
1e23 * planck_constant**2/electron_volt
/ (2 * neutron_mass * atomic_mass_constant))

#: Velocity[m/s] <=> wavelength[Å]:
#: h = p λ = m v λ
#: λ[Å] = h[J s] / ( m_n[kg] v[m/s] ) 10^10[Å/m]
VELOCITY_FACTOR = (
1e10 * planck_constant / (neutron_mass * atomic_mass_constant))

def neutron_wavelength(energy):
r"""
Convert neutron energy to wavelength.
Expand All @@ -210,7 +210,7 @@ def neutron_wavelength(energy):
where
$h$ = planck's constant in |Js|
$h$ = Planck constant in |Js|
$m_n$ = neutron mass in kg
Expand All @@ -235,7 +235,7 @@ def neutron_wavelength_from_velocity(velocity):
where
$h$ = planck's constant in |Js|
$h$ = Planck constant in |Js|
$m_n$ = neutron mass in kg
"""
Expand All @@ -259,7 +259,7 @@ def neutron_energy(wavelength):
where:
$h$ = planck's constant in |Js|
$h$ = Planck constant in |Js|
$m_n$ = neutron mass in kg
"""
Expand Down Expand Up @@ -289,7 +289,7 @@ def _CHECK_scattering_potential(sld):
$\hbar = h / (2 \pi)$
$h$ = planck's constant in |Js|
$h$ = Planck constant in |Js|
$N_b = \sum{ n_i b_i } / V$
Expand Down
13 changes: 7 additions & 6 deletions periodictable/xsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@
from numpy import nan, pi, exp, sin, cos, sqrt, radians

from .core import Element, Ion, default_table, get_data_path
from .constants import (avogadro_number, plancks_constant, speed_of_light,
electron_radius)
from .constants import (
avogadro_number, planck_constant, speed_of_light, electron_volt,
electron_radius)
from .util import require_keywords

def xray_wavelength(energy):
Expand All @@ -214,11 +215,11 @@ def xray_wavelength(energy):
where:
$h$ = planck's constant in eV\ |cdot|\ s
$h$ = Planck constant in J\ |cdot|\ s
$c$ = speed of light in m/s
"""
return plancks_constant*speed_of_light/numpy.asarray(energy)*1e7
return planck_constant/electron_volt*speed_of_light/numpy.asarray(energy)*1e7

def xray_energy(wavelength):
r"""
Expand All @@ -238,11 +239,11 @@ def xray_energy(wavelength):
where:
$h$ = planck's constant in eV\ |cdot|\ s
$h$ = Planck constant in J\ |cdot|\ s
$c$ = speed of light in m/s
"""
return plancks_constant*speed_of_light/numpy.asarray(wavelength)*1e7
return planck_constant/electron_volt*speed_of_light/numpy.asarray(wavelength)*1e7

class Xray(object):
"""
Expand Down
4 changes: 2 additions & 2 deletions test/test_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test():
assert elements.D.density == elements.H.density * elements.D.mass/elements.H.mass

# check number density and unit cell width
assert abs(elements.Ca.interatomic_distance - 3.50166387163) < 1e-10
assert abs(elements.Fe.number_density - 8.4910635606518029e+22) < 1e12
assert abs(elements.Ca.interatomic_distance - 3.5016640712645786) < 1e-10
assert abs(elements.Fe.number_density - 8.491062108378546e+22) < 1e12
assert elements.Ca.interatomic_distance_units == "angstrom"
assert elements.Fe.number_density_units == "1/cm^3"

Expand Down
4 changes: 2 additions & 2 deletions test/test_nsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def test():
assert abs(depth-depth2)<1e-14

# Test energy <=> velocity <=> wavelength
# PAK: value changes with updated neutron and atomic mass constants [2023-08]
assert abs(nsf.neutron_wavelength_from_velocity(2200) - 1.7981972619684314) < 1e-14
# PAK: value changes with updated neutron and atomic mass constants [2024-10]
assert abs(nsf.neutron_wavelength_from_velocity(2200) - 1.7981972755018132) < 1e-14
assert abs(nsf.neutron_wavelength(25) - 1.8) < 0.1
assert abs(nsf.neutron_energy(nsf.neutron_wavelength(25)) - 25) < 1e-14

Expand Down

0 comments on commit 48135c6

Please sign in to comment.