Summer School on Computational Materials Science:

Basic Simulation Techniques


Lecture 1:  Introduction

 Why is computer simulation important?

Many-body problems are ubiquitous in physics, chemistry, biology, and materials science. Simulations provide a very powerful way of solving these problems, enabling one to go directly from a microscopic Hamiltonian to macroscopic properties measured in experiment, essentially without approximation.  Some of the reasons why simulations have become so important are: The above reasons have lead to a "boom" in the development of simulations. Originating at the dawn of the computer age (1950) direct simulations have now spread to most areas of pure and applied science. Computational physics has been said to constitute a third way of doing physics, comparable to theory and experiment. We will see that simulations do have both theoretical and experimental aspects. Simulations have become so important that all scientists should learn its fundamentals.

There are many applied applications, for example, simulated annealing for optimization, economics (stock markets). The literature on simulation is quickly expanding but there are few comprehensive textbooks. Most interesting techniques have not yet been invented or tried; there are plenty of developments coming out.

Two approaches to simulation are often presented:

We will concentrate on the first type of problem. The second problem is quite different and success is not so well defined, but occasionally it is extremely successful (chaos, cellular automata...)

Further reading. "Microscopic Simulations in Physics" by D. Ceperley, Rev. Mod. Phys. 71, S438, 1999.

Some of the issues concerned with in simulations are:

 Statistical Mechanics Background:

The physical foundation of simulation is statistical mechanics. Without statistical mechanics, it would be difficult to make the connection between the rather small systems simulated for short periods of time with measurements on macroscopic samples. Statistical mechanics "course grains"- separates the thermodynamic macroscopic variables like pressure and temperature from the microscopic variables: the individual atomic positions and velocities.

Even though most of the simulations we will talk about are classical, it is actually easier to understand the fundamental principles if we use the basic concepts of stationary states in quantum mechanics. This is because the energy states are a countable finite set. We shall indicate a few salient points after defining some terminology.

Phase Space

A mechanical system is composed of many particles with position, qi, and momentum, pi, denoted as q and p for short. This is the phase space. Any mechanical systems with such coordinates can be characterized by a function, H(q, p; t), typically, the Hamiltonian of the system which determines the energy for any coordinates.

Ensemble

The collection of all possible sets of allowed values of {qi} and {pi} for the system, compatible with the constraints, e.g. fixed N, Volume, V, and energy, E, for microcanonical, is called the "ensemble" (in the original sense of the word, a collection or group). If there are G accessible states, then there are G systems in the ensemble. There are different types of ensembles depending on the constraints, constant-NVE, constant-NVT, constant- m VT, and so on.

Suppose that we have a system with fixed N and V. Then:

While we have discussed the constant energy ensemble (micro-canonical) we will encounter other ensembles soon, for example, constant pressure, constant temperature (canonical), grand canonical (where the system can exchange particles with the heat bath), etc.

Classical Statistical Mechanics

The above discussion was formulated in terms of quantum states. Let us now take the classical limit of the Boltzmann formula. Suppose H=K+U where K is the kinetic operator and U is the potential operator. For high enough temperatures we can write exp(-b H) = exp(-b K) exp(-b U). (See the formula page.) One finds that the probability of being in a volume dpdr in phase space is proportional to exp(-b E) where E is the classical energy E= p2/2m+V(R). To summarize, if a system is allowed to exchange energy and momentum with outside systems its distribution will equal the canonical distribution. Quantum mechanics does introduce a new feature, an N! coming from the fact the particles are often indistinguishable. Usually this feature drops out classically.

The momentum part of the Maxwell-Boltzmann distribution (the Maxwell distribution) is just a "normal" Gaussian distribution. It is completely uncorrelated with the position part. If you know something about the positions you have no knowledge about the momentum (and vice-versa) in thermal equilibrium. The average kinetic energy is exactly 3/2kBT (equipartition).

After doing the momentum integrals, we are left with the configuration distribution and partition function.
 

Time Average versus Ensemble Average

In experiments one typically considers a large number of successive times (t1 .... tM) to make measurements, each of which reveals the current state of the system. Then <A> = S AiPi where Pi = ni/M and ni is the number of times the systems is in state i out of M total. This is a time average over a single system because the value of ni were obtained by successive observations. Now  consider a classical simulation for a fixed number of particles and a given potential energy function V(R) isolated from any heat bath. Newton tells us the system will evolve according to F = -grad(V)= ma. We assign initial positions and velocities (implying an initial total energy and momentum). If we let it evolve what will happen? Will it go to the canonical distribution?

First, a few constants of motion maybe be known: energy, momentum, number of particles, etc. These will not change but in a system of more than 2 particles the number of degrees of freedom is greater than the number of constants of motion.  Gibbs introduced the artifice of a large number of replicas of the system (i.e., the ensemble) and imagined them to trace out paths on the energy surface. Basically, we could follow A(t) for one system for infinite time and average, or just consider the value of A for each member of the ensemble and average. They should be the same thing. So Gibbs replaced <A>time with <A>ens. Gibbs adopted the view from the outset that this was only a device to calculate the probable behavior of a system.

In other words, instead of starting from a single initial condition, we start from the canonical distribution of positions and momentum. By Louiville Theorem, it is easy to show that this distribution is preserved. What we are doing in Molecular Dynamics is assuming we can interchange the average over initial condition with the average over time. In an MD simulation, tMDsteps cannot go over infinite time, but hopefully an average of long finite tMDsteps is satisfactory. Thus, <A>time = (1/MDsteps) S MDsteps A(t)

Gibbs clearly recognized the relation to entropy to probability and observed the most probable situation (equilibrium) corresponds to maximum entropy subject to given constraints.
 
 

The Ergodic Hypothesis

Is <A>time=<A>ens really true, which is what Boltzman wanted to prove?

It is true if <A>= < <A>ens >time = < <A>time >ens = <A>time. Equality one is true if ensemble is stationary. For equality two, it is assumed that interchanging averages should not matter. The third equality is only true if system is ERGODIC.

ERGODIC: [adjective] from Greek, erg + hodos (energy path), leading to the German construction "ergodenhypothese" (hypothesis on the path of energy). The Ergodic Hypothesis of Boltzmann (also called the continuity of path by Maxwell) is simply that a phase point for any isolated system passes in succession through every point compatible with the energy of the system before finally returning to its original position in phase space. This journey takes a Poincare cycle.

Ergodicity of a system has been the fundamental assumption of classical statistical mechanics, and it is usually assumed in simulations as well. If the system has ergodic or chaotic behavior it will eventually sample all the phase space it can subject to the conserved numbers. There are a number of related concepts:

Actually physical systems and systems being simulated are often not ergodic.

Non-Ergodic Behavior

If the system is non-ergodic; it gets stuck or very slowly decays to equilibrium. This was discovered by Fermi, Pasta and Ulam (FPU) in 1954 on the Los Alamos MANIAC I in perhaps the most profound computer simulation discovery in the early years of computers. These notes are from G. Benettin in MD Simulations of Statistical Mechanical Systems. The FPU Hamiltonian is of N equally massive particles connected by anharmonic springs:

V(x) = k/2 x2 + z x3

For z = 0, one has decoupled harmonic oscillators with well-known normal modes. For non-zero z, FPU put all the energy into one normal mode and watched the energy spread into the other normal modes. Equipartition says that each mode should get equal energy (at least if you wait long enough). Instead they found:

Let us say here that the results of our computations were, from the beginning, surprising us. Instead of a continuous flow of energy from the first mode to the higher modes, all of the problems show an entirely different behavior. ... Instead of a gradual increase of all the higher modes, the energy is exchanged, essentially, among only a certain few. It is, therefore, very hard to observe the rate of "thermalization" or mixing in our problem, and this was the initial purpose of the calculation.
Collected papers of E. Fermi, Vol II, U. of Chicago Press, p 978, 1966.

For higher values of z, the system does approach equipartition after long enough. Thus, whether the system reaches equipartition depended upon its initial conditions. In many respects, this was a precursor to the "chaos" ideas of recent years.

In the intervening years it has been established that non-ergodic behavior is characteristic of most systems at low enough temperature. It is not a small system or one-dimensional effect, but a low temperature effect. For this reason it is not all that relevant to condensed matter physics since quantum mechanics takes over from classical mechanics at low temperatures. But is something one should be aware of since the temperatures are not all that low. For example, 64 argon atoms below 5K (a good harmonic solid) will never reach equilibrium but stay with whatever phonons they start with. Also celestial mechanics is happy with ordered dynamics. They provide explanations for planetary, ring systems and spiral galaxies.

There are at least 3 different concepts related to ergodicity that characterize a particular system and trajectory:

On the other hand, in statistical mechanics we expect our system to converge to equilibrium. Whether it does or not cannot usually be proven mathematically but must be determined "experimentally". In general we don't know if its ergodic or if it is stuck for a long-time (on our scale). At low temperature very complicated things can happen. It is up to you to decide if it is in fact ergodic. Non-ergodic behavior is both good and bad. On the one hand we are never sure if we have reached true equilibrium (nature has much longer time scales). On the other hand simulation can be used to study metastable states that occur in nature such as the freezing of a super-cooled liquid or a glass. Another example where metastable states may be physically important is in the folding of a protein.

Contact with the outside world

Often it is good to introduce some contact with a thermal bath. (Langevin equation) Normal laboratory systems are in contact with the outside world. How else can we account for flux of particles, energy and momentum coming from the outside? The boundary conditions depend critically on physics. There is a whole continuum of algorithms that can all sample the same canonical distribution, distinguished from each other by how much randomness is allowed.

Once one adds any randomness, ergodicity and convergence to the canonical distribution usually follows. Whether any particular run (of finite length) has in fact converged remains an "experimental" question.

Statistical Errors.

Now I am going to review a basic idea that is central to simulations: how to estimate the errors of a calculation. Simulation without error bars are only suggestive. Suppose we are trying to estimate the mean value of some quantity, say A(t) where t refers to the simulation 'time.' 'A' is some property we measure such as the energy. We want to determine 'A' in thermal equilibrium. We denote the 'exact' value < A >. (What does exact mean? The integral over the exact distribution function.) The simulation is started and there is an initial transient as the system comes into equilibrium.

First let me define a simulation. A simulation has some "state" variables, which we denote by S. In classical mechanics these
are the positions and velocities of the particles. In an Ising model they are the spins of the particles. We start the simulation at
some initial state S0. We have some process which modifies the state to produce a new state so that we can write
Sn+1=T(Sn). We will call the iteration index "time". It is in quotes because it may not refer to real time but a fictitious time or
pseudo-time, sometimes called Monte Carlo time.

The iteration function T(S) can either be deterministic (like Newton's equations of motion called Molecular Dynamics) or
have a random element to it (called Monte Carlo). In the random case, we say that the new state is sampled from the
distribution T(S). What we discuss in this lecture and in much of the course, is the situation where the "dynamics" is ergodic,
which we define roughly to mean that after a certain time one loses memory of the initial state, S0, except possibly for certain
conserved quantities like energy, momentum etc. This implies there is a correlation or renewal time. For time differences
much greater than the correlation time, all properties of the system not explictly conserved are unpredictable as if they were
randomly sampled from some distribution.  Ergodicity is often easy to prove for the random transition but usually difficult for
the deterministic simulation. We will discuss ergodicity further in the next lecture.

Assuming the system is ergodic one can discuss the state of the system as a probability distribution: An(S). (it is the
distribution of outcomes that you get if you take a distribution of initial states.) At large time this will approach a unique
distribution, the equilibrium state A*(S). In classical statistical mechanics this is the Boltzmann distribution.

The main goal of most simulations is the calculation of a set of properties in equilibrium. The most common example is the
internal energy E = <e(S)> where the average means over F*(S). In a simulation we sample e(Sn) for n<T where T is the
total length of the run. The curve of e versus T we call the trace. Calculating an estimate of E is easy: just take an average
over the run. The only "trick" is to be sure to throw away the part of the trace that too much influenced by the initial
conditions. This is called the transient, equilibration portion or warm-up. (Question: if you have a big spike at the
beginning of your trace and you neglect to throw it out of the average, how long does it take before the influence
of the spike is less than the statistical error? That is, how does the estimated mean depend on the propertiess of
the warm up portion?)

The next order of business is to figure how accurate is the estimate of the exact value: namely the estimated error in the
estimated mean commonly called the error bar. Simulation results without error bars are only suggestive. Without error bars
one has no idea of its significance.  All respectable papers in the literature should  contain estimates of any properties that are
important to the conclusion of the paper.  Many mistakes are
made in estimating errors. You should  understand both the equations and get an intuitive feel for how to estimate errors.
(“eye ball” method) Although we have prepared a code to automatically estimate errors, you should know the formulas and
what they mean. On the exam you will have to do it without DataSpork. Often one hears the complaint that one cannot
estimate errors because the quantity being measure is a very complicated function of the state. However, it is always possible
to get a rough idea of the error bar which is often all that is needed,  by simply rerunning the entire code a few times with
different initial conditions and looking at the spread of results. This is called the "eyeball" method. While there are many ways
for errors to be underestimated, the eyeball method will not seriously overestimate the errors.

The fundamental theorem on which error estimates is based is the central limit theorem due to Gauss. It says that the
average of any statistical processes will be "normally" or have a Gaussian distribution. Further the error bar will equal square
root of the  variance of the distribution divided by the number of uncorrelated steps. Later we will discuss in detail the
conditions under which this result holds. The correlation time of sequence is the number of steps it takes for a fluctuation to
disappear.

There is a terminology which we use to describe the process of estimating the <A> and estimating the error of our estimate.
You need to learn what all these terms mean so you can communicate with your fellow scientists about statistical
distributions. We have developed a JAVA Analysis Tool,  DataSpork, which does the computations for you discussed here.
In the first homework you have to learn how to use it and what the results mean.

The symbols are defined on the fomula page.

See also the detailed page pdf formulas.
 
 

Molecular Dynamics

By Molecular Dynamics is meant the evolution of a classical equation by Newton's equation of motion. See AT pgs 1-4 for a brief history of the development of MD. In this lecture we discuss how to numerically solve F=ma .While as in nature time advances continuously, in MD time is discrete. Normally there is a fixed increment of time is denoted h throughout this lecture.

MD is the solution of : md2R/dt2 = - F(R)

where F(R) = - Ñ V(R).

Potential Cutoff

Energy (E= T+V) conservation is very important. It is the basis for thermodynamics. For numerical method to exhibit energy conservation the potential energy must be differentiable. This is often a problem at the edge of the box or when the potential is "cutoff" a common beginner's mistake. The cutoff must be done continuously by a procedure such as

Vc (r) = V(r) - V(rc) where rc is the cutoff radius.

Please look at the code fragment to see how the simplest Lennard-Jones force calculation is programmed.
 

Integrators

A & T pgs. 71-84

Criteria for selecting an integrator:

Some additional questions: Characteristics of simulations which affect choice of estimator. The nearly universal choice for an integrator is the Verlet algorithm (reference Verlet .

Derivation of the Verlet algorithm.

Let us make a Taylor solution of trajectory about the current position:

r(t+h) = r(t) + v(t) h + 1/2 a(t) h2 + b(t) h3 + O(h4)
Substitute in for -t:
r(t-h) = r(t) - v(t) h + 1/2 a(t) h2 - b(t) h3 + O(h4)
Add the two expansions:
r(t+h) = 2 r(t) - r(t-h) + a(t) h2 + O(h4)
Velocities are eliminated. One can estimate them as:
v(t) = (r(t+h) - r(t-h))/(2h)  + O(h2)
Time reversal invariance and momentum conservation are built in. This implies that the energy has no drift. Probably the dynamics generated by the Verlet algorithm has a constant of motion which is nearly but not exactly equal to the total energy.

Velocity Verlet is algebraically equivalent but avoids taking differences between large numbers.

r(t+h) = r(t) + v(t) h + 1/2 a(t) h2
v(t+h) = v(t) + 1/2 (a(t) + a(t+h))h
Higher order algorithms are available (Gear etc.) These are useful only when high accuracy is needed and the potential and several derivatives are smooth.

The graph below from Berendsen and van Gunsteren (in MD simulation of Statistical-Mechanical Systems, 1986) shows a study of energy conservation versus time step for the Verlet algorithm and higher order Gear algorithms on a protein. If is seen that for large time steps the Verlet algorithm is considerably more stable. Higher order algorithms have only a the marginal increase in efficiency and actually get worse beyond 7th order.

The following quote is from their article:

How accurate a simulation has to be in order to provide reliable statistical results is still a matter of debate. The purpose is never to produce reliable trajectories. Whatever accuracy the forces and the algorithms have, significant deviations from the exact solution will inevitably occur. Also in the real physical world individual trajectories have no meaning: in a quantum mechanical sense they do not exist and even classically they become unpredictable in the long run due to the nonisolated character of any real system. So what counts are statistical averages. It seems that very little systematic evaluation of algorithms has been done with this in mind. We have the impression that a noise as high as 10% of the kinetic energy fluctuation is still acceptable, although the accuracy of fluctuations may not be sufficient to obtain thermodynamic date from them. With such a level of inaccuracy the Verlet of leap frog algorithm is always to be preferred.
David Ceperley, University of Illinois May  2001