Skip to content

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

Open

Description

@rcgiri-physics

Hi, thanks for maintaining MDAnalysis. The module docs define norm="density" as the single particle density n_ab(r) = rho g_ab(r) (equation-nab). In InterRDF._conclude (package/MDAnalysis/analysis/rdf.py), both "rdf" and "density" divide by n_frames * shell volume, but only the "rdf" branch also applies N / box_vol with N = nA * nB. As a result, "density" returns the pair count per shell volume summed over all a particles, which is nA * n_ab(r).

Check with MDAnalysis 2.11.0: an ideal gas of 40 A and 200 B atoms placed at uniform random positions in a 30 Å box, 20 frames, range=(3, 12). Here n_ab should equal rho_B = nB/V = 0.00741 Å^-3.

mean over bins
norm="rdf" 0.999 (correct)
norm="density" 0.296, which is 40.0 x rho_B = nA x rho_B

Dividing by nA (adjusted for exclusions, as in the "rdf" branch) would match the docs. InterRDF_s computes per-pair counts, so it is not affected in the same way.

I found this while testing physverify, a small verification tool I'm working on, against public codes. The tests and this write-up were done with help from an AI assistant; the numbers come from actually running the code.

Activity

  1. sumitsaraswat362 commented on Oct 24, 2026

    @sumitsaraswat362
    Contributor

    Hi @rcgiri-physics, thanks for catching this and opening the issue!

    I investigated the implementation in package/MDAnalysis/analysis/rdf.py and can confirm your findings:

    1. results.count stores the accumulated pairwise counts between all particles in g1 ($n_A$) and g2 ($n_B$).
    2. For norm="rdf", norm is multiplied by normalization_density which accounts for the full pair capacity $N = n_A n_B$ (accounting for exclusions if specified).
    3. For norm="density", the documentation defines the target output as the single-particle density $n_{ab}(r) = \rho_2 g_{ab}(r)$ around a reference $a$ particle. Because results.count aggregates across all $n_A$ reference particles, dividing solely by $T \cdot \Delta V$ returns the collective density $n_A \cdot n_{ab}(r)$, which is $n_A$ times the documented single-particle value.

    Scaling norm *= nA in _conclude() when self.norm == "density" directly corrects this. With this fix, the fundamental identity:
    results_density == results_rdf * results.density_2
    holds across all bins for unexcluded pairs.

    I have tested this fix locally along with an analytical test verifying the relation to results.density_2 and updated reference values in test_rdf.py. I would be glad to submit a PR for this if maintainers would like to proceed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions