Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InterRDF_s when given density=True #2812

Merged
merged 2 commits into from
Jul 12, 2020

Conversation

VOD555
Copy link
Contributor

@VOD555 VOD555 commented Jul 1, 2020

Fixes #2811

Changes made in this Pull Request:

  • Fix number of atom pairs in InterRDF_s.

PR Checklist

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

@VOD555 VOD555 changed the title Fix rdf density Fix InterRDF_s when given density=True Jul 1, 2020
@codecov
Copy link

codecov bot commented Jul 1, 2020

Codecov Report

Merging #2812 into develop will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2812      +/-   ##
===========================================
- Coverage    92.22%   92.21%   -0.01%     
===========================================
  Files          184      184              
  Lines        24141    24138       -3     
  Branches      3123     3123              
===========================================
- Hits         22263    22260       -3     
  Misses        1813     1813              
  Partials        65       65              
Impacted Files Coverage Δ
package/MDAnalysis/analysis/rdf.py 100.00% <100.00%> (ø)

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 3e56b70...9046bf5. Read the comment docs.

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.

Please add an entry to CHANGELOG.

Could you add note in the docs for InterRDF_s what the normalization is, namely, the mathematical equation for the site RDF?

package/MDAnalysis/analysis/rdf.py Show resolved Hide resolved
@orbeckst
Copy link
Member

orbeckst commented Jul 2, 2020

Btw, there's an error in the reST for Suppose we have two AtomGroups A and B. A contains atom A1, A2, and B contains B1, B2. Give A and B to class:InterRDF, t (the "class" is missing a leading colon), see https://www.mdanalysis.org/docs/documentation_pages/analysis/rdf.html#average-radial-distribution-function

Could you please fix it while you're at it? Thanks.

@pep8speaks
Copy link

pep8speaks commented Jul 7, 2020

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

Line 417:80: E501 line too long (84 > 79 characters)

Line 116:1: W391 blank line at end of file

Comment last updated at 2020-07-10 23:50:35 UTC

@orbeckst
Copy link
Member

orbeckst commented Jul 8, 2020 via email

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.

There's only a horizontal rule that needs to stay in CHANGELOG.

While you're at it, can you please fix/update some of the reST? Thanks.

  • for MDAnalysis.analysis.rdf.InterRDF_s.get_cdf and make sure that the math and Returns display properly (needs a r""" at the beginning and perhaps a blank line).
  • add a section Attributes to InterRDF and InterRDF_s and list the attributes in which results are stored bins, rdf, edges, count and bins, rdf, edges, count, indices, cdf (I think). See our doc guidelines or examples how to add Attributes.

The other comments can be addressed after this PR is merged.

package/CHANGELOG Show resolved Hide resolved
Comment on lines 58 to 70
In :class:`InterRDF_s`, we provide an option `density`. When `density` is
`True`, it will return the RDF :math:`g_{ab}(r)`; when `density` is False`,
it will return the density of particle :math:`b` in a shell at distance
:math:`r` around a :math:`a` particle, which is

.. math::
n_{ab}(r) = \rho g_{ab}(r)
Copy link
Member

Choose a reason for hiding this comment

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

This is confusing: if we set density=False then we get a density?!?

We should then change the kwarg setting to density=True to get the density.

I want to add the fix to the backport PR #2798 so we cannot change the defaults as this can break people's code.

We can make a second PR to change this.

Comment on lines 254 to 256
Calculate :math:`g_{ab}(r)` if set to ``True``; or calculate
:math:`n_{ab}(r)` if set to ``false``; the default is
``True``.
Copy link
Member

Choose a reason for hiding this comment

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

Reverse so that density=True calculates the number density n_ab(r).

I want to add the fix to the backport PR #2798 so we cannot change the defaults as this can break people's code.

We can make a second PR to change this.

@orbeckst orbeckst added this to the 1.0.x milestone Jul 10, 2020
@orbeckst
Copy link
Member

orbeckst commented Jul 10, 2020

To be used for squashed commit message

* Fixes #2811
* enable hitherto undocumented kwarg density for InterRDF_s (but changed 
   meaning of True/False):
   If you used density=False since 0.19.0 to calculate a single particle density then you 
   now have to use density=True. The default remains the same: calculate the RDF and not
   the density.
* Fix normalization for InterRDF_s(..., density=True)
* add test to compare InterRDF and InterRDF_s
* add description for density option
* update CHANGELOG

@orbeckst
Copy link
Member

@VOD555, I'll quickly add the doc fix ups while I am merging...

@orbeckst orbeckst self-assigned this Jul 10, 2020
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.

@VOD555 can you please have a look at my comments and reply? I'll block the merge until you're ok with my changes and we're clear on what we're doing.

Comment on lines +32 to +34
* rdf.InterRDF_s density keyword documented and now gives correct results for
density=True; the keyword was available since 0.19.0 but with incorrect
semantics and not documented and did not produce correct results (Issue
#2811, PR #2812)
Copy link
Member

Choose a reason for hiding this comment

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

I changed the meaning of the density keyword so that it makes more sense. Given that we never documented it, this should be ok and I will classify it as a fix so that it can go into 1.0.1 PR #2798

Comment on lines +62 to +65
In :class:`InterRDF_s`, we provide an option `density`. When `density` is
``False``, it will return the RDF :math:`g_{ab}(r)`; when `density` is
``True``, it will return the density of particle :math:`b` in a shell at
distance :math:`r` around a :math:`a` particle, which is
Copy link
Member

Choose a reason for hiding this comment

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

Note that density=False now means "calculate g(r)" and density=True means "calculate density".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we still need another PR to change the default density, right?

Copy link
Member

Choose a reason for hiding this comment

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

No, this PR switched the behavior.

Copy link
Member

Choose a reason for hiding this comment

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

See comment above #2812 (comment)

package/MDAnalysis/analysis/rdf.py Outdated Show resolved Hide resolved
package/MDAnalysis/analysis/rdf.py Outdated Show resolved Hide resolved
Comment on lines +454 to +451
This is the :ref:`cumulative count<equation-countab>` within a given
radius, i.e., :math:`N_{ab}(r)`.
Copy link
Member

Choose a reason for hiding this comment

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

Why are we calculating the counts and calling it CDF? This is confusing...

I made it clear in the text but still: why did we do this instead of having separate methods that just do the thing that they are named after?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should have seperate functions to give CDF and cummulative N.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, new issue.

Copy link
Member

Choose a reason for hiding this comment

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

@VOD555 can you raise issues for MDAnalysis and PMDA, please?

VOD555 and others added 2 commits July 10, 2020 16:48
- fix MDAnalysis#2811
  (see also MDAnalysis/pmda#120)
- add test to compare InterRDF and InterRDF_s
- add description for density option (was not documented since 0.19.0)
- updated docs for rdf
  - updated docs with equationi
  - attributes for InterRDF and InterRDF_s
  - reference equations
  - minor grammar/style fixes
  - remove ill-advised usage of InterRDF_s from docs
- update CHANGELOG
- fix (because it was not documented before)
- density=True now means "calculate the single site density";
  default is still "calculate RDF" (now meaning density=False)
- update docs
- update tests (add test for default behavior)
- update CHANGELOG
@orbeckst
Copy link
Member

I rewrote the history so that it can be nicely merged.

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.

Wrong rdf values from InterRDF_s when given 'density=True'
4 participants