diff --git a/package/CHANGELOG b/package/CHANGELOG index b405b1bd796..553070b122a 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -57,6 +57,8 @@ Changes (PR #4174, Issue #3819) Deprecations + * Incorrectly spelt Boltzmann unit entry will be removed in version 2.8.0 + (PR #4230, Issue #4229) * The hole2 module is deprecated in favour of the the MDAKit: https://github.com/MDAnalysis/hole2-mdakit (Issue #4179, PR #4200) * MDAnalysis no longer officially supports 32 bit installations (they are diff --git a/package/MDAnalysis/units.py b/package/MDAnalysis/units.py index 951416d02ce..49b05e94a74 100644 --- a/package/MDAnalysis/units.py +++ b/package/MDAnalysis/units.py @@ -172,6 +172,23 @@ """ +import warnings + + +# Remove in 2.8.0 +class DeprecatedKeyAccessDict(dict): + deprecated_kB = 'Boltzman_constant' + + def __getitem__(self, key): + if key == self.deprecated_kB: + wmsg = ("Please use 'Boltzmann_constant' henceforth. The key " + "'Boltzman_constant' was a typo and will be removed " + "in MDAnalysis 2.8.0.") + warnings.warn(wmsg, DeprecationWarning) + key = 'Boltzmann_constant' + return super().__getitem__(key) + + # # NOTE: Whenever a constant is added to the constants dict, you also # MUST add an appropriate entry to @@ -189,13 +206,13 @@ #: http://physics.nist.gov/Pubs/SP811/appenB8.html#C #: #: .. versionadded:: 0.9.0 -constants = { +constants = DeprecatedKeyAccessDict({ 'N_Avogadro': 6.02214129e+23, # mol**-1 'elementary_charge': 1.602176565e-19, # As 'calorie': 4.184, # J 'Boltzmann_constant': 8.314462159e-3, # KJ (mol K)**-1 'electric_constant': 5.526350e-3, # As (Angstroms Volts)**-1 -} +}) #: The basic unit of *length* in MDAnalysis is the Angstrom. #: Conversion factors between the base unit and other lengthUnits *x* are stored. diff --git a/testsuite/MDAnalysisTests/utils/test_units.py b/testsuite/MDAnalysisTests/utils/test_units.py index 41373fb41ec..618550396e5 100644 --- a/testsuite/MDAnalysisTests/utils/test_units.py +++ b/testsuite/MDAnalysisTests/utils/test_units.py @@ -52,6 +52,7 @@ class TestConstants(object): ('elementary_charge', 1.602176565e-19), # As ('calorie', 4.184), # J ('Boltzmann_constant', 8.314462159e-3), # KJ (mol K)**-1 + ('Boltzman_constant', 8.314462159e-3), # remove in 2.8.0 ('electric_constant', 5.526350e-3), # As (Angstroms Volts)**-1 ) @@ -59,6 +60,13 @@ class TestConstants(object): def test_constant(self, name, value): assert_almost_equal(units.constants[name], value) + def test_boltzmann_typo_deprecation(self): + wmsg = ("Please use 'Boltzmann_constant' henceforth. The key " + "'Boltzman_constant' was a typo and will be removed " + "in MDAnalysis 2.8.0.") + with pytest.warns(DeprecationWarning, match=wmsg): + units.constants['Boltzman_constant'] + class TestConversion(object): @staticmethod