4.7.3. Radial Distribution Functions — MDAnalysis.analysis.rdf
¶
This module contains two classes to calculate radial pair distribution functions (radial distribution functions or “RDF”). The RDF \(g_{ab}(r)\) between types of particles \(a\) and \(b\) is
which is normalized so that the RDF becomes 1 for large separations in a homogenous system. The RDF effectively counts the average number of \(b\) neighbours in a shell at distance \(r\) around a \(a\) particle and represents it as a density.
The radial cumulative distribution function is
and the average number of \(b\) particles within radius \(r\)
(with the appropriate density \(\rho\)). The latter function can be used to compute, for instance, coordination numbers such as the number of neighbors in the first solvation shell \(N(r_1)\) where \(r_1\) is the position of the first minimum in \(g(r)\).
4.7.3.1. Average radial distribution function¶
InterRDF
is a tool to calculate average radial distribution functions
between two groups of atoms. 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, the output will be the
average of RDFs between A1
and B1
, A1
and B2
, A2
and
B1
, A2
and B2
. A typical application is to calculate the RDF of
solvent with itself or with another solute.

class
MDAnalysis.analysis.rdf.
InterRDF
(g1, g2, nbins=75, range=(0.0, 15.0), exclusion_block=None, **kwargs)[source]¶ Intermolecular pair distribution function
InterRDF(g1, g2, nbins=75, range=(0.0, 15.0))
Parameters:  g1 (AtomGroup) – First AtomGroup
 g2 (AtomGroup) – Second AtomGroup
 nbins (int (optional)) – Number of bins in the histogram [75]
 range (tuple or list (optional)) – The size of the RDF [0.0, 15.0]
 exclusion_block (tuple (optional)) – A tuple representing the tile to exclude from the distance array. [None]
 start (int (optional)) – The frame to start at (default is first)
 stop (int (optional)) – The frame to end at (default is last)
 step (int (optional)) – The step size through the trajectory in frames (default is every frame)
 verbose (bool (optional)) – Show detailed progress of the calculation if set to
True
; the default isFalse
.
Example
First create the
InterRDF
object, by supplying two AtomGroups then use therun()
methodrdf = InterRDF(ag1, ag2) rdf.run()
Results are available through the
bins
andrdf
attributes:plt.plot(rdf.bins, rdf.rdf)
The exclusion_block keyword allows the masking of pairs from within the same molecule. For example, if there are 7 of each atom in each molecule, the exclusion mask (7, 7) can be used.
New in version 0.13.0.

run
(start=None, stop=None, step=None, verbose=None)¶ Perform the calculation
Parameters:
4.7.3.2. Sitespecific radial distribution function¶
InterRDF_s
calculates sitespecific radial distribution
functions. Instead of two groups of atoms it takes as input a list of pairs of
AtomGroup, [[A, B], [C, D], ...]
. Give the same A
and B
to
InterRDF_s
, the output will be a list of RDFs between A1
and
B1
, A1
and B2
, A2
and B1
, A2
and B2
(and similarly
for C
and D
). These sitespecific radial distribution functions are
typically calculated if one is interested in the solvation shells of a ligand
in a binding site or the solvation of specific residues in a protein. A common
use case is to choose A
and C
to be AtomGroups that only contain a
single atom and W
all solvent molecules: InterRDF_s(u, [[A, W], [B,
W]])
will then produce the RDF of solvent around atom A[0]
and around
atom B[0]
.

class
MDAnalysis.analysis.rdf.
InterRDF_s
(u, ags, nbins=75, range=(0.0, 15.0), density=True, **kwargs)[source]¶ Sitespecific intermolecular pair distribution function
Parameters:  u (Universe) – a Universe that contains atoms in ags
 ags (list) – a list of pairs of
AtomGroup
instances  nbins (int (optional)) – Number of bins in the histogram [75]
 range (tuple or list (optional)) – The size of the RDF [0.0, 15.0]
 start (int (optional)) – The frame to start at (default is first)
 stop (int (optional)) – The frame to end at (default is last)
 step (int (optional)) – The step size through the trajectory in frames (default is every frame)
Example
First create the
InterRDF_s
object, by supplying one Universe and one list of pairs of AtomGroups, then use therun()
method:from MDAnalysisTests.datafiles import GRO_MEMPROT, XTC_MEMPROT u = mda.Universe(GRO_MEMPROT, XTC_MEMPROT) s1 = u.select_atoms('name ZND and resid 289') s2 = u.select_atoms('(name OD1 or name OD2) and resid 51 and sphzone 5.0 (resid 289)') s3 = u.select_atoms('name ZND and (resid 291 or resid 292)') s4 = u.select_atoms('(name OD1 or name OD2) and sphzone 5.0 (resid 291)') ags = [[s1, s2], [s3, s4]] rdf = InterRDF_s(u, ags) rdf.run()
Results are available through the
bins
andrdf
attributes:plt.plot(rdf.bins, rdf.rdf[0][0][0])
(Which plots the rdf between the first atom in
s1
and the first atom ins2
)To generate the cumulative distribution function (cdf), use the
get_cdf()
methodcdf = rdf.get_cdf()
Results are available through the :attr:’cdf’ attribute:
plt.plot(rdf.bins, rdf.cdf[0][0][0])
(Which plots the cdf between the first atom in
s1
and the first atom ins2
)New in version 0.19.0.

get_cdf
()[source]¶ Calculate the cumulative distribution functions (CDF) for all sites. Note that this is the actual count within a given radius, i.e., \(N(r)\). :returns: cdf – list of arrays with the same structure as
rdf
:rtype: list

run
(start=None, stop=None, step=None, verbose=None)¶ Perform the calculation
Parameters: