Skip to content

Commit

Permalink
Fixes MDAnalysis.analysis.density.convert_density() method has an inv…
Browse files Browse the repository at this point in the history
…alid default unit value (#4833)
  • Loading branch information
tanishy7777 authored Dec 14, 2024
1 parent fa73478 commit c6bfa09
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit c6bfa09

Please sign in to comment.