diff --git a/package/CHANGELOG b/package/CHANGELOG index 4c379523fe3..bad516022dc 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -180,6 +180,9 @@ Enhancements checking if it can be used in parallel analysis. (Issue #2996, PR #2950) Changes + * `analysis.rdf.InterRDF` and `analysis.rdf.InterRDF_s` now store + their result attributes using the `analysis.base.Results` class + (Issue #3276, #3261) * Adds a `force` parameter to the RDKitConverter to allow conversion of molecules with no hydrogen atom, and a `set_converter_cache_size` function to change how many items are retained in the cache (PR #2942) @@ -199,10 +202,10 @@ Changes (Issues #3289, #3291) * `analysis.hole2.HoleAnalysis` now stores ``sphpdbs``, ``outfiles`` and ``profiles`` in the `analysis.base.Results` class (Issues #3261, #3269) - * `helix_analysis.HELANAL` now uses the `analysis.base.Results` class to - store results attributes (Issue #3261, #3267) * `analysis.diffusionmap.DistanceMatrix` class now stores `dist_matrix` using the `analysis.base.Results` class (Issues #3288, #3290) + * `helix_analysis.HELANAL` now uses the `analysis.base.Results` class to + store results attributes (Issue #3261, #3267) * `analysis.align.AlignTraj` and `analysis.align.AverageStructure` now store their result attributes using the `analysis.base.Results` class (Issues #3278 and #3261) @@ -225,7 +228,7 @@ Changes analysis.hydrogenbonds.hbond_analysis (Issues #2739, #2746) * `GNMAnalysis`, `LinearDensity`, `PersistenceLength` and `AnalysisFromFunction` use the `results` attribute. - * Fixed inaccurate docstring inside the RMSD class (Issue #2796, PR #3134) + * Fixed inaccurate docstring inside the RMSD class (Issue #2796, PR #3134) * TPRParser now loads TPR files with `tpr_resid_from_one=True` by default, which starts TPR resid indexing from 1 (instead of 0 as in 1.x) (Issue #2364, PR #3152) * Introduces encore specific C compiler arguments to allow for lowering of @@ -269,6 +272,11 @@ Changes * Added OpenMM coordinate and topology converters (Issue #2863, PR #2917) Deprecations + * The `bins`, `edges`, `count`, `rdf` attributes for `analysis.rdf.InterRDF` + and `analysis.rdf.InterRDF_s`, and `cdf` attributes for + `analysis.rdf.InterRDF_s` are now deprecated in favour of `results.bins`, + `results.edges`, `results.count`, `results.rdf` and `results.cdf` + (Issue #3276, #3261) * The `hydrogenbonds.WaterBridgeAnalysis.table` attribute is now deprecated and will be removed in 3.0.0. * The `hydrogenbonds.WaterBridgeAnalysis.network` attribute is now deprecated @@ -291,7 +299,7 @@ Deprecations ``results.sphpdbs``, ``results.outfiles`` and ``results.profiles`` (Issues #3261, #3269) * The `analysis.diffusionmap.DistanceMatrix.dist_matrix` is now deprecated in - favour of `analysis.diffusionmap.DistanceMatrix.results.dist_matrix`. + favour of `analysis.diffusionmap.DistanceMatrix.results.dist_matrix`. It will be removed in 3.0.0 (Issues #3288, #3290) * The `analysis.align.AlignTraj.rmsd` attribute is now deprecated in favour of `analysis.align.AlignTraj.results.rmsd` (Issue #3278, #3261) @@ -309,7 +317,7 @@ Deprecations * The `angles` attribute for the `dihedrals` classes (Dihedral, Ramachandran, Janin) is now deprecated in favour of `results.angles`. It will be removed in 3.0.0 (Issue #3261) - * The `analysis.Contacts.timeseries` attribute is now deprecated in favour of + * The `analysis.Contacts.timeseries` attribute is now deprecated in favour of `analysis.Contacts.results.timeseries`. It will be removed in 3.0.0 (Issue #3261) * The `density` attribute of `analysis.density.DensityAnalysis` is now diff --git a/package/MDAnalysis/analysis/rdf.py b/package/MDAnalysis/analysis/rdf.py index c85ab37eb90..6a63191f348 100644 --- a/package/MDAnalysis/analysis/rdf.py +++ b/package/MDAnalysis/analysis/rdf.py @@ -90,26 +90,65 @@ :members: :inherited-members: + .. attribute:: results.bins + + :class:`numpy.ndarray` of the centers of the `nbins` histogram + bins. + + .. versionadded:: 2.0.0 + .. attribute:: bins - :class:`numpy.ndarray` of the centers of the `nbins` histogram - bins. + Alias to the :attr:`results.bins` attribute. - .. attribute:: edges + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.bins` instead. + + .. attribute:: results.edges :class:`numpy.ndarray` of the `nbins + 1` edges of the histogram bins. - .. attribute:: rdf + .. versionadded:: 2.0.0 + + .. attribute:: edges + + Alias to the :attr:`results.edges` attribute. + + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.edges` instead. + + .. attribute:: results.rdf :class:`numpy.ndarray` of the :ref:`radial distribution - function` values for the :attr:`bins`. + function` values for the :attr:`results.bins`. - .. attribute:: count + .. versionadded:: 2.0.0 + + .. attribute:: rdf + + Alias to the :attr:`results.rdf` attribute. + + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.rdf` instead. + + .. attribute:: results.count :class:`numpy.ndarray` representing the radial histogram, i.e., - the raw counts, for all :attr:`bins`. + the raw counts, for all :attr:`results.bins`. + .. versionadded:: 2.0.0 + + .. attribute:: count + + Alias to the :attr:`results.count` attribute. + + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.count` instead. Site-specific radial distribution function ------------------------------------------ @@ -128,50 +167,99 @@ :members: :inherited-members: - .. attribute:: bins + .. attribute:: results.bins :class:`numpy.ndarray` of the centers of the `nbins` histogram bins; all individual site-specific RDFs have the same bins. - .. attribute:: edges + .. versionadded:: 2.0.0 + + .. attribute:: bins + + Alias to the :attr:`results.bins` attribute. + + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.bins` instead. + + .. attribute:: results.edges :class:`numpy.ndarray` of the `nbins + 1` edges of the histogram bins; all individual site-specific RDFs have the same bins. + .. versionadded:: 2.0.0 + + .. attribute:: edges + + Alias to the :attr:`results.edges` attribute. + + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.edges` instead. + + .. attribute:: results.rdf + + :class:`list` of the site-specific :ref:`radial distribution + functions` or :ref:`density + functions` for the :attr:`bins`. The list contains + ``len(ags)`` entries. Each entry for the ``i``-th pair ``[A, B] + = ags[i]`` in `ags` is a :class:`numpy.ndarray` with shape + ``(len(A), len(B))``, i.e., a stack of RDFs. For example, + ``results.rdf[i][0, 2]`` is the RDF between atoms ``A[0]`` + and ``B[2]``. + + .. versionadded:: 2.0.0 + .. attribute:: rdf - :class:`list` of the site-specific :ref:`radial distribution - functions` or :ref:`density - functions` for the :attr:`bins`. The list contains - ``len(ags)`` entries. Each entry for the ``i``-th pair ``[A, B] - = ags[i]`` in `ags` is a :class:`numpy.ndarray` with shape - ``(len(A), len(B))``, i.e., a stack of RDFs. For example, - ``rdf[i][0, 2]`` is the RDF between atoms ``A[0]`` and ``B[2]``. + Alias to the :attr:`results.rdf` attribute. + + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.rdf` instead. + + .. attribute:: results.count + + :class:`list` of the site-specific radial histograms, i.e., the + raw counts, for all :attr:`results.bins`. The data have the same + structure as :attr:`results.rdf` except that the arrays contain + the raw counts. + + .. versionadded:: 2.0.0 .. attribute:: count - :class:`list` of the site-specific radial histograms, i.e., the - raw counts, for all :attr:`bins`. The data have the same - structure as :attr:`rdf` except that the arrays contain the raw - counts. + Alias to the :attr:`results.count` attribute. - .. attribute:: cdf + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.count` instead. - :class:`list` of the site-specific :ref:`cumulative - counts`, for all :attr:`bins`. The data have the same - structure as :attr:`rdf` except that the arrays contain the cumulative - counts. + .. attribute:: results.cdf - This attribute only exists after :meth:`get_cdf` has been run. + :class:`list` of the site-specific :ref:`cumulative + counts`, for all :attr:`results.bins`. The data + have the same structure as :attr:`results.rdf` except that the arrays + contain the cumulative counts. + This attribute only exists after :meth:`get_cdf` has been run. + + .. versionadded:: 2.0.0 + + .. attribute:: cdf + Alias to the :attr:`results.cdf` attribute. + .. deprecated:: 2.0.0 + This attribute will be removed in 3.0.0. + Use :attr:`results.cdf` instead. .. Not Implemented yet: .. - Structure factor? .. - Coordination number """ +import warnings import numpy as np from ..lib.util import blocks_of @@ -216,10 +304,10 @@ class InterRDF(AnalysisBase): rdf = InterRDF(ag1, ag2) rdf.run() - Results are available through the :attr:`bins` and :attr:`rdf` - attributes:: + Results are available through the :attr:`results.bins` and + :attr:`results.rdf` attributes:: - plt.plot(rdf.bins, rdf.rdf) + plt.plot(rdf.results.bins, rdf.results.rdf) The `exclusion_block` keyword allows the masking of pairs from within the same molecule. For example, if there are 7 of each @@ -232,6 +320,10 @@ class InterRDF(AnalysisBase): Support for the ``start``, ``stop``, and ``step`` keywords has been removed. These should instead be passed to :meth:`InterRDF.run`. + .. versionchanged:: 2.0.0 + Store results as attributes ``bins``, ``edges``, ``rdf`` and ``count`` + of the ``results`` attribute of + :class:`~MDAnalysis.analysis.AnalysisBase`. """ def __init__(self, g1, g2, nbins=75, range=(0.0, 15.0), exclusion_block=None, @@ -250,16 +342,15 @@ def _prepare(self): count, edges = np.histogram([-1], **self.rdf_settings) count = count.astype(np.float64) count *= 0.0 - self.count = count - self.edges = edges - self.bins = 0.5 * (edges[:-1] + edges[1:]) + self.results.count = count + self.results.edges = edges + self.results.bins = 0.5 * (edges[:-1] + edges[1:]) # Need to know average volume self.volume = 0.0 # Set the max range to filter the search radius self._maxrange = self.rdf_settings['range'][1] - def _single_frame(self): pairs, dist = distances.capped_distance(self.g1.positions, self.g2.positions, @@ -267,13 +358,14 @@ def _single_frame(self): box=self.u.dimensions) # Maybe exclude same molecule distances if self._exclusion_block is not None: - idxA, idxB = pairs[:, 0]//self._exclusion_block[0], pairs[:, 1]//self._exclusion_block[1] + idxA = pairs[:, 0]//self._exclusion_block[0] + idxB = pairs[:, 1]//self._exclusion_block[1] mask = np.where(idxA != idxB)[0] dist = dist[mask] count = np.histogram(dist, **self.rdf_settings)[0] - self.count += count + self.results.count += count self.volume += self._ts.volume @@ -290,16 +382,48 @@ def _conclude(self): N -= xA * xB * nblocks # Volume in each radial shell - vol = np.power(self.edges[1:], 3) - np.power(self.edges[:-1], 3) - vol *= 4/3.0 * np.pi + vols = np.power(self.results.edges, 3) + vol = 4/3 * np.pi * np.diff(vols) # Average number density box_vol = self.volume / self.n_frames density = N / box_vol - rdf = self.count / (density * vol * self.n_frames) - - self.rdf = rdf + rdf = self.results.count / (density * vol * self.n_frames) + + self.results.rdf = rdf + + @property + def edges(self): + wmsg = ("The `edges` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.bins` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.edges + + @property + def count(self): + wmsg = ("The `count` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.bins` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.count + + @property + def bins(self): + wmsg = ("The `bins` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.bins` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.bins + + @property + def rdf(self): + wmsg = ("The `rdf` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.rdf` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.rdf class InterRDF_s(AnalysisBase): @@ -348,9 +472,10 @@ class InterRDF_s(AnalysisBase): rdf = InterRDF_s(u, ags) rdf.run() - Results are available through the :attr:`bins` and :attr:`rdf` attributes:: + Results are available through the :attr:`results.bins` + and :attr:`results.rdf` attributes:: - plt.plot(rdf.bins, rdf.rdf[0][0, 0]) + plt.plot(rdf.results.bins, rdf.results.rdf[0][0, 0]) (Which plots the rdf between the first atom in ``s1`` and the first atom in ``s2``) @@ -361,9 +486,9 @@ class InterRDF_s(AnalysisBase): cdf = rdf.get_cdf() - Results are available through the :attr:`cdf` attribute:: + Results are available through the :attr:`results.cdf` attribute:: - plt.plot(rdf.bins, rdf.cdf[0][0, 0]) + plt.plot(rdf.results.bins, rdf.results.cdf[0][0, 0]) (Which plots the cdf between the first atom in ``s1`` and the first atom in ``s2``) @@ -375,6 +500,10 @@ class InterRDF_s(AnalysisBase): Support for the ``start``, ``stop``, and ``step`` keywords has been removed. These should instead be passed to :meth:`InterRDF_s.run`. + .. versionchanged:: 2.0.0 + Store results as attributes ``bins``, ``edges``, ``rdf``, ``count`` + and ``cdf`` of the ``results`` attribute + of :class:`~MDAnalysis.analysis.AnalysisBase`. """ def __init__(self, u, ags, nbins=75, range=(0.0, 15.0), density=False, **kwargs): @@ -391,18 +520,15 @@ def _prepare(self): # Empty list to store the RDF count_list = [] count, edges = np.histogram([-1], **self.rdf_settings) - count_list = [np.zeros((ag1.n_atoms, ag2.n_atoms, len(count)), dtype=np.float64) - for ag1, ag2 in self.ags] - - self.count = count_list - self.edges = edges - self.bins = 0.5 * (edges[:-1] + edges[1:]) + self.results.count = [np.zeros((ag1.n_atoms, ag2.n_atoms, len(count)), + dtype=np.float64) for ag1, ag2 in self.ags] + self.results.edges = edges + self.results.bins = 0.5 * (edges[:-1] + edges[1:]) # Need to know average volume self.volume = 0.0 self._maxrange = self.rdf_settings['range'][1] - def _single_frame(self): for i, (ag1, ag2) in enumerate(self.ags): pairs, dist = distances.capped_distance(ag1.positions, @@ -411,16 +537,15 @@ def _single_frame(self): box=self.u.dimensions) for j, (idx1, idx2) in enumerate(pairs): - self.count[i][idx1, idx2, :] += np.histogram(dist[j], - **self.rdf_settings)[0] + self.results.count[i][idx1, idx2, :] += np.histogram(dist[j], + **self.rdf_settings)[0] self.volume += self._ts.volume - def _conclude(self): # Volume in each radial shell - vol = np.power(self.edges[1:], 3) - np.power(self.edges[:-1], 3) - vol *= 4/3.0 * np.pi + vols = np.power(self.results.edges, 3) + vol = 4/3 * np.pi * np.diff(vols) # Empty lists to restore indices, RDF indices = [] @@ -435,12 +560,13 @@ def _conclude(self): density = 1 / box_vol if self._density: - rdf.append(self.count[i] / (vol * self.n_frames)) + rdf.append(self.results.count[i] / (vol * self.n_frames)) else: - rdf.append(self.count[i] / (density * vol * self.n_frames)) + rdf.append( + self.results.count[i] / (density * vol * self.n_frames)) - self.rdf = rdf - self.indices = indices + self.results.rdf = rdf + self.results.indices = indices def get_cdf(self): r"""Calculate the cumulative counts for all sites. @@ -449,24 +575,64 @@ def get_cdf(self): radius, i.e., :math:`N_{ab}(r)`. The result is returned and also stored in the attribute - :attr:`cdf`. + :attr:`results.cdf`. Returns ------- cdf : list - list of arrays with the same structure as :attr:`rdf` + list of arrays with the same structure as :attr:`results.rdf` """ # Calculate cumulative distribution function # Empty list to restore CDF cdf = [] - for count in self.count: + for count in self.results.count: cdf.append(np.cumsum(count, axis=2) / self.n_frames) - # Results stored in self.cdf - # self.cdf is a list of cdf between pairs of AtomGroups in ags - self.cdf = cdf + # Results stored in self.results.cdf + # self.results.cdf is a list of cdf between pairs of AtomGroups in ags + self.results.cdf = cdf return cdf + + @property + def edges(self): + wmsg = ("The `edges` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.bins` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.edges + + @property + def count(self): + wmsg = ("The `count` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.bins` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.count + + @property + def bins(self): + wmsg = ("The `bins` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.bins` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.bins + + @property + def rdf(self): + wmsg = ("The `rdf` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.rdf` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.rdf + + @property + def cdf(self): + wmsg = ("The `cdf` attribute was deprecated in MDAnalysis 2.0.0 " + "and will be removed in MDAnalysis 3.0.0. Please use " + "`results.cdf` instead") + warnings.warn(wmsg, DeprecationWarning) + return self.results.cdf diff --git a/testsuite/MDAnalysisTests/analysis/test_rdf.py b/testsuite/MDAnalysisTests/analysis/test_rdf.py index 5839b31aae0..16f0e326ec3 100644 --- a/testsuite/MDAnalysisTests/analysis/test_rdf.py +++ b/testsuite/MDAnalysisTests/analysis/test_rdf.py @@ -47,7 +47,7 @@ def test_nbins(u): s2 = u.atoms[3:] rdf = InterRDF(s1, s2, nbins=412).run() - assert len(rdf.bins) == 412 + assert len(rdf.results.bins) == 412 def test_range(u): @@ -56,8 +56,8 @@ def test_range(u): rmin, rmax = 1.0, 13.0 rdf = InterRDF(s1, s2, range=(rmin, rmax)).run() - assert rdf.edges[0] == rmin - assert rdf.edges[-1] == rmax + assert rdf.results.edges[0] == rmin + assert rdf.results.edges[-1] == rmax def test_count_sum(sels): @@ -65,14 +65,14 @@ def test_count_sum(sels): # should see 8 comparisons in count s1, s2 = sels rdf = InterRDF(s1, s2).run() - assert rdf.count.sum() == 8 + assert rdf.results.count.sum() == 8 def test_count(sels): # should see two distances with 4 counts each s1, s2 = sels rdf = InterRDF(s1, s2).run() - assert len(rdf.count[rdf.count == 4]) == 2 + assert len(rdf.results.count[rdf.results.count == 4]) == 2 def test_double_run(sels): @@ -80,11 +80,20 @@ def test_double_run(sels): s1, s2 = sels rdf = InterRDF(s1, s2).run() rdf.run() - assert len(rdf.count[rdf.count == 4]) == 2 + assert len(rdf.results.count[rdf.results.count == 4]) == 2 def test_exclusion(sels): # should see two distances with 4 counts each s1, s2 = sels rdf = InterRDF(s1, s2, exclusion_block=(1, 2)).run() - assert rdf.count.sum() == 4 + assert rdf.results.count.sum() == 4 + + +@pytest.mark.parametrize("attr", ("rdf", "bins", "edges", "count")) +def test_rdf_attr_warning(sels, attr): + s1, s2 = sels + rdf = InterRDF(s1, s2).run() + wmsg = f"The `{attr}` attribute was deprecated in MDAnalysis 2.0.0" + with pytest.warns(DeprecationWarning, match=wmsg): + getattr(rdf, attr) is rdf.results[attr] diff --git a/testsuite/MDAnalysisTests/analysis/test_rdf_s.py b/testsuite/MDAnalysisTests/analysis/test_rdf_s.py index 7fafc37def4..f3aee0a3fcb 100644 --- a/testsuite/MDAnalysisTests/analysis/test_rdf_s.py +++ b/testsuite/MDAnalysisTests/analysis/test_rdf_s.py @@ -54,49 +54,54 @@ def rdf(u, sels): def test_nbins(u, sels): rdf = InterRDF_s(u, sels, nbins=412).run() - assert len(rdf.bins) == 412 + assert len(rdf.results.bins) == 412 def test_range(u, sels): rmin, rmax = 1.0, 13.0 rdf = InterRDF_s(u, sels, range=(rmin, rmax)).run() - assert rdf.edges[0] == rmin - assert rdf.edges[-1] == rmax + assert rdf.results.edges[0] == rmin + assert rdf.results.edges[-1] == rmax def test_count_size(rdf): # ZND vs OD1 & OD2 - # should see 2 elements in rdf.count - # 1 element in rdf.count[0] - # 2 elements in rdf.count[0][0] - # 2 elements in rdf.count[1] - # 2 elements in rdf.count[1][0] - # 2 elements in rdf.count[1][1] - assert len(rdf.count) == 2 - assert len(rdf.count[0]) == 1 - assert len(rdf.count[0][0]) == 2 - assert len(rdf.count[1]) == 2 - assert len(rdf.count[1][0]) == 2 - assert len(rdf.count[1][1]) == 2 + # should see 2 elements in rdf.results.count + # 1 element in rdf.results.count[0] + # 2 elements in rdf.results.count[0][0] + # 2 elements in rdf.results.count[1] + # 2 elements in rdf.results.count[1][0] + # 2 elements in rdf.results.count[1][1] + assert len(rdf.results.count) == 2 + assert len(rdf.results.count[0]) == 1 + assert len(rdf.results.count[0][0]) == 2 + assert len(rdf.results.count[1]) == 2 + assert len(rdf.results.count[1][0]) == 2 + assert len(rdf.results.count[1][1]) == 2 def test_count(rdf): # should see one distance with 5 counts in count[0][0][1] # should see one distance with 3 counts in count[1][1][0] - assert len(rdf.count[0][0][1][rdf.count[0][0][1] == 5]) == 1 - assert len(rdf.count[1][1][0][rdf.count[1][1][0] == 3]) == 1 + sel0 = rdf.results.count[0][0][1] == 5 + sel1 = rdf.results.count[1][1][0] == 3 + assert len(rdf.results.count[0][0][1][sel0]) == 1 + assert len(rdf.results.count[1][1][0][sel1]) == 1 def test_double_run(rdf): # running rdf twice should give the same result - assert len(rdf.count[0][0][1][rdf.count[0][0][1] == 5]) == 1 - assert len(rdf.count[1][1][0][rdf.count[1][1][0] == 3]) == 1 + sel0 = rdf.results.count[0][0][1] == 5 + sel1 = rdf.results.count[1][1][0] == 3 + assert len(rdf.results.count[0][0][1][sel0]) == 1 + assert len(rdf.results.count[1][1][0][sel1]) == 1 def test_cdf(rdf): rdf.get_cdf() - assert rdf.cdf[0][0][0][-1] == rdf.count[0][0][0].sum()/rdf.n_frames + ref = rdf.results.count[0][0][0].sum()/rdf.n_frames + assert rdf.results.cdf[0][0][0][-1] == ref @pytest.mark.parametrize("density, value", [ @@ -106,11 +111,19 @@ def test_cdf(rdf): def test_density(u, sels, density, value): kwargs = {'density': density} if density is not None else {} rdf = InterRDF_s(u, sels, **kwargs).run() - assert_almost_equal(max(rdf.rdf[0][0][0]), value) + assert_almost_equal(max(rdf.results.rdf[0][0][0]), value) if not density: s1 = u.select_atoms('name ZND and resid 289') s2 = u.select_atoms( 'name OD1 and resid 51 and sphzone 5.0 (resid 289)') rdf_ref = InterRDF(s1, s2).run() - assert_almost_equal(rdf_ref.rdf, rdf.rdf[0][0][0]) + assert_almost_equal(rdf_ref.results.rdf, rdf.results.rdf[0][0][0]) + +@pytest.mark.parametrize("attr", ("rdf", "bins", "edges", "count", "cdf")) +def test_rdf_attr_warning(rdf, attr): + if attr == "cdf": + rdf.get_cdf() + wmsg = f"The `{attr}` attribute was deprecated in MDAnalysis 2.0.0" + with pytest.warns(DeprecationWarning, match=wmsg): + getattr(rdf, attr) is rdf.results[attr]