molecular dynamics hooke-lennard-jones hybrid method

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

Upload: rafika

Post on 22-Dec-2015

243 views

Category:

Documents


0 download

DESCRIPTION

Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

TRANSCRIPT

Page 1: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

Page 2: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Copyright 2012, Morgan Groves

Page 3: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Dedicated to my wonderful husband, Jason, who has been so helpful and supportive

every step of the way.

Page 4: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

ACKNOWLEDGMENTS

Many thanks to

Dr. Philip Smith

Dr. Kevin Long

Chris Hansen

Jason Groves

ii

Page 5: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

CONTENTS

ACKNOWLEDGMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . ii

ABSTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv

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

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

I INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

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

2.1 Definitions and Associations . . . . . . . . . . . . . . . . . . . 4

2.2 Hooke’s Potential . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.3 Lennard-Jones Potential . . . . . . . . . . . . . . . . . . . . . 9

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

Page 6: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

ABSTRACT

In this thesis we apply Hookes law and the Lennard-Jones potential together form-

ing a hybrid potential energy function to model atomic interaction. These molecular

dynamics simulations are then implemented in Matlab. For each simulation, we con-

struct a cubic lattice of particles set at an equilibrium distance apart with most par-

ticles 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 implemen-

tation, 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

Page 7: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

LIST OF TABLES

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

3.1 Run times for 4 different sized systems . . . . . . . . . . . . . . . . . 243.2 Real time seconds required to run one complete loop to calculate the

energy of the system using Hooke’s law and Lennard-Jones’ method. . 253.3 Times required to perform the RK4 integration algorithm . . . . . . . 263.4 Percentages of time used to run specific functions. . . . . . . . . . . . 27

v

Page 8: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

LIST OF FIGURES

2.1 Experimental Spring Force . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Hooke’s Law - approximation of experimental spring force . . . . . . 72.3 V (x) = 1

2kx2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.4 String of particles under Hooke’s law . . . . . . . . . . . . . . . . . . 82.5 Lennard-Jones force, σ = 1, ε = 1 . . . . . . . . . . . . . . . . . . . . 112.6 Lennard-Jones potential, σ = 1, ε = 1 . . . . . . . . . . . . . . . . . 112.7 Hooke’s law illustration of a 2D layout of particles . . . . . . . . . . . 13

3.1 Initial configuration of a simulation of size 3× 3× 3. . . . . . . . . . 153.2 Neighbors of selected particles: corner, edge, interior particles . . . . 163.3 Matlab codes of the loops used to calculate potential energy of each

system using Hooke’s law and Lennard-Jones’ method . . . . . . . . . 26

4.1 Change in Energy: 3× 3× 3, k = 1, dt = 0.0011 . . . . . . . . . . . . 294.2 Change in Energy: 3× 3× 3, k = 100, dt = 0.0022 . . . . . . . . . . 294.3 Change in Energy: 4× 4× 4, k = 10, dt = 0.0011 . . . . . . . . . . . 294.4 Change in Energy: 5× 5× 5, k = 10, dt = 0.0011 . . . . . . . . . . . 294.5 Total Energy: 3× 3× 3, k = 100, dt = 0.0011 . . . . . . . . . . . . . 304.6 Total Energy: 4× 4× 4, k = 100, dt = 0.0011 . . . . . . . . . . . . . 304.7 Potential Energy: 3× 3× 3, k = 100, dt = 0.0011 . . . . . . . . . . . 304.8 Potential Energy: 4× 4× 4, k = 100, dt = 0.0011 . . . . . . . . . . . 304.9 Kinetic Energy: 3× 3× 3, k = 100, dt = 0.0011 . . . . . . . . . . . . 314.10 Kinetic Energy: 4× 4× 4, k = 100, dt = 0.0011 . . . . . . . . . . . . 314.11 3× 3× 3, k = 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.12 4× 4× 4, k = 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.13 3× 3× 3, k = 100 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

5.1 Bending Potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

vi

Page 9: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

CHAPTER I

INTRODUCTION

Molecular dynamics (MD) is a computer simulation technique using Newtons sec-

ond 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 par-

ticles 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

Page 10: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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. Hooke’s potential, calculated by taking the integral of

the force F = −kx, where k is the spring constant and x is the particle’s 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 Hooke’s 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.

2

Page 11: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

Units Computational Real World

Length 1 10−10m

Time 1 10−12s

Mass (proton) 1 1.67262158× 10−27kg

Velocity 1 100 m/s

Energy 1 1.67262158× 10−25kg m2

s2

Boltzmann constant 0.82544092250681 1.3806503× 10−23kg m2

s2K.

Temperature 1 1 K

Spring Constant 1 0.0017kg

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× 10−23m2kg

s2K· (10−12s)2(1K)

(10−10m)2(1.67262158× 10−27kg)= 0.82544092250681

3

Page 12: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 conser-

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

WC =

∫C

F · dx =

∫C

F · v dt (2.1)

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

v = dxdt

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

V = −∫

F · dx. (2.2)

This means the force is equal to the negative gradient of the potential,

F = −∇V. (2.3)

4

Page 13: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 Hooke’s 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 Hooke’s Potential

Robert Hooke was described as the “single greatest experimental scientist of the

17th century” [17]. His life’s work was very eclectic, but he is best known for the

discovery of Hooke’s 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].

Hooke’s 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 spring’s 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 Nm

or kgs2

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

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

5

Page 14: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

Figure 2.1: Experimental Spring Force

real world value of the spring constant is

1.67262158× 10−27kg

(10−12s)2= 0.001673

kg

s2= 1.673× 10−3

kg

s2

Molecular dynamics simulations use Newton’s second law of motion to model molec-

ular 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 Hooke’s 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 Hooke’s law is a force equation, we can apply (2.2) and integrate to get the

potential energy function V , as seen here.

VH = −∫ x

x0

−kx · dx

VH =1

2k(x− x0)

2 (2.5)

This function results from summing the energy required to incrementally com-

press the spring. That is, it is integrated over the displacement of the spring from

6

Page 15: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

Figure 2.2: Hooke’s Law - approximation of experimental spring force

Figure 2.3: V (x) = 12kx

2

the equilibrium position x0 to a position x. The graph of Hooke’s 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 Hooke’s 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 Hooke’s law. The particles can move in three

dimensions and have locations r1, · · · , rn. Neighboring particles are connected by a

7

Page 16: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 Hooke’s 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:

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

(r2 − r1||r2 − r1||

)Fj = k

[(||rj − rj−1|| − α)

(rj − rj−1||rj − rj−1||

)− (||rj+1 − rj|| − α)

(rj+1 − rj||rj+1 − rj||

)], j = 2 : n− 1

Fn = −k(||rn − rn−1|| − α)

(rn − rn−1||rn − rn−1||

)(2.6)

This leads to the system of ODEs:

m1r′′1 = k(||r2 − r1|| − α)

(r2 − r1||r2 − r1||

)mjr

′′j = k

[(||rj − rj−1|| − α)

(rj − rj−1||rj − rj−1||

)− (||rj+1 − rj|| − α)

(rj+1 − rj||rj+1 − rj||

)], j = 2 : n− 1

mnr′′n = −k(||rn − rn−1|| − α)

(rn − rn−1||rn − rn−1||

)(2.7)

We can write the potential energy function as

V (r1, · · · , rn) =1

2kn−1∑j=1

[(||rj+1 − rj|| − α)]2 (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

Page 17: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

Though Hooke’s 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 imple-

mented and mathematically simple and convenient. The general form of the Lennard-

Jones potential in one dimension is

VLJ(r) = 4ε

[(σr

)12−(σr

)6](2.9)

In three dimensions, the Lennard-Jones potential can be written as

VLJ(r1, . . . , rn) = 4ε∑i

∑j>i

[(σr

)12−(σr

)6](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

Page 18: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

σHe = 1.480A [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.02127kcalmol

[27].

The Lennard-Jones potential combines a short-range repulsive force, represented

by the 1r12

term, with a long-range attractive force, the 1r6

term. The attraction force

stems from the van der Waals dispersion forces due to fluctuating dipoles. The repul-

sion force has two justifications. First, when one electron shell collides with another,

the nuclear charges are no longer completely screened, resulting in the particles re-

pelling one another. The second reason is the well-known Pauli’s 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

FLJij = −48ε

[(σ12

r13

)−(σ6

r7

)](ri − rj||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 par-

ticles 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-trunc(r) =

VLJ(r)− VLJ(rc) for r ≤ rc

0 for r > rc

(2.12)

10

Page 19: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

Page 20: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

potential is located at the minimum position on the graph, which is r = 216σ. Since

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

particles is 216 .

2.4 Hybrid Potential

As we have discussed, Hooke’s potential is local while the Lennard-Jones poten-

tial is global. In an attempt to model a solid using an MD simulation in Matlab,

we combine Hooke’s 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 Hooke’s

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 Hooke’s 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 to-

gether preserving the structure’s initial shape, while the Lennard-Jones potential

prevents particles from becoming too close together and violating Pauli’s 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

Page 21: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

Figure 2.7: Hooke’s law illustration of a 2D layout of particles

13

Page 22: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 simu-

lations 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. Thus, each particle was initially placed in a cubic lattice with spacing of 216

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

Page 23: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 × 10−25kg

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 × 10−26kg, and the interior particles have a mass of 1, or

1.67× 10−27kg. These masses were chosen strictly for their simplicity since we do not

have a specific solid material in mind.

15

Page 24: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

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

Since we are using Hooke’s 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.1673kgs2

,

respectively.

Since Hooke’s 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

Page 25: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

Fi(r) = 24

(2

r13− 1

r7

)(ri − rj||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

jth particle when using Hooke is given by

Fi(r) = −k(r − 2

16

)( ri − rj||ri − rj||

)(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 Hooke’s law is set for σ = 1 in the

Lennard-Jones potential (2.10). This is why I set the equilibrium position (α > 0) of

the spring to be 216 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 equa-

tions 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 Taylor’s 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′ = f(t, y), y(t0) = y0 is

yn+1 = yn + δ

tn+1 = tn + h

17

Page 26: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

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

k1 = hf(tn, yn),

k2 = hf(tn +1

2h, yn +

1

2k1),

k3 = hf(tn +1

2h, yn +

1

2k2),

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 + 12k1.

• k3: step based on the slope at the midpoint of the interval, using yn + 12k2.

• k4: step based on the slope at the end of the interval, using yn + k3.

By averaging the ki’s, we get

δ =1

6(k1 + 2k2 + 2k3 + k4)

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 Hooke’s

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

Hooke’s potential added together to represent the system’s total potential energy,

VT = VLJ + VH (3.3)

18

Page 27: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

r12− 1

r6

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

VLJ(r1, . . . , rn) =n∑i=1

∑j>i

4

(1

||ri − rj||12− 1

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

For Hooke’s potential, we set the equilibrium position for Hooke’s law to be 216 as

shown here

VHi=

1

2k(r − 2

16

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

2

∑i

∑j>i

(||ri − rj|| − 2

16

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

TE = KE + PE. (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

Page 28: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 thatdp

dt= m

dv

dt= ma = F.

Thus, we can write (3.9) as

F · vdt =dp

dt· vdt = v · dp = v · d(mv) (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

F · vdt = m(v · dv) =m

2d(v · v) =

m

2dv2 = d

(mv2

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

EK =

∫F · dx =

∫v · d(mv) =

∫d

(mv2

2

)=mv2

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 system’s

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

Page 29: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 = −∇rjV , then V is the potential energy and total energy is constant

with respect to time, i.e.

1

2

n∑j=1

mj||r′j(t)||2 + V (r1(t), . . . , rn(t)) = c,

where c is some constant.

Proof. We know that by writing the norm as a dot product and applying the chain

rule, we have

||r′j(t)||2 = r′j(t) · r′j(t)

This implies that the derivative of the kinetic energy is

d

dt

[1

2mj||r′j(t)||2

]=

d

dt

[1

2mjr

′j(t) · r′j(t)

]=

1

2mj[r

′′j · (t)r′j(t) + r′j(t) · r′′j (t)]

= mjr′′j (t) · r′j(t)

Since Fj = mjr′′j , we can write the derivative of the kinetic energy for each particle

asd

dt

[1

2mjr

′j(t) · r′j(t)

]= Fj · r′j(t)

Therefore, the derivative of the total kinetic energy of the system is

d

dt

[1

2

n∑j=1

mjr′j(t) · r′j(t)

]=

n∑j=1

Fj · r′j(t)

21

Page 30: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

dVjdt

= ∇rjV · r′j(t)

where ∇rj is the gradient with respect to the jth position vector. Since we know the

force is equal to the negative gradient of the potential, we have

∇rjV · r′j(t) = −Fj · r′j(t)

This means the derivative of the total potential energy of the system can be written

asn∑j=1

∇rjV · r′j(t) =n∑j=1

−Fj · r′j(t)

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,

d

dt

[1

2

n∑j=1

mjr′j(t) · r′j(t) + V (r1(t), . . . , rn(t))

]=

n∑j=1

(Fj · r′j(t)− Fj · r′j(t)) = 0

To show that Hooke’s potential and the Lennard-Jones potential are both potential

energy functions that satisfy the theorem, we must show that FHj= −∇rjVH and

FLJj = −∇rjVLJ. So, differentiating (3.7), we have

∇VH =1

2k∑i

∑j>i

2(||ri − rj|| − 2

16

)( ri − rj||ri − rj||

)= k

∑i

∑j>i

(||ri − rj|| − 2

16

)( ri − rj||ri − rj||

)where i and j are neighboring particles. This is the negative of Hooke’s force law

(3.2). See Appendix C for the derivation of ∇rj(||ri − rj||).

22

Page 31: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

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

∇rjVLJ = 4∑i

∑j>i

(−12

||ri − rj||13− −6

||ri − rj||7

)(ri − rj||ri − rj||

)= −24

∑i

∑j>i

(2

||ri − rj||13− 1

||ri − rj||7

)(ri − rj||ri − rj||

)which is the negative of the Lennard-Jones force (3.1). Therefore, Hooke’s 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 simulation’s 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. (3.14)

23

Page 32: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 3× 3× 3 4× 4× 4 5× 5× 5 6× 6× 6 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:

limm→∞

(m+ 1)3

m3= lim

m→∞

(1 +

3

m+

3

m2+

1

m3

)= 1.

To break these times down more, let’s 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

Page 33: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 Hooke’s 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 3× 3× 3 4× 4× 4 5× 5× 5 6× 6× 6

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 Hooke’s 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 let’s 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

Page 34: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

%Lennard-Jones

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

%Hooke

for j = 1:n

for i = 1:6

neighbor = Index_dummy(j, i);

if neighbor == 0

else

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

rij = norm(sij, 2);

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

V = V + V_select;

end

end

end

Figure 3.3: Matlab codes of the loops used to calculate potential energy of each system

using Hooke’s law and Lennard-Jones’ method

3× 3× 3 4× 4× 4 5× 5× 5 6× 6× 6

RK4 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

Page 35: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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.

Function 3× 3× 3 4× 4× 4 5× 5× 5 6× 6× 6

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%

Energy (% of total run time) 0.0226% 0.0237% 0.0393% 0.0382%

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

Page 36: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

ever, the number of significant figures in the energy calculations that remained con-

stant was large enough to qualify as satisfactory results.

The graphs below show the change in energy throughout a simulation of a 3-

grid 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× 10−7

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× 10−8.

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

Page 37: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

Figure 4.1: Change in Energy: 3× 3× 3,

k = 1, dt = 0.0011

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

100, dt = 0.0022

Figure 4.3: Change in Energy: 4× 4× 4,

k = 10, dt = 0.0011

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

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

Page 38: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

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

100, dt = 0.0011

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

100, dt = 0.0011

Figure 4.7: Potential Energy: 3 × 3 × 3,

k = 100, dt = 0.0011

Figure 4.8: Potential Energy: 4 × 4 × 4,

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 Hooke’s law.

30

Page 39: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

Figure 4.9: Kinetic Energy: 3 × 3 × 3,

k = 100, dt = 0.0011

Figure 4.10: Kinetic Energy: 4 × 4 × 4,

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

Page 40: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 con-

stant 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 system’s 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 Mat-

32

Page 41: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

Figure 4.12: 4× 4× 4, k = 1

lab, and modeling a cubic structure using Hooke’s 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

Page 42: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

Page 43: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 particle’s 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 π2

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

will decrease back to π2

radians. This is very similar to how Hooke’s 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

Page 44: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 Matlab’s 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 con-

serving 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 Euler’s method

[24].

36

Page 45: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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. Inter-national Journal of Bifurcations Chaos, 2:427–449, 1992.

[4] Falquet L. Kuznetsov D. Dejaegere, A. and R. Stote. Molecular dynamics simu-lations, CHARMM. http://www.ch.embnet.org/MD_tutorial/, Oct. 1999.

[5] Furio Ercolessi. A Molecular Dynamics Primer. Spring College in ComputationalPhysics, ICTP, Trieste, Italy, 1997.

[6] Goland A. N. Milgram M. Gibson, J. B. and G. H. Vineyard. Dynamics ofradiation damage. Phys. Rev., 120:1229 – 1253, 1960.

[7] Richard Haberman. Mathematical Models: Mechanical Vibrations, PopulationDynamics, 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 Jo-vanovich, San Diego, CA, San Diego, CA.

[11] Mahesh C. Jain. Textbook of Engineering Physics (Part I). PHI Learning PrivateLimited, 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 DifferentialSystems: 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 ChemicalEducation, 79(5):601, 2002.

[15] R. D. Levine. Molecular Reaction Dynamics. Cambridge University Press, Cam-bridge, UK, 2005.

37

Page 46: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

[16] Oleg A. Mazyar, Srirangam V. Addepalli, and William L. Hase. Size effects onthe kinetics of heat transfer from a nanoscale diamond particle to a diamondsurface. The Journal of Physical Chemistry C, 112(23):8564–8569, 2008.

[17] Kathy A. Miles. Seeing further, the legacy of Robert Hooke. http://

starryskies.com/articles/spec/hooks.html, June 1996.

[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 MathematicalSciences, 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, 8thed. Cengage Learning, 2010.

[23] Dr. Smith, Philip. Personal Communication.

[24] William C. Swope, Hans C. Andersen, Peter H. Berens, and Kent R. Wilson. Acomputer simulation method for the calculation of equilibrium constants for theformation of physical clusters of molecules: Application to small water clusters.The Journal of Chemical Physics, 76(1):637–649, 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. Thermodynamicalproperties of Lennard-Jones molecules. Phys. Rev., 159:98–103, Jul 1967.

[27] D. Yin and A.D. MacKerell. Combining ab initio/empirical approach for op-timization of Lennard-Jones parameters. Journal of Computational Chemistry,19(3):334–348, 1998.

38

Page 47: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

APPENDIX A

In this section, you will find the driver program written to initialize each simu-lation. This program sets up the initial positions and velocities of each particle inthe system as well as assigns masses to each particle depending on its location in thecube.

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 = size(MVector);%needed to get number of particles from mass matrix

%so that we can set up proper loop limits

m = (grid-2)^3; %number of interior points

u = zeros(3,n); %sets up initial position matrix for n particles

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

Page 48: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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); %particle’s 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

Page 49: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 Hooke’s 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

Page 50: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

end

end

end

end

end

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

end

42

Page 51: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

APPENDIX B

In this section, you will find the main program written to run all of the calculationsneeded for each simulation. This file performs the RK4 quadrature method, computesthe forces on each particle, computes the energies on each particle, and plots thesystem at each time step of the simulation. Then it takes the plots and convertsthem 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 Hooke’s 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

Page 52: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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); %calls the RK4 method with current matrix to

%calculate the integral of the first order ODE

W = W_new; %updates the matrix

end

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

Page 53: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

Page 54: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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

% particle’s neighbor, i.e. Index(1,2)=4 means that

46

Page 55: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

% particle 1’s 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 Newton’s third law (every action has an equal and

%opposite reaction) to add in the opposite reactions of each particle’s

%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; %Newton’s third law

end

end

%Hooke’s 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 it’s 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

Page 56: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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;

%Newton’s 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, energy_counter)

%This function calculates the total energy, both potential and kinetic,

%using both the Lennard-Jones potential algorithm and Hooke’s Law, along

%with masses MVector, and the 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

Page 57: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

V = 0;

b = size(W);

u = W(1:3, :);

n = 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 Hooke’s 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 it’s 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 it’s

%neighbor, PE = -1/2Kx^2

V = V + V_select;

49

Page 58: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

Texas Tech University, Morgan Groves, May 2012

%adds this potential to particle’s 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

Page 59: Molecular Dynamics Hooke-Lennard-Jones Hybrid Method

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 + y2 + z2 from the definition of a Euclidean norm. Then,

∇(r2) =∂r2

∂xi +

∂r2

∂yj +

∂r2

∂zk = 2xi + 2yj + 2zk = 2(xi + yj + zk)

By the chain rule, we know that

∇(r2) = ∇r · 2r = 2r∇r

So,

2(xi + yj + zk) = 2r∇r ⇒ ∇r =xi + yj + zk

r

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

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

Since

∇r =xi + yj + zk

r

we can write

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

= 1/2((x− u)2 + (y − v)2 + (z − w)2)−12 · (2(x− u)i + 2(y − v)j + 2(z − w)k)

=(x− u)i + (y − v)j + (z − w)k

||ri − rj||=

ri − rjrij

51