You are on page 1of 59

Molecular Dynamics: Hooke-Lennard-Jones Hybrid Method

by
Morgan Groves, B.S.
A Thesis
In
MATHEMATICS
Submitted to the Graduate Faculty
of Texas Tech Univeristy in
Partial Fulfillment of
the Reguirements for
the Degree of
MASTER OF SCIENCES
Approved
Dr. Philip Smith
Chair of Committee
Dr. Kevin Long
Peggy Gordon Miller
Dean of the Graduate School
May, 2012

Copyright 2012, Morgan Groves

Dedicated to my wonderful husband, Jason, who has been so helpful and supportive
every step of the way.

Texas Tech University, Morgan Groves, May 2012

ACKNOWLEDGMENTS

Many thanks to
Dr. Philip Smith
Dr. Kevin Long
Chris Hansen
Jason Groves

ii

Texas Tech University, Morgan Groves, May 2012

CONTENTS

ACKNOWLEDGMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . .

ii

ABSTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

iv

LIST OF TABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LIST OF FIGURES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

vi

I INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . .

II POTENTIAL ENERGY FUNCTIONS . . . . . . . . . . . . . . . .

2.1

Definitions and Associations . . . . . . . . . . . . . . . . . . .

2.2

Hookes Potential . . . . . . . . . . . . . . . . . . . . . . . . .

2.3

Lennard-Jones Potential . . . . . . . . . . . . . . . . . . . . .

2.4

Hybrid Potential . . . . . . . . . . . . . . . . . . . . . . . . . .

12

III THE HYBRID METHOD . . . . . . . . . . . . . . . . . . . . . . . .

14

3.1

Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . .

14

3.2

Computing Forces . . . . . . . . . . . . . . . . . . . . . . . . .

17

3.3

Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

17

3.4

Energy Calculations and Conservation . . . . . . . . . . . . . .

18

3.5

Time Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

IV RESULTS AND CONCLUSIONS . . . . . . . . . . . . . . . . . . .

28

4.1

Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

28

4.2

Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32

V FUTURE WORK . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

APPENDIX A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

39

APPENDIX B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

43

APPENDIX C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51

iii

Texas Tech University, Morgan Groves, May 2012

ABSTRACT

In this thesis we apply Hookes law and the Lennard-Jones potential together forming a hybrid potential energy function to model atomic interaction. These molecular
dynamics simulations are then implemented in Matlab. For each simulation, we construct a cubic lattice of particles set at an equilibrium distance apart with most particles given an initial random velocity. The simulations are representative of generic
solids. We observe how the system moves through time as the particles interact with
one another. We are interested in investigating the efficiency of our Matlab implementation, evaluating the accuracy of the Runge-Kutta integration algorithm being used,
and assessing the appropriateness of this hybrid potential to model cubic lattices.
This paper discusses the advantages and disadvantages of applying the fourth
order Runge-Kutta (RK4) quadrature method to Newtons second law of motion in
order to produce the trajectories of each particle in the system as they vary with
time. Knowing that the RK4 method will not conserve energy, we observe how large
our simulations can get before it produces too much error resulting in the loss or gain
of energy. We also report on the run time performance of the code and suggest future
improvements.

iv

Texas Tech University, Morgan Groves, May 2012

LIST OF TABLES

1.1

Comparison of computational units with real world units . . . . . . .

3.1
3.2

Run times for 4 different sized systems . . . . . . . . . . . . . . . . .


Real time seconds required to run one complete loop to calculate the
energy of the system using Hookes law and Lennard-Jones method. .
Times required to perform the RK4 integration algorithm . . . . . . .
Percentages of time used to run specific functions. . . . . . . . . . . .

24

3.3
3.4

25
26
27

Texas Tech University, Morgan Groves, May 2012

LIST OF FIGURES

2.1
2.2
2.3
2.4
2.5
2.6
2.7

Experimental Spring Force . . . . . . . . . . . . . . . . . .


Hookes Law - approximation of experimental spring force
V (x) = 12 kx2 . . . . . . . . . . . . . . . . . . . . . . . . . .
String of particles under Hookes law . . . . . . . . . . . .
Lennard-Jones force, = 1, = 1 . . . . . . . . . . . . . .
Lennard-Jones potential, = 1, = 1 . . . . . . . . . . .
Hookes law illustration of a 2D layout of particles . . . . .

3.1
3.2
3.3

.
.
.
.
.
.
.

6
7
7
8
11
11
13

Initial configuration of a simulation of size 3 3 3. . . . . . .


Neighbors of selected particles: corner, edge, interior particles .
Matlab codes of the loops used to calculate potential energy of
system using Hookes law and Lennard-Jones method . . . . . .

. . .
. . .
each
. . .

15
16

4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
4.10
4.11
4.12
4.13

Change in Energy: 3 3 3, k = 1, dt = 0.0011 . .


Change in Energy: 3 3 3, k = 100, dt = 0.0022
Change in Energy: 4 4 4, k = 10, dt = 0.0011 .
Change in Energy: 5 5 5, k = 10, dt = 0.0011 .
Total Energy: 3 3 3, k = 100, dt = 0.0011 . . .
Total Energy: 4 4 4, k = 100, dt = 0.0011 . . .
Potential Energy: 3 3 3, k = 100, dt = 0.0011 .
Potential Energy: 4 4 4, k = 100, dt = 0.0011 .
Kinetic Energy: 3 3 3, k = 100, dt = 0.0011 . .
Kinetic Energy: 4 4 4, k = 100, dt = 0.0011 . .
3 3 3, k = 1 . . . . . . . . . . . . . . . . . . . .
4 4 4, k = 1 . . . . . . . . . . . . . . . . . . . .
3 3 3, k = 100 . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

29
29
29
29
30
30
30
30
31
31
32
33
34

5.1

Bending Potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

vi

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

26

Texas Tech University, Morgan Groves, May 2012

CHAPTER I
INTRODUCTION

Molecular dynamics (MD) is a computer simulation technique using Newtons second law of motion to model atomic properties. These properties include the atomic
positions, velocities, and accelerations of each particle in a system evolving through
time. Knowing these properties will allow us to calculate physical attributes of the
system including the energy, both kinetic and potential, and the temperature of the
system. Since each particle moves in three dimensions, (x, y, z), there are 3N position
coordinates that must be updated at each time step, where N is the number of particles in the system. Likewise, the forces acting on each particle can induce momenta
in any of the three dimensions resulting in 3N momenta updates required at each
time step. It follows that we are working in a 6N -dimensional phase space [20].
MD is used to model atomic systems that are too large and complex to model
by hand, and it provides a way to see how systems evolve over time. There are
some advantages and disadvantages to working with MD simulations. Advantages
include testing of new theoretical ideas on systems much too complex to work through
manually, and providing verification and explanation of laboratory experimental data.
In a simulation, it is also possible to safely and inexpensively model extreme conditions
that may be difficult in a real laboratory, such as simulations that require pressures
at the earths core or the temperature at the surface of the sun [14]. The goal is to
make each simulation as realistic as possible.
One of the major disadvantages of an MD simulation is it can become very time
consuming. It can also be very computationally expensive to run an MD simulation
because of the values that must be stored (positions and velocities for each particle),
and the number of calculations that must be completed in order to reduce the amount
of error the program may produce. In fact, simulating a gram of material is completely
beyond the reach of current or foreseeable technology. For systems we can model,
creating efficient programs is a major consideration when writing MD code.
1

Texas Tech University, Morgan Groves, May 2012

In order to accurately model a physical system, it is vital that the appropriate


potential energy function, V , is chosen. Since each particle moves in three dimensional
space, the positions of each particle are stored in a vector ri , where i = 1, . . . , n. The
function V is a real valued function of the positions. By taking the negative gradient
of the potential energy function with respect to atomic displacements we obtain the
force vector for the system of N particles:
F = V (r1 , . . . , rn )

(1.1)

Different potentials are used to model different things. For instance, one potential
may have been designed to represent a dilute noble gas while another was created to
model covalently bonded atoms in an organic compound [14]. Since we want to model
a solid, we must use a potential energy function that prevents particles from moving
too far apart from one another. Hookes potential, calculated by taking the integral of
the force F = kx, where k is the spring constant and x is the particles displacement
from equilibrium in three dimensions, ensures that the particles do not move too far
apart. However, it does not have a stiff repulsive force to prevent particles from
coming too close together. Thus, we need another potential energy function that is
designed to keep particles from trying to overlap one another in a simulation. The
Lennard-Jones potential prevents particles from coming too close together due to its
strong repulsive property at r = 0. It is the joint efforts of both Hookes potential
and the Lennard-Jones potential that enables us to model a solid at the molecular
level.
In MD simulations, physical quantities are expressed in dimensionless or reduced
units [25]. As a result, simulation results should be scaled to approximate physical
units so that the data can be easily understood. Table 1.1 below shows the values
used in the computations done in this thesis compared to the real world values.

Texas Tech University, Morgan Groves, May 2012

Units

Computational

Real World

Length

1010 m

Time

1012 s

Mass (proton)

1.67262158 1027 kg

Velocity

100 m/s

Energy

1.67262158 1025

Boltzmann constant 0.82544092250681

1.3806503 1023

Temperature

1K

Spring Constant

0.0017

kg m2
s2

kg m2
.
s2 K

kg
s2

Table 1.1: Comparison of computational units with real world units

Notice that the Boltzmann constant is the only one that does not have unit value
in the simulations. This is due to the fact that it was calculated based on the base
units of length, time, and mass defined above. We used the values of these units
to reduce the Boltzmann constant to a dimensionless state by the simple method of
dimensional analysis, as shown below:

1.3806503 1023 m2 kg
(1012 s)2 (1K)

= 0.82544092250681
s2 K
(1010 m)2 (1.67262158 1027 kg)

Texas Tech University, Morgan Groves, May 2012

CHAPTER II
POTENTIAL ENERGY FUNCTIONS

2.1 Definitions and Associations


A potential energy function is a function that models the energy of a system due
to the position or arrangement of the particles in the system [22]. It is the energy
stored in the system that can be potentially used. As mentioned earlier, it is very
important to choose the right potential energy function for the given problem.
Every conservative force gives rise to a potential energy function [21]. A conservative force is one in which the work done in moving an object between two points
is independent of the path chosen. Thus, any path taken from point A to point B
and back to point A that is closed has a net work of zero. More clearly, the energy of
an object subject only to a conservative force is dependent upon its position and not
the path it followed to reach that position. Thus, we can define a potential energy
function that depends on position only [18].
A potential energy function V is equal to the work that must be done against the
applying force on an object in order to move the object from a reference point x0
to a different position x. The general definition of mechanical work is given by the
following line integral:
Z

Z
F dx =

WC =
C

F v dt

(2.1)

where C is the path traversed, F is the force vector, x is the position vector, and
v=

dx
dt

is the velocity. If the force is known and it is a conservative force, then the

potential energy can be calculated by integrating the force since the work done is
equal to the potential energy. In three dimensions we have
Z
V = F dx.

(2.2)

This means the force is equal to the negative gradient of the potential,
F = V.
4

(2.3)

Texas Tech University, Morgan Groves, May 2012

There are different types of potential energy functions, all of which are used to
model a particular type of force. For instance, if the force is elastic, then the work is
called elastic potential energy, such as Hookes Law. If the force is gravity, then the
work is known as gravitational potential energy. Work associated with a Coulomb
force is known as electric potential energy. Work for intermolecular forces is called
intermolecular potential energy, such as the Lennard-Jones potential [21]. These are
all examples of how different potential energies are associated with different forces.
Choosing the right potential energy function for a simulation is vital.
2.2 Hookes Potential
Robert Hooke was described as the single greatest experimental scientist of the
17th century [17]. His lifes work was very eclectic, but he is best known for the
discovery of Hookes law. He first discovered the well-known law of elasticity in 1660
[17].
The spring-force can be modeled as seen in Figure 2.1 below. This force only
depends on the amount of stretching of the spring and no other quantities. As can
be seen in Figure 2.1, if the string is stretched (x > 0), then the spring exerts a
force pulling the mass back towards the equilibrium position (F < 0). Similarly, if
the spring is compressed (x < 0), then the spring pushes the mass again towards the
equilibrium position (F > 0). This force is called a restoring force [7].
Hookes law states that the stress on a substance is directly proportional to the
strain produced, provided the stress is less than the elastic limit of the substance [22].
This simply means that the linear equation F = kx is a good approximation for the
spring-force as long as the mass is not too far from the springs equilibrium position
[7]. The spring constant k is a value that represents the rate at which the spring
will attempt to snap back to its equilibrium position. Thus, for large values of k, the
spring is very tight and strong, not easily stretched. The spring constant is usually
measured in

N
m

or

kg
.
s2

However, as discussed earlier, in a computer simulation, values

are dimensionless. Thus, if the spring constant k = 1 is used in our simulation, the

Texas Tech University, Morgan Groves, May 2012

Figure 2.1: Experimental Spring Force

real world value of the spring constant is


1.67262158 1027 kg
kg
kg
= 0.001673 2 = 1.673 103 2
12
2
(10 s)
s
s
Molecular dynamics simulations use Newtons second law of motion to model molecular systems. Therefore, we have F = ma from Newton and F = kx from Hooke.
Putting these two force equations together, we get
ma = kx

(2.4)

which implies that Hookes law is a good approximation for the spring-force as long
as the displacement x from equilibrium does not become too large, as seen in Figure
2.2 below [7].
Since Hookes law is a force equation, we can apply (2.2) and integrate to get the
potential energy function V , as seen here.
Z x
VH =
kx dx
x0

1
VH = k(x x0 )2
2

(2.5)

This function results from summing the energy required to incrementally compress the spring. That is, it is integrated over the displacement of the spring from

Texas Tech University, Morgan Groves, May 2012

Figure 2.2: Hookes Law - approximation of experimental spring force

Figure 2.3: V (x) = 21 kx2

the equilibrium position x0 to a position x. The graph of Hookes potential energy


function in two dimensions is a positive parabola, as seen in Figure 2.3.
In this graph, x represents the displacement from the below equilibrium position
of the spring. It is clear the potential energy of Hookes law is always positive. As the
spring is stretched, the displacement is positive and the potential energy increases. As
the spring is compressed, the displacement is negative but the potential still increases.
The tendency of the spring is to decrease its potential by returning to its equilibrium
state.
For instance, we can model a string as a chain of n discrete particles with masses
m1 , . . . , mn , connected by springs using Hookes law. The particles can move in three
dimensions and have locations r1 , , rn . Neighboring particles are connected by a
7

Texas Tech University, Morgan Groves, May 2012

single spring, as illustrated below in Figure 2.4. This means that the spring connected
to particle 1 will only exert a force on particle 2, but the springs connected to particle
2 will exert a force on particles 1 and 3. Likewise, the springs attached to particle j
(1 < j < n) will exert forces on particles j 1 and j + 1, but the last spring attached
to particle n will only exert a force on particle n 1.

Figure 2.4: String of particles under Hookes law

For simplicity, we assume that the distance ( > 0) at which the spring force is
zero is the equilibrium position of two neighboring particles. This leads us to the
following forces on each particle for a given configuration:


r2 r1
F1 = k(||r2 r1 || )
||r2 r1 ||





rj+1 rj
rj rj1
(||rj+1 rj || )
,j = 2 : n 1
Fj = k (||rj rj1 || )
||rj rj1 ||
||rj+1 rj ||


rn rn1
Fn = k(||rn rn1 || )
(2.6)
||rn rn1 ||
This leads to the system of ODEs:


r2 r1
00
m1 r1 = k(||r2 r1 || )
||r2 r1 ||





rj rj1
rj+1 rj
00
mj rj = k (||rj rj1 || )
(||rj+1 rj || )
,j = 2 : n 1
||rj rj1 ||
||rj+1 rj ||


rn rn1
00
(2.7)
mn rn = k(||rn rn1 || )
||rn rn1 ||
We can write the potential energy function as
n1

1 X
V (r1 , , rn ) = k
[(||rj+1 rj || )]2
2 j=1

(2.8)

Later in this thesis we will move from a one-dimensional string to a three dimensional
cubic lattice with appropriate assignment of neighbors and spring equilibrium lengths.
8

Texas Tech University, Morgan Groves, May 2012

Though Hookes potential energy function goes to zero as the displacement goes to
zero, there is no strong repulsive tendency that will prevent particles in the simulations
from occupying the same space. Thus, we need a potential energy function that has
a strong repulsive property as particles become close together.
2.3 Lennard-Jones Potential
John Edward Lennard-Jones was considered to be the father of computational
chemistry. His research focused on atomic and molecular structures and the forces
between atomic particles. In a 1931 paper, which introduced a method for the atomic
Self-Consistent Field equations, he proposed a potential energy as a function of the
separation of atoms. It became known as the Lennard-Jones potential [9].
The Lennard-Jones potential is the standard potential used when investigating
fundamental properties of a molecular simulation, such as particle interactions. It
represents the pairwise sum of energies of all possible interacting non-bonded atoms.
Thus, it is a global potential. This potential is favorable because it is easily implemented and mathematically simple and convenient. The general form of the LennardJones potential in one dimension is
 

12  6
VLJ (r) = 4

r
r
In three dimensions, the Lennard-Jones potential can be written as
X X  12  6 
VLJ (r1 , . . . , rn ) = 4

r
r
i j>i

(2.9)

(2.10)

where r = ||ri rj || for i, j = 1, . . . , n.


The Lennard-Jones potential is often called the 12-6 potential because of the
exponents in the equation. The exponent 12 has no theoretical justification, but
is chosen simply for easy computations. The and are constants that represent
physical properties of the modeled system. The is the finite distance at which the
inter-particle potential is zero [2]. For each simulation discussed in this thesis, we
let = 1. However, an example of a value is that which is used to model helium,
9

Texas Tech University, Morgan Groves, May 2012

He = 1.480
A [27]. The is simply explained by being the depth of the well of
the potential energy function (see Figure 2.6). It is a measure of how strongly two
particles attract one another [2]. Again, we let = 1 for our simulations here, but an
example would be the used in a helium simulation, He = 0.02127 kcal
[27].
mol
The Lennard-Jones potential combines a short-range repulsive force, represented
by the

1
r12

term, with a long-range attractive force, the

1
r6

term. The attraction force

stems from the van der Waals dispersion forces due to fluctuating dipoles. The repulsion force has two justifications. First, when one electron shell collides with another,
the nuclear charges are no longer completely screened, resulting in the particles repelling one another. The second reason is the well-known Paulis exclusion principle,
one conclusion of which is two electrons of the same energy cannot occupy the same
element of space [25].
The Lennard-Jones force between two particles is given by the equation
 12   6  


ri rj
FLJij = 48

r13
r7
||ri rj ||

(2.11)

where r = ||ri rj || for i, j = 1, . . . , n, i 6= j, and FLJij is the force on particle i due


to particle j.
Since we are only interested in investigating a generic solid material, we set both
and to be 1, and the resulting Lennard-Jones force is shown in Figure 2.5 with
the corresponding potential energy function for = 1 and = 1 shown in Figure 2.6
below.
Since the Lennard-Jones potential approaches zero as the distance between particles increases to infinity, often times a cut-off distance is implemented in order to
save computation time. This distance is usually about 2.5. In order to prevent a
jump discontinuity in the function due to the implementation of this cut-off distance,
we can define a piece-wise function for the truncated Lennard-Jones potential such
that at the cut-off distance rc the function value is zero. Thus,

VLJ (r) VLJ (rc )


for r rc
VLJ-trunc (r) =

0
for r > rc
10

(2.12)

Texas Tech University, Morgan Groves, May 2012

Figure 2.5: Lennard-Jones force, = 1, = 1

Figure 2.6: Lennard-Jones potential, = 1, = 1

This is important because the potential energy function must be continuously


differentiable everywhere since we differentiate the potential to get the force on each
particle in the system. It would also be possible to construct a spline that makes this
function continuous and differentiable at the jump discontinuity point.
Another observation concerning the Lennard-Jones potential is the equilibrium
position of any two particles. If two particles are positioned at an equilibrium distance
apart from one another, then there is no force on them. That means that the gradient
of the potential is zero by (2.3). Thus, the equilibrium distance for the Lennard-Jones

11

Texas Tech University, Morgan Groves, May 2012


1

potential is located at the minimum position on the graph, which is r = 2 6 . Since


we have set = 1 for all of our simulations, the equilibrium distance between two
1

particles is 2 6 .
2.4 Hybrid Potential
As we have discussed, Hookes potential is local while the Lennard-Jones potential is global. In an attempt to model a solid using an MD simulation in Matlab,
we combine Hookes potential with the Lennard-Jones potential to create a hybrid
potential energy function that has both local and global properties. In doing so, it
became unnecessary to implement a cut-off distance for Lennard-Jones since Hookes
law will prevent particles from moving too far apart. This is a sufficient solution
assuming we are simulating relatively small systems. In very large systems, it might
be useful or even necessary to implement a cut-off range for Lennard-Jones so that
the computation time is reduced. This is because particles on one side of the system
may be far enough from particles on the opposite side of the system that the potential
energy between them is effectively zero.
Combining Hookes potential with Lennard-Jones potential, we get a potential
energy function which now has the form
V = VH + VLJ

(2.13)

Figure 2.7 below shows a two-dimensional layout of particles connected by springs.


This picture essentially demonstrates how the hybrid potential works. The springs
prevent the particles from moving too far apart and keep neighboring particles together preserving the structures initial shape, while the Lennard-Jones potential
prevents particles from becoming too close together and violating Paulis exclusion
principle.
In the MD simulations done in this thesis, the system has a three-dimensional
cube layout. Obviously, the springs are not actually present in the simulations, but
Figure 2.7 illustrates the spring force that is modeled in each simulation.
12

Texas Tech University, Morgan Groves, May 2012

Figure 2.7: Hookes law illustration of a 2D layout of particles

13

Texas Tech University, Morgan Groves, May 2012

CHAPTER III
THE HYBRID METHOD

The simulation results presented in this chapter are interpreted in the context
of solids. The particles which make up a generic solid are presented using a cubic
structure. The simulations were constructed as follows:
1. Initialize particle positions and velocities.
2. Compute forces on particles.
3. Integrate equation of motion.
4. Calculate energies of the system.
5. Repeat (2) - (4) for the designated period of time.
6. Graph the energies and changes in energies.
3.1 Initialization
The initial particle positions must be chosen so that no particle overlaps with
another. This is simply achieved by placing the particles on a lattice. For the simulations in this thesis, the particles were placed on a simple cubic lattice. The lattice
spacing was chosen to correlate with the Lennard-Jones equilibrium distance when
1

= 1. Thus, each particle was initially placed in a cubic lattice with spacing of 2 6
computational units apart. Figure 3.1 shows the initial positions of the particles in a
3-grid, or 3 3 3 simulation. The eight corners of the cube are marked with stars
in the simulation while the remaining particles are marked with circles. This makes
it easier to track the movement of the boundaries of the cube as the particles interact
with one another through time.
The initial velocities were chosen randomly for each particle with the exception
of the eight corner particles, which are initially fixed, i.e. vc (0) = 0. The velocities

14

Texas Tech University, Morgan Groves, May 2012

Figure 3.1: Initial configuration of a simulation of size 3 3 3.

are selected from a uniform distribution within the range [0, 0.005] computational
units in Matlab by using the command rand(). In order to keep the system from
traveling in the simulation, the average of all of the initial velocities was calculated
then subtracted off of the n particles velocities. That is,
v = 0.01*(rand(3,n)-.5);
vmean = sum(v)/n;
for i = 1:n
v(:,i)

= v(:,i) - vmean;

end
This keeps the center of mass stationary during the simulation.
The masses of the particles are not all identical. In an attempt to simulate a
solid, we designed the corner particles to have a mass of 250, or 4.18155 1025 kg
in real world units. Although there is no element that has a mass this large, we
can imagine these corners as heavy molecules instead of atoms. This will help the
simulation maintain its original cubic shape. The remaining boundary particles each
have a mass of 10, or 1.67 1026 kg, and the interior particles have a mass of 1, or
1.67 1027 kg. These masses were chosen strictly for their simplicity since we do not
have a specific solid material in mind.
15

Texas Tech University, Morgan Groves, May 2012

Figure 3.2: Neighbors of selected particles: corner, edge, interior particles

Since we are using Hookes law to help model the solid, we must choose a spring
constant for the simulation. The simulations discussed in this paper were run using
spring constants of k = 1, 10, 100. These values correspond to k = 0.001673, 0.01673, and 0.1673 kg
,
s2
respectively.
Since Hookes law only applies to neighboring particles, a definition of neighbor is
in order. We define neighboring particles as those that form right angles with respect
to the cube. More simply, a neighbor is one that is either directly above, below, left,
right, behind, or in front of a specific particle. The neighbors of each particle in the
system do not change during the simulation. Also, neighboring particles are easily
identified. The neighbors of the mth particle will have position vectors of the form
r(i 1, j, k), r(i + 1, j, k), r(i, j 1, k), r(i, j + 1, k), r(i, j, k 1), or r(i, j, k + 1) where
i, j, and k are integers. Figure 3.2 identifies neighbors of three selected particles after
the cube is initialized. Notice that a particle in the simulation will have at least three
neighbors but no more than six depending on its location in the lattice.

16

Texas Tech University, Morgan Groves, May 2012

3.2 Computing Forces


Recall that the force is equal to the negative gradient of the potential (1.1). We
implemented the Lennard-Jones potential (2.10) and the Hooke potential (2.8) so
that the force on the ith particle when using Lennard-Jones is given by



ri rj
1
2
Fi (r) = 24 13 7
r
r
||ri rj ||

(3.1)

where r = ||ri rj || is the scalar distance between any two neighboring particles i
and j and and are both taken to be one. The force on the ith particle due to the
j th particle when using Hooke is given by
 r r 
i
j
Fi (r) = k r 2
||ri rj ||


1
6

(3.2)

where r = ||ri rj || is the scalar distance between any two particles i and j. Recall
that the equilibrium position for the application of Hookes law is set for = 1 in the
Lennard-Jones potential (2.10). This is why I set the equilibrium position ( > 0) of
1

the spring to be 2 6 in (2.6). All of these values are in reduced units.


3.3 Integration
We are implementing the fourth order Runge-Kutta (RK4) algorithm seen below.
The RK4 algorithm is a method of numerically integrating ordinary differential equations by using a trial step at the midpoint of an interval to cancel out lower-order error
terms. It can be derived by using a Taylors series expansion [3]. It is known that
this quadrature method will not conserve energy due to the error it accumulates as a
simulation runs. However, since the global error for RK4 is O(h4 ) and the truncation
error is O(h5 ), this method looks as if it will produce accurate enough results when
running simulations [3]. The RK4 algorithm for integrating the ordinary differential
equation y 0 = f (t, y), y(t0 ) = y0 is
yn+1 = yn +
tn+1 = tn + h

17

Texas Tech University, Morgan Groves, May 2012

where = 16 (k1 + 2k2 + 2k3 + k4 ) and


k1 = hf (tn , yn ),
1
k2 = hf (tn + h, yn +
2
1
k3 = hf (tn + h, yn +
2

1
k1 ),
2
1
k2 ),
2

k4 = hf (tn + h, yn + k3 ).
The ki s are step values defined as:
k1 : step based on the slope at the beginning of the interval, using yn .
k2 : step based on the slope at the midpoint of the interval, using yn + 21 k1 .
k3 : step based on the slope at the midpoint of the interval, using yn + 21 k2 .
k4 : step based on the slope at the end of the interval, using yn + k3 .
By averaging the ki s, we get
1
= (k1 + 2k2 + 2k3 + k4 )
6
which is seen in the RK4 algorithm above.
3.4 Energy Calculations and Conservation
The conservation of energy is one important aspect we investigated for this thesis.
In this section, we discuss how we used the Lennard-Jones potential and Hookes
potential together to create the hybrid potential energy function. We will also see a
derivation of kinetic energy and a conservation of energy proof.
The potential energy calculations in our simulations use both Lennard-Jones and
Hookes potential added together to represent the systems total potential energy,
VT = VLJ + VH

18

(3.3)

Texas Tech University, Morgan Groves, May 2012

For Lennard-Jones, we used the standard form of the potential allowing = 1 and
= 1 as seen here

VLJi = 4

1
1
6
12
r
r


(3.4)

where r = ||ri rj ||. The total Lennard-Jones potential energy calculation is a sum
over all pairs of particles in the system. Thus, we can write the global potential more
specifically as
n X 
X
VLJ (r1 , . . . , rn ) =
4
i=1 j>i

1
1

12
||ri rj ||
||ri rj ||6


.

(3.5)

Forcing j > i prevents from calculating the potential twice between the same two
particles, once between i and j, and again between j and i.
1

For Hookes potential, we set the equilibrium position for Hookes law to be 2 6 as
shown here

1 2
1 
V Hi = k r 2 6
2

(3.6)

where r = ||ri rj || for two neighboring particles i and j. The total potential energy
using Hooke is also a sum over pairs of particles in the system with one restriction;
the pairs must be neighboring particles. Thus, we can write (3.6) as
VH (r1 , . . . , rn ) =


1 2
k XX
||ri rj || 2 6
2 i j>i

(3.7)

where j is a neighbor of particle i. Again, making j > i prevents from calculating the
same potential twice.
Computing the potential energy is not the only challenge when trying to conserve
energy in a simulation. We must also calculate the kinetic energy of the system in
order to compute the total energy
T E = KE + P E.

(3.8)

The kinetic energy of a system is the energy which a system possesses due to its
motion. In other words, it is the work needed to accelerate a particle from rest to
some velocity. Thus, in three dimension, we have the dot product of the force and
19

Texas Tech University, Morgan Groves, May 2012

the displacement of each particle in the system. However, the displacement dx can
be written as the velocity times the infinitesimal time interval dt. Thus, we have
F dx = F vdt.

(3.9)

If we let p = mv, also known as the momentum, and we use the relationship F = ma,
then we know that
dp
dv
=m
= ma = F.
dt
dt
Thus, we can write (3.9) as
F vdt =

dp
vdt = v dp = v d(mv)
dt

(3.10)

Since we are assuming that the mass of the system does not change, we can rearrange
(3.10) to say
F vdt = m(v dv)

(3.11)

Notice that applying the product rule to d(v v) produces


d(v v) = (dv) v + v (dv) = 2(v dv)
Thus, we can write (3.11) as
m
m
F vdt = m(v dv) = d(v v) = dv 2 = d
2
2

mv 2
2


(3.12)

Since this equation only depends on the final state, it is known as a total differential,
and we can simply integrate to get the kinetic energy. Applying (3.10) and (3.12),
we have
Z
EK =

Z
F dx =

Z
v d(mv) =

mv 2
2


=

mv 2
2

(3.13)

Therefore, we conclude that the kinetic energy is equal to the integral of the dot
product of the velocity of the system and the infinitesimal change of the systems
momentum (p)[11].
For the simulations described in this thesis, the masses are different depending on
the initial location of each particle in the system. To adjust for this, we made the
20

Texas Tech University, Morgan Groves, May 2012

mass value m in (3.12) a matrix containing the correct masses of each particle in the
system.
Now that we have potential energy and kinetic energy, we can take a look at the
concept of conservation of energy. The following proof provides detailed explanations
for this idea of energy conservation.
Theorem 3.1. If there exists a function V (r1 , . . . , rn ) such that the force on particle
j satisfies Fj = rj V , then V is the potential energy and total energy is constant
with respect to time, i.e.
n

1X
mj ||r0j (t)||2 + V (r1 (t), . . . , rn (t)) = c,
2 j=1
where c is some constant.
Proof. We know that by writing the norm as a dot product and applying the chain
rule, we have
||r0j (t)||2 = r0j (t) r0j (t)
This implies that the derivative of the kinetic energy is




d 1
d 1
0
0
2
0
mj ||rj (t)|| =
mj rj (t) rj (t)
dt 2
dt 2
1
= mj [r00j (t)r0j (t) + r0j (t) r00j (t)]
2
= mj r00j (t) r0j (t)
Since Fj = mj r00j , we can write the derivative of the kinetic energy for each particle
as


d 1
0
0
mj rj (t) rj (t) = Fj r0j (t)
dt 2
Therefore, the derivative of the total kinetic energy of the system is
" n
#
n
X
X
d 1
0
0
mj rj (t) rj (t) =
Fj r0j (t)
dt 2 j=1
j=1

21

Texas Tech University, Morgan Groves, May 2012

Also, if we let Vj = Vj (rj ) where Vj (rj ) := V (r1 , . . . , rn ), we can apply the chain rule
to the derivative of the potential energy function to get
dVj
= rj V r0j (t)
dt
where rj is the gradient with respect to the j th position vector. Since we know the
force is equal to the negative gradient of the potential, we have
rj V r0j (t) = Fj r0j (t)
This means the derivative of the total potential energy of the system can be written
as

n
X

rj V

r0j (t)

j=1

n
X

Fj r0j (t)

j=1

Total energy equals the sum of the kinetic energy and the potential energy of the
system. If the total energy is constant throughout the simulation, then the time
derivative of the total energy is zero. So,
#
" n
n
X
d 1X
0
0
mj rj (t) rj (t) + V (r1 (t), . . . , rn (t)) =
(Fj r0j (t) Fj r0j (t)) = 0
dt 2 j=1
j=1

To show that Hookes potential and the Lennard-Jones potential are both potential
energy functions that satisfy the theorem, we must show that FHj = rj VH and
FLJj = rj VLJ . So, differentiating (3.7), we have
 r r 
1
1 XX 
i
j
VH = k
2 ||ri rj || 2 6
2 i j>i
||ri rj ||
 r r 
XX
1
i
j
6
=k
||ri rj || 2
||ri rj ||
i j>i
where i and j are neighboring particles. This is the negative of Hookes force law
(3.2). See Appendix C for the derivation of rj (||ri rj ||).

22

Texas Tech University, Morgan Groves, May 2012

Next, for Lennard-Jones, we take (3.5) and differentiate to get




XX
ri rj
6
12
rj VLJ = 4

13
||r

r
||
||ri rj ||7
||ri rj ||
i
j
i j>i




XX
2
ri rj
1
= 24

||ri rj ||13 ||ri rj ||7


||ri rj ||
i j>i
which is the negative of the Lennard-Jones force (3.1). Therefore, Hookes potential
and the Lennard-Jones potential are both potential energy functions that will conserve
energy by the theorem.
The exact energy calculations we obtained from each simulation are unimportant
since our system does not model a specific material. The way in which the energy
calculations change, however, are very important here. This report focuses on the
ability to conserve energy using RK4 and the simulations response to having two
different stretch potentials applied to it in Matlab. How the energy changes will tell
us if it is being conserved.
3.5 Time Analysis
The time required to run a simulation is very important. The more efficient we
can make our programs, the faster they will perform and the more runs we can do to
collect data. Some of the run times of simulations performed for this thesis are seen in
Table 3.1. The times recorded in this table are in real world seconds and represent the
amount of time required to do all of the main calculations for the simulations, such as
energy calculations and running RK4. These times do not include the initialization
of the simulation or the creation of the movie. However, they do include the plot
time required to print each frame for the movie.
In Table 3.1 below, the number of computational seconds and the number of
frames used on each system are listed under specs. These values are important for
one main reason: they are used to calculate the step size dt. That is,
dt =

seccomp
.
300M

23

(3.14)

Texas Tech University, Morgan Groves, May 2012

The 300 represents the number of steps taken between each frame and was chosen
out of convenience. It can be changed with the only penalty being the amount of
time required to run the simulation. Originally, our simulations used the value 3000
instead of 300, but these simulations took too long to complete. Also, the step size
dt is inversely proportional to the run time. If we half the step size, then we are
doubling the number of steps that must be taken, and thus doubling the run time.
For instance, notice in Table 3.1 for a 3-grid system the run time for the simulation
using step size 0.0044 is 61.23 seconds, whereas the runtime for the same simulation
using step size 0.0022 is 120.56 seconds, which is about twice as long.
dt

333

444

555

666

specs

0.0011

241.88s

1091.86s

2504.94s

7418.01s

50s, 150f

0.0022

120.56s

553.86s

1224.75s

3672.35s

50s, 75f

0.0033

80.75s

370.93s

813.71s

2459.75s

50s, 50f

0.0044

61.23s

283.60s

619.54s

1899.82s

50s, 38f

Table 3.1: Run times for 4 different sized systems

One thing to notice is the pattern of the change in run times as the systems
increase in size. It took approximately 4.5 times longer to run a 4-grid system than
it did a 3-grid system, 3.5 times longer to run a 5-grid system than it took to run
a 4-grid system, and 3.0 times longer to run a 6-grid system than a 5-grid system.
This behavior is expected to continue as the grid size increases. In fact, this factor
will approach 1 as the grid size goes to infinity. If we compare the m-grid to the
(m + 1)-grid system, we see that as m goes to infinity, the ratio of the grid sizes goes
to one:


(m + 1)3
3
3
1
lim
= lim 1 +
+
+
= 1.
m
m
m3
m m2 m3
To break these times down more, lets take a look at the amount of time required
to perform only the energy calculations. Table 3.2 compares different size grids to the

24

Texas Tech University, Morgan Groves, May 2012

approximate amount of time required to run the loops for calculating the energy of
the system using the Lennard-Jones method and Hookes law for just one time step.
Figure 3.3 shows the Matlab code corresponding to the times in Table 3.2. The code
for the simulation can be found in its entirety in Appendix A and B.
Energy

333

444

555

666

Hooke

0.0001291s

0.0003247s

0.0006192s

0.001059s

Lennard-Jones 0.0004494s

0.002626s

0.009374s

0.02770s

Table 3.2: Real time seconds required to run one complete loop to calculate the energy of
the system using Hookes law and Lennard-Jones method.

From Table 3.2 we see the Lennard-Jones loop requires much more time to run
than the Hooke loop. This is because Lennard-Jones is a global potential; it must
compute energies between all pairs of particles in the system, whereas Hooke is local
and only computes the energies between neighboring particles. From Figure 3.3, it is
easy to see that the Lennard-Jones code requires (n 1)(n 2) iterations for each
time step while the Hooke code only requires 6n iterations, where n is the number of
particles in the system.
One very costly algorithm to run is the RK4 integration algorithm. Table 3.3
compares the run times in real world seconds required to run the RK4 algorithm
once. Keep in mind that the RK4 algorithm is called 300M times for each simulation,
where M is the number of frames the program produces for the video. For instance,
if we run a simulation with grid size 5 and frame count 50, then the time spent on
running the RK4 algorithm alone is approximately 878.55 real time seconds, or 14.6
minutes. Also notice it takes approximately 3 times longer to perform the RK4 for
an m-grid system than is required for an (m 1)-grid system for the small grid sizes
explored in this thesis.
Now lets take a look at the amount of time each of these four grid sizes take to
run specific operations. Table 3.4 shows the percentage of the total run time required
25

Texas Tech University, Morgan Groves, May 2012

%Lennard-Jones

%Hooke

for i = 1:n-1

for j = 1:n

for j= i+1:n

for i = 1:6

sij = u(:, i) - u(:, j);

neighbor = Index_dummy(j, i);

rij = norm(sij, 2);

if neighbor == 0

r2 = rij*rij;

else

r6 = r2^3;

sij = u(:, j) - u(:, neighbor);

r12 = r6^2;

rij = norm(sij, 2);

V = V + 4*(1/r12 - 1/r6);

V_select = 0.5*K*(rij-2^(1/6))^2;

end

V = V + V_select;

end

end
end
end

Figure 3.3: Matlab codes of the loops used to calculate potential energy of each system
using Hookes law and Lennard-Jones method

RK4

333

444

555

666

0.003346s

0.01527s

0.05325s

0.1550s

Table 3.3: Times required to perform the RK4 integration algorithm

to run the RK4 algorithm, which within it calls the function that calculates the
forces (accel ). The table also shows the percentage of the RK4 run time required to
perform the Lennard-Jones and Hooke force calculations. Lastly, Table 3.4 compares
the percentage of the total run time devoted to doing the energy calculations of several
grid sizes. The energy calculations are computed approximately every tenth time step

26

Texas Tech University, Morgan Groves, May 2012

starting with the first calculation being done at the beginning of the simulation. The
values in Table 3.4 were calculated by running simulations that use a step size of
dt = 0.0022 for 50 computational seconds taking 75 frames.
333

444

555

666

RK4 (% of total run time)

62.4%

62.0%

97.8%

95.0%

Force (% of RK4 run time)

23.3%

25.8%

25.7%

25.1%

0.0226%

0.0237%

0.0393%

0.0382%

Function

Energy (% of total run time)

Table 3.4: Percentages of time used to run specific functions.

As Table 3.4 illustrates, the percentage of the total run time spent on calculating
the integral and forces on each particle for simulations smaller than 5-grid is just
slightly more than is required to plot the positions, which is where the remaining
percentage of the total run times is spent. However, as we grow to systems of grid
size 5 and larger, the percentage of time spent on the RK4 algorithm dominates the
total run time.

27

Texas Tech University, Morgan Groves, May 2012

CHAPTER IV
RESULTS AND CONCLUSIONS

In this chapter, we will evaluate our approach and code. We will comment on
the appropriateness of the RK4 method. We will discuss the preservation of the
total energy calculated relative to the size of the systems. We will also show images
of several simulations taken at various points during the run to illustrate how the
particles move in the system. In particular, we will point out the degree of preservation
of the cubic lattice. Lastly, we will conclude the research with some observations.
4.1 Results
As expected, energy was not perfectly preserved in any of our simulations. However, the number of significant figures in the energy calculations that remained constant was large enough to qualify as satisfactory results.
The graphs below show the change in energy throughout a simulation of a 3grid system. Ideally, these graphs would be horizontal lines at E = 0. Figure 4.1
shows in computational units that for a step size of 0.0011 and a run time of 100
picoseconds, the amount of change in the energy calculations was less than 2 107
for the 3-grid simulation using a spring constant of k = 1. Likewise, Figure 4.2 shows
that the change in energy in computational units for a 3-grid simulation run for 100
picoseconds with a step size of 0.0022 using a spring constant of k = 100 was less
than a factor of 5 108 .
These energy changes are very small. As the systems get larger, the change in
energy also increases. Figures 4.3 and 4.4 show the change in energy in computational
units of a 4-grid system and a 5-grid system run for 50 picoseconds using a spring
constant of k = 10 and a step size of 0.0011. Notice that when we increased the grid
size by one, the energy calculations lost a significant figure of accuracy.
Figures 4.5 and 4.6 show the total energy of two systems, a 3-grid and a 4-grid,
respectively, graphed using computational units. Figures 4.7 and 4.8 compare the

28

Texas Tech University, Morgan Groves, May 2012

Figure 4.1: Change in Energy: 3 3 3,

Figure 4.2: Change in Energy: 3 3 3, k =

k = 1, dt = 0.0011

100, dt = 0.0022

Figure 4.3: Change in Energy: 4 4 4,

Figure 4.4: Change in Energy: 5 5 5, k =

k = 10, dt = 0.0011

10, dt = 0.0011

same two systems total potential energies in computation units, and Figures 4.9 and
4.10 compare the total kinetic energies of the same two systems again in computational
units. Note that kinetic energy is proportional to the temperature. Thus, the plots of
the temperatures of these systems would look the same as the kinetic energy graphs.
Comparing the potential energy graphs to their respective kinetic energy graphs,
we see that they are almost exactly mirror images of each other. This means that when
the two energies are added together (3.8), we get a near perfect straight horizontal
line for the graphs of the total energy. This is true since Figures 4.1 and 4.2 have
near zero slope. Thus, the changes in energy are small enough that we can say energy

29

Texas Tech University, Morgan Groves, May 2012

Figure 4.5: Total Energy: 3 3 3, k =

Figure 4.6: Total Energy: 4 4 4, k =

100, dt = 0.0011

100, dt = 0.0011

Figure 4.7: Potential Energy: 3 3 3,

Figure 4.8: Potential Energy: 4 4 4,

k = 100, dt = 0.0011

k = 100, dt = 0.0011

is conserved for small systems up to a variable delta error that is dependent on the
grid size of the system and the step size taken during the simulation.
In order to understand exactly how the hybrid potential works, we compare several
frames of a 3-grid simulation using a spring constant k = 1 and a step size of dt =
0.0011. We circled the same particle in each image so that it is easy to see how
that particle moved during the simulation. Notice that it remained an edge particle
until the figure lost its shape at the end of the simulation. This is because of the
application of Hookes law.

30

Texas Tech University, Morgan Groves, May 2012

Figure 4.9: Kinetic Energy: 3 3 3,

Figure 4.10: Kinetic Energy: 4 4 4,

k = 100, dt = 0.0011

k = 100, dt = 0.0011

Under the same conditions as the 3-grid system above, here is a sequence of images
taken from a simulation of a 4-grid system. The spring constant is still k = 1 and the
step size is dt = 0.0011. Again, we circled one particle so that it is easy to see how
it moves throughout the simulation. Notice that it simply oscillates around its initial
position.

31

Texas Tech University, Morgan Groves, May 2012

Figure 4.11: 3 3 3, k = 1

Next, we compare images of the previous 3-grid system, which had a spring constant value of k = 1, and the 3-grid system modeled below, which uses a spring
constant value of k = 100. Notice how the higher spring constant helps to preserve
the initial cubic structure.

Using higher spring constants is more effective at keeping the systems original
shape when modeling solids.
4.2 Conclusions
The purpose of this thesis was to address the issue of the RK4 quadrature method
not conserving energy in MD simulations, implementing an MD simulation in Mat32

Texas Tech University, Morgan Groves, May 2012

Figure 4.12: 4 4 4, k = 1

lab, and modeling a cubic structure using Hookes stretch potential combined with
the Lennard-Jones potential. We investigated how accurate the RK4 method can
approximate the forces in a system and how this approximation effects the energy
calculations of the system as it varies with time. We ran numerous simulations of
different sized grids using various time steps and performed a time analysis on the
program to compare the run times of a system to its grid size.
The implementation of this MD simulation in Matlab gave us the ability to easily
store properties for each particle by using matrices. Since Matlab, short for Matrix
Laboratory, is designed to utilize matrices for swift computations of large systems
of equations, it is one of the better options for modeling a molecular system since
there are n ordinary differential equations (ODEs) to solve for each time step in a

33

Texas Tech University, Morgan Groves, May 2012

Figure 4.13: 3 3 3, k = 100

simulation of n particles. Though there are different methods to solve a system of


ODEs, the use of Matlab makes them easier and faster to solve regardless of the
algorithm used.
We chose to solve the system of ODEs by way of the RK4 method because we
were interested to see how adversely affected the energy calculations would be. We
discovered that even though RK4 does not conserve energy, as long as the systems
remain small the error accrued during the calculations is negligible. Also, the time
required to perform the calculations for the simulations nearly equals that required
to graph the systems for minimally small systems.

34

Texas Tech University, Morgan Groves, May 2012

CHAPTER V
FUTURE WORK

The most exciting aspect of this project is how far it can be taken. There are many
different paths in which this simulation can be taken that will make it more realistic,
which is ultimately the goal; MD simulations are meant to model the physical world.
One such improvement is to select a specific particles mass to use when running the
simulations. Also, the addition of a bending potential would enable a simulation of
solids to be more realistic. A bending potential would ensure that the angle between
the springs connecting neighboring particles does not vary much from 90 degrees.
That is, as neighboring particles interact with one another, the angle that three
particles create has an equilibrium radian of

.
2

Figure 5.1 illustrates this idea. If

< 2 , then the particles will push on one another in such a way as to increase back
to

radians. Likewise, if > 2 , then the particles will pull on one another so that

will decrease back to

radians. This is very similar to how Hookes stretch potential

works and will provide more realism to the simulation of a solid.

Figure 5.1: Bending Potential

Another option is to change the shape of the layout of the particles. We chose to
use a cubic layout for simplicity, but changing the shape to a tetrahedral, for instance,

35

Texas Tech University, Morgan Groves, May 2012

would allow us to model a specific material, say a diamond, that is known to have a
tetrahedral chemical form.
Ultimately, this research is leading to the examination of heat transfer through a
solid on a molecular level. That is, we can take this simulation, add a heat source to
one side of the cube, and observe how the system reacts as the heat transfers through
it [16]. Modeling heat transfer through materials is a common type of simulation
performed in MD labs.
Also, making the program more efficient is very important when we want to model
large systems. We can do this by utilizing Matlabs vectorizing capability to store
the information more concisely. We can also write the program so that it will run on
multiple cores at once, decreasing the run time. Parallelizing the code will allow us
to run larger systems much more quickly.
The concern about the conservation of energy is still present. This leads to the idea
of examining other integrators that would combat energy drift in simulated molecular
systems. This would allow us to model large systems while still approximately conserving energy. For instance, Velocity Verlet is a numerical quadrature method used
in MD simulations which offers more stability and the preservation of the symplectic
form on phase space with approximately the same cost as the simple Eulers method
[24].

36

BIBLIOGRAPHY
[1] Azmy S. Achleh. Classical and Modern Numerical Analysis: Theory, Methods,
and Practice. CRC Press, Taylor & Francis Group, London, UK, 2010.
[2] Peter Atkins and Julio de Paula. Physical Chemistry for the Life Sciences. W.H.
Freeman and Company, New York, NY, 2006.
[3] J. H. E. Cartwright and O. Piro. The dynamics of runge-kutta methods. International Journal of Bifurcations Chaos, 2:427449, 1992.
[4] Falquet L. Kuznetsov D. Dejaegere, A. and R. Stote. Molecular dynamics simulations, CHARMM. http://www.ch.embnet.org/MD_tutorial/, Oct. 1999.
[5] Furio Ercolessi. A Molecular Dynamics Primer. Spring College in Computational
Physics, ICTP, Trieste, Italy, 1997.
[6] Goland A. N. Milgram M. Gibson, J. B. and G. H. Vineyard. Dynamics of
radiation damage. Phys. Rev., 120:1229 1253, 1960.
[7] Richard Haberman. Mathematical Models: Mechanical Vibrations, Population
Dynamics, and Traffic Flow. SIAM, Englewood Cliffs, New Jersey, 1998.
[8] Chris Hansen. Personal Communication.
[9] David Dr. Hartley. EDSAV99. http://www.cl.cam.ac.uk/conference/
EDSAC99/reminiscences, July 1999.
[10] J. N. Israelachvili. Intermolecular and Surface Forces. Harcourt Brace Jovanovich, San Diego, CA, San Diego, CA.
[11] Mahesh C. Jain. Textbook of Engineering Physics (Part I). PHI Learning Private
Limited, New Delhi, 2009.
[12] I. G. Kaplan. Intermolecular Interactions. John Wiley & Sons, Ltd., Chichester,
England, 2006.
[13] J.D. Lambert and D. Lambert. Numerical Methods for Ordinary Differential
Systems: The IVP. John Wiley & Sons Ltd., New York, NY, 1991.
[14] Vincent E. Lamberti, Lloyd D. Fosdick, Elizabeth R. Jessup, and Carolyn J. C.
Schauble. A hands-on introduction to molecular dynamics. Journal of Chemical
Education, 79(5):601, 2002.
[15] R. D. Levine. Molecular Reaction Dynamics. Cambridge University Press, Cambridge, UK, 2005.

37

Texas Tech University, Morgan Groves, May 2012

[16] Oleg A. Mazyar, Srirangam V. Addepalli, and William L. Hase. Size effects on
the kinetics of heat transfer from a nanoscale diamond particle to a diamond
surface. The Journal of Physical Chemistry C, 112(23):85648569, 2008.
[17] Kathy A. Miles. Seeing further, the legacy of Robert Hooke.
starryskies.com/articles/spec/hooks.html, June 1996.

http://

[18] Carl R. Nave. Potential Energy. http://hyperphysics.phy-astr.gsu.edu/


hbase/pegrav.html, August 2000.
[19] N. Ogbonna. Molecular dynamics simulation. African Institute for Mathematical
Sciences, May 2004.
[20] R. K. Pathria and Paul D. Beale. Statistical Mechanics. Elsevier Ltd., Burlington,
MA, 2011.
[21] D. E. Rutherford. Vector Methods Applied to Differential Geometry, Mechanics,
and Potential Theory. Dover Publications, Inc., Mineola, New York, 2004.
[22] Jewett Serway. Physics for Scientists and Engineers with Modern Physics, 8th
ed. Cengage Learning, 2010.
[23] Dr. Smith, Philip. Personal Communication.
[24] William C. Swope, Hans C. Andersen, Peter H. Berens, and Kent R. Wilson. A
computer simulation method for the calculation of equilibrium constants for the
formation of physical clusters of molecules: Application to small water clusters.
The Journal of Chemical Physics, 76(1):637649, 1982.
[25] D. Tabor. Gases, Liquids, and Solids, and Other States of Matter, 3rd Ed.
Cambridge University Press, Cambridge, UK, 1991.
[26] Loup Verlet. Computer experiments on classical fluids. I. Thermodynamical
properties of Lennard-Jones molecules. Phys. Rev., 159:98103, Jul 1967.
[27] D. Yin and A.D. MacKerell. Combining ab initio/empirical approach for optimization of Lennard-Jones parameters. Journal of Computational Chemistry,
19(3):334348, 1998.

38

Texas Tech University, Morgan Groves, May 2012

APPENDIX A
In this section, you will find the driver program written to initialize each simulation. This program sets up the initial positions and velocities of each particle in
the system as well as assigns masses to each particle depending on its location in the
cube.
function md_RK4_driver_3d(grid, sec, M)
clear MVector;
%sets up global variables spring constant K and a mass matrix MMatrix,
%and assigns them values to be
%used throughout the program
global K MVector Index Corners Index_dummy;
K = 10;
n = grid^3;
Index = zeros(n,6); %matrix that loads the indices
%of the neighbors of each particle
Corners = zeros(8,1); %vector that loads the indices
%of the corners of the cube
for i = 1:n
MVector(i) = 10; %masses of boundary non-corner particles is 10
end
b =
%so
m =
u =
v =

size(MVector);%needed to get number of particles from mass matrix


that we can set up proper loop limits
(grid-2)^3; %number of interior points
zeros(3,n); %sets up initial position matrix for n particles
zeros(3,n); %sets up initial velocity matrix for n particles

remainder = rem(m,2);
if remainder == 0 %for even grid systems
k = (n-m)/2 + 2;
kk = (n+m)/2 + 1;
for i = k:kk
MVector(i) = 1; %interior particles have mass 1
end
else %for odd grid systems
k = (n-m)/2 + 1;
kk = (n+m)/2;
for i = k:kk
MVector(i) = 1; %interior particles have mass 1
end

39

Texas Tech University, Morgan Groves, May 2012

end

num = 0;
for i = 0:grid -1
for j = 0:grid-1
for k = 0:grid-1
num = num+1;
u(:, num) = 2^(1/6)*([i, j, k]); %initial positions set
end
end
end
for jj = 1:n %first particle
counter = 1;
for j = 1:n %second particle
if jj == j
else
dist = u(:,jj) - u(:, j); %distance between particles
r = norm(dist, 2); %particles 3D "distance" apart
if r <= 1.4 %test to see if particles are neighbors
Index(jj,counter) = j;
counter = counter + 1;
end
end
end
end
j = 1;
for i = 1:n %loops through the n particles
if Index(i,4) == 0 %particles with only 3 neighbors => corner
Corners(j) = i; %records which particles are corners
j = j+1;
end
end
for i = 1:8 %loops to assign the corner partcles larger masses
t = Corners(i, 1);
MVector(t) = 250; %corner particles mass
end
ax = [0 12/10 0 12/10 0 12/10]*n^(1/3); %needed for 3d

40

Texas Tech University, Morgan Groves, May 2012

j = 1; %counter for corners


for i = 1:n %loops through all particles to plot them
if j <= 8 %tests that we do not exceed 8 corners
tt = Corners(j,1); %grabs the index for a corner
if i == tt %if we are wanting to plot a corner, we do this:
plot3(u(1, tt),u(2, tt),u(3, tt), *)%plot corners with *
hold on
j = j+1; %incrament our corner counter
else
hold on
plot3(u(1, i),u(2, i),u(3, i), o)
%plot the rest of our points that are not corners
end
end
end
axis(ax)
FF(1) = getframe;
%grabs frame and puts it in a struct vector to make a movie later
v = 0.01*(rand(3,n)-.5); %randomly generated initial velocities
vmean = sum(v)/n; %velocity average
for i = 1:n
v(:,i) = v(:,i) - vmean; % keeps center of mass stationary
end
for j = 1:8
v(:, Corners(j)) = 0; %sets initial velocity of corners to zero
end

%This loops ensures that we do not double count potentials


%between the same two particles when applying Hookes law.
Index_dummy = Index;
for i = 1:n
for j = 1:6
p = Index_dummy(i, j);
if p == 0
else
for jj = 1:6
if Index_dummy(p,jj) == i
Index_dummy(p, jj) = 0;
41

Texas Tech University, Morgan Groves, May 2012

end
end
end
end
end

md_RK4_hybrid(sec, u, v, M, FF);
end

42

Texas Tech University, Morgan Groves, May 2012

APPENDIX B
In this section, you will find the main program written to run all of the calculations
needed for each simulation. This file performs the RK4 quadrature method, computes
the forces on each particle, computes the energies on each particle, and plots the
system at each time step of the simulation. Then it takes the plots and converts
them to an .avi movie file.
function md_RK4_hybrid(sec, u,v, M, FF)
%molecular dynamics
%sec = seconds of simulation
%The global variable n = number of particles in simulation of cube.
%This program uses both Lennard-Jones potential and Hookes law to
%calculate the total energy and forces on each particle of the system.
%Global variables: Corners = indices of the particles that are
%
corners of the cubed system
%
n = number of particles in the entire system
global Corners n
g = size(u); %gets the dimensions of the position vector u
n = g(2); %gets the number of particles in the system
%close all
W = [u;v];
%creates a matrix of the position and velocities coordinates of each
%particle
ax = [0 12/10 0 12/10 0 12/10]*n^(1/3);
%needed for 3d, fixes the axis for plotting
Nsteps = 300; %number of steps between each frame
ssec = sec/M;
dt = ssec/Nsteps; %h, step size
prun = 10;
%prints out data about every 10th run
%(rounding might cause +-1 discrepency)
energy_counter = 0;
format long
%set up time and energy vectors that will hold data points for plot
tt = M/prun;
tt = round(tt);
time = zeros(1,tt);
time(1,1)=0;
genergy=zeros(1,tt);

43

Texas Tech University, Morgan Groves, May 2012

temp = zeros(1, tt);


boltz = 0.825440922506811; %Boltzmann constant converted to
%computational value used to find temp
tic; %starts timer
energies = Energy(W, energy_counter);
%initial Energy Calc
genergy(1,1)= energies(1,1);
KE(1,1) = energies(1,2);
PE(1,1) = energies(1,3);
temp(1,1) = ((2/(3*n*boltz))*energies(1,2)); %calculate initial temp
index_counter = 1; %counter for loading the genergy and time vectors
for i = 1:M
for jjj = 1:Nsteps
W_new = RK(W, dt);
W = W_new;
end

%calls the RK4 method with current matrix to


%calculate the integral of the first order ODE
%updates the matrix

r = rem(i,prun);
%calculates the energy every 10th run
if r == 0 || i == M
energies = Energy(W, energy_counter);
genergy(1,index_counter+1)= energies(1, 1);
%calls the energy function to calculate energy
KE(1,index_counter+1) = energies(1,2);
PE(1,index_counter+1) = energies(1,3);
time(1,index_counter+1)=time(1,index_counter)+ dt*Nsteps*prun;
temp(1, index_counter+1) = (((2/3)*energies(1,2)/n)/boltz);
index_counter = index_counter + 1;
end
j = 1; %counter for corners
hold off
for ii = 1:n %loops through all particles to plot them
if j <= 8 %tests that we do not exceed 8 corners
tt = Corners(j,1); %grabs the index for a corner
if ii == tt %plot a corner:
plot3(W(1, tt),W(2, tt),W(3, tt), *);
hold on
44

Texas Tech University, Morgan Groves, May 2012

j = j+1; %incrament our corner counter


else
plot3(W(1, ii),W(2, ii),W(3, ii), o);
%plot the rest of our points that are not corners
hold on
end
end
axis(ax); %Locks the axis
end
FF(i+1) = getframe; %grabs frame and stores it in the structure
%FF that will be used to build the video
end
run_time = toc %ends timer
l = size(genergy);
length = l(2);
energy_differences = zeros(1,length-1);
for i = 1:length
energy_differences(1, i) = genergy(1,1) - genergy(1, i);
end
movie2avi(FF, 3D_Hybrid_test.avi,compression, None, fps, 2);
%builds the movie with title 3D_Hybrid.avi
close all
figure
plot(time, genergy), axis auto
title(Time vs. Energy, FontSize, 14)
xlabel(Time(s), FontSize, 12)
ylabel(Energy,FontSize,12)
figure
plot(time, KE), axis auto
title(Time vs. Kinetic Energy, FontSize, 14)
ylabel(Kinetic Energy,FontSize,12)
xlabel(Time(s), FontSize, 12)
figure
plot(time, PE), axis auto
title(Time vs Potential Energy, FontSize, 14)
xlabel(Time(s), FontSize, 12)
ylabel(Potential Energy,FontSize,12)
figure
plot(time, energy_differences), axis auto
title(Change in Energy, FontSize, 14)
45

Texas Tech University, Morgan Groves, May 2012

xlabel(Time (computational seconds), FontSize, 12)


ylabel(Change in Energy (computational energy),FontSize,12)
figure
plot(time, temp), axis auto
title(Time vs Temp, FontSize, 14)
xlabel(Time(s), FontSize, 12)
ylabel(Temp(K),FontSize,12)
end

function W_new = RK(W, h)


%This function performs the Runga-Kutta 4th order integration algorithm
%and returns the integral value W_new to the main funtion.
K1 = h*F(W);
K2 = h*F(W + 1/2*K1);
K3 = h*F(W + 1/2*K2);
K4 = h*F(W + K3);
W_new = W + (1/6)*(K1 + 2*(K2 + K3) + K4);
end

function R = F(W)
%This function separates a second order ODE into two first order ODEs
%by putting them in a vector, which the RK4 function will call. It
%also calls the acceleration function to get the second derivative.
Y1 = W(4:6, :);
Y2 = accel(W(1:3, :));
R = [Y1; Y2];
end

function A = accel(u)
%This function performs various calculations to approximate forces on
%each particle in the system. Lennard-Jones needs F = -gradient(PE)
%Since we are in 3 dimensions, we have to norm the positions of each
%particle. For Hooke, we need F = -kx, where x is the distance from
%equilibrium between any two neighboring particles.
%Globle variables: K = spring constant
%
MVector = vector of particle masses
%
n = number of particles in the system
%
Index_dummy = nx6 matrix of the "number" of each
%
particles neighbor, i.e. Index(1,2)=4 means that
46

Texas Tech University, Morgan Groves, May 2012

particle 1s second neighbor is particle 4.


global MVector K n Index_dummy

A = 0*u; %initializes the acceleration matrix A to have the same


%size as u, but filled with zeros.
sum_LJ_accel = 0;
%This nested loop performs the Lennard-Jones calculation to find the
%accelerations on each particle due to all of the other particles in the
%system. It then uses Newtons third law (every action has an equal and
%opposite reaction) to add in the opposite reactions of each particles
%interactions with other particles.
for i = 1:n-1
for j= i+1:n
sij = u(:, i) - u(:, j);
rij = norm(sij, 2);
r2 = rij*rij;
r6 = r2^3;
r12 = r6^2;
s = (sij*24/r2)*(2/r12 -1/r6);
A(:, j) = A(:,j) - s;
A(:, i) = A(:,i) + s; %Newtons third law
end
end
%Hookes Law
A_select = 0; %an initial value for the force, F = -Kx
%other particles
sum_H_accel = 0;
for j = 1:n %loop over all of the particles in the system
for i = 1:6 %loop over all of the neighbors of each particle
neighbor = Index_dummy(j, i); %grabs the index for the
%neighbor of particle j
if neighbor == 0 %if the index for the neighbor has a value of
%0, then move on to the next neighbor index value
else %otherwise, do the following calculations
sij = (u(:, neighbor) - u(:,j));
%distance between particle j and one of its neighbor
rij = norm(sij, 2);
%norm of the distance vector to get a scalar distance
A_select = -K*(rij - 2^(1/6))*(sij/rij);
%force calculation: F = -kx, with a normalizing constant
%sij/rij that turns this back into a vector
47

Texas Tech University, Morgan Groves, May 2012

A(:, neighbor) = A(:, neighbor) + A_select;


%adds the forces on particle neighbor due to particle j
A(:, j) = A(:, j) - A_select;
%Newtons third law of motion: for every action, there is
%an equal and opposite reaction. So, instead of
%recalculating this same force with a different sign, we
%just put this force in the matrix where the value for
%forces acting on particle j due to particle neighbor
%goes.
end
end
end
%to acutally calculate the force in each coordinate direction, we need
%to divide by the mass of each particle in each coordinate direction.
for j=1:n
for i=1:3
A(i,j) = A(i,j)/MVector(j);
end
end
end
function energies = Energy(W,
%This function calculates the
%using both the Lennard-Jones
%with masses MVector, and the

energy_counter)
total energy, both potential and kinetic,
potential algorithm and Hookes Law, along
total number of particles n.

global K MVector n Index_dummy;


%calculate kinetice energy
TE = 0;
%variable for total energy of the system - sum of potential and kinetic
ke = 0; %variable for kinetic energy of the system
svels = zeros(n,1); %sum of velocity squared needed for kinetic calc
for j=1:n
svels(j, 1) = norm(W(4:6, j),2);
%norm of current particle velocities
end
ke = 0.5*MVector*(svels.^2);
%creates vector that must be summed for total kinetic energy
ke = sum(ke);
%this calculates the potential energy using the Lennard-Jones potential.
48

Texas Tech University, Morgan Groves, May 2012

V
b
u
n

=
=
=
=

0;
size(W);
W(1:3, :);
b(2);

sum_LJ_Energy = 0;
for i = 1:n-1
for j= i+1:n
sij = u(:, i) - u(:, j);
rij = norm(sij, 2);
r2 = rij*rij;
r6 = r2^3;
r12 = r6^2;
V = V + 4*(1/r12 - 1/r6);
end
end
%calculate potential energy using Hookes law: V = -1/2kx^2
u = W(1:3, :);
V_select = 0; %initializes a variable that will be the potential energy
%of a single particle due to a neighboring particle
sum_H_energy = 0;
for j = 1:n
for i = 1:6
neighbor = Index_dummy(j, i);
%gets the index for a neighbor of particle j
if neighbor == 0
%if the index for the neighbor particle is 0, then there is
%no neighbor or no more neighbors, so we skip to the next
%step.
else
sij = u(:, j) - u(:, neighbor);
%get distance between particle j and one of its neighbors
rij = norm(sij, 2);
%norm this distance to get a scalar distance value
V_select = 0.5*K*(rij-2^(1/6))^2;
%calculates potential between jth particle and its
%neighbor, PE = -1/2Kx^2
V = V + V_select;
49

Texas Tech University, Morgan Groves, May 2012

%adds this potential to particles potential total


end
end
end
energy_counter = energy_counter + 1;
KE(1,energy_counter) = ke;
PE(1,energy_counter) = V;
TE = ke + V %calculates total energy of the system
energies = [TE KE PE];
end

50

Texas Tech University, Morgan Groves, May 2012

APPENDIX C
The following derivation shows the detailed steps to taking the gradient of
||ri rj ||.
Suppose r2 = x2 + y 2 + z 2 from the definition of a Euclidean norm. Then,
(r2 ) =

r2
r2
r2
i+
j+
k = 2xi + 2yj + 2zk = 2(xi + yj + zk)
x
y
z

By the chain rule, we know that


(r2 ) = r 2r = 2rr
So,
2(xi + yj + zk) = 2rr r =

xi + yj + zk
r

Let ri = (x, y, z)i and rj = (u, v, w)j . Then,


1

rij = ||ri rj || = [(x u)2 + (y v)2 + (z w)2 ] 2


Since
r =

xi + yj + zk
r

we can write
1

ri (rij ) = ri ||ri rj || = ri [(x u)2 + (y v)2 + (z w)2 ] 2


1

= 1/2((x u)2 + (y v)2 + (z w)2 ) 2 (2(x u)i + 2(y v)j + 2(z w)k)
(x u)i + (y v)j + (z w)k
ri rj
=
=
||ri rj ||
rij

51

You might also like