0% found this document useful (0 votes)
9 views

Chapter-5---Computer-experiments_2023_Understanding-Molecular-Simulation

Chapter 5 discusses the methodology and importance of computer experiments in Molecular Dynamics (MD) and Monte Carlo simulations, focusing on how these simulations can be used to measure observable properties of many-body systems. It distinguishes between physical and numerical measurements, emphasizing the need for careful data analysis to account for systematic and statistical errors. The chapter also covers static and dynamical properties, the role of Planck's constant in classical simulations, and techniques for measuring thermodynamic quantities such as temperature, internal energy, heat capacity, and pressure.

Uploaded by

2993115435
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Chapter-5---Computer-experiments_2023_Understanding-Molecular-Simulation

Chapter 5 discusses the methodology and importance of computer experiments in Molecular Dynamics (MD) and Monte Carlo simulations, focusing on how these simulations can be used to measure observable properties of many-body systems. It distinguishes between physical and numerical measurements, emphasizing the need for careful data analysis to account for systematic and statistical errors. The chapter also covers static and dynamical properties, the role of Planck's constant in classical simulations, and techniques for measuring thermodynamic quantities such as temperature, internal energy, heat capacity, and pressure.

Uploaded by

2993115435
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

Chapter 5

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.

Understanding Molecular Simulation. https://doi.org/10.1016/B978-0-32-390292-2.00013-1 125


Copyright © 2023 Elsevier Inc. All rights reserved.
126 PART | I Basics

In what follows, we distinguish between static and dynamical properties.


Static properties can be computed by sampling the equilibrium configurations
on a many-body system, which can be done by both MC and MD simulations.
Typical examples of static properties that can be sampled in a simulation are
the quantities that appear in thermodynamic relations, such as internal energy,
temperature, pressure, and heat capacity, but not quantities such as entropy or
free energy that cannot be expressed as an ensemble average. We will discuss
free-energy-related properties separately in Chapter 8.
Dynamical properties describe how a system evolves in time in response
to an external perturbation. Examples are shear flow, heat flow, or diffusion.
Of course, when a system has been subjected to an external perturbation, it
is brought out of equilibrium. However, as discussed in section 2.5.2, we can
compute the dynamical response of a system to a weak external perturbation by
studying the decay of fluctuations in equilibrium. This linear-response theory
discussed allows us to derive expressions for transport coefficients in terms of
time-correlation functions of microscopic fluxes that can be expressed explicitly
in terms of the coordinates and momenta of the particles in the system —and that
is precisely what we need in simulations.
In what follows, we first discuss the statistical mechanical basis of tech-
niques for computing static properties of a system by MC or MD. After that, we
discuss the numerical measurement of transport properties.

Planck’s constant in classical simulations


The simulation techniques described in this book are all based on classical statis-
tical mechanics. As a consequence, none of the computed measurable quantities
can depend on the value of Planck’s constant h. Some quantities (for instance,
the chemical potential, discussed in section 8.5) seem to depend on h through
the thermal De Broglie wavelength, . However, in that case, Planck’s constant
has been inserted by hand to achieve consistency with known quantum results.
Changing the value of h would result in an overall shift of the chemical po-
tential, which does not affect a single measurable property of a purely classical
system. In reality, the separation between the classical and the quantum world
is not clean. Many molecules have internal vibrations (or even rotations), with
level spacings that are not small compared to the thermal energy. In that case, a
choice has to be made: if the excitation energies are much larger than kB T , these
modes will be mostly in their ground state, and it is reasonable to ignore them.
However, in many cases, there is some degree of coupling between the quantum
degrees of freedom and the classical bath. One consequence of the quantum
nature of the internal degrees of freedom of a molecule is that the thermal con-
tribution to its average internal energy is lower than the corresponding classical
value. Many molecular properties are barely affected by the quantized internal
degrees of freedom, but quantum effects can have a large effect on quantities
such as heat capacity and thermal conductivity. This problem cannot be resolved
within the context of purely classical simulations.
Computer experiments Chapter | 5 127

5.1 Static properties


The first step in a simulation study is usually to characterize the thermody-
namic state of the model system. That is: we wish to determine the relation
between “control parameters”, such as the temperature, pressure, or applied
electrical/magnetic field (i.e., all intensive quantities), and the resulting state
functions, such as energy, volume or polarization (which are all extensive quan-
tities). Depending on the nature of the simulation, some of these quantities may
have been imposed, e.g., the temperature in constant-N V T MC simulations, or
the energy in constant-N V E simulations. In Chapters 6 and 7, we will discuss
techniques to carry out simulations in other ensembles than N V T for MC and
N V E for MD. For instance, we can carry out MD simulations at constant N P T .
In that case, the primary thermodynamic quantities to measure in a simulation
would be the internal energy E and the average volume V . However, even when
we impose P and T , it is still useful to measure the temperature and the pres-
sure to verify that these quantities are indeed equal to the imposed values. Such
measurements provide a powerful diagnostic tool.

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

The number of degrees of freedom of an N -particle system is equal to N d − Nc ,


where d is the dimensionality, and Nc is the number of constraints (e.g., bond
lengths) or conserved quantities (e.g., momentum or energy). In a system with
periodic boundary conditions, angular momentum is not a conserved quantity,
but in the absence of external forces, the total momentum is conserved. It is
important to distinguish N from the number of molecules in a system: if a sys-
tem consists of M molecules, each comprising m atoms (or groups described
as atoms), then N = mM. For a system without hard constraints, f is equal to
N d − (d + 1), which is usually close to N d, but not equal.

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

served, but rather the “shadow”-Hamiltonian HS (see Eq. (4.3.22)).1 It is this


Hamiltonian that determines the density in phase space, and that should enter in
the Boltzmann factor. We can then use
  
∂HS  
pi = pi ṙitrue N V T kB T . (5.1.2)
∂pi NV T

But, for the shadow Hamiltonian


ṙitrue = (pi /mi ) . (5.1.3)
Rather, to compute the correct temperature, we have to estimate the true ve-
locities ṙitrue by interpolation from several consecutive positions [115]. Then
pi ṙitrue  = kB T .
In most simple MD codes, this procedure is not followed. However, the effect
of using the wrong velocities can lead to a serious discrepancy between the
translational and vibrational temperature, when estimating the temperature of a
system of molecules that have high-frequency internal motions, e.g., proteins in
solution [115] (see Illustration 1).

5.1.2 Internal energy


Measuring the internal energy E of a system is usually straightforward, as it
follows from our knowledge of the Hamiltonian of the system. However, there
may be exceptions, in particular, if the interaction between particles is described
by an effective, temperature-dependent potential, which is not really a potential
but a free-energy (an example is the depletion interaction [128]). In that case,
the energy follows from E = (∂βF /∂β), which vanishes for depletion forces.

5.1.3 Partial molar quantities


Many applications of Molecular Dynamics focus on the study of mixtures. In
those situations, we often need to know how the extensive properties of a system
(e.g., internal energy, enthalpy, volume) change with the composition of the
mixture. Let us take the enthalpy H , of an m-component mixture as an example.
The partial molar enthalpy h of species α is defined as
 
∂H
hα ≡ .
∂Nα P ,T ,{Nβ=α }

The total enthalpy of a mixture can be written as



m
H = E +PV = hα Nα .
α=1

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].

5.1.4 Heat capacity


It is a bit misleading to suggest that the internal energy of a system can be mea-
sured experimentally. Thermodynamic experiments only determine the internal
energy up to an additive constant. However, what experiments can measure is
the variation of the internal energy with temperature or pressure.
As an example, we focus on the CV , the heat capacity of a system at constant
N and V :
 
∂E
CV ≡ . (5.1.4)
∂T N,V
Clearly, if we measure E in a simulation (up to a constant), then we can obtain
CV by carrying out simulations over a range of temperatures and estimating
CV by numerical differentiation. However, we can also determine CV at a fixed
temperature, by studying the spontaneous fluctuations in the internal energy. We
start with the expression
       
∂E ∂E dβ −1 ∂E
CV = = = . (5.1.5)
∂T N V ∂β N V dT kB T 2 ∂β N V

Next, using Eqs. (2.2.13) and (2.2.14), we can write


   
∂E ∂ 2 ln Q(N, V , T )
=− = − E 2  − E2 , (5.1.6)
∂β NV ∂β 2 NV

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

the kinetic energy, K:


 
3N kB2 T 2 3N kB
K2 − K2N V E = 1− . (5.1.8)
NV E 2 2CV

For a more detailed discussion, see ref. [21].


Eq. (5.1.7) suggests how similar expressions can be derived for the heat ca-
pacity at constant pressure, Cp :
 
∂H
CP = , (5.1.9)
∂T N P

the isothermal compressibility and a number of other “susceptibilities”, i.e.,


quantities that describe that variation of an extensive thermodynamic quantity
with an intensive variable. In Appendix F.4 discusses how, for instance, the elas-
tic constants of a solid can be obtained from a fluctuation expression.

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

From Eq. (2.3.6), we know that


 
F = −kB T ln Q (N, V , T ) = c(N, T )−kB T ln ··· drN exp −βU rN ,
V V
(5.1.11)
in which c(N, T ) will not contribute to the pressure as it is independent of V .
Differentiating with respect to volume is a bit tricky, as the limits of the
configurational integral depend on the volume of the system. This complication
can be addressed by defining scaled coordinates s through
ri
si ≡ for i = 1, 2, · · · , N, (5.1.12)
L
where L is the diameter of the box. To simplify the notation, we have assumed
that the periodically repeated box is cubical in shape, such that V = L3 .
Computer experiments Chapter | 5 131

The integral over s ranges from 0 to 1, independent of V . Then

  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

where d is the dimensionality, and we have used the fact that


 
∂ri ri
= . (5.1.17)
∂V si dV
132 PART | I Basics

Eq. (5.1.16) is often written as


1
Pexc = W  , (5.1.18)
dV
which defines the virial W :
N    
 ∂U
W≡ Fi · ri − dV . (5.1.19)
∂V si N,T
i=1 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

In that case, we can write:


N   
1   ∂u(rij )
Pexc = − · ri
dV ∂ri
i=1 j =i N,T
 
1 
N 
= f(rij ) · ri . (5.1.20)
dV
i=1 j =i N,T

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

5.1.5.1 Pressure by thermodynamic integration


There are cases where Eq. (5.1.14) cannot be used, for instance, for lattice
models, where the volume is not a continuous variable. In such cases, we can
compute the pressure of a fluid using the thermodynamic relation

d(P V )V T = N dμ . (5.1.22)

Methods to perform simulations under conditions where μ, V , and T are the


control variables, are discussed in section 6.5.

5.1.5.2 Local pressure and method of planes


Eq. (5.1.14) yields a global expression for the pressure. Even though Eq. (5.1.21)
suggests that, for pairwise additive interactions, the pressure could be decom-
posed into contributions due to individual particles, it would be wrong to
interpret these contributions as local pressures. The mechanical definition of
the pressure does have a local meaning as the force acting per unit area on a
plane (say, at position x) in the system. We can have different choices for x, and
hence these could yield different pressures. However, for a system in mechani-
cal equilibrium, the average pressure should not depend on x, otherwise, there
would be a net force acting on a volume element bounded by planes at x + x
and at x.

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.

5.1.5.3 Virtual volume changes


For non-pairwise-additive interactions we cannot use the standard virial route to
compute the pressure. For such systems —but also for systems of non-spherical
hard-core particles, for which the virial approach becomes rather cumbersome
—it may be attractive to compute the pressure by using a finite-difference ver-
sion of Eq. (2.1.35):
P ≈ −(F /V )N T . (5.1.23)
To this end, we must compute the free-energy difference between a system con-
tained in volume V and the same system contained in a volume V  = V + V ,
where V must be chosen sufficiently small that F is linear in V . As V is
small, we can use a perturbation expression for the free energy (see Eq. (8.6.10))
to compute F :

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).

5.1.6 Surface tension


Up to this point, we have been discussing how simulations can be used to es-
timate the bulk properties of materials, where it is useful to employ periodic
boundary conditions as these minimize the finite-size effects associated with the
presence of surfaces. However, the properties of surfaces are interesting in their
own right. Here we discuss the calculation of one key surface property, namely
the surface tension γ , which measures the free-energy cost associated with a
change, at constant N , V , and T , of the area of a flat, unstructured surface or
interface. We focus initially on unstructured interfaces because, as we shall see
later, computing the free energy of structured interfaces (e.g., a crystal-liquid
interface) requires different methods.
We start with the expression for the variation of the Helmholtz free energy
of a one-component system with N , V , T , and with the surface area A:
dF = −SdT − P dV + μdN + γ dA , (5.1.29)
136 PART | I Basics

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

We consider a periodically repeated system containing two phases in parallel


slabs (see Fig. 5.1). We assume that the surface is perpendicular to the z-
direction, and consider the effect of stretching the surface in the x-direction
by a factor λ: the new surface area A is then related to the original surface area
by A = λA. Note, however, that the system contains two interfaces, hence the
total surface area A = 2S, where S is the area per interface. The height of the
box in the z-direction is scaled by a factor 1/λ, such that the volume of the box
remains unchanged. Due to this transformation, all x-coordinates in the system
are scaled by a factor λ, and all z-coordinates are scaled by a factor λ−1 . We can
then use the statistical mechanical expression for the Helmholtz free energy to
arrive at an expression for the surface tension. In analogy with Eq. (5.1.15) we
write3
 
∂F
γ=
∂A N,V ,T
⎛  1    ⎞
∂ ln 0 dsN exp −βU sN ; λW, H /λ
= −kB T ⎝ ⎠
∂A
N,V ,T
 N  
1 ∂U s ; λW, H /λ
= . (5.1.31)
2S ∂λ
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

We now focus on continuous pairwise-additive potentials.4 For continuous po-


tentials, we can write
       !
∂U sN ; λW, H /λ N
∂U (rN ) ∂U (rN )
= xi − zi
∂λ ∂xi ∂zi
λ=1 i=1

N
 
=− fi;x xi − fi;z zi , (5.1.32)
i=1

where fi;α denotes the force on particle


 i in the α direction. For pairwise ad-
ditive potentials, we can write fi;α = j =i fij ;α , where fij ;α is the pair-force
between particles i and j in the α-direction. As in Eq. (5.1.21), we now use the
fact that i and j are dummy indices that can be permuted.
  
1 
N
∂U sN ; λW, H /λ 
= fij ;z zij − fij ;x xij , (5.1.33)
∂λ 2
λ=1 i=1 j =i

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.

Surface tension from virtual moves


In complete analogy with the direct approach to measure the pressure by per-
forming virtual volume moves (Section 5.1.5.3), we can also compute the sur-
face tension by considering (say) a vertical slab of liquid in the system sketched
4 The expression for particles with discontinuous interactions can be recovered from the continuous
case by replacing the force acting on a particle with the average momentum transfer per unit of time.
138 PART | I Basics

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]).

Surface free-energy density and surface stress


In the previous section, we considered the surface tension of a flat liquid inter-
face, or for that matter, the surface tension of a liquid at a perfectly flat solid
wall. The expression for γ derived above makes use of the fact that we can
change the surface area of a liquid by an infinitesimal amount, without chang-
ing the bulk properties. Such an approach will not work if any of the two phases
is a solid, because as we stretch the surface of a solid, we change its interfacial
free energy.
For solids, we can still write the contribution of the surface to the free energy
as Fs = γ A, where γ is now called the surface free-energy density. But now we
cannot use Eq. (5.1.31) to compute γ , because
   
∂Fs ∂γ
=γ +A ≡ ts , (5.1.36)
∂A ∂A

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].

Free energy of curved surfaces


In general, the surface tension of an interface will depend on its curvature. Cur-
vature effects become important when at least one of the radii of curvature of
the surface is not much larger than a typical molecular diameter.
In contrast to the case of a flat interface, the value of the surface tension of a
curved surface depends on our choice of the location of the surface. These and
5 Of course, deforming the surface of a solid may also change its bulk elastic free energy, but that
effect can be computed separately.
6 The distinction has observable consequences. For instance, the Laplace pressure inside a small
crystal is not determined by γ but by ts , which can be negative [139,140].
Computer experiments Chapter | 5 139

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.

5.1.7 Structural properties


Thus far we discussed the measurement of thermodynamic observables. How-
ever, many experiments provide information about the microscopic structure
of a system. Although some experiments, such as confocal microscopy, can
provide an instantaneous snapshot of the configuration of a system, most exper-
iments yield information about some averaged descriptors of the local structure
in a system. Scattering experiments (X-ray, neutron) yield information about the
mean-squared value of the Fourier transform of the scattering density, whereas
real-space experiments such as confocal microscopy can be used to obtain in-
formation about the averaged local density profile around a selected particle. As
we discuss below, the two quantities are related.

5.1.7.1 Structure factor


Static scattering experiments usually probe the angle-dependence of the inten-
sity of radiation scattered by the sample. The scattered intensity is proportional
to the mean-squared value of the scattering amplitude A(q), where q denotes
the scattering wave-vector; for instance, for monochromatic X-rays with wave-
length λ0 : q = (4π/λ0 ) sin(θ/2). The instantaneous scattering amplitude de-
pends on the configuration of the system and is typically of the form


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

where the real-space single-particle density ρ(r) is defined by


N
ρ(r) ≡ δ(r − ri ) . (5.1.39)
i=1
140 PART | I Basics

With this definition, we can write


1
S(q) = |ρ(q)|2  − |ρ(q)|2
N
1 
= dr dr ρ(r)ρ(r ) − ρ2 eiq·(r−r ) . (5.1.40)
N V V

The quantity ρ(r)ρ(r ) is the density correlation function. It is often written


as
ρ(r)ρ(r ) = ρ(r)ρ(r )g(r, r ) . (5.1.41)
Eq. (5.1.41) defines the pair distribution function g(r, r ). In an isotropic, homo-
geneous liquid ρ(r) is constant and equal to the average density ρ, and g(r, r )
only depends on the scalar distance r ≡ |r − r |. g(r) is called the radial distri-
bution function: it probes how the local density around a particle in a classical
fluid is decreased/enhanced due to the intermolecular interactions. g(r) plays a
key role in liquid-state theory. In the next section, we discuss how g(r) can be
measured in a simulation.
As S(q) is related to g(r), g(r) can be obtained from S(q) by inverse Fourier
transform. This might seem to be a needlessly complicated route for obtaining
g(r). However, a naive calculation of g(r) requires O(N 2 ) operations, whereas
the computational effort required to compute S(q) by Fast-Fourier transform,
scales as N ln N.
It might seem straightforward to obtain S(q) of a liquid from g(r) using

S(q) = ρ dr [g(r) − 1]eiq·r . (5.1.42)


V

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].

5.1.7.2 Radial distribution function


Computing the radial distribution function is probably one of the very first
measurements that a novice in simulations will perform because it is such a
simple calculation. For a given instantaneous configuration, we can easily com-
pute all N (N − 1)/2 pair distances between the particles in the system. We
can then make a histogram of the number of pairs with a distance between r
and r + . Choosing the bin-width  is a compromise between resolution (fa-
voring a small value of ) and statistical accuracy (the relative error in g(r)
Computer experiments Chapter | 5 141

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

where we integrate over N − 1 coordinates, because particle i is held fixed.


We can now write
   
∂g(r) 1 ∂ 
= d r̂ δ(r − rj ) . (5.1.46)
∂r ρ ∂r
j =i

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

As the arguments of the δ-function is r − rj , we can replace r̂ · ∇r by −r̂j · ∇rj


and perform a partial integration:
    N 
∂g(r) −1 drN −1 e−βU (r ) j =i r̂ · ∇r δ(r − rj )
d r̂
= 
drN −1 e−βU (r )
N
∂r ρ
  N −1 −βU (rN ) 
j =i δ(r − rj )r̂j · ∇rj U (r )
N
−β d r̂ dr e
= 
drN −1 e−βU (r )
N
ρ
 
β 
= d r̂ δ(r − rj )r̂j · Fj (rN ) , (5.1.48)
ρ
j =i N −1

(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 ) .

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).

Illustration 2 (Force-method to estimate the g(r)). At large r, g(r) approaches


one. It then follows from Eq. (5.1.50) that, provided that g(r = 0) = 0,
 (r) N (r) N 
β   Fj (r ) − Fi (r )
N
1 = g(r) = = g(r) − h(r) , (5.1.51)
2Nρ 4π rij 2
i=1 j =i N −1

where h(r) ≡ g(r) − 1. It then follows that


 (r) (r) 
β 
N Fj (rN ) − Fi (rN )
h(r) = − θ (rij − r) . (5.1.52)
2Nρ 4π rij 2
i=1 j =i N −1

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).

Example 5 (Static properties of the Lennard-Jones fluid). Let us illustrate the


results of the previous sections with an example. Like in the section on Monte
Carlo simulations, we choose the Lennard-Jones fluid as our model system.
We use a truncated and shifted potential (see also section 3.3.2.2):
"
lj lj
utr−sh (r) = u (r) − u (rc ) r ≤ rc , (5.1.53)
0 r > rc

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

0.8442, which is a typical liquid density, close to the triple (gas-liquid-solid)


point of the Lennard-Jones fluid. When we start the MD simulation from this
initial configuration, the potential energy will decrease and, because energy
is conserved, the kinetic energy will go up —Fig. 5.4.

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).

Next, we consider error estimates. We used the method of Flyvbjerg and


Petersen [148] to estimate the statistical error in the potential energy (see
Fig. 5.5. In this figure, the number of blocking operations by M, and from the
plateau, we obtain an estimate of the standard deviation in our results. The
146 PART | I Basics

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.

In Fig. 5.6, the radial distribution function is shown. To determine g(r), we


used Algorithm 8. This g(r) shows the characteristics of a dense liquid. We
can use the radial distribution function to calculate the energy and pressure.
The potential energy per particle can be calculated from

1 ∞
U/N = ρ dr u(r)g(r)
2 0

= 2πρ dr r 2 u(r)g(r) (5.1.54)
0

and for the pressure from

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

where u(r) is the pair potential.


Eqs. (5.1.54) and (5.1.55) can be used to check the consistency of the en-
ergy and pressure calculations and the determination of the radial distribution
function. In our example, we obtained from the radial distribution function for
the potential energy U/N = −4.419 and for the pressure P = 5.181, which is
in good agreement with the direct calculation.
For more details, see SI (Case Study 4).
Computer experiments Chapter | 5 147

Algorithm 8 (The radial distribution function)

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

Specific Comments (for general comments, see p. 7)


1. Function grsample accumulates a histogram of pair distances
2. Function grnormalize normalizes the radial distribution function at the end
of the simulation
3. The array g contains nhis bins. It accumulates a histogram of pair distances
4. One bin in g corresponds to a radial shell with thickness delg
5. Before the first call of grsample, we zero the array g(nhis) and ngr, which
counts the number of calls of the function grsample.
6. The number-density of the system is denoted by ρ
7. For reasons of computational efficiency, the sampling g(r) is usually com-
bined with the force calculation (see Algorithm 5).

5.2 Dynamical properties


Both the thermodynamic properties and the structural properties mentioned pre-
viously do not depend on the time evolution of the system: they are static
equilibrium averages. Such averages can be obtained equally well by Molec-
148 PART | I Basics

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)

where D, the constant of proportionality, is referred to as the diffusion coeffi-


cient.7 In what follows, we shall be discussing a particularly simple form of
diffusion, namely, the case where the molecules of the diffusing species are iden-
tical to the other molecules, but for a label that does not affect the interaction of
the labeled molecules with the others. For instance, this label could be a partic-
ular polarization of the nuclear spin of the diffusing species (see e.g., [149]) or
a modified isotopic composition. Diffusion of a labeled molecule among other
identical molecules is called self-diffusion.8
We can use Fick’s law to compute the time-dependence of the concentration
profile c(r, t) of the tagged species, under the assumption that, at time t = 0, the
tagged species was concentrated at the origin of our coordinate frame. To com-
pute the time evolution of the concentration profile, we combine Fick’s law with

7 In Appendix D we discuss diffusion in the context of non-equilibrium thermodynamics, where


the primary driving force is the gradient of the chemical potential, rather than the concentration
gradient.
8 Eq. (5.2.1) is a simplification of the basic diffusion equation relating the particle flux to the
gradient of the chemical potential. The full expression can be found in ref. [57]. However, for self-
diffusion, Eq. (5.2.1) is not an approximation.
Computer experiments Chapter | 5 149

an equation that expresses conservation of the total amount of labeled material:

∂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

c(r, 0) = δ(r) (5.2.4)

(δ(r) is the d-dimensional Dirac delta function) to yield


 
1 r2
c(r, t) = exp − , (5.2.5)
(4πDt)d/2 4Dt

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:

r 2 (t) ≡ dr c(r, t)r 2 , (5.2.6)

where we have used the fact that we have imposed

dr c(r, t) = 1. (5.2.7)

We can obtain an expression for the time evolution of r 2 (t) by multiplying


Eq. (5.2.3) by r 2 and integrating over all space. We then obtain:


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

=D dS (r 2 ∇c(r, t)) − 2D dr r · ∇c(r, t)

= 0 − 2D dr (∇ · rc(r, t)) + 2D dr (∇ · r)c(r, t)

= 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)

Inserting Eq. (5.2.14) in Eq. (5.2.13), we obtain


t  
2D = lim 2 dt  vx (t − t  )vx (0)
t→∞ 0

D= dτ vx (τ )vx (0) . (5.2.16)
0

In the last line of Eq. (5.2.16) we introduced the coordinate τ ≡ t − t  .


Eq. (5.2.16) shows that we can relate the diffusion coefficient D to the inte-
gral of the velocity auto-correlation function. Eq. (5.2.16) is an example of a
Green-Kubo relation (see section 2.5.2).
One note of caution: the calculation of the diffusion coefficient is subject
to large and slowly decaying finite-size effects. Due to the hydrodynamic in-
teractions between a particle and its periodic images, the diffusion coefficient
approaches the infinite-system limit as 1/N 1/3 [150–152] in 3d. In 2d, the dif-
fusion coefficient diverges.9

Illustration 3 (Diffusion coefficients). There are different ways to measure


diffusion coefficients experimentally. An interesting example is the diffu-
sion coefficient of gases adsorbed in a porous material (e.g., a zeolite or
metal-organic framework). These materials are used to separate gases or as
membranes. For these applications, it is important to have a molecular under-
standing of the diffusion of these gases in the pores.
With pulse-field-gradient NMR, one can measure the self-diffusion coeffi-
cient, D s [153]. However, in practical applications of these materials, we are
more interested in the transport or Fick diffusion coefficient D t . This diffusion
coefficient is often estimated from the rate at which the weight of material
increases upon adsorption. These two diffusion coefficients are not the same,
so in comparing molecular simulation results with experimental data, it is
important to be aware of these differences.
The transport or Fick diffusion coefficient D t , is obtained by measuring
the flux, J caused by a gradient in the concentration:

J (c) ≡ −D t (c)∇c. (5.2.17)

9 The fact that the integral in Eq. (5.2.16) may diverge does not mean that particles diffuse infinitely

fast, just that x 2 (t) increases faster than linear with t.


152 PART | I Basics

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

where L(c) is the Onsager transport coefficient. As the flux we measure is


independent of how we define the diffusion coefficient, the relation between
these diffusion coefficients is:

1 ∇μ
Dt = Dc = D c ,
kB T c ∇ ln c

where  is the thermodynamic coefficient:


1 ∂μ ∂ ln f
= = ,
kB T ∂ ln 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 →∞ = ∞ .

Hence, close to saturation D t → ∞. This result may appear counter-intuitive


as one would expect that, at saturation, the molecules are packed tightly
and unable to move much. However, here the difference between the self-
diffusion coefficient and the transport-diffusion coefficient becomes impor-
tant. The self-diffusion coefficient is a measure of the mobility of a single,
labeled molecule in the fluid. In contrast, the transport diffusion coefficient
measures the flux of molecules; hence, if a pore is saturated and we add one
molecule on one end of the crystal, instantaneously, on the other end of the
crystal, one molecule drops out. Hence, the flux, the number of molecules
Computer experiments Chapter | 5 153

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].

The collective diffusion coefficient is computed from the velocity correla-


tion function:
1 ∞ 
Dc = dτ vi (o)vj (τ ). (5.2.19)
3 0
i,j

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

where, for pairwise-additive potentials,


⎛ ⎞
N
1 
σ xy = ⎝mi vix v y + xij fy (rij )⎠ ; (5.2.22)
i
2
i=1 j =i

the thermal conductivity λT ,

1 ∞  
λT = dt jze (0)jze (t) (5.2.23)
V kB T2 0

with, in the pairwise-additive case,10


⎛ ⎞
d 
N
1 
jze = zi ⎝mi vi2 + u(rij )⎠ ; (5.2.24)
dt 2
i=1 j =i

and electrical conductivity σe

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.

5.2.2 Order-n algorithm to measure correlations


The calculation of transport coefficients from the integral of a time-correlation
function, or from a (generalized) Einstein relation, is not efficient in memory use
(if we need to correlate for long times) nor in memory use (in the naive version
sketched in Algorithm 9, the computing time scales quadratically with the length
of the maximum time separation over which we compute correlations).
To illustrate this problem, consider the calculation of the velocity autocor-
relation function and the diffusion coefficient of a molecular liquid. In a dense
medium, the velocity autocorrelation function changes rapidly on microscopic
time scales (O(10−13 )s). We must therefore sample the velocity at even shorter
time intervals. Yet, when probing the long-time decay of the velocity auto-
correlation function, it is not necessary to sample with the same frequency. The
example shown in Algorithm 9 does not allow for adjusting the sampling fre-
quency.
Below, we describe an algorithm that allows us to measure fast and slow
decay simultaneously at minimal computational cost. This scheme can be used
to measure the correlation function itself, but in the example that we discuss,
we show how it can be used to compute the associated transport coefficient.
Let us denote by t the time interval between successive measurements of the
velocity of the particles in the system. We can define block sums of the velocity
of a given particle as follows:


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)

function dif diffusion; switch = 0 init.


= 1 sample, and = 2 results
if switch == 0 then Initialization
ntel=0 time counter
dtime=dt*nsamp time between two samples
for 1 ≤ i ≤ tmax do tmax total number of time step
ntime(i)=0 number of samples for time i
vacf(i)=0
r2t(i)=0
enddo
else if switch == 1 then sample
ntel=ntel+1
if mod(ntel,it0) == 0 then decide to take a new t = 0
t0 = t0 + 1 update number of t = 0
tt0=mod(t0-1,t0max)+1 see note 1
time0(tt0)=ntel store the time of t = 0
for 1 ≤ i ≤ npart do
x0(i,tt0)=x(i) store position for given t = 0
vx0(i,tt0)=vx(i) store velocity for given t = 0
enddo
endif
for 1 ≤ t ≤ min(t0,t0max) do update vacf and r2, for t = 0
delt=ntel-time0(t)+1 actual time minus t = 0
if delt < tmax then
vacf(delt)=vacf(delt)+ update vx (0)vx (t)
+ vx(i)*vx0(i,t)
r2t(delt)=r2t(delt)+ update (x(t))2
+ (x(i)-x0(i,t))**2
enddo
endif
enddo
else if switch == 2 then determine results
for 1 ≤ i ≤ tmax do
time=dtime*(i+0.5) time
vacf(i)=vacf(i) vx (0)vx (t)
+ /(npart*ntime(i))

r2t(i)=r2t(i)/(npart*ntime(i)) (x(t))2
enddo
endif
end function
Computer experiments Chapter | 5 157

Specific Comments (for general comments, see p. 7)


1. We define a new time origin every it0-th function call. For each time origin,
we store the current positions and velocities. The term t0max is the maximum
number of time origins that we can store. If we sample more time origins, the
first one will be overwritten: this overwriting of old data limits the maximum
time over which we can correlate to t0max*it0, which should not be smaller
than tmax, the total number of time steps we sample. In section 5.2.2 and
Algorithm 10, we show how to correlate for arbitrarily long times.
2. Because nsamp determines the frequency at which the function dif is called,
the time between two calls is nsamp*delt, where delt is the time step.


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).

FIGURE 5.8 Coarse graining the velocities.


158 PART | I Basics

The total storage per particle for a simulation of length t = ni t is i × n.


This should be compared to the conventional approach where, to study corre-
lations over the same time interval, the storage per particle would be ni . In the
conventional calculation of correlation functions, the number of floating-point
operations scales at t 2 (or t ln t, if the Fast Fourier technique is used). In con-
trast, in the present scheme, the number of operations scales as t. At every time
step, we have to update v(0) (t) and correlate it with all n entries in the v(0) -array.
The next block sum has to be updated and correlated once every n time steps,
the third every n2 steps, etc. This yields, for the total number of operations,
 
t 1 1 1 t n
× n 1 + + 2 + ··· + i < n . (5.2.29)
t n n n t n − 1
Using this approach, we can quickly and efficiently compute a wide variety of
correlation functions, both temporal and spatial. However, it should be stressed
that each blocking operation leads to more coarse-graining. Hence, any high-
frequency modulation of the long-time behavior of such correlation functions
(e.g., a long-lived oscillation) will be washed out.
Interestingly, even though the VACF itself is approximate at long times, we
can still compute the integral of the VACF (i.e., the diffusion coefficient), with
no loss in numerical accuracy. Below, we discuss this coarse-grained technique
for computing the diffusion coefficient.
Let us define

j
r̄(i) (j ) ≡ v(i) (l)t = r(ni ) − r(0). (5.2.30)
l=0

The square of the displacement of the particle in a time interval ni t can be


written as
2
(r̄2 )(i) (j ) = r(ni ) − r(0) = r̄(i) (j ) · r̄(i) (j ). (5.2.31)

To compute the diffusion coefficient, we should follow the time dependence of


the mean-squared displacement. As a first step, we must determine r̄(i) (j ) for
all i and all j . Moreover, to improve the statistics, we wish to use every sample
point as a new time origin. To achieve this, we again create arrays of length n.
However, these arrays do not contain the same block sums as before, but partial
block sums (see Algorithm 10). In particular:
1. At every time interval t, the lowest-order blocking operation is performed
through the following steps:
a. We first consider the situation that all lowest-order accumulators have
already been filled at least once (this is true if t > nt). The value of the
current velocity v(t) is added to

vsum (1, j ) = vsum (1, j + 1) + v(t) (5.2.32)


Computer experiments Chapter | 5 159

for j = 1,n-1, and


vsum (1, j ) = v(t) (5.2.33)
for j = n.
b. These operations yield
j =t

vsum (1, l) = v(j ). (5.2.34)
j =t−n+l

The equation allows us to update the accumulators for the mean-squared


displacement (5.2.31) for l = 1, 2, . . . , n:

(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

vsum (i, j ) = vsum (i, j + 1) + vsum (i − 1, 1) (5.2.36)

for j = 1,n-1, and

vsum (i, j ) = vsum (i − 1, 1) (5.2.37)

for j = n.
b. These operations yield
=n
j
vsum (i, l) = vsum (i − 1, j ). (5.2.38)
j =n−l+1

The equations allow us to update the accumulators for the mean-squared


displacement, Eq. (5.2.31), for l = 1, 2, . . . , n:

(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

vsum (i, j ) = vsum (i, j ) + vsum (i − 1, 1). (5.2.40)


160 PART | I Basics

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.

5.2.3 Comments on the Green-Kubo relations


As was discussed in section 2.5.2, the GK relations follow naturally from the
statistical-mechanical description of the response of a many-body system to
a weak, Hamiltonian perturbation. In some cases (e.g., heat conduction), the

Algorithm 10 (Diffusion: order-n algorithm)

function dif Sample every nsample MD steps


switch = 0: initialization,
= 1: sample, = 2: results
if switch == 0 then 0: initialization
ntel=0 time counter for this function
dtime=dt*nsamp time between two samples
for 1 ≤ ib ≤ ibmax do ibmax max. number of blocks
ibl(ib)=0 length of current block
for 1 ≤ j ≤ n do n number of steps in a block
tel(ib,j)=0 counter number of averages
delr2(ib,j)=0 running average mean-sq. displ.
for 1 ≤ i ≤ npart do
vxsum(ib,j,i)=0 blocked velocity particle i
enddo
enddo
enddo
else if switch == 2 then 2: print results
ibm = max(ibmax,iblm)
for 1 ≤ ib ≤ ibm do
jbm = min(ibl(ib),n)
for 2 ≤ j ≤ jbm do
time=dtime*j*n**(ib-1) time
r2=delr2(ib,j)*dtime**2 mean-squared displacement
/tel(ib,j)
enddo
enddo
...(continue)....
Computer experiments Chapter | 5 161

...(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

Specific Comments (for general comments, see p. 7)


1. MaxBlock(ntel,n) gives the maximum number of blocking operations that
can be performed on the current time step ntel.

Hamiltonian route is problematic. In that case, it is still possible to derive GK


relations by considering a perturbation of the Lagrangian equations of mo-
tion [33].
162 PART | I Basics

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

It is convenient to use the discretized form


n
max
LAA = A2 (0) t/2 + lim t A(0)A(nt) .
nmax →∞
n=1

 the extreme case that A(0)A(nt) = 0 for all n ≥ 1. In that


Let us consider
case, LAA = A(0)2 t/2, independent of nmax . However, the variance in LAA
does depend on nmax . In what follows, we assume that the fluctuations in A
follow a 1d normal distribution:
max 
n 
σL2 = L2AA (nmax ) − LAA 2
n=1
Computer experiments Chapter | 5 163

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.

Example 6 (Dynamic properties of the Lennard-Jones fluid). As an example


of the numerical determination of a dynamical property we consider the cal-
culation of the self-diffusion coefficient. As shown in the previous section,
the diffusion coefficient can be determined either from the mean-squared dis-
placement, or from the velocity auto-correlation function (VACF). Here, we
follow the approach of Algorithm 9 to compute these observables.

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.

In Fig. 5.9 the mean-squared displacement is shown as a function of the


simulation time. From the mean-squared displacement we can determine the
164 PART | I Basics

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).

Example 7 (Algorithms to calculate the mean-squared displacement). In this


Example, we compare the conventional (Algorithm 9), and the order-n meth-
ods (Algorithm 10) to determine the time-dependence of mean-squared dis-
placement. The example considers a Lennard-Jones fluid.

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.

In Fig. 5.10 we compare the time-dependence of the mean-squared dis-


placement computed with the conventional method and the one obtained
with the order-n scheme. For the order-n scheme, the memory requirement
grows logarithmically with time, but for the conventional scheme it grows
linearly. For the present simulation settings, the calculation using the conven-
tional scheme could not be extended beyond t > 10. For the same memory
allocation the order-n scheme the calculation could be extended to much
longer times with no difficulty: it only depends on the simulation time. In the
Computer experiments Chapter | 5 165

present example, we stopped at t = 200. It is interesting to compare the ac-


curacy of the two schemes. In the conventional scheme, the velocities of the
particles at the current time step are used to update the mean-squared dis-
placement of all time intervals. In the order-n scheme, the current time step
is only used to update the lowest-order array of vsum (see Algorithm 10). The
block sums of level i are updated only once every ni time step. Therefore, for
a total simulation of M time steps, the number of samples is much less for
the order-n scheme; for the conventional scheme, we have M samples for all
time steps, whereas the order-n scheme has M/ni samples for the ith block
velocity. Naively, one would think that the conventional scheme therefore is
more accurate. In the conventional scheme, however, the successive samples
will have much more correlation and therefore are not independent. To inves-
tigate the effect of these correlations on the accuracy of the results, we used
the method of Flyvbjerg and Petersen [148] (see Appendix 5.3.3 and Case
Study 4). In this method, the standard deviation is calculated as a function
of the number of data blocks. If the data are correlated, the standard devia-
tion will increase as a function of the number of blocks until the number of
blocks is sufficient that the data in a data block are uncorrelated. If the data
are uncorrelated, the standard deviation will be independent of the number
of blocks. This limiting value is the standard deviation of interest.

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

5.3 Statistical errors


Measurements in computer “experiments” are subject to the same sources of
error as real experiments —and a few more.
We will not discuss systematic errors due to mistakes in the calculations,
as the number of possible errors is unbounded. Some systematic errors have to
do with the fact that we consider a finite system, and the properties of a finite
system (even with periodic boundary conditions) are not identical to those of
a macroscopic system. Such errors disappear as N , the number of particles in
the system, tends to ∞. Of course, we cannot achieve this limit, but often the
finite-size effects decay as 1/N, which means that for systems of a few thousand
particles, the effects are typically small.
However, as discussed in section 5.2.1, below Eq. (5.2.16), some finite-
size effects decay slower than 1/N. The most striking examples of irreducible
finite-size effects occur in the vicinity of a critical point. Binder [42,163] has
developed the so-called finite-size scaling method to extract the correct limiting
properties of systems at or near the critical point from simulations on finite-size
systems. For more details on this approach, we refer the reader to the extensive
literature on this topic, starting with the works of Binder himself.
The remainder of this section discusses the estimate of statistical errors in
simulation results.

5.3.1 Static properties: system size


Let us consider the statistical accuracy of the measurement of a dynamical quan-
tity A in a Molecular Dynamics simulation (the present discussion applies, with
minor modifications, to Monte Carlo simulations). During a simulation of total
length τ , we obtain the following estimate for the equilibrium-average of A:

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τ :

σ 2 (A) = A2τ − Aτ 2


1 τ τ   
= dtdt  [A(t) − A] A(t  ) − A . (5.3.2)
τ2 0 0
 
Note that [A(t) − A][A(t  ) − A] in Eq. (5.3.2) is simply the time corre-
lation function of fluctuations in the variable A. Let us denote this correlation
function by CA (t − t  ). If the duration of the sampling τ is much larger than the
168 PART | I Basics

characteristic decay time tAc of CA , then we may rewrite Eq. (5.3.2) as

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

# c (5.3.4) shows that the root-mean-square error in Aτ is proportional to


Eq.
tA /τ . This result is hardly surprising. It simply states the well-known fact
the variance in a measured quantity is inversely proportional to the number of
uncorrelated measurements. In the present case, this number is proportional to
τ/tAc . This almost trivial result is important because it shows how the lifetime
and amplitude of fluctuations in an observable A affect the statistical accuracy.
This is of particular importance in the study of fluctuations associated with hy-
drodynamical modes or pretransitional fluctuations near a symmetry-breaking
phase transition. Such modes usually have a characteristic lifetime proportional
to the square of their wavelengths. To minimize the effects of the finite system
size on such phase transitions, it is preferable to study systems with a box size
L large compared with all relevant correlation lengths in the system. However,
due to the slow decay of long-wavelength fluctuations, the number of time steps
needed to keep the relative error fixed should scale as L2 . As the CPU time
for a run of fixed length is proportional to the number of particles (at best), the
CPU time needed to maintain constant accuracy increases quite rapidly with the
linear dimensions of the system (e.g., as L5 in three dimensions).
The example above focused on the case of a quantity A(t) computed in a
Molecular Dynamics simulation, but the example carries over to Monte Carlo
simulations, if we replace time with the number of Monte Carlo cycles. The
above statement does not imply that cycles in MC simulations are equivalent to
time in MD simulations; just that it may take a number of MC cycles before a
fluctuation in quantity A has decayed.
One aspect of Eq. (5.3.4) is not immediately obvious; namely that it
makes a difference whether the observable A can be written as a sum of
weakly correlated single-particle properties. If this is the case, then the ratio

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

If the correlations in the fluctuations in ai and aj can be ignored, then we find


that
 2  
A − A2 1 a 2 − a2
= . (5.3.7)
A2 N a2
From Eq. (5.3.7) it is clear that
√ the statistical error in a single-particle property
is inversely proportional to N. Hence, for single-particle properties, the ac-
curacy improves as we go to larger systems (at fixed length of the simulation).
In contrast, no such advantage is to be gained when computing truly collective
properties.

5.3.2 Correlation functions


We can apply essentially the same arguments to estimate the statistical errors in
time correlation functions. Suppose that we perform a simulation to measure the
(auto)correlation function12 of the dynamical quantity A. To obtain an estimate
of CA (τ ) ≡ A(0)A(τ ), we average the product A(t)A(t + τ ) over the initial
time t. Suppose that the length of our run is τ0 , then our numerical estimate of
CA (τ ) is
τ0
C A (τ ) = 1/τ0 dt A(t)A(t + τ ), (5.3.8)
0
where the bar over CA denotes the average over a finite time τ0 . Next, we con-
sider the variance in C A (τ ) [164]:
 2
C A (τ )2 − C A (τ )
τ0 τ0  
= (1/τ0 2 ) dt  dt  A(t  )A(t  + τ )A(t  )A(t  + τ )
0 0
τ0 τ0   
− (1/τ0 2 ) dt  dt  A(t  )A(t  + τ ) A(t  )A(t  + τ ) . (5.3.9)
0 0

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)

Inserting Eq. (5.3.11) in Eq. (5.3.9), we get


 2
C A (τ )2 − C A (τ )
τ0 τ0   
= (1/τ0 2 ) dt  dt  A(t  )A(t  ) A(t  + τ )A(t  + τ )
0 0
τ0 τ0   
+ (1/τ0 )2
dt  dt  A(t  )A(t  + τ ) A(t  + τ )A(t  )
0 0
τ0 τ0  2
= (1/τ0 )2
dt  dt  A(t  − t  )A(0)
0 0
τ0 τ0   
+ (1/τ0 2 ) dt  dt  A(t  − t  − τ )A(0) A(t  − t  + τ )A(0) .
0 0
(5.3.12)
As we consider the case where the length of the simulation, τ0 , is much longer
than the characteristic decay time of the fluctuations of A, we can write
 2
C A (τ )2 − C A (τ )
∞  
= (1/τ0 ) dx A(x)A(0)2 + A(x − τ )A(0) A(x + τ )A(0) ,
−∞
(5.3.13)
Computer experiments Chapter | 5 171

where we have defined the variable x as t  − t  . It is instructive to consider two


limiting cases, τ = 0 and τ → ∞. For τ = 0, we can write

 2 ∞
C A (τ )2 − C A (τ ) = (2/τ0 ) dx A(x)A(0)2
−∞
2 τc
= 4 A2 (0) . (5.3.14)
τ0

The last line of this equation defines the correlation time τ c :


∞
dx A(x)A(0)2
τ ≡
c 0
 2 . (5.3.15)
A2 (0)

For τ → ∞, the product

A(x − τ )A(0) A(x + τ )A(0) (5.3.16)

vanishes, and we have

 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].

5.3.3 Block averages


It is useful to know that the predicted variance of an observable quantity A is
related to the integral of its auto-correlation function (Eq. (5.3.3)). But we do
not really want to compute the auto-correlation function of every quantity that
we measure, because that would require more effort than computing the average
itself.
The standard approaches for estimating statistical errors in static quantities
make use of some form of block-averaging. A block average is simply a time
average over a finite time interval tB (or, in the MC case, an average over nB
172 PART | I Basics

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

We also need an estimator of the variance of σ 2 (Ā). From standard statistical


analysis (see e.g., [38]), we know that if we have L uncorrelated data points,
the estimator of the true variance in the estimate of the average is

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

As long as successive blocks are significantly correlated, σ 2 (A )/(L − 1)


changes (increases) with every blocking step. But when the blocks are long
enough to be effectively uncorrelated, we have

σ 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

It is important to have such an estimate, because if we perform too many block-


ing operations, the error in the error may increase again (see Fig. 5.5).
In Example 5, the method of ref. [148] method is used to compute the stan-
dard deviation of the energy in a Molecular Dynamics simulation. In Fig. 5.5
a typical plot of this estimate of the variance as a function of block size is
shown. For small values of the number of blocking operations, M, the data are
correlated, and as a consequence, the variance will increase if we perform the
blocking operation. However, for very high values of M, we have only a few
samples, and as a result, the statistical error in the error estimate will be large.
The plateau in between gives us the value of σ 2 (A) we are interested in.

5.4 Questions and exercises


Question 15 (Heat capacity). The heat capacity at constant volume can be
calculated from fluctuations in the total energy in the canonical ensemble.
 2
E − E2
Cv = .
kB T 2
1. Derive this equation.
2. In a constant-N V T MC simulation, one does not calculate fluctuations in
the total energy E but in the potential energy U . Is it then still possible to
calculate the heat capacity? Explain.
3. The heat capacity can be also calculated by differentiating the total energy
of a system with respect to temperature. Discuss the advantages or disad-
vantages of this approach.
4. Eq. (5.1.8) relates the variance in the kinetic energy of a system at constant
N V E to the heat capacity at constant volume (CV ). What constraint does
this expression place on the value of CV ? Explain this constraint in words.
Question 16 (Virial pressure of molecules with high frequency modes).
When computing the pressure of a molecular liquid, one can either consider
the virial due only to forces between the molecular centers of mass, or due to
all forces: inter-molecular and intra-molecular. The average value of the virial
computed by both methods should be the same, but the statistical noise is differ-
ent. To see this, consider an ideal gas of dimers consisting of two harmonically
bound atoms at an average separation a. For convenience, we consider a 1d
system. The dimers have an internal spring constant kS .
1. What is the average value of the force between the two atoms in a dimer.
2. What is the mean-squared value of the force at a temperature T .
3. What happens to the statistical noise in the virial as ks → ∞?
Question 17 (Correlation functions).
1. The value of the velocity autocorrelation function (VACF) at t = 0 is related
to an observable quantity. Which one?
Computer experiments Chapter | 5 175

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

where t is the resolution in time, and ω = 2π/T , where T is the simu-


lation time (T = Mt). If A is a Gaussian variable, then so is A(ω). But
as a system in equilibrium is invariant under translation of the time origin,
different Fourier components of A are uncorrelated. Use the arguments that
were used to derive Eq. (5.3.14) to estimate the dependence of the relative
error in the power spectrum on the length of the simulation.
• Explain your observation.
• Now consider what happens if you increase the ω of a longer simulation
(say T2 ) to match that of a shorter simulation (say T1 ).
Exercise 10 (Molecular dynamics of a Lennard-Jones system). On the book’s web-
site, you can find a Molecular Dynamics (MD) program for a Lennard-Jones fluid
in the N V E ensemble.
We have planted three errors in the code and, as a consequence, the total
energy will not be conserved during a run.
1. Find the three errors in the code. Hint: there are two errors in the integration of
the equations of motion, and one in the force calculation. See the file system.inc
for documentation about some of the variables used in this code.
2. How is the temperature controlled in this program? What does it mean to “con-
trol the temperature”: after all, in a simulation at constant N V E it is the total
energy of the system that should be constant, whilst the temperature fluctuates.
3. To test the energy drift E of the numerical integration algorithm for a given
time step t after N integration steps, one usually computes [126]

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 

One should be careful with the calculation of the mean-squared displace-


ment when periodic boundary conditions are used. Why?
Modify the program in such a way that the self-diffusion coefficient can be
calculated using both methods. Some modifications in codes provided in the SI
are needed. It is not a good idea (although not wrong) to take every time step
as a new time origin for the calculation of the mean-squared displacement and
of the VACF. Explain. What is the unit of D in SI units? How can one transform
D into dimensionless units?
5. For Lennard-Jones liquids, Naghizadeh and Rice [127] report the following
equation for self-diffusion coefficient (dimensionless units, T ∗ < 1.0 and p ∗ <
3.0):

10 log D ∗  = 0.05 + 0.07p ∗ − 1.04 + 0.1p . (5.4.3)
T ∗

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

Exercise 11 (Optimal truncation of Green-Kubo integrals). As explained in the text,


Green-Kubo integrals should be truncated once the statistical noise is dominated
by random noise.
1. Derive Eq. (5.2.42)
2. Compute the diffusion coefficient D of a WF system, using the GK relation
between D and the integral of the VACF.
3. Compute the variance in the computed D as a function of the truncation time
and estimate where the integration should be truncated.

You might also like