Skip to content

Make classes in rdf use the Results class#3284

Merged
IAlibay merged 26 commits intoMDAnalysis:developfrom
VOD555:merge-rdf-results-develop
May 11, 2021
Merged

Make classes in rdf use the Results class#3284
IAlibay merged 26 commits intoMDAnalysis:developfrom
VOD555:merge-rdf-results-develop

Conversation

@VOD555
Copy link
Contributor

@VOD555 VOD555 commented May 7, 2021

Fixes #3276

Changes made in this Pull Request:

  • use self.results instead of self. to save data

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@pep8speaks
Copy link

pep8speaks commented May 7, 2021

Hello @VOD555! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 523:27: E221 multiple spaces before operator
Line 524:80: E501 line too long (83 > 79 characters)
Line 541:80: E501 line too long (92 > 79 characters)

Comment last updated at 2021-05-11 12:19:07 UTC

@codecov
Copy link

codecov bot commented May 7, 2021

Codecov Report

Merging #3284 (c814829) into develop (6d5ef34) will decrease coverage by 0.73%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
package/MDAnalysis/analysis/rdf.py 100.00% <100.00%> (ø)
package/MDAnalysis/analysis/encore/covariance.py 75.38% <0.00%> (-12.31%) ⬇️
...ckage/MDAnalysis/analysis/encore/confdistmatrix.py 67.41% <0.00%> (-10.12%) ⬇️
package/MDAnalysis/coordinates/DMS.py 88.40% <0.00%> (-7.25%) ⬇️
...nalysis/analysis/hydrogenbonds/hbond_autocorrel.py 87.66% <0.00%> (-7.21%) ⬇️
package/MDAnalysis/converters/OpenMMParser.py 92.85% <0.00%> (-7.15%) ⬇️
package/MDAnalysis/coordinates/GMS.py 85.61% <0.00%> (-6.85%) ⬇️
package/MDAnalysis/lib/transformations.py 78.56% <0.00%> (-6.76%) ⬇️
package/MDAnalysis/topology/HoomdXMLParser.py 78.72% <0.00%> (-6.39%) ⬇️
package/MDAnalysis/coordinates/CRD.py 79.20% <0.00%> (-5.95%) ⬇️
... and 93 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d5ef34...c814829. Read the comment docs.

Copy link
Contributor

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⬆️

Comment on lines +163 to +166
.. deprecated:: 2.0.0
This attribute will be removed in 3.0.0.
Use :attr:`results.rdf` instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⬆️

Comment on lines +183 to +185
.. deprecated:: 2.0.0
This attribute will be removed in 3.0.0.
Use :attr:`results.cdf` instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⬆️

Comment on lines +112 to +115
.. deprecated:: 2.0.0
This attribute will be removed in 3.0.0.
Use :attr:`results.rdf` instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⬆️

Comment on lines +98 to +101
.. deprecated:: 2.0.0
This attribute will be removed in 3.0.0.
Use :attr:`results.bins` instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the attribute descriptions given here and put them directly in the docstring of the class? As for example in the GNMAnalysis:

Attributes
----------
results.times : numpy.ndarray
simulation times used in analysis
results.eigenvalues : numpy.ndarray
calculated eigenvalues
results.eigenvectors : numpy.ndarray
calculated eigenvectors

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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...

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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 3 is enough in Py3

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe declare this directly as self.count?

Comment on lines 504 to 505
# Results stored in self.cdf
# self.cdf is a list of cdf between pairs of AtomGroups in ags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Results stored in self.results.cdf
# self.resulrs.cdf is a list of cdf between pairs of AtomGroups in ags

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda echo @PicoCentauri although I'd suggest putting versionadded results.attributes entries and then a versionchanged in the class itself.

Comment on lines +98 to +101
.. deprecated:: 2.0.0
This attribute will be removed in 3.0.0.
Use :attr:`results.bins` instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This attribute will be removed in 3.0.0.
Use :attr:`results.bins` instead.

.. attribute:: edges
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you need them for plotting and downstream processing.

Copy link
Contributor

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got just two suggestions to squash the code a bit. Otherwise I'm happy.

Comment on lines +94 to +112
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Comment on lines +123 to +143
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Contributor

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let's wait for @orbeckst and @IAlibay.

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the short messages, only have time for a really quick review.

``(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]``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

removed. These should instead be passed to :meth:`InterRDF.run`.

.. versionchanged:: 2.0.0
Use :class:`~MDAnalysis.analysis.AnalysisBase` as parent class and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was AnalysisBase not the parent class before 2.0.0?

removed. These should instead be passed to :meth:`InterRDF_s.run`.

.. versionchanged:: 2.0.0
Use :class:`~MDAnalysis.analysis.AnalysisBase` as parent class and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above.

orbeckst referenced this pull request May 8, 2021
* Fixes #3290
* Switch DistanceMatrix to Results class
* add tests for deprecations
* Updated CHANGELOG
@orbeckst
Copy link
Member

orbeckst commented May 8, 2021

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.

@IAlibay
Copy link
Member

IAlibay commented May 8, 2021

However, GitHub did not let me commit and warned me that this would have gone to "develop".

Yeah I think that's just picking up the word develop from the incoming branch. I think you can just dismiss the warning (I remember having to do this a few times during GSoC application periods).

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the one comment to maybe fix, otherwise lgtm

# 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],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the , necessary here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's actually incorrect because now idxA is a tuple. If this still passes tests then I'd like to know why.

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comma that @IAlibay found looks problematic. My other comments are minor.

Comment on lines +98 to +101
.. deprecated:: 2.0.0
This attribute will be removed in 3.0.0.
Use :attr:`results.bins` instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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...

# 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],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's actually incorrect because now idxA is a tuple. If this still passes tests then I'd like to know why.

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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.diff(vols) is also an option

@IAlibay IAlibay merged commit 8618b7d into MDAnalysis:develop May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

update classes in rdf to use new .results

6 participants