From 288e0e1ca1f845ae438e5ce05b2a60108fd87914 Mon Sep 17 00:00:00 2001 From: Xu Hong Chen <110699064+xhgchen@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:47:53 -0700 Subject: [PATCH 1/5] Enable old Boltzmann key with warning * Subclass dict and wrap `__getitem__` with `DeprecationWarning` --- package/MDAnalysis/units.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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. From 09a6cf562833451dd080df1a12fd9eb33164443d Mon Sep 17 00:00:00 2001 From: Xu Hong Chen <110699064+xhgchen@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:58:57 -0700 Subject: [PATCH 2/5] Update tests in `units.py` * Add test for old `Boltzman_constant` key * Add test for deprecation warning with old `Boltzman_constant` key --- testsuite/MDAnalysisTests/utils/test_units.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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 From 2a637fc5f476a3b39f041e3179d56660f30b03ac Mon Sep 17 00:00:00 2001 From: Xu Hong Chen <110699064+xhgchen@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:11:06 -0700 Subject: [PATCH 3/5] Update CHANGELOG --- package/CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package/CHANGELOG b/package/CHANGELOG index b405b1bd796..13e51d5c198 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -21,6 +21,9 @@ The rules for this file: * 2.6.0 Fixes + * Fix Boltzmann constant API break by enabling access to old + 'Boltzman_constant' key with a `DeprecationWarning` in `units.py` + (PR #4230, Issue #4229) * Fix AtomGroup.center_of_charge(..., unwrap=True) giving inconsistent (but scientifically correct) results on Intel macOS (Issue #4211) From 52ef5782e5a1ecb714b79494edf9aa78548fb373 Mon Sep 17 00:00:00 2001 From: Xu Hong Chen <110699064+xhgchen@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:14:25 -0700 Subject: [PATCH 4/5] Move CHANGELOG entry to Deprecations --- package/CHANGELOG | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 13e51d5c198..8dcc65b7a80 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -21,9 +21,6 @@ The rules for this file: * 2.6.0 Fixes - * Fix Boltzmann constant API break by enabling access to old - 'Boltzman_constant' key with a `DeprecationWarning` in `units.py` - (PR #4230, Issue #4229) * Fix AtomGroup.center_of_charge(..., unwrap=True) giving inconsistent (but scientifically correct) results on Intel macOS (Issue #4211) @@ -60,6 +57,9 @@ Changes (PR #4174, Issue #3819) Deprecations + * Fix Boltzmann constant API break by enabling access to old + 'Boltzman_constant' key with a `DeprecationWarning` in `units.py` + (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 From 874a8df7408030a01d4b35c8c2f20804f3b5fc22 Mon Sep 17 00:00:00 2001 From: Xu Hong Chen <110699064+xhgchen@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:16:35 -0700 Subject: [PATCH 5/5] Edit CHANGELOG entry --- package/CHANGELOG | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 8dcc65b7a80..553070b122a 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -57,8 +57,7 @@ Changes (PR #4174, Issue #3819) Deprecations - * Fix Boltzmann constant API break by enabling access to old - 'Boltzman_constant' key with a `DeprecationWarning` in `units.py` + * 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)