From 69ea580fea8d76b9bc31fe5e8e7eb5b108d867db Mon Sep 17 00:00:00 2001 From: wvandertoorn Date: Thu, 12 Mar 2020 08:49:37 +0100 Subject: [PATCH] Finalizing #2537 - [DOC] add sphinx deprecated paragraph to density/BFactor2RMSF docstring - [TEST] decrease precision in assert_almost_equal test_density/test_density_from_PDB - [TEST] Bring back TestGridImport class in test_density - [DOC] Update CHANGELOG --- package/CHANGELOG | 12 ++++---- package/MDAnalysis/analysis/density.py | 3 ++ .../MDAnalysisTests/analysis/test_density.py | 29 ++++++++++++++++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index abe1d9801bd..1884f925866 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -15,7 +15,7 @@ The rules for this file: ------------------------------------------------------------------------------ mm/dd/yy richardjgowers, kain88-de, lilyminium, p-j-smith, bdice, joaomcteixeira, PicoCentauri, davidercruz, jbarnoud, RMeli, IAlibay, mtiberti, CCook96, - Yuan-Yu, xiki-tempula, orbeckst + Yuan-Yu, xiki-tempula, orbeckst, wvandertoorn * 0.21.0 @@ -25,7 +25,7 @@ Fixes * Handle exception when PDBWriter is trying to remove an invalid StringIO (Issue #2512) * Clarifies density_from_Universe docs and adds user warning (Issue #2372) - * Fix upstream deprecation of `matplotlib.axis.Tick` attributes in + * Fix upstream deprecation of `matplotlib.axis.Tick` attributes in `MDAnalysis.analysis.psa` * PDBWriter now uses first character of segid as ChainID (Issue #2224) * Adds a more detailed warning when attempting to read chamber-style parm7 @@ -33,7 +33,7 @@ Fixes * ClusterCollection.get_ids now returns correctly (Issue #2464) * Removes files for stubs mainly introduced in 0.11.0 (Issue #2443) * Removes support for reading AMBER NetCDF files with `cell_angle` units set - to `degrees` instead of the convention agreed `degree` (Issue #2327). + to `degrees` instead of the convention agreed `degree` (Issue #2327). * Removes the MassWeight option from gnm (PR #2479). * AtomGroup.guess_bonds now uses periodic boundary information when available (Issue #2350) @@ -91,15 +91,15 @@ Changes Segment.r1, Universe.s4AKE). Use select_atoms instead (Issue #1377) * Calling Universe() now raises a TypeError advising you to use Universe.empty. Universe.empty() now no longer has n_atoms=0 as default. (Issue #2527) - * deprecated `start`, `stop`, and `step` keywords have been removed from `__init__` - in :class:`AnalysisBase`. These should now be called in :meth:`AnalysisBase.run` + * deprecated `start`, `stop`, and `step` keywords have been removed from `__init__` + in :class:`AnalysisBase`. These should now be called in :meth:`AnalysisBase.run` (Issue #1463) * Standardize `select` keyword by removing `selection`, `atomselection` and `ref_select` (Issue #2461, Issue #2530) * Removes support for setting `start`/`stop`/`step` trajecotry slicing keywords on :class:`HOLEtraj` construction. Also removes undocumented support for passing :class:`HOLE` parameters to :meth:`HOLEtraj.run` - (Issue #2513). + (Issue #2513). * Removes the `nproc` keyword from :class:`Waterdynamics.HydrogenBondLifetimes` as the multiprocessing functionality did not work in some cases(Issues #2511). diff --git a/package/MDAnalysis/analysis/density.py b/package/MDAnalysis/analysis/density.py index d777783609c..7e6bde082e1 100644 --- a/package/MDAnalysis/analysis/density.py +++ b/package/MDAnalysis/analysis/density.py @@ -1264,6 +1264,9 @@ def Bfactor2RMSF(B): ---------- .. [Willis1975] BTM Willis and AW Pryor. *Thermal vibrations in crystallography*. Cambridge Univ. Press, 1975 + + + .. deprecated:: 1.0.0 """ return np.sqrt(3. * B / 8.) / np.pi diff --git a/testsuite/MDAnalysisTests/analysis/test_density.py b/testsuite/MDAnalysisTests/analysis/test_density.py index 5e326ed04f9..f4d1381cffa 100644 --- a/testsuite/MDAnalysisTests/analysis/test_density.py +++ b/testsuite/MDAnalysisTests/analysis/test_density.py @@ -37,6 +37,8 @@ from MDAnalysis.analysis import density from MDAnalysisTests.datafiles import TPR, XTC, GRO, PDB_full +from unittest.mock import Mock, patch +from MDAnalysisTests.util import block_import class TestDensity(object): @@ -452,9 +454,34 @@ def test_density_from_PDB(self, sigma, ref_shape, ref_gridsum): assert isinstance(D, density.Density) assert_equal(D.grid.shape, ref_shape) - assert_almost_equal(D.grid.sum(), ref_gridsum, decimal=6) + assert_almost_equal(D.grid.sum(), ref_gridsum, decimal=5) def test_has_DeprecationWarning(self): with pytest.warns(DeprecationWarning, match="will be removed in release 2.0.0"): density.density_from_PDB(PDB_full, delta=5.0, sigma=2) + +class TestGridImport(object): + + @block_import('gridData') + def test_absence_griddata(self): + sys.modules.pop('MDAnalysis.analysis.density', None) + # if gridData package is missing an ImportError should be raised + # at the module level of MDAnalysis.analysis.density + with pytest.raises(ImportError): + import MDAnalysis.analysis.density + + def test_presence_griddata(self): + sys.modules.pop('MDAnalysis.analysis.density', None) + # no ImportError exception is raised when gridData is properly + # imported by MDAnalysis.analysis.density + + # mock gridData in case there are testing scenarios where + # it is not available + mock = Mock() + with patch.dict('sys.modules', {'gridData':mock}): + try: + import MDAnalysis.analysis.density + except ImportError: + pytest.fail(msg='''MDAnalysis.analysis.density should not raise + an ImportError if gridData is available.''')