From c6bfa09dea0b94df6d0ed79c59fc19e3b16a0ea2 Mon Sep 17 00:00:00 2001 From: Tanish Yelgoe <143334319+tanishy7777@users.noreply.github.com> Date: Sat, 14 Dec 2024 23:54:17 +0530 Subject: [PATCH] Fixes MDAnalysis.analysis.density.convert_density() method has an invalid default unit value (#4833) --- package/CHANGELOG | 1 + package/MDAnalysis/analysis/density.py | 2 +- testsuite/MDAnalysisTests/analysis/test_density.py | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 15fe7cd10b..6fb34a869c 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -19,6 +19,7 @@ The rules for this file: * 2.9.0 Fixes + * Fixes invalid default unit from Angstrom to Angstrom^{-3} for convert_density() function. (Issue #4829) * Fixes deprecation warning Array to scalar convertion. Replaced atan2() with np.arctan2() (Issue #4339) * Replaced mutable defaults with None and initialized them within the function to prevent shared state. (Issue #4655) diff --git a/package/MDAnalysis/analysis/density.py b/package/MDAnalysis/analysis/density.py index 8f3f0b3364..f5c270e7dc 100644 --- a/package/MDAnalysis/analysis/density.py +++ b/package/MDAnalysis/analysis/density.py @@ -826,7 +826,7 @@ def convert_length(self, unit='Angstrom'): self.units['length'] = unit self._update() # needed to recalculate midpoints and origin - def convert_density(self, unit='Angstrom'): + def convert_density(self, unit='Angstrom^{-3}'): """Convert the density to the physical units given by `unit`. Parameters diff --git a/testsuite/MDAnalysisTests/analysis/test_density.py b/testsuite/MDAnalysisTests/analysis/test_density.py index b00a8234c1..c99b671e3d 100644 --- a/testsuite/MDAnalysisTests/analysis/test_density.py +++ b/testsuite/MDAnalysisTests/analysis/test_density.py @@ -384,6 +384,12 @@ def test_warn_results_deprecated(self, universe): with pytest.warns(DeprecationWarning, match=wmsg): assert_equal(D.density.grid, D.results.density.grid) + def test_density_analysis_conversion_default_unit(self): + u = mda.Universe(TPR, XTC) + ow = u.select_atoms("name OW") + D = mda.analysis.density.DensityAnalysis(ow, delta=1.0) + D.run() + D.results.density.convert_density() class TestGridImport(object):