Skip to content

Commit

Permalink
fix: pin scipy constants to version 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
Han Wang committed Jan 11, 2025
1 parent 25e7e4b commit 8d14aa9
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions dpdata/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,49 @@

from scipy import constants # noqa: TID253

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
physical_constants = {}
# use constants up to 2018
physical_constants.update(constants._codata._physical_constants_2002)
physical_constants.update(constants._codata._physical_constants_2006)
physical_constants.update(constants._codata._physical_constants_2010)
physical_constants.update(constants._codata._physical_constants_2014)
physical_constants.update(constants._codata._physical_constants_2018)


# copied from scipy
def scipy_constant_value(key: str) -> float:
"""Value in physical_constants indexed by key.
Parameters
----------
key : Python string
Key in dictionary `physical_constants`
Returns
-------
value : float
Value in `physical_constants` corresponding to `key`
Examples
--------
>>> from scipy import constants
>>> constants.value('elementary charge')
1.602176634e-19
"""
constants._codata._check_obsolete(key)
return physical_constants[key][0]


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 8d14aa9

Please sign in to comment.