From 69ea580fea8d76b9bc31fe5e8e7eb5b108d867db Mon Sep 17 00:00:00 2001 From: wvandertoorn Date: Thu, 12 Mar 2020 08:49:37 +0100 Subject: [PATCH 1/3] 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.''') From 2d7881f2e8fba46b0c5b3fbbe84dd79782f4dd96 Mon Sep 17 00:00:00 2001 From: wvandertoorn Date: Sun, 15 Mar 2020 10:08:28 +0100 Subject: [PATCH 2/3] Update based on review comments. - [DOC] Update AUTHORS - [DOC] More detail on deprecation notice --- package/AUTHORS | 1 + package/MDAnalysis/analysis/density.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/package/AUTHORS b/package/AUTHORS index 70c44845279..e429eb939f0 100644 --- a/package/AUTHORS +++ b/package/AUTHORS @@ -128,6 +128,7 @@ Chronological list of authors 2020 - Charlie Cook - Yuanyu Chang + - Wiep van der Toorn External code ------------- diff --git a/package/MDAnalysis/analysis/density.py b/package/MDAnalysis/analysis/density.py index 7e6bde082e1..7f17e47a6b6 100644 --- a/package/MDAnalysis/analysis/density.py +++ b/package/MDAnalysis/analysis/density.py @@ -1194,6 +1194,8 @@ def notwithin_coordinates_factory(universe, sel1, sel2, cutoff, .. deprecated:: 1.0.0 + :func: `notwithin_coordinates_factory` is no longer supported and will be removed in 2.0.0. as part + of the removal of the :func:`density_from_PDB` function. """ # Benchmark of FABP system (solvent 3400 OH2, protein 2100 atoms) on G4 powerbook, 500 frames # cpu/s relative speedup use_kdtree From 5ea74a8309feadc4238e34e7ce589372b2165b51 Mon Sep 17 00:00:00 2001 From: wvandertoorn Date: Sun, 15 Mar 2020 10:54:53 +0100 Subject: [PATCH 3/3] Documentation fixes - [DOC] Fix formatting - [DOC] Fix deprecation notice mix up --- package/MDAnalysis/analysis/density.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package/MDAnalysis/analysis/density.py b/package/MDAnalysis/analysis/density.py index 7f17e47a6b6..47876147eb2 100644 --- a/package/MDAnalysis/analysis/density.py +++ b/package/MDAnalysis/analysis/density.py @@ -1194,8 +1194,8 @@ def notwithin_coordinates_factory(universe, sel1, sel2, cutoff, .. deprecated:: 1.0.0 - :func: `notwithin_coordinates_factory` is no longer supported and will be removed in 2.0.0. as part - of the removal of the :func:`density_from_PDB` function. + :func:`notwithin_coordinates_factory` is no longer supported and will be + removed in 2.0.0. """ # Benchmark of FABP system (solvent 3400 OH2, protein 2100 atoms) on G4 powerbook, 500 frames # cpu/s relative speedup use_kdtree @@ -1269,6 +1269,8 @@ def Bfactor2RMSF(B): .. deprecated:: 1.0.0 + :func:`Bfactor2RMSF` is no longer supported and will be removed in 2.0.0. + as part of the removal of the :func:`density_from_PDB` function. """ return np.sqrt(3. * B / 8.) / np.pi