Repository navigation
Expose computed density in InterRDF results - #5482
sumitsaraswat362 wants to merge 15 commits into
Conversation
Documentation build overview
17 files changed ·
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5482 +/- ##
========================================
Coverage 93.91% 93.92%
========================================
Files 184 184
Lines 22644 22661 +17
Branches 3219 3223 +4
========================================
+ Hits 21267 21284 +17
Misses 917 917
Partials 460 460 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I think that trying to compute the average density value in the norm="density" case might lead to zero division erros given that a nonzero box_vol is not actually required in these cases in order to compute the distance dependent density. Probably the two cases should be handled separately. I am talking about the line 401 of the diff. I am not an expert or anything though so I would wait someone with more expertise to express his opinion obviously. I was just practicing code reviewing and understing. |
- Only compute results.density/results.rho when box_vol > 0, otherwise set to None - Expose results.rho alias alongside results.density as suggested in MDAnalysis#5362
|
Thanks for the great catch, @sici17! You are completely right—for non-periodic trajectories or simulations without box dimensions where I've just pushed a commit guarding against this:
Really appreciate you taking the time to review! |
|
Before we can review this PR, please restore the original PR template https://github.com/MDAnalysis/mdanalysis/blob/develop/.github/PULL_REQUEST_TEMPLATE.md and answer all questions. |
|
@orbeckst I have restored the official PR template in the PR description and answered all questions, updated @sici17 Good catch! I added guards for zero box volume / non-periodic systems ( |
orbeckst
left a comment
There was a problem hiding this comment.
Quick initial review
- only include
results.density(dropresults.rho) — there should be only one way to access the data - add documentation, for instance,
results.densityneeds to be explained where the otherresultsattributes are listed; add a.. versionadded:: 2.11.0
These are the first things I noticed, there may be more comments.
|
Please also resolve the conflicts with the develop branch. |
|
@orbeckst Thanks for the review! I have addressed the points:
|
orbeckst
left a comment
There was a problem hiding this comment.
The computed "density" is results.density because it's not a density.
(Furthermore, it's confusing because norm="rdf gives results.rdf and then people/LLMs may look for results.density for norm="density".)
We could store it as results.normalization_density or something like that. What would be a good name? Does it still make sense to store this quantity or should we be storing
Whatever we store, we need then document properly, i.e., write down the equations that define the quantity.
We cannot really continue with the PR until we have decided this.
|
Thank you for pointing this out, Oliver. You are completely right. The quantity I have updated the implementation to address this:
The equations and physical definitions have been added to the docstrings of both |
orbeckst
left a comment
There was a problem hiding this comment.
I like your new attributes and docs. Please see comment below for necessary updates.
| s1, s2 = sels | ||
| # When norm is "rdf" | ||
| rdf = InterRDF(s1, s2, norm="rdf").run(**client_InterRDF) | ||
| assert not hasattr(rdf.results, "density") |
There was a problem hiding this comment.
Remove this assertion — why is this here??
|
|
||
| # When norm is "density" | ||
| rdf_dense = InterRDF(s1, s2, norm="density").run(**client_InterRDF) | ||
| assert not hasattr(rdf_dense.results, "density") |
There was a problem hiding this comment.
Remove this assertion — why is this here??
| .. versionadded:: 2.11.0 | ||
|
|
||
| results.density_a : float | ||
| The bulk number density :math:`\rho_a = N_a / \langle V \rangle` of the |
There was a problem hiding this comment.
rename to density_1 and density_2 and change the equations in the doc string to use 1 instead of a and 2 instead of b.
In this way it better matches g1 and g2.
I think we can leave the general docs at the module level. Readers should be able to make the jump between a=1 and b=2.
|
|
||
| .. versionadded:: 2.11.0 | ||
|
|
||
| results.density_b : float |
| This attribute will be removed in 3.0.0. | ||
| Use :attr:`results.count` instead. | ||
|
|
||
| results.normalization_density : float |
| s1 = u.select_atoms("name OW") | ||
| s2 = u.select_atoms("name HW1 HW2") | ||
| rdf = InterRDF(s1, s2, norm="density").run(**client_InterRDF) | ||
| assert not hasattr(rdf.results, "density") |
There was a problem hiding this comment.
??? Is this an LLM remnant ???
| kwargs = {"density": density} if density is not None else {} | ||
| rdf = InterRDF_s(u, sels, **kwargs).run(**client_InterRDF_s) | ||
| assert_almost_equal(max(rdf.results.rdf[0][0][0]), value) | ||
| assert not hasattr(rdf.results, "density") |
| assert not hasattr(rdf.results, "density") | ||
| assert hasattr(rdf.results, "box_volume") | ||
| assert hasattr(rdf.results, "normalization_density") | ||
| assert rdf.results.box_volume > 0 |
| s2 = u.select_atoms("name OD1 and resid 51") | ||
| ags = [[s1, s2]] | ||
| rdf = InterRDF_s(u, ags, norm="density").run(**client_InterRDF_s) | ||
| assert not hasattr(rdf.results, "density") |
| Enhancements | ||
| * InterRDF and InterRDF_s now expose computed average box volume and densities | ||
| as results.box_volume, results.normalization_density, and (for InterRDF) | ||
| results.density_a and results.density_b when norm is "rdf" or "density" |
|
Thanks for the careful review, @orbeckst! I have addressed all feedback in the latest commits:
|
Fixes #5362
Changes made in this Pull Request:
results.density(and aliasresults.rho) inInterRDFandInterRDF_swhennormis"rdf"or"density".test_rdf.pyandtest_rdf_s.py.package/CHANGELOGandpackage/AUTHORS.LLM / AI generated code disclosure
LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: no
PR Checklist
package/CHANGELOGfile updated?package/AUTHORS? (If it is not, add it!)Developers Certificate of Origin
I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.