From 799044bd4ef337561d581e4982ead46ba48e1c6d Mon Sep 17 00:00:00 2001 From: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:37:31 +0800 Subject: [PATCH] fix: pin scipy constants to version 2018 (#775) fix issue https://github.com/deepmodeling/dpdata/issues/773 Co-authored-by: Han Wang --- dpdata/unit.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/dpdata/unit.py b/dpdata/unit.py index 09981b969..9c96827cd 100644 --- a/dpdata/unit.py +++ b/dpdata/unit.py @@ -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 = {