Skip to content

Commit

Permalink
fix: pin scipy constants to version 2018 (#775)
Browse files Browse the repository at this point in the history
fix issue #773

Co-authored-by: Han Wang <[email protected]>
  • Loading branch information
wanghan-iapcm and Han Wang authored Jan 12, 2025
1 parent 25e7e4b commit 799044b
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions dpdata/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@

from abc import ABC

from scipy import constants # noqa: TID253
# scipy physical constant version 2018
physical_constants = {
"Avogadro constant": 6.02214076e23, # mol^-1
"elementary charge": 1.602176634e-19, # C
"atomic unit of length": 5.29177210903e-11, # m
"atomic unit of energy": 4.3597447222071e-18, # J
"Rydberg constant": 10973731.568160, # m^-1
"Planck constant": 6.62607015e-34, # J·s
"speed of light in vacuum": 299792458, # m·s^-1
}


def scipy_constant_value(key: str) -> float:
return physical_constants[key]


AVOGADRO = constants.Avogadro # Avagadro constant
ELE_CHG = constants.elementary_charge # Elementary Charge, in C
BOHR = constants.value("atomic unit of length") # Bohr, in m
HARTREE = constants.value("atomic unit of energy") # Hartree, in Jole
RYDBERG = constants.Rydberg * constants.h * constants.c # Rydberg, in Jole
AVOGADRO = scipy_constant_value("Avogadro constant") # Avagadro constant
ELE_CHG = scipy_constant_value("elementary charge") # Elementary Charge, in C
BOHR = scipy_constant_value("atomic unit of length") # Bohr, in m
HARTREE = scipy_constant_value("atomic unit of energy") # Hartree, in Jole
RYDBERG = (
scipy_constant_value("Rydberg constant")
* scipy_constant_value("Planck constant")
* scipy_constant_value("speed of light in vacuum")
) # Rydberg, in Jole

# energy conversions
econvs = {
Expand Down

0 comments on commit 799044b

Please sign in to comment.