Chapter-5---Computer-experiments_2023_Understanding-Molecular-Simulation
Chapter-5---Computer-experiments_2023_Understanding-Molecular-Simulation
Computer experiments
In the preceding chapters, we described the basics of Monte Carlo and Molecu-
lar Dynamics simulations. With these techniques, we can sample the equilibrium
configurations of a classical many-body system, and in the case of MD simula-
tions, we can follow its time evolution. But this is only the first step. The most
common aims of Molecular Dynamics are to predict observable properties or to
test theoretical predictions. In other words, we use our simulations to perform
measurements. Measurements in a computer simulation are in many ways sim-
ilar to experiments in physical systems: we have to prepare a sample, we have
to decide on the best measuring technique, we have to accumulate enough data,
and we should analyze the effect of possible systematic and statistical errors in
our results. For these reasons, we use the word measurement to refer to the cal-
culation of observable properties, mainly for lack of a better word. Whenever
confusion might arise, we will refer to measurements on real physical systems
as physical measurements, as opposed to numerical measurements.
There is an important distinction between physical and numerical measure-
ments. In physical measurements, we register how a physical probe responds
when brought in contact with a many-body system. Examples of such probes
are pressure-gauges, thermometers, or beams of photons or neutrons. In con-
trast, in simulations, we have to deduce the value of observable properties from
our knowledge of the coordinates and momenta of all the particles in the system.
Sometimes it is obvious how the value of the relevant macroscopic observable
follows from our knowledge at the microscopic level. For instance, the aver-
age flow velocity in a one-component system is simply the average velocity
of all particles. However, in most cases, the relation between the macroscopic
observable and the raw simulation data is more subtle. To give an example, in ex-
periments, the pressure is often determined by measuring the displacement of a
pressure gauge under the influence of the force exerted on it by the molecules in
the sample. But in simulations, we usually wish to determine the pressure from
the properties of a bulk system subject to periodic boundary conditions. Intro-
ducing a pressure gauge in a simulation would be a bad idea because systems
with interfaces exhibit large finite-size effects. Fortunately, Statistical Mechan-
ics allows us to relate the observable properties of a macroscopic system to
the microscopic information about coordinates and momenta, which we obtain
during a simulation. Below, we discuss some of the more important of these
relations.
5.1.1 Temperature
As was briefly discussed in Chapter 4, the temperature is often measured by
computing the average kinetic energy per degree of freedom. For a system with
f degrees of freedom, the temperature T is given by
2K
kB T = . (5.1.1)
f
Discretization errors
The above description is an oversimplification for MD simulations, where
we necessarily use discrete time steps. The main reason is that, as pointed
out in refs. [114,115], the relation between the velocity, as generated by the
velocity-Verlet algorithm, and the momentum, is not simply vi = pi /mi . Rather,
the “true” velocity is defined through Hamilton’s equations of motion ṙitrue ≡
∂H/∂pi . For simulations with a finite time step, the Hamiltonian is not con-
128 PART | I Basics
1 Strictly speaking, this conservation law only holds for potentials that are infinitely differentiable.
But the present discussion appears to apply, even when this is not strictly the case.
Computer experiments Chapter | 5 129
Naively, one might think that we can compute the partial molar enthalpy of a
species by computing the average energy and volume per particle of species α.
This, however, is not correct (or, more precisely, it is usually ill-defined). Hence,
somewhat surprisingly, special techniques are required to compute partial molar
quantities, even when computing the total quantity (such as H ) is straightfor-
ward. The simplest (but not the cheapest) approach is to compute H for two
systems that differ only in Nα . That method works —even for solid mixtures,
where other techniques often fail. However, for liquids and dense gases, more
efficient techniques are available [129].
and hence
1
CV = E 2 − E2 . (5.1.7)
kB T 2
We note that Eq. (5.1.7) is an example of a static fluctuation expression of the
type discussed in section 2.5.2.
As CV is related to the fluctuations in the energy at a constant temperature, it
would seem that we cannot use a fluctuation expression to determine CV from an
MD simulation at constant N, V , and E. However, Lebowitz et al. [106] showed
that we can determine CV at constant N , V , E by measuring the fluctuations in
130 PART | I Basics
5.1.5 Pressure
One of the most important thermodynamic observables of a many-body system
is its pressure. In experiments, the operational definition of the pressure of a
system is the average force exerted by the system on a unit area of the wall
of the confining container. The above definition is less attractive in simulations
because the introduction of a physical wall in a system would result in large
finite-size effects in most observables. For this reason, expressions for the pres-
sure, P , in a periodic system are often derived starting from the thermodynamic
relation (Eq. (2.1.35) in Chapter 2):
∂F
P =− . (5.1.10)
∂V N,T
1 1
··· drN exp −βU rN = V N ··· dsN exp −βU sN ; L .
V V 0 0
(5.1.13)
U sN ; L depends on L, because if we change L while keeping all si constant,
all
real distances are changed. For the sake of compactness, we will replace
· · · with a single integral sign. We can then write
⎛ 1 ⎞
∂ ln V N + ln 0 dsN exp −βU sN ; L
P = kB T ⎝ ⎠ , (5.1.14)
∂V
N,T
where we have used the fact that c(N, T ) is independent of V . The first term
on the right of Eq. (5.1.14) yields the ideal-gas pressure N kB T /V . The second
term describes the excess pressure due to intermolecular interactions:
⎛ 1 ⎞
∂ ln 0 dsN exp −βU sN ; L
Pexc = kB T ⎝ ⎠
∂V
N,T
N
∂U s ; L
=− . (5.1.15)
∂V
N,T
To proceed, we note that the potential energy U depends on the volume of the
system because the real positions (ri = si L) scale with L. But in some cases, the
potential energy may also have a contribution that depends on V , but not on the
particle coordinates [130]. This happens, for instance, when the potential energy
contains a density-dependent term that does not depend on the coordinates of
the particles within a periodic box, but on the distance between the centers of
different periodic boxes. Using the chain rule, we can then write
N
∂U ∂ri ∂U
Pexc = − +
∂ri ∂V ∂V ri
i=1 N,T
N
1 ∂U
= Fi · ri − , (5.1.16)
dV ∂V ri
i=1 N,T N,T
At first sight, Eq. (5.1.16) looks less suited for systems with periodic boundary
conditions, as it seems to depend on where (in which replica box) we choose
ri . However, this is not much of a problem, as the total force on the particles
in the periodically repeated box is zero. Thompson and Plimpton [131] have
generalized Eq. (5.1.16) to the case where the potential energy can be expressed
as a sum of group contributions (not necessarily pairwise additive), and where
the sums of the intra-group forces vanish, as in the case of pair potentials where
fij + fj i = 0. The more general decomposition can be achieved if the poten-
tial can be written as a sum of n-body terms —although it excludes the case
of forces derived on the fly from quantum calculations. We refer the reader to
[131] for details about the group method. In Chapter 8, we discuss how, using a
free-energy perturbation expression (8.6.11), we can compute the pressure of a
system with many-body interactions that cannot be decomposed.
In simulations, we often use potential-energy functions that can be written
as a sum of pairwise contributions:
N−1
N
U rN = u(rij ).
i=1 j =i+1
We now use the fact that for pair potentials, f(rij ) = −f(rj i ), and that i and j
are dummy indices:
N
1
N
P = ρkB T + f(rij ) · ri + f(rj i ) · rj
2dV
i=1 j =i j =1 i=j N,T
N
1
= ρkB T + f(rij ) · rij
2dV
i=1 j =i N,T
Computer experiments Chapter | 5 133
ρ2
= ρkB T + drg(r)rf (r) . (5.1.21)
2d
The decomposition of the potential energy into group terms may affect what part
of the pressure in Eq. (5.1.16) is considered to be explicitly volume dependent.
To illustrate this point, consider a perfect atomic crystal at T = 0, and at a finite
pressure P . At T = 0, the system is at a minimum of the potential energy, and
hence the net forces Fi on all particles i vanish. According to Eq. (5.1.16),
the pressure is then exclusively due to the explicit volume dependence of U .
However, if, in the spiritof ref. [131], we decompose the net forces into pair
forces, then we find that i,j >i fij · rij does not vanish and Eq. (5.1.21) gives a
correct description of the pressure.
For molecular systems, we have different choices to compute the virial: one
is based on the forces between atoms (or, more precisely, force centers), and the
other is based on forces between the molecular centers of mass. For the average
value of the virial, the choice makes no difference. However, it does make a
difference for the statistical error, in particular, if we describe intra-molecular
forces by stiff spring constants. The reason is that the mean-squared fluctuations
in such forces may be very large, even if the average vanishes.2
d(P V )V T = N dμ . (5.1.22)
2 However, the strong fluctuations of the intra-molecular forces have little effect on the accuracy of
Green-Kubo integrals (see sections 2.5.2 and 5.3.2).
134 PART | I Basics
If we would take the local virial pressure, for instance, near a hard wall at
x = 0, we would find that this measure of the pressure is not constant: hence its
gradient is not related to a mechanical force.
But we can compute the mechanical pressure directly. Let us consider a fic-
titious plane at x. We can then compute the force on that plane as the average
momentum transfer through that plane due to all particles on the left (say) of
that plane. This force has two contributions: 1) momentum transfer due to par-
ticles that carry their own momentum, exerting a net force ρ(x)kB T and 2) the
force due to the fact that the particles on the left of the dividing plane interact
with particles on the right-hand side (note: the choice of “left” or “right” is im-
material). We can compute this force for any plane (and for any potential, even a
many-body potential). However, for pairwise additive potentials, the expression
simplifies because we can write the force acting through a plane as the sum of
all pair forces fx (rij ) for which xi < x and xj > x. This method of computing
the pressure is commonly referred to as the “method of planes” [132]. By con-
struction, the mechanical force thus obtained is independent of x for a system
in mechanical equilibrium.
F kT Q(N, V , T )
− = ln
V V Q(N, V , T )
kT V N dsN exp −βU sN ; V
= ln , (5.1.24)
V V N dsN exp −βU sN ; V
or:
kT
P = Pid − lim ln exp −βU sN , (5.1.25)
V →0 V
where U ≡ U sN ; V − U sN ; V and Pid is the ideal gas pressure. For
systems with continuous potential-energy functions, V can be chosen both
Computer experiments Chapter | 5 135
positive and negative. For hard-core systems, the situation may be a bit more
tricky because (for spherical particles) U is always zero upon expansion. In
such cases, one should use V < 0. However, for sufficiently non-spherical
particles even volume expansion may occasionally lead to overlaps. In that case,
the results for simulations with positive and negative V should be combined
as will be explained in section 8.6.3.
In practice, the virtual-volume-move approach can be made much more effi-
cient by decomposing the free-energy changes in contributions due to individual
particles. Such an approach becomes rigorous in the limit V → 0 see [133].
5.1.5.4 Compressibility
Once we have computed the pressure of a system as a function of density, we
can obtain the isothermal compressibility βT from
1 ∂V 1 ∂ρ
βT ≡ − = . (5.1.26)
V ∂P N,T ρ ∂P N,T
However, as in the case of the heat capacity, we can use a fluctuation expression
to estimate the compressibility from a simulation at constant pressure at a single
state point. We use the fact that
∂ ln Q (N, P , T )
V N,P ,T = −kB T . (5.1.27)
∂P
It then follows that
−1 ∂V V 2 − V 2
βT = = . (5.1.28)
V ∂P N,T V kB T
Similar expressions exist for the elastic constants of solids (see section F.4).
FIGURE 5.1 The figure with the solid frame shows a (periodically repeated) box with height H
and width W , containing two phases separated by flat interfaces (dashed lines). The original box is
then deformed such that the volume remains constant. This is achieved by scaling W by a factor λ,
and H by a factor λ−1 . The boundary of the deformed box is indicated by dotted lines. Due to this
transformation, the surface area separating the two phases changes from 2S to 2λS (there are two
surfaces).
and hence,
∂F
γ≡ . (5.1.30)
∂A N,V ,T
3 The coordinate transformation due to scaling will also change the momenta (see Appendix F.4,
however for a volume conserving transformation, rescaling of the momenta does not change
Eq. (5.1.31).
Computer experiments Chapter | 5 137
and hence
N
1
γ= fij ;z zij − fij ;x xij . (5.1.34)
4S
i=1 j =i
It would seem that there is something wrong with Eq. (5.1.34) because the
number of particles in the numerator scales with the volume V , whereas the
denominator scales with the surface area S. In fact, there is no problem, because
the environment of a particle (say i) far away from the surface is isotropic, then
fij ;z zij = fij ;x xij . (5.1.35)
j =i j =i
The net result is that pairs ij that are in the bulk of the liquid do not contribute
to the surface tension. In a simulation, it is advisable not to include such pairs
in the sum in Eq. (5.1.34), because they would contribute to the statistical noise,
but not to the average. The derivation above is just one route to computing the
surface tension. Other approaches are described in refs. [134,135] —see also
SI L.2. However, as was shown by Schofield and Henderson [136], the most
commonly used expressions are equivalent.
in Fig. 5.1. Just as in Eq. (5.1.25), we can compute the free-energy change due to
a change in the surface area at constant total volume. The finite-difference form
of Eq. (5.1.31), is usually referred to as the “test-area method”. This method
remains valid when estimating the surface tension of a system with arbitrary
non-pairwise-additive interactions [134,137]. For flat fluid-fluid interfaces, the
test-area method remains correct for finite virtual-area changes, because the sur-
face tension is independent of the area. In practice, large test area changes are
not advisable if the energy changes in forward and backward test-area moves do
not overlap (see section 8.6.1). An illustration of the problems caused by non-
overlapping distributions in the test-area method can be found in ref. [138]).
where we have introduced the surface stress ts .5 For liquids, γ does not de-
pend on A, and hence γ = ts , but this equality does not hold for solids6 : special
free-energy techniques (as discussed in section 8.4.2) are needed to compute
γ for solid interfaces [141], however to compute the free-energy change upon
bringing a solid and a liquid into contact, one can use the relatively straight-
forward thermodynamic-integration technique proposed by Leroy and Müller-
Plathe [142].
other features of curved surfaces imply that computing the free energy of curved
surfaces is subtle and full of pitfalls. We will not discuss this topic, but refer the
reader to ref. [143] for further background information.
N
A(q) ∼ bi (q)eiq·ri , (5.1.37)
i=1
where bi (q) is the scattering amplitude of particle i. The bi (q) depends on the
internal structure of the particles. We note that if b(q) is a known function of
q, simulations can be used to predict the scattering intensity. Often the data
of scattering experiments are analyzed to yield information about the so-called
structure factor S(q), which is equal to 1/N times mean-squared fluctuation in
the amplitude of ρ(q), the Fourier transform of the single-particle density. ρ(q)
is equal to
N
ρ(q) = eiq·ri = dr ρ(r)eiq·r , (5.1.38)
i=1 V
N
ρ(r) ≡ δ(r − ri ) . (5.1.39)
i=1
140 PART | I Basics
However, in simulations, this procedure is tricky. The reason is that g(r) is usu-
ally computed up to a spherical cut-off distance rmax = L/2, where L is the
diameter of the simulation box. But often r 2 (g(r) − 1) has not yet decayed to
zero at rmax . In that case, spherical truncation of the integral can give rise to un-
physical behavior of the apparent S(q) —for instance, it may show oscillations
and even negative values at small q values. For this reason, it is safer to compute
S(q) using Eq. (5.1.40). Computationally, this is not a big problem because Fast
Fourier Transforms are ... fast [38].
FIGURE 5.2 The figure shows three different calculations of the radial distribution function of an
864-particle Lennard-Jones fluid [144]. The noisy curve (dots) was obtained using the conventional
histogram method for a single liquid configuration (histogram bin-width equal to 0.005σ ). The other
two, almost indistinguishable curves, are the results using the histogram method for a run of 10,000
simulation steps (triangles) and the result obtained for a single configuration, using the method
of [144] (gray curve). Figure: courtesy of Samuel Coles.
√
scales as 1/ ). Suppose that the number of pairs in the interval {r, r + r} is
Np (r), then we divide this number by the average number of pairs that would
be found in the same range in an ideal (non-interacting) system. That number is
Npid (r) = 12 Nρ(4π/3)[(r + r)3 − r 3 ] (in three dimensions). The factor (1/2) is
due to the fact that we count every pair only once. Then our estimate for g(r) is
Np (r)
g(r) = . (5.1.43)
Npid (r)
This calculation is so simple that it seems hard to imagine that one can do bet-
ter, and indeed during the first six decades of molecular simulation, the above
approach was overwhelmingly used to compute g(r). However, in 2013 Borgis
et al. [144,145] (see also [146]) proposed an alternative method to compute g(r)
that has two advantages: 1) it yields a smaller statistical error and 2) it does not
require binning. In deriving the result of Ref. [144] we follow a slightly different
approach than that paper.
The value of the radial distribution function at a distance r from a reference
particle is equal to the angular average of ρ(r)/ρ:
1 1
g(r) = d r̂ ρ(r)N −1 = d r̂ δ(r − rj ) , (5.1.44)
ρ ρ
j =i N −1
where N is the total number of particles in the system, ρ denotes the average
number density (ρ ≡ (N/V )) and rj is the distance of particle j from the origin,
where particle i is located. r̂ is the unit vector in the direction of r. For simplicity,
142 PART | I Basics
we have written down the expression for g(r) for a given particle i, and hence
the sum of j = i is keeping i fixed, but in practice the expression is averaged
over all equivalent particles i. The angular brackets denote the thermal average
drN −1 e−βU (r ) (· · · )
N
· · · N −1 ≡ , (5.1.45)
drN −1 e−βU (r )
N
The only term that depends on r (the length of r) is the δ-function. We can
therefore write
∂g(r) 1
= d r̂ r̂ · ∇r δ(r − rj ) . (5.1.47)
∂r ρ
j =i
(r)
where r̂ · Fj ≡ Fj denotes the force on particle j in the radial direction. We
can now integrate with respect to r
β r
(r) N
g(r) = g(r = 0) + dr d r̂ δ(r − rj )Fj (r )
ρ 0
j =i N −1
δ(r
(r)
β j =i − rj )Fj (rN )
= g(r = 0) + dr
ρ r <r 4πr 2
N −1
(r)
β Fj (rN )
= g(r = 0) + θ (r − rj ) , (5.1.49)
ρ 4πrj 2
j N −1
Computer experiments Chapter | 5 143
where θ denotes the Heaviside step function. To make a connection to the results
of ref. [144], we note that in a homogeneous system, all particles i of the same
species are equivalent. We can therefore write
(r)
β
N Fj (rN )
g(r) = g(r = 0) + θ (r − rij ) .
Nρ
i=1 j =i
4πrij2
N −1
But i and j are just dummy indices. So we obtain the same expression for g(r)
by permuting i and j , except that if r̂ = r̂ij , then r̂ = −r̂j i . Adding the two
equivalent expressions for g(r) and dividing by two, we get
(r) (r)
β Fj (rN ) − Fi (rN )
N
g(r) = g(r = 0) + θ (r − rij ) .
2Nρ 4πrij 2
i=1 j =i N −1
(5.1.50)
Eq. (5.1.50) is equivalent to the result of Ref. [144].
The remarkable feature of Eq. (5.1.50) is that g(r) depends not just on the
number of pairs at distance r, but on all pair distances less than r. We stress that
we have not assumed that the interactions in the system are pairwise additive:
Fi − Fj is not a pair force.
Note that the choice of r in Eqs. (5.1.50) and (5.1.52) is arbitrary, hence no
binning is required and therefore the statistical accuracy of Eq. (5.1.46) does
not depend on the choice of a bin width. In the examples shown in Fig. 5.2, the
prediction based on Eq. (5.1.52) appears to be more accurate than that obtained
in a direct calculation of g(r) with a reasonable choice for the bin width. As ex-
plained in Illustration 2, the statistical error can be further reduced by combining
two independent estimates of g(r).
In the above equation, h(r) depends only on pairs with a distance larger than
r. Interestingly, this expression in Eq. (5.1.52) for g(r) − 1 is numerically not
identical to Eq. (5.1.49): one expression is more accurate for small r, the other
for large r; the variance in the estimate of g(r) can be reduced by combining
the two results [147]: see Fig. 5.3.
144 PART | I Basics
FIGURE 5.3 This figure shows the variance in the estimate of g(r) using, Eq. (5.1.50)
(triangles), Eq. (5.1.52) (squares) and the optimal, weighted combination of the two [147]
(circles). The figure shows that the overall variance can be reduced by combining the two
independent estimates of g(r). The system studied was a Lennard-Jones fluid (N=864, T =
1.35 and ρ = 0.8). Figure: courtesy of Samuel Coles.
The limitation of the method of Ref. [144] is that it only works for sys-
tems in thermal equilibrium. But that limitation can also be an advantage: if
Eq. (5.1.49) disagrees with the standard expression for g(r), then that is an
indication that the system is not in thermal equilibrium (the converse is not
true).
where ulj (r) is the Lennard-Jones potential and for these simulations rc = 2.5σ
is used.
During a simulation, we must check if the system has equilibrated, or at
least has reached a state that is stable on the timescale of the simulations. We
then collect data about observable quantities and, at the end of the simula-
tion, we compute averages and estimate the statistical errors. This Example
illustrated how such a simulation might proceed.
At the beginning of the simulation, we prepare the system in state that, of
course, is not yet equilibrated. Here, we will assume that the particles were
originally positioned on the lattice sites of a face-centered cubic crystal.
We initialize the velocities of the particles such that the initial kinetic
energy corresponds to a temperature T = 0.728. The density is fixed at ρ =
Computer experiments Chapter | 5 145
FIGURE 5.4 Total, potential, and kinetic energy per particle U/N as a function of the num-
ber of time steps Ntime .
In Fig. 5.4 shows the time evolution from the start of the simulation of the
total energy, kinetic energy, and potential energy. Note that the total energy,
whilst fluctuating slightly, does not drift. The kinetic and potential energies
change strongly during the equilibration period but after that they oscillate
around their equilibrium value. The figure suggests that for this (very small)
system, equilibration is complete in less than 1000 time steps. However,
longer equilibrations will be needed for larger systems, and for glassy sys-
tems, MD may not achieve equilibration at all.
FIGURE 5.5 The standard deviation σ in the potential energy as a function of the number
of block operations M for a simulation of 150,000 and 600,000 time steps. This variance is
calculated using Eq. (5.3.28).
figure also shows the effect of increasing the total length of the simulation by
a factor of 4; as expected, the statistical error in the potential energy decreases
by a factor of 2.
We obtain the following results: for the potential energy U = −4.4190 ±
0.0012 and for the kinetic energy K = 2.2564 ± 0.0012, the latter correspond-
ing to an average temperature of T = 1.5043 ± 0.0008. For the pressure, we
find 5.16 ± 0.02.
FIGURE 5.6 Radial distribution function of a Lennard-Jones fluid close to the triple point:
T = 1.5043 ± 0.0008 and ρ = 0.8442.
1 ∞
U/N = ρ dr u(r)g(r)
2 0
∞
= 2πρ dr r 2 u(r)g(r) (5.1.54)
0
1 1 2 ∞ du(r)
P = ρkB T − ρ dr rg(r)
32 0 dr
2 ∞ du(r) 3
= ρkB T − πρ 2 dr r g(r), (5.1.55)
3 0 dr
function grsample
delg=box/(2*nhis) delg is bin size
ngr=ngr+1 calling grsample increments ngr
for 1 ≤ i ≤ npart-1 do
for i+1 ≤ j ≤ npart do loop over all pairs
xr=x(i)-x(j)
xr=xr-box*round(xr/box) nearest image only
√
r= xr**2+yr**2+yz**2 In 3d: same for y and z
if r < box/2 then only consider distances < box/2
ig=int(r/delg)
g(ig)=g(ig)+2 histogram incremented for pair ij
endif
enddo
enddo
end function
function grnormalize
gfac = (4/3)*π *delg**3 gf ac convert bins to 3d shells
for 1 ≤ i ≤ nhis do
vb=gfac*((i+1)**3-i**3) 3d volume in i-th bin
nid=vb*ρ number of ideal gas particles in vb
g(i)=g(i)/(ngr*npart*nid) normalize g(r)
enddo
end function
ular Dynamics and Monte Carlo simulations. However, in addition to the static
equilibrium properties, we can also measure dynamic equilibrium properties in
a Molecular Dynamics simulation. At first sight, a dynamic equilibrium prop-
erty appears to be a contradiction: in equilibrium all properties are independent
of time, hence any time dependence in the macroscopic properties of a system
would seem to be related to non-equilibrium behavior. However, as explained
in section 2.5.2 on Linear Response Theory, the time-dependent behavior of
a system that is only weakly perturbed is completely described by the time-
correlation function of fluctuations in the system at equilibrium.
Before discussing the relation between time-correlation functions and trans-
port coefficients, we first describe another widely used method to study transport
properties using equilibrium simulations, using the coefficient of self-diffusion
as an example.
5.2.1 Diffusion
Diffusion is the process whereby an initially nonuniform concentration profile
(e.g., an ink drop in water) is smoothed in the absence of flow (no stirring).
Diffusion is caused by the molecular motion of the particles in the fluid. The
macroscopic law that describes diffusion is known as Fick’s law, which states
that the flux j of the diffusing species is proportional to the negative gradient in
the concentration of that species:
j = −D∇c, (5.2.1)
∂c(r, t)
+ ∇ · j(r, t) = 0. (5.2.2)
∂t
Combining Eq. (5.2.2) with Eq. (5.2.1), we obtain
∂c(r, t)
− D∇ 2 c(r, t) = 0. (5.2.3)
∂t
We can solve Eq. (5.2.3) with the boundary condition
where r is the scalar distance from the origin. As before, d denotes the dimen-
sionality of the system. For what follows we do not need c(r, t) itself, but only
the time dependence of its second moment:
dr c(r, t) = 1. (5.2.7)
∂
dr r 2 c(r, t) = D dr r 2 ∇ 2 c(r, t). (5.2.8)
∂t
The left-hand side of this equation is simply equal to
∂ r 2 (t)
. (5.2.9)
∂t
Applying partial integration to the right-hand side, we obtain
∂ r 2 (t)
= D dr r 2 ∇ 2 c(r, t)
∂t
=D dr ∇ · (r 2 ∇c(r, t)) − D dr ∇r 2 · ∇c(r, t)
150 PART | I Basics
= 0 + 2dD dr c(r, t)
= 2dD. (5.2.10)
Eq. (5.2.10) relates the (self)diffusion coefficient D to the width of the concen-
tration profile. Eq. (5.2.10) was derived by Einstein and is therefore called an
Einstein relation. The important feature of Eq. (5.2.10) is that it relates a macro-
scopic transport coefficient (D), to a microscopic observable (r 2 (t)), which is
the mean-squared distance over which the labeled molecules have moved in a
time interval t. Eq. (5.2.10) suggests how to measure D in a computer simula-
tion. For every particle i, we measure the distance traveled in time t, ri (t), and
we plot the mean square of these distances as a function of the time t:
1
N
r(t)2 = ri (t)2 . (5.2.11)
N
i=1
An example of such a plot is shown in Fig. 5.9. We should be specific about what
we mean with the displacement of a particle in a system with periodic boundary
conditions. The displacement that we are interested in, is the time integral of the
velocity of the tagged particle:
t
r(t) = dt v(t ). (5.2.12)
0
Eq. (5.2.12) allows us to express the diffusion coefficient in terms of the particle
velocities. We start with the relation
∂ x 2 (t)
2D = lim , (5.2.13)
t→∞ ∂t
where, for convenience, we consider only one Cartesian component of the mean-
squared displacement. Expressing x(t) as the time integral of the x-component
of the tagged-particle velocity, we obtain
t 2
x 2 (t) = dt vx (t )
0
t t
= dt dt vx (t )vx (t )
0 0
t t
=2 dt dt vx (t )vx (t ) . (5.2.14)
0 0
Computer experiments Chapter | 5 151
The quantity vx (t )vx (t ) is the velocity autocorrelation function of the tagged
particle (see section 2.5.2, Eq. (2.5.9)). It measures the correlation between the
velocity of a particle at times t and t . As time correlation functions in equilib-
rium only depend on the difference of t and t , we can write
vx (t )vx (t ) = vx (t − t )vx (0) . (5.2.15)
9 The fact that the integral in Eq. (5.2.16) may diverge does not mean that particles diffuse infinitely
However, as discussed in Appendix D, Eq. (D.1.5), the driving force for dif-
fusion is a gradient in the chemical potential, μ. With this definition, we
obtain the third definition of a diffusion coefficient, which we refer to as the
collective diffusion coefficient (or corrected, or Maxwell-Stefan diffusion co-
efficient), D c , which for a system at constant temperature reads:
L(c) D c (c)
J (c) ≡ − ∇μ = − ∇μ, (5.2.18)
kB T kB T c
1 ∇μ
Dt = Dc = D c ,
kB T c ∇ ln c
where we have replaced the chemical potential by the fugacity, f . For ad-
sorption in a porous material, the relation between the concentration in the
pores and the pressure is given by the adsorption isotherm. Fig. 5.7a gives a
typical isotherm. For low pressures, we can assume ideal gas behavior, f = P .
Hence, the adsorption is given by the Henry coefficient:
c = H P = Hf
and
kB T ∂ ln f
P →0 = =1.
c ∂ ln c
At saturation, one needs an infinite increase of the chemical potential to in-
crease the concentration inside the pores by 1 more molecule. Hence:
P →∞ = ∞ .
that pass a unit surface per time unit, is infinite. While at the same time, our
labeled molecule has hardly moved.
FIGURE 5.7 (a) a typical example of an adsorption isotherm of a gas adsorbed in a porous
media c is the loading (molecules per unit volume) as a function of the pressure. (b) the three
different diffusion coefficients as a function of loading c; transport diffusion coefficient D t ,
collective diffusion coefficient D c , and self diffusion coefficient D s , figure based on data
from [154].
In the limit of P → 0, one does not expect any correlations between the ve-
locities of particles i and j . Hence for i = j , we have vi (o)vj (τ ) = 0. Hence
in this limit, the collective diffusion coefficient is equal to the self-diffusion
coefficient.
1 ∞ 1 ∞
Dc = dτ vi (o)vj (τ ) ≈ dτ vi (o)vi (τ )δij = D s .
3N 0 3N 0
i,j i,j
(5.2.20)
We now have seen three diffusion coefficients that each have a different de-
pendence on the loading in pores. In Fig. 5.7b, these diffusion coefficients
are reported for molecules in a pore. Interestingly, in the limit of zero loading,
these three diffusion coefficients take the same value.
Green-Kubo relations have been derived for many other transport coeffi-
cients, such as the shear viscosity η,
1 ∞
η= dt σ xy (0)σ xy (t) (5.2.21)
V kB T 0
154 PART | I Basics
1 ∞
λT = dt jze (0)jze (t) (5.2.23)
V kB T2 0
1 ∞
σe = dt jxel (0)jxel (t) (5.2.25)
V kB T 0
with
N
jxel = qi vix . (5.2.26)
i=1
A simple derivation of the Green-Kubo (GK) relations for electrical conductivity
and viscosity is given in Appendix F.2 and F.3, respectively. For a more rigorous
derivation (including the expression for the thermal conductivity), see ref. [59].
When using the GK expression to compute the viscosity of a molecule with
internal vibrations, we can either compute the stress tensor using the forces act-
ing on individual atoms, or we can consider only the forces acting between
molecular centers of mass. The integral of the stress correlation is the same in
both cases. However, the atomic description results in high-frequency oscilla-
tions in the stress auto-correlation function, which tends to obscure the overall
shape of the stress Auto-Correlation Function (ACF) [159]. However, these
high-frequency components do not affect the GK integral, which corresponds
to the zero-frequency component of the stress ACF.
In some cases, e.g., polymers, expressing the stress in terms of center-of-
mass forces is not useful. In that case, we can perform coarse-graining (or, more
generally, filtering) of the stress ACF [160] following an approach similar to the
10 In the general case of non-pairwise additive interactions, the expressions for the heat flux are
no longer simple (see e.g., [155]). Under those conditions, it may be attractive to impose a (small)
explicit energy flux [156–158] and measure the resulting temperature gradient. The same argument
applies to measuring the viscosity in non-pairwise additive systems.
Computer experiments Chapter | 5 155
one described in section 5.2.2 below. Similar arguments apply to the calculation
of the thermal conductivity.
Time-correlation functions can be measured directly in a Molecular Dynam-
ics simulation. For classical systems, the GK relation for D and the Einstein
relation are strictly equivalent. There may be practical reasons for preferring
one approach over the other, but in classical mechanics, the distinction is never
fundamental. Algorithm 9 provides a simple illustration of the calculation of the
mean-squared displacement and velocity auto-correlation function.
jn
v(i) (j ) ≡ v(i−1) (l) (5.2.27)
l=(j −1)n+1
with
v(0) (l) ≡ v(l), (5.2.28)
where v(l) is the velocity of a particle at time l. Eq. (5.2.27) is a recursive
relation between block sums of level i and i − 1. The variable n determines the
number of terms in the summation. For example, v(3) (j ) can be written as
jn
v(3) (j ) = v(2) (l1 )
l1 =(j −1)n+1
156 PART | I Basics
Algorithm 9 (Diffusion)
r2t(i)=r2t(i)/(npart*ntime(i)) (x(t))2
enddo
endif
end function
Computer experiments Chapter | 5 157
jn
l1 n
l2 n
= v(l3 )
[l1 =(j −1)n+1] [l2 =(l1 −1)n+1] [l3 =(l2 −1)n+1]
3
n j
= v(l)
l=(j −1)n3 +1
1 n3 j r(n3 j ) − r(n3 (j − 1) + 1)
≈ dt v(t) = .
t l=(j −1)n3 +1 t
Clearly, the block sum of the velocity is related to the displacement of the par-
ticle in a time interval ni t. In Fig. 5.8 the blocking operation is illustrated.
From the block sums defined above, we can compute the Velocity autocorre-
lation function (VACF) with a resolution that decreases with increasing time.
At each level of blocking, we need to store n × N block sums, where N is the
number of particles (in practice, it will be more convenient to store the block-
averaged velocities).
(r̄2 )(0) (l) = (r̄2 )(0) (l) + v2sum (1, l)t 2 . (5.2.35)
2. If the current time step is a multiple of n, we perform the first blocking opera-
tion. If it is a multiple of n2 we perform the second blocking, etc. Performing
blocking operation i involves the following steps:
a. As before, we first consider the situation that all ith-order accumulators
have already been filled at least once (i.e., t > ni t). Using the i − 1th
block sum (vsum (i − 1, 1)), we update
for j = n.
b. These operations yield
=n
j
vsum (i, l) = vsum (i − 1, j ). (5.2.38)
j =n−l+1
(r2 )(i) (l) = (r2 )(i) (l) + v2sum (i, l)t 2 . (5.2.39)
3. Finally, we must consider how to handle arrays that have not yet been com-
pletely filled. Consider the situation that only nmax of the n locations of the
array that contains the ith-level sums have been initialized. In that case, we
should proceed as follows:
a. Update the current block length: nmax = nmax+1 (nmax < n).
b. For j = 1,nmax-1
c. For j = nmax
vsum (i, j ) = vsum (i − 1, 1). (5.2.41)
The update of Eq. (5.2.31) remains the same.
In Case Study 6, we compare the present algorithm and the conventional
algorithm for computing the diffusion coefficient of the Lennard-Jones fluid.
...(continue)....
else ifswitch == 1 then sample
ntel=ntel+1
iblm=MaxBlock(ntel,n) maximum number of possible
blocking operations
for 1 ≤ ib ≤ iblm do
if ntel % n**(ib-1)==0 then is ntel a multiple of nib ?
ibl(ib)=ibl(ib)+1 increase current block length
inm=max(ibl(ib),n) set maximum block length to n
for 1 ≤ i ≤ npart do
if ib == 1 then
delx=vx(i) 0th block: ordinary velocity
else
delx=vxsum(ib-1,1,i) previous block velocity
endif
for 1 ≤ in ≤ inm do
if inm =
n then test block length equal to n
inp=in
else
inp=in+1
endif
if in < inm then
vxsum(ib,in,i)=
+ vxsum(ib,inp,i)+delx Eqs. (5.2.36) or (5.2.40)
else
vxsum(ib,in,i)=delx Eqs. (5.2.37) or (5.2.41)
endif
enddo
for 1 ≤ in ≤ inm do
tel(ib,in)=tel(ib,in)+1 counter number of updates
delr2(ib,in)=delr2(ib,in) update Eq. (5.2.39)
+ +vxsum(ib,inm-in+1,i)**2
enddo
endif
enddo
endif
end function
Note, however, that the heat flux, or for that matter, the stress tensor, is
not uniquely defined. However, as was pointed out by Baroni and collabora-
tors [155,161], the GK integrals (i.e., the observable transport properties) are
not changed by the addition of the flux associated with the time evolution of a
bounded, conserved function of coordinates and momenta. Adding such a flux
would change the time-dependence of the GK integrand and would therefore
affect the interpretation of the finite-frequency response obtained by Fourier-
transforming the flux auto-correlation function. But the integral (i.e., the zero-
frequency response) would not be affected.
The robustness of the zero-frequency response is to be expected in view
of Onsager’s earlier expression for transport coefficients in terms of auto-
correlation functions of fluxes [55,56], which was based on irreversible ther-
modynamics rather than on statistical mechanics. Onsager’s expressions for
transport coefficients in terms of integrals of flux-correlation functions required
little more than the assumption that small fluctuations of extensive quantities in
many-body systems are Gaussian and that, to the lowest order, the fluxes are
linear in the thermodynamic restoring forces. The ability to transform the value
of the GK integrands without changing the value of the integral, can be used to
improve the statistical accuracy of the integrals [155,161].
Improving the accuracy of GK integration is important because correlation
functions obtained in simulations are intrinsically noisy. Hence, the signal-to-
noise ratio goes to zero as we increase the upper limit of the integral. Once
the value of the integrand is not significantly different from zero, further in-
tegration only makes the results less accurate. By using the trick proposed in
refs. [155,161], it is possible to mitigate (but not eliminate) this inevitable noise
problem. Let us consider a simple example to clarify the effect of statistical
noise in transport coefficients due to noise in the relevant correlation func-
tion. Suppose that we wish to measure a transport coefficient LAA given by
the Green-Kubo relation
t
LAA = lim dt A(0)A(t ) .
t→∞ 0
2
= constant + 2(t)2 A(0)2 (nmax − 1) . (5.2.42)
Eq. (5.2.42) shows that the numerical estimate of σL2 grows linearly with nmax ,
which corresponds to a linear variation with tmax in the continuous case. Of
course, the real σL2 will be lower because it will be divided by the number of
independent starting points.
√ A reasonable way to truncate the GK integration is
therefore to plot σL vs tmax and determine the point where the linear part of
σL becomes non-negligible compared with LAA (tmax ). See also Exercise 11.
A second comment on GK integrals is also in place: a more direct route to
compute the linear response of a system to an external perturbation was pro-
posed in the 1970’s by Ciccotti et al. [162]. In this approach, the effect of a
(very) weak perturbation on the time evolution of the system (i.e., on its trajec-
tory through phase space) is computed directly. The response of the system is
obtained by computing the time evolution of the observable of interest along the
perturbed and unperturbed trajectories. Subtracting the unperturbed from the
perturbed value of the observable yields (upon averaging) the time-dependent
linear response. The approach of ref. [162] is more general than the GK route,
but it also runs into a noise problem at longer times.
FIGURE 5.9 (Left) Mean-squared displacement r(t)2 as a function of the simulation time
t. Note that for long times, r(t)2 varies linearly with t. The slope is then given by 2dD,
where d is the dimensionality of the system and D the self-diffusion coefficient. (Right) Ve-
locity auto-correlation function v(0) · v(t) as a function of the simulation time t.
diffusion using Eq. (5.2.13). This equation is however only valid in the limit
t → ∞. In practice this means that we have to verify that we compute the
mean-squared displacement in the long-time regime where all transient ef-
fects have died down, and only the linear dependence on t remains.
The Green-Kubo integral of the VACF provides an alternative route to cal-
culate the diffusion coefficient (Eq. (5.2.16)). Strictly speaking, the upper limit
of the GK integral corresponds to t → ∞. In practice, we must stop at an
earlier time tc , because once the VACF has decayed into the noise, further in-
tegration increases the noise but not the signal. A rough estimate of tc can be
obtained by determining the time where the integral seems to have reached a
plateau value. Hopefully, all transients in the mean-squared displacement to
have died down beyond tc . However, if an ACF has a long-time tail that has a
small amplitude, but a large integral, then truncation at tc would introduce a
large systematic error.
For more details, see SI (Case Study 5).
FIGURE 5.10 Mean-squared displacement as a function of time for the Lennard-Jones fluid
(ρ = 0.844, N = 108, and T = 1.50); comparison of the conventional method with the order-n
scheme.
FIGURE 5.11 Relative error in the mean-squared displacement as a function of the number
of data blocks as defined by Flyvbjerg and Petersen. The figures compare the conventional
scheme (solid squares) with the order-n method (open circles) to determine the mean-squared
displacement. The right figure is for t = 0.1 and the left figure for t = 1.0.
In these simulations the time step was t = 0.001 and the block length was
set to n = 10. For both methods, the total number of time steps was equal.
To calculate the mean-squared displacement, we have used 100,000 sam-
ples for all times in the conventional scheme. For the order-n scheme, we
have used 100,000 samples for t ∈ [0, 0.01], 10,000 for t ∈ [0.01, 0.1], 1,000
for t ∈ [0.1, 1], etc. This illustrates that the number of samples in the order-n
scheme is considerably less than in the conventional scheme. The accuracy
of the results, however, turned out to be the same. This is shown in Fig. 5.11
166 PART | I Basics
for t = 0.1 and t = 1.0. Since the total number of data blocking operations
that can be performed on the data depends on the total number of samples,
the number of blocking operations is less for the order-n method. Fig. 5.11
shows that for t = 0.1, the order-n scheme yields a standard deviation that is
effectively constant after three data blocking operations, indicating the sam-
ples are independent, whereas the standard deviation using the conventional
method shows an increase for the first six to eight data blocking operations.
For t = 1.0, the order-n method is independent of the number of data blocks,
the conventional method only after 10 data blocks. This implies that one has
to average over 210 ≈ 1000 successive samples to have two independent data
points. In addition, the figure shows that the plateau value of the standard de-
viation is essentially the same for the two methods, which implies that for this
case, the two methods are equally accurate, but, as shown below, the order-n
method is computationally cheaper.
FIGURE 5.12 Percentage increase of the total CPU time as a function of the total time for
which we determine the mean-squared displacement; comparison of the conventional scheme
with the order-n scheme for the same system as is considered in Fig. 5.10.
In Fig. 5.12 we compare the CPU requirements of the two algorithms for
simulations with a fixed total number of time steps. This figure shows the
increase of the total CPU time of the simulation as a function of the total
time for which the mean-squared displacement has been calculated. With the
order-n scheme, the CPU time should be (nearly) independent of the total time
for which we determine the mean-squared displacement, which is indeed
what we observe. For the conventional scheme, however, the required CPU
time increases significantly for longer times. At t = 1.0 the order-n scheme
gives an increase of the total CPU time of 17%, whereas the conventional
scheme shows an increase of 130%.
This example illustrates that the saving in memory as well as in CPU time
of the order-n scheme can be significant, especially if we are interested in the
mean-squared displacement at long times.
For more details, see SI (Case Study 6).
Computer experiments Chapter | 5 167
1 τ
Aτ = dt A(t), (5.3.1)
τ 0
where the subscript on Aτ refers to averaging over a time τ . If the ergodic hy-
pothesis is justified then Aτ → A, as τ → ∞, where A denotes the ensemble
average of A. We can estimate σ 2 (A), the variance in Aτ :
1 ∞
σ 2 (A) ≈ dt CA (t)
τ −∞
2t c
≈ A CA (0). (5.3.3)
τ
In the last equation, we have used the definition of tAc as the integral from 0 to
∞ of the normalized correlation function CA (t)/CA (0). The relative variance
in Aτ , therefore, is given by11
2
σ 2 (A) A − A2
≈ (2t c
A /τ ) . (5.3.4)
A2 A2
11 Some quantities have correlation functions that integrate rigorously to zero (for instance, the
auto-correlation function of the force on a particle). Typically, such quantities are time derivatives
of other (bounded) observables (Ḃ = A). In that case it follows from Eq. (5.3.1) that σ 2 (A) scales
as σ 2 (B)/τ 2 .
Computer experiments Chapter | 5 169
A2 − A2 / A2 is inversely proportional to the number of particles, N . To
see this, consider the expressions for A and A2 − A2 in this case:
N
A = ai = N a (5.3.5)
i=1
and
N
N
A2 − A2 = [ai − a] aj − a . (5.3.6)
i=1 j =1
12 The extension to cross-correlation functions of the type A(t)B(0) is straightforward and is left
as an exercise to the reader.
170 PART | I Basics
The first term on the right-hand side of Eq. (5.3.9) contains a fourth-order cor-
relation function. To simplify matters, we shall assume that the fluctuations in
A follow a Gaussian distribution. This is not the simple Gaussian distribution
that describes, for instance, the Maxwell distribution of particle velocities in
equilibrium, but a multidimensional distribution that describes all correlations
between fluctuations of A at different times. Here we only consider real fluctu-
ations at discrete times. Then the generalized Gaussian distribution would be of
the following form:
⎡ ⎤
1
P (A(t1 ), A(t2 ), · · · , A(τ0n )) = const. × exp ⎣− A(ti )α(ti − tj )A(tj )⎦ ,
2
i,j
(5.3.10)
where the matrix α(ti − tj ) is the “matrix” inverse of the (discrete) time corre-
lation function CA (ti − tj ), meaning that dτ CA (t − τ )α(τ − t ) = δ(t − t ).
For Gaussian variables, we can factorize all higher-order correlation functions.
In particular,
A(t )A(t + τ )A(t )A(t + τ )
= A(t )A(t + τ ) A(t )A(t + τ )
+ A(t )A(t ) A(t + τ )A(t + τ )
+ A(t )A(t + τ ) A(t + τ )A(t ) . (5.3.11)
2 ∞
C A (τ )2 − C A (τ ) = (2/τ0 ) dx A(x)A(0)2
−∞
2 τc
= 4 A2 (0) . (5.3.14)
τ0
2 2 τc
C A (τ )2 − C A (τ ) = 2 A2 (0) . (5.3.17)
τ0
Comparison of Eq. (5.3.14) with Eq. (5.3.17) shows that the absolute error in
CA (τ ) changes only little with τ . As a consequence, the relative error in time
correlation functions increases rapidly as CA (τ ) decays to 0. In this derivation,
we have assumed that the total number of samples for each τ is equal; how-
ever, we typically have fewer samples for large τ , and hence for long times, the
estimate of the error based on Eq. (5.3.17) is overly optimistic.
It should be stressed that the preceding error estimate is approximate, be-
cause it relies on the validity of the Gaussian approximation. Of course, devi-
ations from the Gaussian approximation may occur. However, Jones and Man-
dadapu have presented evidence showing that, in a number of cases of practical
interest, the Gaussian approximation is actually quite good [165].
MC cycles):
1 tB
AB ≡ dt A(t). (5.3.18)
tB 0
A simulation yields a sequence of values of A equally space in time. With these
data, we can easily accumulate block averages for a given block length tB . Our
choice of tB is arbitrary but typically such that the total simulation time τ0 must
contain a fair number of blocks (less than 10 becomes risky —see Fig. 5.5).
Having accumulated these block averages, we can then average adjacent block
averages to obtain averages for blocks of length τB ≡ (2, 3, · · · , n)×tB . The
number of such blocks is nB = τ0 /τB .
Now consider the variance in the block averages for a given value of τB :
1
nB
2
σ 2 (AB ) = AB − A . (5.3.19)
nB
b=1
If τB is much larger than the correlation time tAc , we know from Eq. (5.3.4) that
tc
σ 2 (AB ) ≈ A2 − A2 A
. (5.3.20)
τB
But, as yet, we do not know tAc . We, therefore, compute the product
σ 2 (AB )
P (τB ) ≡ τB × . (5.3.21)
A2 − A2
In the limit τB tAc , we know that P (τB ) must approach tAc . We can now plot
P (τB ) versus τB (or, more conveniently, 1/P (τB ) versus 1/τB ) and estimate
the limit of P (τB ) for τB → ∞. This yields our estimate of tAc and thereby our
error estimate for A. The above analysis of block averages provides a powerful
tool to determine whether a simulation is long enough to yield a sufficiently
accurate estimate of a particular quantity: if we find that P (τB ) is still strongly
dependent on τB in the limit tB = τ , then we know that τ0 , the total length of
the simulation, is too short.
A widely used implementation of the block-averaging approach for estimat-
ing the statistical error in averages obtained in a simulation was proposed by
Flyvbjerg and Petersen [148]. Let A1 , A2 , . . . , AL be L consecutive samples of
some fluctuating quantity A. We want to estimate A, the equilibrium average
of A, and estimate its statistical error. The equilibrium average of A is estimated
as the average over all L sampled data points
1
L
A ≈ Ā ≡ Ai . (5.3.22)
L
i=1
Computer experiments Chapter | 5 173
1
L
2
σ 2 (Ā) ≈ Ai − Ā . (5.3.23)
L(L − 1)
i=1
However, Eq. (5.3.23) would only be valid if all distinct samples were uncor-
related (of course, a sample is always correlated with itself). For the raw data,
successive points are usually strongly correlated, which is why we cannot use
Eq. (5.3.23) directly on the sequence of measure A-values.
To address this problem, ref. [148] applied repeated blocking of the data
until successive blocks are effectively uncorrelated.
As every step in the blocking procedure is the same (averaging to adjacent
blocks, thereby halving the number of blocks), it is best written as a recursive
procedure: We start with the data set A1 , A2 , . . . , AL , and apply one blocking
step to generate a data set A1 , A2 , . . . , AL , which has half the size of the original
set:
Ai = 0.5(A2i−1 + A2i ) (5.3.24)
with
L = 0.5L. (5.3.25)
Note that the average of the new set Ā
is the same as for the original one.
However, the mean-squared error in A is given by13
1 2
L
2
2 2
σ (A ) = A
2
− A = A i − Ā . (5.3.26)
L
i=1
σ 2 (A )
≈ Constant. (5.3.27)
L − 1
This limiting value is used as our estimator of the variance in the measured
average. Flyvbjerg and Petersen [148] also give an estimate of the statistical
error in the error:
(
σ 2 (A ) 2σ 4 (A )
σ 2 (Ā) ≈ ± . (5.3.28)
L −1 (L − 1)3
13 It is important to distinguish between the mean-squared error in the data (A ) and in the variance
in their average (Ā ).
174 PART | I Basics
2. What is the limiting value of the VACF for t → ∞? Motivate your answer.
3. What is the physical meaning of VACF < 0?
4. In MD simulations, we can compute the self-diffusion coefficient and the
viscosity. However, for the same simulation time, the relative errors in the
two quantities will be different. Explain.
5. Rather than measuring correlation functions, we can also measure power
spectra. Suppose that we study a fluctuating observable A(t). The numeri-
cally determined power spectrum of A is then defined as
1
GA (ω) = lim |AM (ω)|2
M→∞ M
where
M
AM ((m − 1)ω) ≡ A(nt)ei(m−1)ω(n−1)t ,
n=1
i=N ) )
1 )) E (0) − E (it) ))
E (t) = ) ).
N E (0)
i=1
In this equation, E (x) is the total energy (kinetic + potential) of the system at
time x. Change the program (only the central loop) in such a way that E is
176 PART | I Basics
computed and make a plot of E as a function of the time step. How does the
time step for a given energy drift change with the temperature and density?
4. An important quantity of a liquid or gas is the so-called self-diffusion coefficient
D. Here we the calculation of D in a three-dimensional system. There are two
methods to calculate D:
a. by integrating the velocity autocorrelation function (VACF):
1 ∞
D= v (t) · v t + t dt
3 0
∞ i=N
0 i=1 v (i, t) · v i, t + t dt
= (5.4.1)
3N
in which N is the number of particles and v (i, t) is the velocity of particle
i at time t. To obtain independent samples of the VACF, one should choose
t in such a way that independent time origins are taken, i.e., t = iat,
i = 1, 2, · · · , ∞ and v (t) · v (t + at) ≈ 0.
b. by calculating the mean-squared displacement:
) )
)x t + t − x (t))2
D = lim . (5.4.2)
t →∞ 6t
Compare this phenomenological equation with your own simulations. How can
one translate D ∗ to a diffusion coefficient in SI units?
6. For a system of particles interacting through a pair potential u (r), the average
potential energy U can be computed, if we know the radial distribution function
g (r). Derive an expression for U in terms of u (r) and g (r). Compare this
calculation with a direct calculation of the average energy. A similar method
can be used to compute the average pressure.
7. In the current version of the code, the equations of motion are integrated by the
Verlet algorithm. Make a plot of the energy drift E for the following integration
algorithms:
• Verlet
• Velocity Verlet
• Euler (never use this algorithm in real simulations).
Computer experiments Chapter | 5 177