Jump to content

Rep:Mod:P0TAT0

From ChemWiki

Molecular Dynamics Simulations of Simple Liquids

Ab9314 (talk) 11:11, 24 March 2017 (UTC)

Introduction

Molecular dynamics (MD) is a method to simulate the motion of many particles by numerically integrating Newton's Laws of Motion over time. The simulation can be conducted in an ensemble, e.g. NVT or NVE, by setting limits on temperatures and pressures (thermostatting and barostatting respectively).[1] MD can be used to simulate the behaviour of protein folding, lipid bilayers, and other biological systems, thereby making this a very practical and convenient way to experiment with complex systems.[2] The potential between particles were calculated using pairwise-additive 12-6 Lennard-Jones potentials. All simulations were performed on the HPC system using the LAMMPS software package.

Velocity Verlet Algorithm

To begin the simulation, a lattice of atoms can be initiated with atoms a user-defined length apart (inputted in reduced units). All particles were given an initial velocity (according to Maxwell-Boltzmann distribution). Integrating each particle's velocity over time iteratively gave the new positions of the atoms in the system. This was done using the velocity-Verlet algorithm.

At first, the timestep of the simulation was varied to observe the errors in the positions with passing time when using the velocity-Verlet algorithm. This was done by calculating the exact position of a simple harmonic oscillator, and comparing against the position given by the velocity-Verlet calculation.

For a simple harmonic oscillator, x(t)=Acos(ωt+ϕ). Using an Excel spreadsheet, the error in the Velocity-Verlet algorithm was calculated. In this case, A=ω=1 and ϕ=0. The error is plotted in Figure 1, and the maxima in the error is plotted against time in Figure 2.

By changing the timestep in the spreadsheet, it was found that the error in x(t) as calculated by the velocity-Verlet algorithm is less than 1% over the course of the simulation when the timestep is less than 0.025.

The total energy of the system should be monitored to make sure that the energy is conserved in the system, and to check if the system is in thermal equilibrium. If the total energy is not stable, then the thermodynamic values derived from the system will not be equilibrium values, and cannot be compared to other MD systems.

Atomic Forces

In order to make the calculations easier, the LJ-potentials were given a 'cut-off' distance - any atoms separated by a distance larger than this truncation distance will not be included in the LJ force calculations.[3]

When σ=ϵ=1.0:

ϕ(r)=4(1r121r6)

ϕ(r)dr=4(112r11+16r5)+c=23r513r11+c

Thus, when limits are introduced:

2σϕ(r)dr=2.07102

2.5σϕ(r)dr=6.81103

3σϕ(r)dr=2.74103

From the above calculations, the force of attraction reduces very quickly when the distance from the Lennard-Jones centre is greater than 2σ. Hence, truncation at such a distance will introduce only a very small error in the system.

Periodic Boundary Conditions

As it is very heavy computationally to simulate even millimole amounts in LAMMPS, Periodic Boundary Conditions (PBCs) are used to cut down the calculation times.[3] The reason for this difficulty can be seen by considering the number of particles in a small volume of water.

For example, 1 mL of water contains: 1186.0221023=3.3461022 molecules.

In most cases, the number of particles used will be between 103 and 104.

104 water molecules take up a volume of: 1046.022102318=2.991019mL

PBCs allow for the relatively small number of particles in our simulation to act as though it's part of a bulk solution. To this end, the particles are simulated such that when moves off one edge of the box, it reappears on the opposite face with the same velocity. Hence, the number of particles in the box, N, is always conserved.

For example, consider an atom at (0.5,0.5,0.5) in a cubic box with vertices at (0,0,0) and (1,1,1). If this atom moves by vector (0.7,0.6,0.2) in a single timestep, then the final position of the particle will be: (0.2,0.1,0.7).

Reduced Units

Reduced units are used to make the numbers more manageable.

For Argon, σ=0.34nm. Given that the LJ-cutoff in reduced units is at r*=3.2, the cutoff in nanometers is: r=r*σ=3.20.34=1.088nm.

Given ϵkB=120,

well depth, ϵ=120kB=1.661021J=1.661021NA1000kJmol1=9.98101kJmol1.

Therefore, when T*=1.5, and given ϵkB=120,

T=ϵkBT*=1201.5=180K.

Equilibriation

The Simulation Box

The particles for the simulation were initiated in a simple cubic lattice structure. A random set of coordinates were not used. This was to avoid two atoms being generated too close together - this would lead to a very large potential, and cause the pair to split violently apart. This simulation would be unlikely to be a good representation of a real life scenario of a crystal melting.

In this simulation, a lattice density of 0.8 was used (0.8 lattice points per unit volume). If a face-centred cubic (fcc) lattice had been used instead, with a lattice density of 1.2, then the side length of the cubic unit cell, a, can be found thus:

ρ=NV

1.2=41000(10a)3

a=40001.2310=1.49380

Properties of atoms

The reaction conditions such as the lattice density are passed into LAMMPS using text commands in the input file. Part of the commands are shown below:

mass 1 1.0 

mass defines the property of the atom that is being defined. 1 indicates the type of particle being defined; all particles in LAMMPS are given a type, in form of an integer number. For example, if considering a mixture with 2 types of atoms, then the particles in LAMMPS would be differentiated by having type 1 and type 2 particles, and so on.

1.0 indicates the mass of the particle in g mol-1.


pair_style lj/cut 3.0

This line defines the potential between two interacting particles. Once again, the pair_style keyword indicates the property being defined. lj/cut defines the potential as a truncated Lennard-Jones potential, while the 3.0 defines the potential to be truncated at 3.0σ. Overall, the potential is being defined as:

ϕ(r)=4ϵ[(σr)12(σr)6]r<rc


pair_coeff * * 1.0 1.0

This line is defining the force that each particle exerts on all other particles is the same as that defined by the negative of the derivative of the Lennard-Jones potential.

The generated particles are then given initial coordinates, and their initial velocities. As xi(0) and vi(0) are both specified, the velocity-Verlet integration is used for the simulations.

Running the Simulation

The final lines of the input file are as follows:

variable timestep equal 0.001

variable n_steps equal floor(100/${timestep})

### RUN SIMULATION ###
run ${n_steps}

variable timestep equal 0.001 creates a variable so that any subsequent occurence of the string ${timestep} is replaced by 0.001. The number of steps the simulation is run for is also determined by the value of the timestep. By assigning a variable name to the timestep, editing the timestep value will automatically adjust the number of steps, avoiding tedious editing of the value in two different places each time the timestep is changed.

Checking Equilibriation

Several different simulations were run using different timesteps, and the total energy of the system was monitored at each step. Figure 3 shows the results of the simulations.

Energy vs. Time
Figure 3: Energy vs. Time for differing timesteps

All systems reach equilibrium, except for the system where the timestep is 0.015. The equilibrium was reached by around time0.6 - in quite a short amount of time.

Of the five timesteps used, the largest acceptable timestep is 0.01. A particularly bad choice would be a timestep of 0.015. This is because the total energy of the system seems to be increasing indefinitely with increasing time with large fluctuations. This is a poor representation of a real system, hence this simulation timestep length is too long for this system.

NPT Simulation

This section looks at running simulation under specific conditions, using an NPT ensemble. This is done using barostats and thermostats.

Temperature and Pressure Control

Temperature, T, fluctuates in the simulation, and the target temperature is 𝔗. As temperature is related to the total kinetic energy of particles within the system, the temperature is kept roughly constant by multiplying the velocities of the particles by a factor γ. Hence, these two equations can be surmised from the above, from which an expression of γ is derived:

12imivi2=32NkBT

12imi(γvi)2=32NkB𝔗12γ2imivi2=32NkB𝔗

12γ232NkBT=32NkB𝔗

γ=2𝔗T

The Input Script

The thermodynamic property values of the system were periodically computed and saved to file using the following command in the input script:

fix aves all ave/time 100 1000 100000 v_dens v_temp v_press v_dens2 v_temp2 v_press2

These values are time-averaged in a specific way. The arguments 100 1000 100000 instruct LAMMPS to compute the properties every 100000 steps using preceding 1000 values in intervals of 100 values. For example, at the 200000th step, the properties are averaged using values at steps number 100100, 100200, 100300... 199000, 200000.

Plotting the Equations of State

Simulations of a crystal melting were run at two different pressures, P = 2.5 and P = 3.0, with 8 temperatures for each pressure. A graph of density against temperature was then plotted, along with the density predicted by the Ideal Gas Law with respect to temperature at these two pressures. The results are shown in Figure 4. It can be seen that in general, the MD simulation predicts a lower density than the ideal gas law. This is because the ideal gas law does not take the forces between particles into account. In the Lennard-Jones potential model, the repulsive forces are very strong (compared to the attractive forces). Hence, the MD simulations show the particles will prefer to be more spread out (i.e. less dense) so as to minimise the unfavourable repulsive forces. The discrepancy decreases with increasing temperature, because the particles in the MD systems will move further apart. This in turn decreases the magnitude of the forces between particles, bringing it closer to the ideal system of no forces between particles.


Density vs. Temperature
Figure 4: Density vs. Temperature for varying pressure as found by MD simulations, compared to results predicted by the Ideal Gas Law.

Heat Capacity Calculations using Statistical Physics

To investigate the effect of changing temperature on the heat capacity, a simulation was run in the NVT ensemble for two different densities (ρ=0.2 and ρ=0.8). The results of the simulations are summarised in Figure 5.


Heat Capacity per Unit Volume vs. Reduced Temperature
Figure 5: Heat Capacity per Unit Volume vs. Reduced Temperature for differing lattice densities.

The expected value for CVV in an ideal system is:

CVV=32N1V=32ρ

Hence, for an ideal gas, when ρ=0.3,CVV=0.1 and when ρ=0.8,CVV=1.2.

The value of CV found in the simulations are around 4 orders of magnitude smaller than what is predicted the ideal system, even at low densities (more ideal system). Also, the simulation shows variation of CV with increasing temperature (approximately CV1Tn,n<2).[4] The value of n is unknown, and must be found by fitting different curves to the data. We know that CVVar(E)T2 and that Var(E)Tm,m>0. Hence, we can estimate that n=2mn<2. This is in contrast to the ideal system, which predicts no variation of heat capacity with temperature.

However, qualitatively, the trends seen are reasonable. As the temperature is raised, the particles have more and more energy, yet the number of available degrees of freedom fall. As CV is a measure of how easily the system is excited to higher energy states - an already excited system requires even more energy to put the particles in a higher vibrational energy states. Increasing the number of particles, N, also leads to a larger number of degrees of freedom, leading to an increase in the heat capacity, CV. Consequently, increasing ρ=NV also leads to an increase in CVV. This trend is clearly seen in Figure 3.

Finally, the apparent reversal in trends from T*=2.3 to T*=2.4 is showing the change from a liquid to a gaseous phase.

The Input Script

One of the scripts used for running the NVT simulations is shown below:

### CREATING VARIABLE TO DEFINE LATTICE DENSITY
variable rho equal 0.8

### DEFINE SIMULATION BOX GEOMETRY ###
lattice sc ${rho}
region box block 0 15 0 15 0 15
create_box 1 box
create_atoms 1 box

### DEFINE PHYSICAL PROPERTIES OF ATOMS ###
mass 1 1.0
pair_style lj/cut/opt 3.0
pair_coeff 1 1 1.0 1.0
neighbor 2.0 bin

### SPECIFY THE REQUIRED THERMODYNAMIC STATE ###
variable T equal 2.2
variable timestep equal 0.0025

### ASSIGN ATOMIC VELOCITIES ###
velocity all create ${T} 12345 dist gaussian rot yes mom yes

### SPECIFY ENSEMBLE ###
timestep ${timestep}
fix nve all nve

### THERMODYNAMIC OUTPUT CONTROL ###
thermo_style custom time etotal temp press
thermo 10

### RECORD TRAJECTORY ###
dump traj all custom 1000 output-1 id x y z

### SPECIFY TIMESTEP ###

### RUN SIMULATION TO MELT CRYSTAL ###
run 10000
unfix nve
reset_timestep 0

### BRING SYSTEM TO REQUIRED STATE ###
variable tdamp equal ${timestep}*100
variable pdamp equal ${timestep}*1000
fix nvt all nvt temp ${T} ${T} ${tdamp}
run 10000
reset_timestep 0

### ENDING NVT ONCE SYSTEM IN REQUIRED STATE. NVE RESTATED.
unfix nvt
fix nve all nve

### MEASURE SYSTEM STATE ###
thermo_style custom step etotal temp press density
variable temp equal temp
variable temp2 equal temp*temp
variable eng equal etotal
variable eng2 equal etotal*etotal
fix aves all ave/time 100 1000 100000 v_temp v_temp2 v_eng v_eng2
run 100000

variable avetemp equal f_aves[2]
variable errtemp equal sqrt(f_aves[5]-f_aves[2]*f_aves[2])

### CALCULATION OF C_V
variable vareng equal (f_aves[8]-f_aves[7]*f_aves[7])
variable cv equal (3375*3375*${vareng})/(${avetemp}*${avetemp})

### PRINTING CALCULATED VALUES TO OUTPUT FILE
print "Averages"
print "--------"
print "Temperature: ${avetemp}"
print "Stderr: ${errtemp}"
print "Heat Capacity: ${cv}"

Structural Properties and the Radial Distribution Function

The Radial Distribution Function (RDF, or g(r)) can provide some insight into the structure of the particles in the simulation. The three phases, solid, liquid and gas, have distinctive RDF plots. These RDF plots can be compared directly to X-Ray diffraction plots produced experimentally, so that the identity of the systems can be verified by this property.[3] Figure 6 shows the RDF plots acquired by varying the density and temperature of the NVT simulation.

3 closest neighbours of any atom on an fcc lattice.
Figure 8: Three closest neighbours of each atom on an face-centred lattice shown by vectors 1, 2 and 3 in increasing order of magnitude.

As can be seen from Figure 6, from σ=0 to σ1 is where the repulsive forces between the adjacent atoms are too great to be overcome, and hence is empty space.

The RDF of solids have sharp peaks at well defined spacing. The atoms responsible for each of the first three main peaks are outlined in Table 1 using Figure 8 as a reference. The lattice parameter is the distance between two adjacent atoms on the fcc lattice along a straight edge (i.e. not diagonally adjacent). This appears to be approximately 1.775σ. The RDF decreases slowly as the radius increases.

By using the plot of g(r)dV against r (see Figure 7), the coordination number around a single reference atom as the distance, r, increases. The coordination numbers at symmetry related lattice vectors 1, 2 and 3 for this fcc lattice are tabulated in Table 1.

Table 1: Summary of data inferred from RDF data.
Vector Distance from central atom/σ Coordination Number
1 1.025 8
2 1.775 8
3 2.725 16

The liquid has a smooth RDF, with the peaks similar distances apart, but its decay is faster than that of the solid's. The progressively smaller peaks indicate the coordination shells around each atom.

Finally, the RDF of the gas phase tends to 1 very quickly, with no visible oscillations about g(r)=1. This indicates a uniform distribution of particles in the simulation box, as is expected of a gas in equilibrium.

Dynamical properties and the Diffusion Coefficient

Mean Square Displacement (MSD)

Figure 9: A particle moving from initial position r(0) at time 0 to another position r(t) at time t.

The motion of the particles in the molecular simulation were investigated by finding several properties of the systems.

The Mean Square Deviation (MSD) of the system is a measure of how freely the particles in the system can move to a new position (see Figure 9). The MSD is calculated thus:

MSD=[r(0)r(t)]2

Hence, as time progresses in a system with diffusion, the sum of MSD over all time intervals will be increasing. As t, the rate of increase of MSD is approximately constant. The diffusion coefficient, D, is defined as:

D=16r2(t)t

This equation is true as t; at small values of t, there are few or no collisions, and the increase in MSDt2. D can thus be estimated by fitting a straight line to the linear portion of a plot of MSD against time. Figures 10, 11, 12 and 13 show the calculation of the diffusion coefficient from the MSD plots. Table 2 records the values of D - a clear trend of increasing values of diffusion coefficients with decreasing density can be seen from the data. Atoms in gases can therefore diffuse 20 times as fast as atoms in solids.

Table 2: Diffusion coefficient data for solid, liquid and gaseous states.
State ρ* Diffusion Coefficients, D/σ2timestep1
Solid 1.3 2.74106
Liquid 0.8 3.47104
Gas 0.1 5.23103

The above simulations were performed with thousands of particles, and this can be considered as a relatively small amount - not even a fraction of a femtomole of atoms. To simulate a larger system, a set of simulations were run with 1 million atoms. The difference in the MSD plots (see Figures 14, 15, 16 and 17) is most marked in the solid state - whereas in the smaller system, there was a definite increase in MSD over time for all timesteps, the larger system oscillates slowly oscillates around MSD=0.0066. Physically, this observation shows that most of the particles in the solid are vibrating and colliding into each other very often. In the smaller system, the collisions are much less frequent, so that |r(0)r(t)| is larger for each atom. The diffusion coefficients of the million atoms in the three states are tabulated in Table 3.

Table 3: Diffusion coefficient data for 1 million atoms in solid, liquid and vapour states.
State Diffusion Coefficients, D/σ2timestep1
Solid 2.37108
Liquid 3.50104
Gas 1.25102

Velocity Autocorrelation Function

The diffusion coefficient, D, can also be estimated from the velocity autocorrelation function (VACF), C(τ), if C(τ)0 at large τ[3]:

C(τ)=v(t)v(t+τ)

D=130v(0)v(τ)dτ

Below, the normalised velocity autocorrelation function is evaluated for a 1D harmonic oscillator.

Given C(τ)=v(t)v(t+τ)dtv2(t)dt, and x(t)=Acos(ωt+ϕ)v(t)=Aωsin(ωt+ϕ):

C(τ)=Aωsin(ωt+ϕ)Aωsin[ω(t+τ)+ϕ)]dtA2ω2sin2(ωt+ϕ)dt

Simplifying,

C(τ)=sin(ωt+ϕ)sin[ω(t+τ)+ϕ)]dtsin2(ωt+ϕ)dt

Using the trigonometric identity sin(a+b)sin(a)cos(b)+sin(b)cos(a), the following can be surmised:

sin[ω(t+τ)+ϕ)]=sin(ωt+ωτ+ϕ)=sin(ωt+ϕ)cos(ωτ)+cos(ωt+ϕ)sin(ωτ)

Hence,

C(τ)=sin2(ωt+ϕ)cos(ωτ)+sin(ωt+ϕ)cos(ωt+ϕ)sin(ωτ)dtsin2(ωt+ϕ)dt

C(τ)=cos(ωτ)sin2(ωt+ϕ)+sin(ωτ)sin(ωt+ϕ)cos(ωt+ϕ)dtsin2(ωt+ϕ)dt

Rearranging sin2(x)1cos(2x)2,

C(τ)=cos(ωτ)+sin(ωτ)sin[2(ωt+ϕ)]dt21cos[2(ωt+ϕ)]2dt

Simplifying,

C(τ)=cos(ωτ)+sin(ωτ)sin[2(ωt+ϕ)]dt1cos[2(ωt+ϕ)]dt

C(τ)=cos(ωτ)+sin(ωτ)12ω[cos()cos()]1cos[2(ωt+ϕ)]dt

However, cos(a)=cos(a) as this is an even function.

Thus, cos()cos()=0:

C(τ)=cos(ωτ)

This result shows that for a simple harmonic oscillator, the VACF is a sinusoidal function that depends on the time passed, as well as the frequency of the oscillator.

The VACF of the solid and liquid states were calculated during the simulations. In addition, the analytical solution to the VACF of a particle doing simple harmonic motion with frequency, ω=12π was also calculated. These are all plotted in Figure 18.


From Figure 18, it can be observed that the VACF of the simple harmonic oscillator is sinusoidal, whereas the liquid and solid VACF are best described as damped sinusoidal. The solid's VACF tends to 0 faster that that of the liquid.

The global minima in the plots for the solid and liquid indicate when all the particles have had at least one collision. By this point, each of the atoms have a different velocity vector associated with it. Hence, the VACF rebounds towards 0. As the simple harmonic oscillator is a lone particle's motion, with no interactions with any other atoms, hence its VACF is very different to the Lennard-Jones solid and liquid. Its velocity vector also changes in a cyclic manner, and does not change from one oscillation to another. Hence, the amplitude of the VACF does not change as time increases.

In the solid, the particles are in close contact due to the high density - the atoms are arranged so that the repulsive forces are minimised, and the attractive forces maximised. This is the distance at which the LJ-potential is at a minimum. Here, the atoms are very stable, and are reluctant to leave the locations they are at.Their motion is therefore a vibration around their eqiulibrium positions, with a reversal of velocity at the end of each oscillation. This explains the oscillatory behaviour of the VACF. However, the damping is explained by perturbative forces acting on the atoms that disrupt the oscillations. Liquids are similar to solids - however, the density here is lower, and diffusion is faster. Here, the diffusive forces are the perturbative forces, and hence the VACF decays much more rapidly than the solid's VACF.

In contrast, the VACF from a system in the gaseous state (see Figure 19) decays much more slowly. The large separation distances between particles in the gaseous phase mean the forces are weaker. Hence, the inter=particle forces between them only affect their velocities very slowly, over a long time. For this reason, the VACF decays much more slowly than the liquid and the solid VACF.

The area under the VACF, and thus the diffusion coefficient, D, was estimated by using the trapezium rule, by using the following formula:

D=130v(0)v(τ)dτ

The cumulative integral is plotted in Figures 18 and 19. The gas has a very large D, compared to the liquid and the solid; the diffusion coefficient of the liquid is approximately 100 times as large as that of the solid. The trend of lower D with higher density is as found earlier in Tables 2 and 3.

Table 4: Diffusion coefficient data derived from MSD and VACD compared for solid, liquid and gaseous states.
State Diffusion Coefficients (MSD), D/σ2timestep1 Diffusion Coefficients (VACD), D/σ2timestep1
Solid 2.37108 0.0487
Liquid 3.50104 15.1
Gas 1.25102 544

A larger system with a million atoms was also simulated to simulate a system more akin to a real-life system. These plots (see Figures 22 and 23) are much smoother and give a more accurate value of the diffusion coefficient, D. The values of D acquired for the 1 million atom simulation from the VACD is compared to that of the values acquired from the MSD in Table 4. The table shows D values gotten from the VACD values are much higher than those derived from the MSD values. The largest source of errors of calculation of D from VACF is from the use of trapezium rule to approximate the area under the graph.

References

Template loop detected: Template:Reflist