Jump to content

Rep:Mod:sm17122

From ChemWiki

Simulation of a Simple Liquid

Numerical Intergration

TASK: Open the file HO.xls. In it, the velocity-Verlet algorithm is used to model the behaviour of a classical harmonic oscillator. Complete the three columns "ANALYTICAL", "ERROR", and "ENERGY": "ANALYTICAL" should contain the value of the classical solution for the position at time t, "ERROR" should contain the absolute difference between "ANALYTICAL" and the velocity-Verlet solution (i.e. ERROR should always be positive -- make sure you leave the half step rows blank!), and "ENERGY" should contain the total energy of the oscillator for the velocity-Verlet solution. Remember that the position of a classical harmonic oscillator is given by x(t)=Acos(ωt+ϕ) (the values of A, ω, and ϕ are worked out for you in the sheet).

The graphs below show the results of each column, Analytical, Error and Energy versus time.


TASK: For the default timestep value, 0.1, estimate the positions of the maxima in the ERROR column as a function of time. Make a plot showing these values as a function of time, and fit an appropriate function to the data.

The graph below shows the the maxima of the error versus time with the function written on the graph.


TASK: Experiment with different values of the timestep. What sort of a timestep do you need to use to ensure that the total energy does not change by more than 1% over the course of your "simulation"? Why do you think it is important to monitor the total energy of a physical system when modelling its behaviour numerically?

After experimenting with different timesteps it was found that a timestep of 0.0968 gave a maximum error of 0.005 which is 1% of the total energy 0.5. Therefore, any timestep under this value will give an error of less than 1%. The Error vs Time is shown below:

It is important to monitor the total energy of a system as we expect energy to be conserved. If this is not the case and energy is increasing or decreasing it can be a sign that our system is not stable and has not reached equilibrium. Fluctuation around an average energy is to be expected as the particles move and interact but overall it should remain constant.

Atomic Forces

The quantum physics needed to work out the forces acting upon a set of atoms can't be solved easily so approximations are made. From classical physics the force acting on an object is given as:

Fi=dU(rN)dri

rN stands for the position vectors of every atom in system. The force that a single atom feels is determined by the position of every other atom. Finding a function U that includes all the key physics of the interatomic interactions in the system for simple liquids can be achieved using the Lennard-Jones potential. U therefore can be written as:

U(rN)=iNijN{4ϵ(σ12rij12σ6rij6)}

'TASK: For a single Lennard-Jones interaction, ϕ(r)=4ϵ(σ12r12σ6r6), find the separation, r0, at which the potential energy is zero. What is the force at this separation? Find the equilibrium separation, req, and work out the well depth (ϕ(req)). Evaluate the integrals 2σϕ(r)dr, 2.5σϕ(r)dr, and 3σϕ(r)dr when σ=ϵ=1.0.

a) When potential energy is zero:

0=4ϵ(σ12r12σ6r6)

0=σ12r12σ6r6

σ12σ6=r12r6

σ6=r6

σ=r

The force at this separation can then be worked out using the above differential:

Fi=4ϵ(12σ12r0136σ6r07)

Substituting σ for r gives us:

Fi=4ϵ(12σ+6σ)

Fi=24ϵσ


b) The equilibrium separation is the minimum of the curve. We can take the first derivative of our equation and equal the force to zero, the value of r is therefore the equilibrium separation.

0=4ϵ(12σ12r0136σ6r07)

2σ6=r6

21/6σ=r

c) Substituting the equilibrium value of r into the Lennard-Jones formula gives us the well depth:

ϕ=4ϵ(σ12(21/6σ)12σ6(21/6σ)6)

This gives:

ϕ=ϵ

Below the integrals in the task are evaluated with σ=ϵ=1.0

2σϕ(r)dr=0.025

2.5σϕ(r)dr=8.17x103

3σϕ(r)dr=3.29x103

Periodicity Boundary Conditions

TASK:Estimate the number of water molecules in 1ml of water under standard conditions. Estimate the volume of 10000 water molecules under standard conditions.

a) First we must work out the number of moles of water in 1ml. Water has a molecular mass of 18g/mol. As 1ml of water weighs one gram, if we divide 1 by 18 we get the number of moles which equals 0.056. Multiplying this by Avogadro's number gives the number of water molecules:

0.056 x 6.022×1023 = 3.35x1022 molecules.

b) As 1ml of water equals 1g, if we work out the weight of 10000 water molecules we get the volume. The number of moles in 10000 molecules equals:

10000/6.022×1023 = 1.66x10-20moles

Multiplying this by the molecular mass of water equals:

1.66x10-20 x 18g/mol = 2.99x10-19g

The volume of water therefore equals 1.66x10-20cm3

TASK: Consider an atom at position \left(0.5, 0.5, 0.5\right) in a cubic simulation box which runs from \left(0, 0, 0\right) to \left(1, 1, 1\right). In a single timestep, it moves along the vector \left(0.7, 0.6, 0.2\right). At what point does it end up, after the periodic boundary conditions have been applied?

As the box runs from (0, 0, 0) to (1, 1, 1) when the atom is moved along each coordinate it stays in the same box. For example, moving 0.7 along the x axis from 0.5 would give us 1.2, but as this is not allowed in the confines of the box the resulting x value is 0.2. Therefore for all axis, the resulting point is (0.2, 0.1, 0.7).

Reduced Units

TASK:The Lennard-Jones parameters for argon are σ=0.34nm,ϵ=120/kBK. If the LJ cutoff is 3.2σ, what is it in real units? What is the well depth in kJmol1? What is the reduced temperature T*=1.5 in real units?

a) Multiplying the sigma value for argon and the LJ cut-off gives the real units of:

3.2 x 0.34nm = 1.088nm

b) We know from previous tasks that ϕ=ϵ. Therefore the well depth is -120/kBK. To convert this to kJ mol-1 we must multiply by kB and NA and then divide by 1000 to give the correct units:

-120 x kB x NA/1000 = -0.10 Kj mol-1

c) The reduced temperature can be written as:

T*=Tkb/ϵ

Therefore multiplying T* by epsilon gives us the temperature:

1.5 x 120 = 180K

Equilibration

Creating the simulation box

TASK:Why do you think giving atoms random starting coordinates causes problems in simulations? Hint: what happens if two atoms happen to be generated close together?

If two atoms are generated close together their potentials can overlap leading to a high energy state not found a real liquid and ultimately repulsion. It is therefore better to place the atoms in a cubic lattice and allow them to reach equilibrium so they arrange themselves into more realistic configurations.

TASK: Satisfy yourself that this lattice spacing corresponds to a number density of lattice points of 0.8. Consider instead a face-centred cubic lattice with a lattice point number density of 1.2. What is the side length of the cubic unit cell?

The input file has the line:

'lattice sc 0.8'

This defines the lattice to be a cubic lattice with a number density of 0.8. The lattice spacing is also defined, with one line of our log output file reading:

 'Lattice Spacing in x,y,x = 1.07722 1.07722 1.07722'

We can confirm that this separation does indeed correspond to a number density of 0.8. The side lengths of the unit cell would be equal to 1.07722. The volume of a cubic cell is A³ therefore the volume of this cell would equal 1.07722³ which equals 1.25. There is only one atom in a cubic lattice unit cell so as:

Number density = Number of atoms/Volume

If we divide 1 by 1.25 we then get the density of 0.8.

A face centered cubic unit cell has 4 atoms in each unit: each of the 8 corners gives 0.25 and each of the 4 centered atoms give 0.5 to the cell. (8 x 0.25)+(4 x 0.5) = 4. Using the above equation, dividing the number of atoms by the number density of 1.2 gives the volume of 3.33. Taking the cube root of this value will give us the cell length: 3.33⅓ = 1.49.

TASK: Consider again the face-centered cubic lattice from the previous task. How many atoms would be created by the create_atoms command if you had defined that lattice instead?

In our input file there is the command:

region box block 0 10 0 10 0 10
create_box 1 box

Our log file has the corresponding line:

Created orthogonal box = (0 0 0) to (10.7722 10.7722 10.7722)

This command gives us a box of 10x10x10 unit cells, and as each cell contains one atom, 1000 atoms. If we were to instead use a face-centered cubic lattice as mentioned before, our 10x10x10 lattice would contain 4000 atoms.

Setting the properties of the atoms

TASK: Using the LAMMPS manual, find the purpose of the following commands in the input script:

mass 1 1.0
pair_style lj/cut 3.0
pair_coeff * * 1.0 1.0

a) mass I value is the generic format for the script above, setting the mass for all atoms. I can be a numeric value or a 'wild-card asterisk' such as 'n' or '*' can be used to set the mass for multiple atom types. The value is a the mass of the atom.

b) pair_style style args is the generic format of this script. This denotes the interaction between a pair of atoms. Here, lj/cut 3.0 refers to a Lennard Jones interactions between the two atoms with a cut off of 3.0 distance units.

c) pair_coeff I J args is the generic format of this script with I and J being atom types and args being the force field coefficients of I and J. Above the '* *' is used to set the coefficients for all I,J pairs, and the '1.0 1.0' setting them both to 1.0.

TASK: Given that we are specifying xi(0) and vi(0), which integration algorithm are we going to use?

We will use the Velocity Verlet Algorithm as this includes both the position x(0) and the velocity v(0) while the Verlet algorithm only specifies the position x(0).

Running the Simulation

TASK: Look at the lines below.

### SPECIFY TIMESTEP ###
variable timestep equal 0.001
variable n_steps equal floor(100/${timestep})
variable n_steps equal floor(100/0.001)
timestep ${timestep}
timestep 0.001

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

The second line (starting "variable timestep...") tells LAMMPS that if it encounters the text ${timestep} on a subsequent line, it should replace it by the value given. In this case, the value ${timestep} is always replaced by 0.001. In light of this, what do you think the purpose of these lines is? Why not just write:

timestep 0.001
run 100000

The timestep is repeated many times throughout the script when referenced to other commands. This value needs to be kept constant throughout therefore writing out the full definition of the timestep ensures this so that there is no need to keep defining it in further coding.

Checking equilibration

TASK: make plots of the energy, temperature, and pressure, against time for the 0.001 timestep experiment (attach a picture to your report). Does the simulation reach equilibrium? How long does this take? When you have done this, make a single plot which shows the energy versus time for all of the timesteps (again, attach a picture to your report). Choosing a timestep is a balancing act: the shorter the timestep, the more accurately the results of your simulation will reflect the physical reality; short timesteps, however, mean that the same number of simulation steps cover a shorter amount of actual time, and this is very unhelpful if the process you want to study requires observation over a long time. Of the five timesteps that you used, which is the largest to give acceptable results? Which one of the five is a particularly bad choice? Why?

Below are the plots of energy, temperature and pressure against time for the 0.001 timestep experiment.

We can see that the system does reach equilibrium, and by zooming in on the first graph we can estimate this time to be around 0.4 seconds.

The graph below shows the Time vs Energy plots for the timesteps 0.001, 0.0025, 0.0075, 0.01 and 0.015.

The timesteps in the range of 0.001-0.01 all reach equilibrium and show similar results with and energy ranges less than 0.05 units apart. The simulation of the 0.015 timestep does not reach equilibrium and instead becomes unstable and increases rapidly. This makes it an unsuitable choice for a simulation.

Simulations Under Specific Conditions

Temperature and Pressure Control

TASK: Choose 5 temperatures (above the critical temperature T*=1.5), and two pressures (you can get a good idea of what a reasonable pressure is in Lennard-Jones units by looking at the average pressure of your simulations from the last section). This gives ten phase points — five temperatures at each pressure. Create 10 copies of npt.in, and modify each to run a simulation at one of your chosen (p,T) points. You should be able to use the results of the previous section to choose a timestep. Submit these ten jobs to the HPC portal. While you wait for them to finish, you should read the next section.


For these ten simulations I have chosen the timestep of 0.0025 after looking at the results of the previous section. The temperatures; 1.6, 1.8, 2.0, 2.2 and 2.4 were chosen with the pressures of 2.5 and 2.8 after looking at the pressures of the output files from previous simulations.

Thermostats and Barostats

TASK: We need to choose γ so that the temperature is correct T=𝔗 if we multiply every velocity γ. We can write two equations:

12imivi2=32NkBT

12imi(γvi)2=32NkB𝔗

Solve these to determine γ.

To determine γ we can divide equation 2 by equation one resulting in:

γ2=T/𝔗

Taking the square root therefore gives us:

γ=(T/𝔗)½

Examining the Input Script

TASK: Use the manual page to find out the importance of the three numbers 100 1000 100000. How often will values of the temperature, etc., be sampled for the average? How many measurements contribute to the average? Looking to the following line, how much time will you simulate?

a) 100 refers to Nevery: a command that uses input values every specified timesteps, in this instance 100. 1000 refers to Nrepeat: the number of times to use the input values for calculating averages. 100000 refers to Nfreq: this command calculates averages every 100000 timesteps in this script.

b) The temperature will therefore be sampled every 100 timesteps for the average.

c) 1000 measurements will therefore be used for the average.

d) As the run lasts 100000 timesteps and one average is calculated every 100000 timesteps, only one average will be calculated. As the timestep chosen was 0.0025, the amount of time simulated will be 0.0025 x 100000 = 250 seconds.

Plotting the Equations of State

TASK: When your simulations have finished, download the log files as before. At the end of the log file, LAMMPS will output the values and errors for the pressure, temperature, and density (NV). Use software of your choice to plot the density as a function of temperature for both of the pressures that you simulated. Your graph(s) should include error bars in both the x and y directions. You should also include a line corresponding to the density predicted by the ideal gas law at that pressure. Is your simulated density lower or higher? Justify this. Does the discrepancy increase or decrease with pressure?

a)Below shows the graphs for T vs N/V at pressures of 2.5 and 2.8.

The table below shows the error for each graph in the experimental values:

Temperature 1.6 1.8 2.0 2.2 2.4
T Error at P = 2.5 0.0226 0.0247 0.0279 0.0305 0.0338
N/V Error at P= 2.5 0.0041 0.0041 0.0041 0.0045 0.0041
T Error at P = 2.8 0.0229 0.0253 0.0291 0.0314 0.0330
N/V Error at P = 2.8 0.0040 0.0041 0.0041 0.0041 0.0050

b) The Experimental values are all lower than the values calculated by the ideal gas law (N/V = P/T). This is because the ideal gas law does not take into account interactions between atoms and once this is factored in the number density decreases as repulsive interactions mean atoms are less likely to be found close together.

c)The discrepancies decrease with pressure as at higher pressures the atoms are forced closer together therefore behaving more like an ideal gas.

Calculating Heat Capacities using Statistical Physics

TASK: As in the last section, you need to run simulations at ten phase points. In this section, we will be in density-temperature (ρ*,T*) phase space, rather than pressure-temperature phase space. The two densities required at 0.2 and 0.8, and the temperature range is 2.0,2.2,2.4,2.6,2.8. Plot CV/V as a function of temperature, where V is the volume of the simulation cell, for both of your densities (on the same graph). Is the trend the one you would expect? Attach an example of one of your input scripts to your report.

An example script for the density 0.8 at temperature 2.8 can be found here

The graph below shows the collated data from the ten inputs, 5 at the pressure 0.2 and 5 at 0.8:

We can see from the graph that the heat capacity is larger when the density is higher. This is to be expected; at a higher density there are more atoms per volume and as heat capacity is directly related to the number of molecules it will be higher.

Structural Properties and the Radial Distribution Function

TASK: perform simulations of the Lennard-Jones system in the three phases. When each is complete, download the trajectory and calculate g(r) and g(r)dr. Plot the RDFs for the three systems on the same axes, and attach a copy to your report. Discuss qualitatively the differences between the three RDFs, and what this tells you about the structure of the system in each phase. In the solid case, illustrate which lattice sites the first three peaks correspond to. What is the lattice spacing? What is the coordination number for each of the first three peaks?

a)The radial distribution functions for a solid, gas and liquid were collated below. The solid had a fcc lattice with a density of 1.2 and a temperature of 1.0. The gas had a density of 0.2 and a temperature of 2.5, and the liquid had a density of 0.2 and a temperature of 1.0.

b)From the graphs we can see that they all have a neighbour close to them initially. For the gas function, this then tails off with no further peaks. We can infer that there is one initial neighbour and then a long time before another is found - correct with what we know about the disperse nature of gases. Looking at the liquid function, there is a second peak and almost a third. It has more closer neighbours than a gas but if we compare to the solids radial distribution function it is still only near a few molecules at a time. The solids function supports what we know about lattices with periodic peaks suggesting a highly structured system.

c) The picture below depicts which lattice sites the first three points correspond to.

d) We can work out the coordination number for each peak and the lattice spacing by investigating the first three minimum of the RDF for the solid. These integrals can be found by corresponding the the reduced unit at the minimum and using the graph below to find the integration of the area below.

The first three minimum correspond to distances of 1.275, 1.675 and 1.975. When extrapolated from the graph above this gives 12.01, 17.97 and 42.26. By subtracting the previous integrals from these values (ie subtract 12.01 from 17.97) we get the rounded coordination numbers of 12, 6 and 24. We know that the second peak must correspond to the atom in the corner of the cube, as it is the closest to our initial atom. The distance of this atom is therefore the length of the cube, and so the lattice spacing is 1.675.

Dynamical Properties and the Diffusion Coefficient

Mean Squared Displacement

TASK: make a plot for each of your simulations (solid, liquid, and gas), showing the mean squared displacement (the "total" MSD) as a function of timestep. Are these as you would expect? Estimate D in each case. Be careful with the units! Repeat this procedure for the MSD data that you were given from the one million atom simulations.

a) Below are the graphs for the Mean Squares Distribution for solid liquid and gas:

b) In the solid lattice movement is restricted as each atom is tightly packed together. This is then shown as a very small diffusion coefficient and agrees with theory. Atoms in a liquid have more freedom to move but the interactions between atoms mean that they never completely separate. This is reflected in the diffusion coefficient being much larger than in the solid. In a gas complete separation is found as gas atoms can freely move far apart from each other. We can see the effect of this with the largest diffusion coefficient out of the three.

c) D can be estimated by the gradient of each graph once it has reached equilibrium. Using the equation below we can divide the slope by six:

D=16r2(t)t

This table shows the gradient and final D value for each graph.

State Gradient D
Solid 1.05x10-8 1.31x10-9
Liquid 9.41x10-3 1.57x10-3
Gas 2.40x10-2 4.01x10-3

d)The MSD graphs for the one million atom simulations are shown below:

State Gradient D
Solid 1.08x10-7 1.81x10-8
Liquid 1.06x10-3 1.78x10-4
Gas 3.65x10-2 6.09x10-3

Overall the graphs show similar trends, with the million atom graphs showing smoother lines, as to be expected with more data and averages available. Comparing both sets of data we see that the liquid diffusion constant gets smaller with more atoms in the simulation while both the gas and solid diffusion constants get larger with more atoms in the simulation.

Velocity Autocorrelation Function

Part 1

TASK: In the theoretical section at the beginning, the equation for the evolution of the position of a 1D harmonic oscillator as a function of time was given. Using this, evaluate the normalised velocity autocorrelation function for a 1D harmonic oscillator (it is analytic!):

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

Be sure to show your working in your writeup. On the same graph, with x range 0 to 500, plot C(τ) with ω=1/2π and the VACFs from your liquid and solid simulations. What do the minima in the VACFs for the liquid and solid system represent? Discuss the origin of the differences between the liquid and solid VACFs. The harmonic oscillator VACF is very different to the Lennard Jones solid and liquid. Why is this? Attach a copy of your plot to your writeup.


a) From our previous task we know that x(t)=Acos(ωt+ϕ) and that the velocity of this harmonic oscillator is = v = dx/dt. If we differentiate the equation above we get:

v(t) = -Aωsin(ωt + φ)

Therefore:

v(t + г) = -Aωsin(ω(t + г) + phi)

We can combine these equations with the original integral to give:

This can be rearranged to give:

Knowing that sin(a+b)= sin(a)cos(b)+ cos(a)sin(b):

This can be rearranged to:

This can be simplified into two fractions:

The first fraction cancels to cos(ωt). The second fraction cannot be cancelled. If we inspect the numerator we see the function is odd, when integrated will give an answer of zero. It does not matter the value of the denominator as we know we can't have infinity as an answer (i.e 0/x) so we can cancel out the whole second fraction to give:

C(г) = cos(ωt)

b) Using the above formula with ω =½π, the simple harmonic oscillator was plotted onto the graph below with the VACFs of the solid and liquid.

Both plots show some negative minimas as they oscillate around zero. These minimas correspond to negative correlation to the initial velocity due to collisions which produce backward scatters of particles with deflections of nearly 180°. The harmonic oscillator ignores interactions with other particles and so remains periodic and constant throughout. This is not the same for the liquid and solid plot which change throughout. At first they both show a sharp drop as particle interactions and collisions change the velocity. The solid plot has a slower drop, this is understandable as a solid has few collisions with other atoms than a liquid which has more freedom to move. The solid plot shows the lattice constraints as it resembles a damped version harmonic oscillator more closely than the liquid plot.

Part 2

TASK: Use the trapezium rule to approximate the integral under the velocity autocorrelation function for the solid, liquid, and gas, and use these values to estimate D in each case. You should make a plot of the running integral in each case. Are they as you expect? Repeat this procedure for the VACF data that you were given from the one million atom simulations. What do you think is the largest source of error in your estimates of D from the VACF?

Below show the VACF plots of the solid, liquid and gas data with their corresponding plots of the running integral calculated by the trapezium rule. For the solid data:

For the liquid data:

For the gas data:

The values for where the running integrals equilibrated were calculated and divided by three to give the diffusion coefficients. This gave values of -0.025, 256.634 and 635.819 for solid, liquid and gas respectively. This follows what we expect with the largest diffusion coefficient being for gas and then liquid with solid having the lowest with the most restrictions of movement.

This was repeated with the data for 1 million atoms. The graphs are shown below. For the solid data:

For the liquid data:

For the vapour data:

The values for the diffusion coefficient were calculated as before and found to be 0.006, 44.877 and 1563.701 for solid, liquid and vapour respectively. There is a large difference between results for calculating D with the MSD, with many orders of magnitude difference. The trapezium rule is only an estimation of area and so gives us many errors in results. This could also be explained by the length of time the VACF takes to reach zero which can lead to a large overestimation of the integral and therefore a larger diffusion coefficient. MSD only relies on the gradient of the graph which is irrelevant to time, making the VACF estimation much larger than the MSD.

Overall:

State D from MSD D from VACF
Solid 1.31x10-9 -0.025
Solid 1 million 1.81x10-8 0.006
Liquid 1.57x10-3 256.634
Liquid 1 million 1.78x10-4 44.877
Gas 4.01x10-3 635.819
Gas 1 million 6.09x10-3 1563.701