Skip to content

Fix: normalize InterRDF(norm='density') by nA reference atoms (#5519) - #5522

Open
sumitsaraswat362 wants to merge 3 commits into
MDAnalysis:developfrom
sumitsaraswat362:fix-5519-interrdf-density-norm
Open

sumitsaraswat362 wants to merge 3 commits into
MDAnalysis:developfrom
sumitsaraswat362:fix-5519-interrdf-density-norm

Conversation

@sumitsaraswat362

@sumitsaraswat362 sumitsaraswat362 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5519

Changes made in this Pull Request:

  • Corrected single-particle density normalization in InterRDF._conclude() for norm="density" by dividing accumulated pair counts by the reference atom count $n_A = \text{len}(g_1)$.
  • Added regression test test_density_matches_rdf_times_bulk_density verifying the exact relationship rdf_density == rdf_rdf * results.density_2.
  • Updated test reference value in test_norm to reflect the single-particle normalization ($1.956823 / 2 = 0.9784115$).
  • Updated package/CHANGELOG under 2.12.0 Fixes.

LLM / AI generated code disclosure

LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: no

PR Checklist

  • Issue raised/referenced?
  • Tests updated/added?
  • Documentation updated/added?
  • package/CHANGELOG file updated?
  • Is your name in package/AUTHORS? (If it is not, add it!)
  • I have read and understand the current AI Policy
  • LLM/AI disclosure was updated.

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.

@read-the-docs-community

read-the-docs-community Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.57%. Comparing base (ae9ff4b) to head (c1dc3cb).
⚠️ Report is 8 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5522      +/-   ##
===========================================
- Coverage    93.92%   93.57%   -0.35%     
===========================================
  Files          184      184              
  Lines        22661    22663       +2     
  Branches      3223     3223              
===========================================
- Hits         21284    21208      -76     
- Misses         917      987      +70     
- Partials       460      468       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sumitsaraswat362
sumitsaraswat362 force-pushed the fix-5519-interrdf-density-norm branch from ab73504 to a75423e Compare October 26, 2026 14:27

@kammmran kammmran left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the fix. Checking density == g(r) * density_2 in the test is a nice way to pin this down, because it tests the physical relationship rather than a magic number.

A few thoughts:

InterRDF_s has its own _conclude() in the same file and also supports norm="density". Does it need the same correction, or is it already normalised per reference atom? It might be worth a quick check, or a similar test, so the two classes stay consistent.

This changes the output of norm="density" by a factor of nA, so anyone comparing against older results will see different numbers. Besides the CHANGELOG entry, a .. versionchanged:: note on the norm parameter in the docstring would help users understand why.

Small question: with exclusion_block set, N is reduced, but the density normalization uses nA directly. I think that's correct, since it's per reference atom regardless of exclusions, but I wanted to confirm that was intended.

@sumitsaraswat362

Copy link
Copy Markdown
Contributor Author

Added the docstring note and a consistency test for InterRDF_s (it calculates per site where nA = 1, so its density already matches g(r) * 1/). And yes, using nA for density with exclusions is intended since the single-particle density is defined per reference atom regardless of excluded pairs.

@IAlibay

IAlibay commented Nov 9, 2026

Copy link
Copy Markdown
Member

@kammmran - I have seen several of your reviews across the ecosystem, all being done at pretty much the same time. This indicates to me that you are doing these reviews using AI assistance, and are not declaring it, which would be in breach of of MDAnalysis' AI policy. We ask you to not do this.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InterRDF(norm="density") is nA times the documented single-particle density

3 participants