Forces, Constraints and MD Ensembles

Forces, constraints and ensembles for MD
simulation
Dr Billy D. Todd
Centre for Molecular Simulation
Swinburne University of Technology
PO Box 218, Hawthorn Victoria 3122, Australia
Email: [email protected]
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
1
Overview
You will have already covered the calculation of pairwise forces in
Module 3. However, in this Module you will learn how to use the
neighbour list developed in Module 7 to calculate pairwise forces, thus
saving considerable execution time. In addition we will also cover how
to formulate the equations of motion with constraints, and use such
constraints to simulate particles in various statistical mechanical
ensembles.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
2
Topic 1: Calculation of forces via the neighbour list
In Module 7 we learnt how to formulate a neighbour list. However,
apart from forming it, we did nothing with it! In what follows, we now
demonstrate the value of the neighbour list in the calculation of
intermolecular forces. In fact, it is only in the force routine that the
neighbour list is ever used. The calculation of intermolecular forces is
by far the most computationally expensive section of any MD code,
and thus it is important to ensure its execution is as efficient as
possible.
In this Topic we will present only the bare essentials of the force
routine. Normally, one includes other calculations within the force
routine, but these will be considered later in this Module and in
Module 10, where we discuss what it is we actually want out of an MD
simulation, and how to calculate these quantities.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
3
Topic 1: Calculation of forces via the neighbour list
(cont.)
As you have already covered how to calculate intermolecular forces in
Module 3 we present here only a sample of the force routine
incorporating the neighbour list. Before we do this, first we need to
consider what form of intermolecular potential we are using.
In this example, we will use the so-called ‘WCA’ potential (named after
Weeks, Chandler and Andersen [1], the authors who proposed it), which
is a shifted and truncated form of the standard 6-12 Lennard-Jones (LJ)
potential you encountered in Module 3. Its usefulness rests in the fact
that:
• It is a shorter ranged potential than the full LJ potential, so is faster to
evaluate, and
• It is truncated at the LJ potential minimum, thus introducing no
discontinuity in the intermolecular forces.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
4
Topic 1: Calculation of forces via the neighbour list
(cont.)
The potential is thus written as:
  σ 12  σ  6 
4ε   −    + ε
φWCA ( r ) =   r   r  

0
r < rc
(9.1)
r ≥ rc
Here, rc is the value of the interatomic separation at which the potential is
zero, i.e. rc = 21/6σ.
A comparison of the standard LJ potential and the WCA potential is given
on the next page.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
5
Topic 1: Calculation of forces via the neighbour list
(cont.)
8
6
WCA potential
LJ potential
4
φ(r)
2
0
-2
0.5
1
1.5
2
2.5
3
r
Figure 9.1. Comparison of WCA and LJ potentials. Reduced units used (σ = ε = 1).
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
6
Topic 1: Calculation of forces via the neighbour list
(cont.)
The force is obtained by taking the gradient of the potential, i.e.,
Fi = −
∂φWCA ( rij )
∂ri

 24 ε 2
= σ

0
 σ
2 
  rij


σ  
 −    {ixij + j yij + kzij }

 rij  
14
8
rij < rc
(9.2)
rij ≥ rc
where i, j, k are the unit vectors in the x, y and z directions, respectively,
and xij = xi – xj, yij = yi – yj, zij = zi – zj.
Problem 1 asks you to derive this expression.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
7
Topic 1: Calculation of forces via the neighbour list
(cont.)
Code for evaluation of forces via neighbour list
int i, j, k, ipair, mfirst, mlast;
double fijx[LEN], fijy[LEN], fijz[LEN]; // LEN is large and of same
double rx, ry, rz, rsq, rsi, r6;
// size as iatom and jatom
// arrays (see Module 7)
for (i=0; i<=NP; i++) { // initialise force variables
fx[i] = 0.;
fy[i] = 0.;
fz[i] = 0.;
}
u = 0.; // initialise potential energy
// fij = force on i due to j.
for (ipair = 1; ipair <= npair; ipair++) { // loop over all pairs
// created in neighbour
i = iatom[ipair];
// list (see Module 7)
j = jatom[ipair];
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
8
Topic 1: Calculation of forces via the neighbour list
(cont.)
// calculate minimum image distances
rx = x0[i] - x0[j];
ry = y0[i] - y0[j];
rz = z0[i] - z0[j];
// apply periodic boundary conditions
pbcs(&cube, &rx, &ry, &rz);
rsq = rx*rx
fijx[ipair]
fijy[ipair]
fijz[ipair]
+
=
=
=
ry*ry + rz*rz;
0.; // intialise pair interactions
0.;
0.;
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
9
Topic 1: Calculation of forces via the neighbour list
(cont.)
if (rsq <= rmax) { // rmax = rc*rc. This ensures truncation of
rsi = 1./rsq;
// the potential at rc
r6
= pow(rsi,3);
u += 4.*r6*(r6 - 1.) - shift; // potential is shifted such that
// its minimum is zero.
fijx[ipair]= rsi*rx*r6*(2.*r6 - 1.);
fijy[ipair]= rsi*ry*r6*(2.*r6 - 1.);
fijz[ipair]= rsi*rz*r6*(2.*r6 - 1.);
}
}
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
10
Topic 1: Calculation of forces via the neighbour list
(cont.)
mfirst = 1;
// mfirst is first pair number
for (i=1; i<=NP-1; i++) {// i is atom number
mlast = last[i];
// mlast is last pair number (see Module 7)
if(mfirst <= npair) { // npair is total number of pairs
for (k=mfirst; k<=mlast; k++) {
j = jatom[k];
fx[j] -= 24.*fijx[k];
fy[j] -= 24.*fijy[k];
fz[j] -= 24.*fijz[k];
fx[i] += 24.*fijx[k];
fy[i] += 24.*fijy[k];
fz[i] += 24.*fijz[k];
}
mfirst= mlast + 1;
}
}
// interaction force accumulation complete
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
11
Topic 1: Calculation of forces via the neighbour list
(cont.)
Now lets consider in detail each section of code in pp. 8-11.
• On p. 8 we first initialise all variables. Note that some variables are
already defined in the neighbour list routine. Other variable, such as
the potential energy (u) and force components (fx, fy, fx) will have
been declared elsewhere.
• Next, we loop over all pairs created in the neighbour list (npair). In
this loop we calculate all the interatomic forces between pairs of atoms
(i,j), namely fijx, fijy, fijz. Note that fijx, fijy, fijz are
arrays of size LEN, and LEN is a large array of size approximately
4πre3ρN/6.
• Note that the interactions depend only on the relative distances
between atoms i and j (rx, ry, rz). Note also that periodic boundary
conditions are applied to these distances to form minimum images.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
12
Topic 1: Calculation of forces via the neighbour list
(cont.)
•
•
•
•
•
The actual calculation of the force components fx, fy and fz occur
on p.11. It is in this double loop over particle number and pair number
that most of the computational expense is incurred. This is because for
every particle i we need to compute all its pairs, j. If we had no
neighbour list, this loop would involve N(N-1) calculations. With the
neighbour list the number of calculations is significantly fewer. Note
in particular the following about this double loop:
The loop over i is over particle number.
The index k ranges over all possible pairs for atom i.
The index j identifies which atoms pair with i.
The force on atom j is first evaluated for every interaction between
atoms i and j. Then Newton’s 3rd law is used to simply calculate the
force on atom i due to atom j (i.e., Fi = -Fj).
Note: this loop is NOT easy to vectorise for vector processors!
However, for large N it is still computationally more efficient than
using an N(N-1) loop. For small N, the latter may actually be faster on
vector processors, as the loop will have close to 100% vectorisation.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
13
Topic 1: Calculation of forces via the neighbour list
(cont.)
To illustrate the workings of the double loop, consider some output of a
typical MD run. This simulation was run for 108 WCA atoms and a
‘snapshot’ was taken at an arbitrary value of the time. Output are the atom
number (i), mfirst, mlast, k and j. The value of npair was 591 (i.e.,
there were 591 pairs of atoms. Thus forces needed only to be calculated
591 times compared to 108x107=11556 times, an improvement by a factor
of 19.5!
The output is listed on the next page. Listed are just the details for atoms 1
and 2, though similar information is obtained about all the other 106 atoms.
In Problem 2 you are asked to write a double loop to calculate the forces by
the ‘brute-force’ method of N(N-1) interactions. You are then supplied with
some bare MD code and asked to compare the efficiency of this method
with the neighbour list method.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
14
Topic 1: Calculation of forces via the neighbour list
(cont.)
atom 1
mfirst
k = 1
k = 2
k = 3
k = 4
k = 5
k = 6
k = 7
k = 8
k = 9
k = 10
k = 11
= 1 mlast = 11
j = 2
j = 12
j = 28
j = 35
j = 56
j = 59
j = 64
j = 66
j = 73
j = 93
j = 94
atom 2
mfirst = 12 mlast = 21
k = 12 j = 5
k = 13 j = 13
k = 14 j = 20
k = 15 j = 22
k = 16 j = 28
k = 17 j = 38
k = 18 j = 66
k = 19 j = 67
k = 20 j = 69
k = 21 j = 78
Atom i=1 has 11 pairs of interacting particles
given by the j index, labelled from mfirst=1
to mlast=11.
Atom i=2 has 10 pairs of interacting particles
given by the j index, labelled from mfirst=12
to mlast=21.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
15
Topic 1: Calculation of forces via the neighbour list
(cont.)
•
•
•
•
Points to note:
mfirst and mlast are just ‘pointers’ (not in the C-language sense of
the word!) to the first and last pairs of any particular atom. k starts at
mfirst and increments up to mlast. k starts at 1 and goes to 11 for
atom 1. It then starts at 12 and goes up to 21 for atom 2, and so on and
so forth for all other N-2 atoms. Thus, mfirst for the next atom is
always mlast (for the current atom) + 1.
Atom 1 has atoms 2,12,28,35,56,59,64,66,73,93 and 94 as interacting
neighbours, a total of 11 other atoms.
Atom 2 has atoms 5,13,20,22,28,38,66,67,69 and 78 as interacting
neighbourns, a total of 10 other atoms.
Note that atom 1 is not listed as a neighbour of atom 2, yet atom 2 is
listed as a neighbour of atom 1! This is because Newton’s 3rd law takes
care of the fact that the force on atom 2 due to atom 1 is just of equal
magnitude but opposite sign of the force on atom 1 due to atom 2.
Thus, pairs only ever need to be formed once.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
16
Topic 2: Constraints
•
•
•
•
•
At this stage you would be able to write a very basic MD program that
could do the following:
Read an input file specifying such things as density, initial temperature,
and other simulation parameters
Initialise the coordinates and momenta of all particles
Form neighbour lists for all atoms
Calculate all interatomic forces making use of the neighbour list, and
Integrate the equations of motion.
We have not yet synthesised all these separate components into a united
computer program, such that we advance time and allow the trajectories
to evolve. We leave this for a little later.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
17
Topic 2: Constraints (cont.)
Before we do this, there are still gaps in our knowledge of how to
simulate useful statistical mechanical ensembles that correspond to
physically observable thermodynamic systems.
Note that the equations of motion given by Eqns. 7.6(a, b) are
Hamiltonian and, hence, conservative. If we were to run a simulation
using these equations the energy and momenta would both be conserved.
However, many thermodynamically relevant systems are at constant
temperature. Eqns. 7.6 conserve total energy, but not temperature! The
total energy is a sum of potential and kinetic contributions, whereas the
temperature is usually associated with just the kinetic degrees of
freedom, i.e., the particle velocities (note that there are alternative
definitions of the temperature involving the configurational degrees of
freedom, e.g, see reference [2]). If we were to use Eqns. 7.6 the system
would relax to conserve energy, but the temperature would fall from its
initial value to some equilibrium value. It falls because some of the initial
kinetic energy is lost to the configurational degrees of freedom. Hence
the potential energy increases at the expense of the kinetic energy. Both
eventually stabilize, such that the total energy is always constant.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
18
Topic 2: Constraints (cont.)
Fortunately, classical mechanics allows us to re-formulate Hamilton’s
equations such that an additional perturbative force appears in them.
This perturbation, or constraint-force, is a function of either the
coordinates or velocities of particles and serves to constrain certain
desired phase variables to be constants of the motion. There are two
types of constraints:
• Holonomic constraints, in which the constraint may be integrated out
of the equations of motion, and
• Nonholonomic constraints, that are in general non-integrable.
Nonholonomic constraints often involve particle velocities. Constraints
that are relevant for thermodynamic systems involve nonholonomic
constraints. We note here that constraints are not just used to constrain
the temperature to some desired value. They are used to constrain any
relevant quantity, e.g., bond lengths of molecules, pressure, stresses for
shearing fluids, etc.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
19
Topic 2: Constraints (cont.)
2.1 Gauss’ Principle of Least Constraint
There are a number of possible formulations for constraining the
equations of motion [3], but we only have time in this lecture course
to consider one very useful and commonly used type, first proposed
by Gauss in 1829, and known universally as Gauss’ Principle of Least
Constraint.
In short, a ‘Gaussian’ constraint serves to constrain system variables
such that the perturbative force introduced into the equations of
motion minimises the deviations to the classical trajectories of
particles from their unperturbed trajectories.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
20
Topic 2: Constraints (cont.)
Consider the function f (&r&i ) which is a function of the particle
accelerations, &r&i ,

1
Fi 
&&
&&
f ( ri ) = ∑ mi  ri − 
2 i =1 
mi 
N
2
(9.3)
If f = 0, clearly Eqn 9.3 just reduces to Newton’s (or, equivalently,
Hamilton’s) equations of motion for the system of N unconstrained
particles. However, if f ≠ 0 the particles are now constrained and
evolve under non-Newtonian equations. Gauss’ principle tells us
that the physical acceleration of the set of N particles occurs when
the function f is a minimum. We thus need to find this minimum,
subject to the applied constraint. Bearing in mind that the constraint
function, g, can also be written as a function of acceleration, we can
write the constraint equation as:
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
21
Topic 2: Constraints (cont.)
∂
f (&&
ri ) − ς g ( &&ri ) ) = 0
(
&&
∂ri
(9.4)
where ζ is a Lagrangian (or Gaussian) multiplier.
2.2 Application of Gauss’ principle to constrain the temperature
Probably the most common (and useful) application of Gauss’ principle in
MD simulations is to constrain the kinetic temperature of the system, such
that it is a constant of the motion. Thus, the total energy is no longer
conserved (at the expense of the kinetic energy), but will fluctuate about
some average value.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
22
Topic 2: Constraints (cont.)
Consider the constraint function G that constrains the kinetic energy to
be constant:
mi r& 2 3NkT
G ( r&i , t ) = ∑
−
=0
2
2
i =1
N
(9.5)
Eqn (9.5) simply states that we want the velocities of particles
constrained such that the kinetic energy is proportional to the kinetic
temperature, T, a constant of the motion. Eqn (9.5) is not in the
appropriate form. To transform it so that it is a function of acceleration,
simply differentiate once with respect to time,
g ( &&
ri , r&i , t ) =
dG ( r&i , t )
dt
N
= ∑ mi r&i .r&&i = 0
(9.6)
i =1
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
23
Topic 2: Constraints (cont.)
Substituting Eqn (9.6) into (9.4) yields
2


N
N


F
∂ 1
j
 ∑ m j  &&
rj −
 + ς ∑ m j r& j .r&&j  = 0

∂&&
ri  2 j =1 
mj 

j =1


(9.7)
Performing the necessary algebraic simplifications, one obtains
mi&&
ri = Fi − ς mi r&i
Newtonian
(9.8)
Constraint force
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
24
Topic 2: Constraints (cont.)
Eqn (9.8) is a 2 nd order differential equation, equivalent to the two first
order DEs:
r&i =
pi
mi
(9.9)
p& i = Fi − ς mi r&i
As an exercise, you are asked to prove this in Problem 3(a).
Substituting Eqns (9.9) into the differential form of the constraint
equation, i.e., Eqn. (9.6) yields the result we want:
N
ς=
∑ r& .F
i
i
i =1
N
(9.10)
∑ m r&
2
i i
i =1
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
25
Topic 2: Constraints (cont.)
Thus, at every timestep in the simulation, one would numerically
integrate Eqns (9.9), and substitute in the new value of ζ, calculated
(also at each timestep) by Eqn. (9.10).
In Problem 3(b), you are asked to derive Eqn. (9.10) by an alternative,
but equivalent, route.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
26
Topic 3: Thermodynamic ensembles
3.1 Constant temperature, volume, density (N, V, T)
In the previous section we saw how to constrain the temperature by
Gauss’ principle. This is by no means the only way to constrain
temperature. Other methods exist, the most noteworthy being the socalled ‘Nose-Hoover’ thermostat [4]. We will not explore other options
in this lecture course due to time restrictions, but simply refer you to the
literature [3].
Let us now examine where Eqns. (9.9 and 9.10) are implemented in our
MD program.
Consider first the implementation of the equations of motion (9.9). We
still consider the Gear algorithm for integrating the equations, but again
note that there are other methods, such as Runge-Kutta and Verlet
schemes [3,5]. We observe that the ‘thermostat’ multiplier, ζ, appears
only in the equation for the momenta, and occurs in the corrector phase
of the integration. The implementation code follows:
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
27
Topic 3: Thermodynamic ensembles (cont.)
for (i=1; i<=NP; i++) {
// corrector loop
pxcor = px1[i] - (fx[i] - zeta*px0[i])*delta;
pycor = py1[i] - (fy[i] - zeta*py0[i])*delta;
pzcor = pz1[i] - (fz[i] - zeta*pz0[i])*delta;
px0[i] -= pxcor*fo1;
py0[i] -= pycor*fo1;
pz0[i] -= pzcor*fo1;
px1[i] -= pxcor;
py1[i] -= pycor;
pz1[i] -= pzcor;
px2[i] -= pxcor*f21;
py2[i] -= pycor*f21;
pz2[i] -= pzcor*f21;
px3[i] -= pxcor*f31;
py3[i] -= pycor*f31;
pz3[i] -= pzcor*f31;
px4[i] -= pxcor*f41;
py4[i] -= pycor*f41;
pz4[i] -= pzcor*f41;
}
Modified equations of motion
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
28
Topic 3: Thermodynamic ensembles (cont.)
The multiplier (zeta) is actually calculated in the force routine,
immediately after the force loop concludes:
// Calculate Gaussian isokinetic multiplier
if(Gauss==1) {
for (i=1; i<=NP; i++) {
zden += px0[i]*px0[i] + py0[i]*py0[i] + pz0[i]*pz0[i];
znum += fx[i]*px0[i] + fy[i]*py0[i] + fz[i]*pz0[i];
}
zeta = znum/zden;
}
Note that zden and znum are initialised to zero at the start of the force
routine. Furthermore, the parameter Gauss is now read from the input
file. It has the value 1 if we want the simulation to run at constant
temperature. If Gauss ≠ 1, the simulation runs at constant energy.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
29
Topic 3: Thermodynamic ensembles (cont.)
3.2 Constant particle number, pressure, temperature (N, P, T)
Another very useful ensemble is the constant pressure ensemble, which is
usually run at constant temperature as well (otherwise known as the
isothermal-isobaric ensemble). This ensemble is formed by constraining
both the pressure and temperature to be constants of the motion, and once
again we consider the Gaussian formulation of this [6], though other
formulations do exist (see references in Chapter 6 in [6]).
The way the algorithm works is to apply an isotropic rate of dilation or
contraction to the system, such that if the system heats up the volume of the
simulation cell increases isotropically in such a way as to keep the pressure
constant. Similarly, if the system cools the volume decreases. Thus, if ε& is
the (constant) dilation/contraction rate, the position vector r must change
as:
r&i =
pi
+ ε&ri
mi
(9.11)
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
30
Topic 3: Thermodynamic ensembles (cont.)
r is thus a combination of a kinetic (the momentum term) contribution
plus the imposed dilation/contraction rate. Eqn (9.11) implies that the
volume V(t) must evolve in time as:
V& ( t ) = 3V ( t ) ε&
(9.12)
The proof of (9.12) is left as an exercise in Problem 4.
Eqns (9.11) and (9.12) are two of the equations of motion that need to be
satisfied for this ensemble. The third involves the momenta, and once
more we invoke Gauss’ principle and write it (without rigorous proof) as:
p& i = Fi − ε& pi − ς pi
(9.13)
ζ is once more the thermostat multiplier.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
31
Topic 3: Thermodynamic ensembles (cont.)
As an exercise, Problem 5 asks you to derive the expression for the
thermostat term, which is given here as:
N
ς = −ε& +
∑ F .p
i
i =1
N
∑p
i
(9.14)
2
i
i =1
The derivation of the dilation/contraction rate is a little more involved,
and we will not consider it here. For now, we just write down its
expression:

φij′ 
1 N
rij .p ij )  φij′′ +

(
∑∑

m i=1 j>i
rij 

(9.15)
ε& =
N

φij′ 
2
rij φij′′ +
 + 9 pV
∑∑


r
i =1 j > i
ij


 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
32
Topic 3: Thermodynamic ensembles (cont.)
We note the following about Eqn. (9.15) and the method in general:
•
•
rij = ri – rj and pij = pi – pj.
∂φ ( rij )
The potential derivative is defined as φij′ ≡
. Similarly for φij′′ .
∂rij
•
•
The masses of all particles are all assumed to be identical and equal to m.
p is just the hydrostatic pressure. We will discuss how to calculate the
pressure in Module 10. However, in this case p is just a constant that is
read into the program at the input stage, just as the temperature T is.
Remember, we are simulating constant p and T!
The pressure is sensitive to long-range potential interaction corrections, so
these must be handled carefully.
Care must also be taken with the Gear implementation of this algorithm.
See Chapter 6, reference [6] for more details.
•
•
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
33
Topic 3: Thermodynamic ensembles (cont.)
While it may seem somewhat tedious to use Eqn. (9.15), the advantage
is that it is fully deterministic and rigorous. Both p and T remain
constants of the motion and do not fluctuate, unlike for other methods.
Other ensembles, such as constant enthalpy, stress, chemical potential,
etc., exist, but will not be considered here, and should be used
according to necessity. You may consult the literature for details of
these ensembles, and the various algorithms (constraint and other) used
to simulate them [3,5,6].
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
34
Problems
Problem 1
Derive Eqn. (9.2), bearing in mind that the form of the WCA potential is
given by Eqn (9.1).
Problem 2
Write a double loop to calculate the forces interacting on pairs of atoms by
the ‘brute-force’ method of N(N-1) interactions. Note that now you do not
make use of the neighbour list.
You may download a very basic MD program and input file at the
following web site: http://www.it.swin.edu.au/xxx. The program uses the
neighbour list algorithm and gives timing information (i.e., how long the
code took to execute). Run the program using the input file supplied and
note how long it took to execute. Now, implement the ‘brute-force’
algorithm and note how long it takes to execute. Compare the efficiency of
this method with the neighbour list method.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
35
Problems (cont.)
•
•
•
•
Problem 2 (cont.)
Note the following points:
The code is written using data structures. Go through the code and see how
different variables are associated with certain data structures.
The input file has the options 1, 2 or 3 for the ‘Type’ parameter. Start at
Type = 1 (starting from lattice), then run with Type = 2 to equilibrate.
Finally, for ‘production runs’, set Type to 3. Note that Type 3 runs read in
the data from the previous run and continue averaging.
The code runs in the microcanonical ensemble (N, V, E). No thermostat is
applied, so the code should execute with good energy conservation over
short to moderate total simulation times.
Only the temperature and energies are output.
Experiment with the code. For example, increase the size of the time-step
(Delta) and observe whether or not energy is conserved.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
36
Problems (cont.)
Problem 3
(a) Prove that the two first order differential equations of motion given
by Eqn (9.9) are indeed equivalent to the single second order
differential equation given by Eqn. (9.8).
(b) By writing the kinetic temperature as a function of the kinetic
energy (see Eqn (8.1) in Module 8), show that you can derive Eqn
(9.10) for the thermostat term, ζ, by noting that the temperature must
be a constant of the motion, i.e., it is time independent.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
37
Problems (cont.)
Problem 4
Prove that the volume of the simulation cell in the (N,P,T) ensemble is
V& ( t ) = 3V ( t ) ε& , as given by Eqn (9.12).
Hint: Observe that the simulation box lengths in all directions will
evolve in time under the application of a uniform dilation/contraction
rate as the second term of Eqn (9.11). Simply replace ri with L, where
the vector L represents (Lx, Ly, Lz). One thus solves the first order
differential equation for the box lengths, from which one may obtain
V(t), and finally differentiate V(t) with respect to time.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
38
Problems (cont.)
Problem 5
From Eqn (9.13), derive Eqn (9.14) for the thermostat term ζ in the
(N,P,T) ensemble. Base your derivation on the method you used to
derive ζ in Problem 3(b). Note that this will involve taking the moment
of p& i with pi.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
39
Problems (cont.)
Problem 6
The MD code you downloaded for Problem 2 currently runs only in
the microcanonical ensemble, i.e. (N, V, E). Modify the code such that
it now has the option to run under constant temperature (N, V, T),
making use of a Gaussian thermostat for this implementation (the socalled Gaussian isothermal ensemble). Place the thermostat multiplier
term (zeta) in the ‘Interact’ data structure. You will also need a
‘switch’, which you can call ‘Gauss’. With Gauss = 0, the program
should run under constant energy; Gauss = 1 implies constant
temperature. Place the parameter Gauss in the ‘Params’ structure.
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
40
Reading Material and References
1. J.D. Weeks, D. Chandler and H.C. Andersen, J. Chem. Phys. 54, 5237
(1971).
2. B.D. Butler, G. Ayton, O.G. Jepps and D.J. Evans, J. Chem. Phys. 109,
6519 (1998).
3. M.P. Allen and D.J. Tildesley, Computer Simulation of Liquids (Oxford
University Press, New York, 1987).
4. S. Nose, J. Chem. Phys. 81, 511 (1984); S. Nose, Mol. Phys. 52, 255
(1984); W.G. Hoover, Phys. Rev. A 31, 1695 (1985).
5. R.J. Sadus, Molecular Simulation of Fluids: Theory, Algorithms and
Object-Orientation (Elsevier, Amsterdam, 1999).
6. D.J. Evans and G.P. Morriss, Statistical Mechanics of Nonequilibrium
Liquids (Academic Press, London, 1990).
 B. D. Todd, Centre for Molecular Simulation, Swinburne University of Technology
41