Make classes in rdf use the Results class#3284
Make classes in rdf use the Results class#3284IAlibay merged 26 commits intoMDAnalysis:developfrom VOD555:merge-rdf-results-develop
Conversation
|
Hello @VOD555! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-05-11 12:19:07 UTC |
Codecov Report
@@ Coverage Diff @@
## develop #3284 +/- ##
===========================================
- Coverage 93.56% 92.83% -0.74%
===========================================
Files 176 171 -5
Lines 22837 22386 -451
Branches 3195 3195
===========================================
- Hits 21368 20781 -587
+ Misses 1418 1063 -355
- Partials 51 542 +491
Continue to review full report at Codecov.
|
PicoCentauri
left a comment
There was a problem hiding this comment.
Good changes and thanks for helping with the results attribute. The code is also easier readable now. I have some comments for improving the docs.
Please add a .. versionchanged:: 2.0.0 describing that the attributes are now stored in the
results attribute. If you want you can put a .. code-block:: python for decorating the examples.
| .. deprecated:: 2.0.0 | ||
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.bins` instead. | ||
|
|
package/MDAnalysis/analysis/rdf.py
Outdated
| .. deprecated:: 2.0.0 | ||
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.rdf` instead. | ||
|
|
package/MDAnalysis/analysis/rdf.py
Outdated
| .. deprecated:: 2.0.0 | ||
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.cdf` instead. |
package/MDAnalysis/analysis/rdf.py
Outdated
| .. deprecated:: 2.0.0 | ||
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.rdf` instead. | ||
|
|
| .. deprecated:: 2.0.0 | ||
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.bins` instead. | ||
|
|
There was a problem hiding this comment.
Should we remove the attribute descriptions given here and put them directly in the docstring of the class? As for example in the GNMAnalysis:
mdanalysis/package/MDAnalysis/analysis/gnm.py
Lines 225 to 232 in da46e84
There was a problem hiding this comment.
I think long term yes, but given the current short deadlines, I'd be inclined to just say let's keep things here and then we can re-format in 2.1.0.
There was a problem hiding this comment.
@PicoCentauri , if you want to raise or find an issue regarding consistent formatting of analysis classes (which will presumably also aid mdacli in documentation extraction) then please do so and start adding TODOs...
package/MDAnalysis/analysis/rdf.py
Outdated
| vol = np.power(self.edges[1:], 3) - np.power(self.edges[:-1], 3) | ||
| vol *= 4/3.0 * np.pi | ||
| vols = np.power(self.edges, 3) | ||
| vol = 4/3.0 * np.pi * (vols[1:] - vols[:-1]) |
package/MDAnalysis/analysis/rdf.py
Outdated
| count, edges = np.histogram([-1], **self.rdf_settings) | ||
| count_list = [np.zeros((ag1.n_atoms, ag2.n_atoms, len(count)), dtype=np.float64) | ||
| l = len(count) | ||
| count_ini = [np.zeros((ag1.n_atoms, ag2.n_atoms, l), dtype=np.float64) |
There was a problem hiding this comment.
Maybe declare this directly as self.count?
package/MDAnalysis/analysis/rdf.py
Outdated
| # Results stored in self.cdf | ||
| # self.cdf is a list of cdf between pairs of AtomGroups in ags |
There was a problem hiding this comment.
# Results stored in self.results.cdf
# self.resulrs.cdf is a list of cdf between pairs of AtomGroups in ags
IAlibay
left a comment
There was a problem hiding this comment.
Kinda echo @PicoCentauri although I'd suggest putting versionadded results.attributes entries and then a versionchanged in the class itself.
| .. deprecated:: 2.0.0 | ||
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.bins` instead. | ||
|
|
There was a problem hiding this comment.
I think long term yes, but given the current short deadlines, I'd be inclined to just say let's keep things here and then we can re-format in 2.1.0.
package/MDAnalysis/analysis/rdf.py
Outdated
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.bins` instead. | ||
|
|
||
| .. attribute:: edges |
There was a problem hiding this comment.
Shouldn't edges and count be results? (I'm not super familiar with the MDA RDF classes so maybe someone like @orbeckst or @fiona-naughton can comment here)
There was a problem hiding this comment.
Yes, you need them for plotting and downstream processing.
PicoCentauri
left a comment
There was a problem hiding this comment.
I got just two suggestions to squash the code a bit. Otherwise I'm happy.
| def test_rdf_attr_warning(sels): | ||
| s1, s2 = sels | ||
| rdf = InterRDF(s1, s2).run() | ||
|
|
||
| wmsg = "The `rdf` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.rdf, rdf.results.rdf) | ||
|
|
||
| wmsg = "The `bins` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.bins, rdf.results.bins) | ||
|
|
||
| wmsg = "The `edges` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.edges, rdf.results.edges) | ||
|
|
||
| wmsg = "The `count` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.count, rdf.results.count) |
There was a problem hiding this comment.
To save some space you can exchange this with
@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]| def test_rdf_attr_warning(rdf): | ||
| wmsg = "The `rdf` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.rdf, rdf.results.rdf) | ||
|
|
||
| wmsg = "The `bins` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.bins, rdf.results.bins) | ||
|
|
||
| wmsg = "The `edges` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.edges, rdf.results.edges) | ||
|
|
||
| wmsg = "The `count` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.count, rdf.results.count) | ||
|
|
||
| rdf.get_cdf() | ||
| wmsg = "The `cdf` attribute was deprecated in MDAnalysis 2.0.0" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(rdf.cdf, rdf.results.cdf) |
There was a problem hiding this comment.
See above
@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]
IAlibay
left a comment
There was a problem hiding this comment.
Sorry for the short messages, only have time for a really quick review.
package/MDAnalysis/analysis/rdf.py
Outdated
| ``(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]``. | ||
| ``results.rdf[i][0, 2]`` is the RDF between atoms ``A[0]`` | ||
| and ``B[2]``. |
package/MDAnalysis/analysis/rdf.py
Outdated
| counts. | ||
| 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. |
package/MDAnalysis/analysis/rdf.py
Outdated
| 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. |
package/MDAnalysis/analysis/rdf.py
Outdated
| removed. These should instead be passed to :meth:`InterRDF.run`. | ||
|
|
||
| .. versionchanged:: 2.0.0 | ||
| Use :class:`~MDAnalysis.analysis.AnalysisBase` as parent class and |
There was a problem hiding this comment.
Was AnalysisBase not the parent class before 2.0.0?
package/MDAnalysis/analysis/rdf.py
Outdated
| removed. These should instead be passed to :meth:`InterRDF_s.run`. | ||
|
|
||
| .. versionchanged:: 2.0.0 | ||
| Use :class:`~MDAnalysis.analysis.AnalysisBase` as parent class and |
* Fixes #3290 * Switch DistanceMatrix to Results class * add tests for deprecations * Updated CHANGELOG
|
Something weird happended: I tried to resolve conflicts between develop and this branch. As usual, CHANGELOG collisions but importantly, restoring a lost CHANGELOG entry 51fa4e4#r50540088 . However, GitHub did not let me commit and warned me that this would have gone to "develop". It is possible that it got confused because the original branch is VOD555/mdanalysis:develop. It gave me the option to rename and I thought it would create a PR onto the PR but it seems it created a new branch VOD555/mdanalysis:merge-rdf-results-develop and substituted it for the original branch of this PR. @VOD555 , I am sorry if this messed up your development environment. I think the way forward for you is to fetch this branch and continue working on it. Apparently, GitHub does not like using the protected branch name, even on forks. |
Yeah I think that's just picking up the word |
IAlibay
left a comment
There was a problem hiding this comment.
Just the one comment to maybe fix, otherwise lgtm
package/MDAnalysis/analysis/rdf.py
Outdated
| # 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], |
There was a problem hiding this comment.
I think it's actually incorrect because now idxA is a tuple. If this still passes tests then I'd like to know why.
| .. deprecated:: 2.0.0 | ||
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.bins` instead. | ||
|
|
There was a problem hiding this comment.
@PicoCentauri , if you want to raise or find an issue regarding consistent formatting of analysis classes (which will presumably also aid mdacli in documentation extraction) then please do so and start adding TODOs...
package/MDAnalysis/analysis/rdf.py
Outdated
| # 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], |
There was a problem hiding this comment.
I think it's actually incorrect because now idxA is a tuple. If this still passes tests then I'd like to know why.
…sis into merge-rdf-results-develop
package/MDAnalysis/analysis/rdf.py
Outdated
| 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 * (vols[1:] - vols[:-1]) |
There was a problem hiding this comment.
np.diff(vols) is also an option
Fixes #3276
Changes made in this Pull Request:
PR Checklist