Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable old Boltzmann key with DeprecationWarning #4230

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions package/MDAnalysis/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions testsuite/MDAnalysisTests/utils/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ 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
)

@pytest.mark.parametrize('name, value', constants_reference)
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
Expand Down
Loading