Talk:Mod:ld2113
JC: General comments: This is an excellent report. You demonstrate a very good understanding of the tasks and the background material and give very clear, concise explanations, well done.
Third Year Liquid Simulation Experiment
Introduction to molecular dynamics simulation
Numerical integration
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 , "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 (the values of , , and are worked out for you in the sheet).
The position of the classical harmonic oscillator as a function of time was determined using with , , and
From figure 1 it can be seen that the results from the Velocity-Verlet algorithm (blue dots) agree very well with the classical solution for the position (red line).
The energy of the classical harmonic oscillator was determined using with , and as determined above.
For the energy as a function of position, the results from the simulation (figure 2) differ from what would be expected for an ideal harmonic oscillator. While in figure 2 the total energy is fluctuating between 0.5000 and 0.4988, it would be expected to be constant for an ideal classical harmonic oscillator (with different contributions of potential and kinetic energy at different positions). The amplitude of the sinusoidal fluctuation is however very small (0.2%) so that the the simulation can be considered to produce acceptable physical behavior.
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 error function was used to analyse the deviation of the results from the Velocity-Verlet algorithm from the classical solution. Despite no error can be seen upon visible inspection of figure 1, figure 3 shows that there is indeed a small variation between the two solution. The error is biggest for values of that give close to . Furthermore, the error at these points increases linearly with time . This cumulative increase in the error over time is due to the approximations used in the Velocity-Verlet algorithm, namely the Taylor expansion of the integral.
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?
It was found that the sinusoidal fluctuation of the energy increases with increasing timesteps while the absolute value of the energy decreases. While for a timestep of 0.1, the fluctuation is very small (figure 4), a timestep of 0.3 produces fluctuations larger than 1% (figure 6). A timestep of 0.2 was found to be the limiting value with fluctuations at 1% (figure 5). Consequently, a timestep below 0.2 has to be chosen ,in order to keep energy fluctuations in the simulations below 1%.
It is important to monitor the total energy of a physical system when modelling its behaviour numerically because only when the system obeys physical laws (energy conservation in this case) to a certain extent, the outputs of the simulation can be considered meaningful.
JC: Good, clear answers to the tasks.
Atomic forces
TASK: For a single Lennard-Jones interaction, , find the separation, , at which the potential energy is zero.
The potential energy is 0 at .
What is the force at this separation?
For a single particle with
:
At , the force is .
Find the equilibrium separation, , and work out the well depth ().
The system is at equilibrium when
:
The Equilibrium separation is therefore .
Using
:
The well depth at is .
Evaluate the integrals , , and when .
For
:
The solution for the three integrals are therefore:
TASK: Estimate the number of water molecules in 1ml of water under standard conditions. Estimate the volume of water molecules under standard conditions.
At standard conditions[1]: , furthermore using and .
There hence are approximately molecules in 1 ml water at standard conditions.
At standard conditions, 10,000 water molecules populate approximately or of space.
JC: All maths correct and very clearly laid out.
TASK: Consider an atom at position in a cubic simulation box which runs from to . In a single timestep, it moves along the vector . At what point does it end up, after the periodic boundary conditions have been applied?.
Without periodic boundary conditions, the atom would be outside the box after one timestep. Namely in position . With the applied periodic boundary conditions, the atom would be in position inside the box.
JC: Correct.
TASK: The Lennard-Jones parameters for argon are . If the LJ cutoff is , what is it in real units? What is the well depth in ? What is the reduced temperature in real units?
In real units, the LJ cutoff is , the well depth is and the Temperature is .
JC: Correct.
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?
Due to the high number of atoms "placed" in the box, there would be a high probability of certain atoms being placed significantly closer together than their equilibrium distance when assigning random starting coordinates to the atoms. In such an event, the atom pair interaction(Lennard-Jones potential) for that specific would be extremely high. Such high potentials would lead to a simulated system that is not a good representation of reality and hence giving inaccurate results when measuring the properties of the system.
JC: A system with very high repulsion forces between atoms will be unstable, which often causes the simulation to crash.
TASK: Satisfy yourself that this lattice spacing corresponds to a number density of lattice points of . 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 number density is defined as and the volume can be calculated from the lattice spacing : .
As it can be seen from figure 6, there is 1 lattice point per unit cell . |
TASK: Consider again the face-centred cubic lattice from the previous task. How many atoms would be created by the create_atoms command if you had defined that lattice instead?
region box block 0 10 0 10 0 10 create_box 1 box create_atoms 1 box
Given that there are 4 lattice points per unit cell in a fcc lattice, this command would have created atoms.
JC: Correct.
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
mass 1 1.0
sets the mass of all atoms of type '1' to 1.0.
pair_style lj/cut 3.0
defines the interaction between atom pairs in the simulation. In this case, a Lennard-Jones potential will be used , but only up to a cut off distance of 3.0 (red. units). As the Lennard-Jones potential decreases rapidly with increasing distance, this is a good approximation to make. Without defining a cutoff distance, an infinite number of atomic interactions would have to be computed, given the periodic boundary conditions we are using in this simulation.
pair_coeff * * 1.0 1.0
defines the pairwise force field coefficients for all atom types (*) in the simulation. In this case the coefficients are both 1.0.
TASK: Given that we are specifying and , which integration algorithm are we going to use?
We are using the Velocity-Verlet integration mechanism, as it requires the position and velocity at time 0 as a starting point (i.e. and ).
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
Defining a timestep and a n_steps variable and then linking the two as done above means that only the timestep will have to be changed when altering the conditions of the simulation. The number of steps will change accordingly so that total simulated time will always be constant. This ensures the production of comparable results when altering simulation conditions.
JC: Good explanation.
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?
From inspection of figures (8 - 10), it can be seen that equilibrium (i.e. relatively constant temperature, pressure and total energy) is reached. Figures 12 - 114 show that this occurs at approximately . The average total energy, temperature and pressure after reaching equilibrium is , and respectively.
As timestep=0.0025 gives roughly the same results for the total energy as timestep=0.001 and all larger timesteps produce substantial deviation from it, timestep=0.0025 can be considered the largest one to give acceptable results. Using timestep=0.0025 instead of timestep=0.001, longer time frames can be simulated without negatively affecting the results.
For timestep=0.0075 and timestep=0.01 it was found (figure 11) that the total energy of the system increases for larger timesteps but still reaches equilibrium (however, with larger fluctuations around the average value with increasing timestep). For timestep=0.015 however, equilibrium was not reached for as can be seen from the same figure. Timestep=0.015 therefore is a particularly bad choice, as the lack of equilibrium will avoid any meaningful results to be found from the simulation.
JC: Good choice of timestep and clear justification.
Running simulations under specific conditions
TASK: Choose 5 temperatures (above the critical temperature ), 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 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.
Based on the findings from the previous section, and and was used for these simulations. was chosen as .
Thermostats and Barostats
TASK: We need to choose so that the temperature is correct if we multiply every velocity . We can write two equations:
Solve these to determine .
Multiplying the velocity with ensures that the fluctuations of around the set value are compensated for at every timestep. To derive an expression for , the two equations above can be added together to give:
Moving the constant out of the summed term, allows to rearrange the equation to:
Using from above, we can now write:
The expression for is therefore .
JC: Good derivation.
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?
fix aves all ave/time 100 1000 100000 v_dens v_temp v_press v_dens2 v_temp2 v_press2 run 100000
The first number declares that every 100th timestep should be sampled to calculate the average. The second number declares that this should be carried out 1000 times, so that the average will cover 10,000 timesteps (the third number). For our simulation of 10,000 atoms, we will therefore be calculating 1 average value to which every 100th timestep contributes.
The following line states, that 100000 calculations should be run. With a timestep of 0.0025, this corresponds to a time of 250 reduced time units.
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 . 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?
From figure 16, it can be seen that he simulated density is lower than the density of an ideal gas at the given temperatures and pressures. This can be explained by comparing the approximations with regards to particle interaction (i.e. potential energy) made in the simulation and an ideal gas. With the absence of particle interaction as assumed in the ideal gas, particles can move very closely to each other without increasing potential energy. In the simulation however, the repulsive term of the Lennard-Jones potential causes an increased potential energy (i.e. unfavourable interaction) between particles that are very close together. It is therefore favourable for the particles in the simulation not to be closer to each other than a minimum distance. This Property causes the average density of the simulated system to be lower that in an ideal gas.
It can also be seen, that for higher pressures (as well as lower temperatures) the discrepancy in higher. This can be can be explained by the fact that at low pressures as well as at high temperatures, the systems behave similar to an ideal gas with little interaction between particles. For high pressures and low temperatures however, particles move slower, are closer together in space and therefore interact more. This makes the system increasingly different to the ideal gas with increasing pressure and decreasing temperature where no particle interaction (i.e. potential energy) is assumed.
JC: Well explained.
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 phase space, rather than pressure-temperature phase space. The two densities required at and , and the temperature range is . Plot as a function of temperature, where 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.
From figure 17 it can be seen that heat capacity per volume increases with density. As heat capacity is an extensive property, it is expected to increase with the number of atoms present. The heat capacity per volume is therefore expected to increase with the number of atoms per unit volume. As number density is defined as the number of atoms per unit volume, it is expected that the heat capacity per unit volume increases with density.
It can also be seen from the same figure that heat capacity per unit volume decreases with temperature. This observation is not very straight forward to explain and a thorough explanation would require a detailed inspection of the electronic structure of the material. Heat capacity is defined as the energy required per increase in unit temperature, i.e. the energy required to bring the system to a higher energy state. Based on the general assumption that energy levels are more closely spaced with increasing energy (i.e. increasing temperature) it only is a logical consequence that the heat capacity per unit volume decreases with increasing temperature.
JC: Good explanation of both trends. Further analysis without electronic structure calculations would be needed to give a more detailed explanation of the change in heat capacity with temperature for the classical Lennard Jones system that you are simulating here.
The following script was used for the simulation at phase point :
### DEFINE SIMULATION BOX GEOMETRY ### variable d equal 0.2 lattice sc ${d} 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.0 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 unfix nvt fix nve all nve ### MEASURE SYSTEM STATE ### thermo_style custom step etotal temp variable temp equal temp variable etotal equal etotal variable etotal2 equal etotal*etotal fix aves all ave/time 100 1000 100000 v_temp v_etotal v_etotal2 run 100000 variable avetemp equal f_aves[1] variable avetemp2 equal f_aves[1]*f_aves[1] variable aveetotal equal f_aves[2] variable aveetotal2 equal f_aves[3] variable ave2etotal equal f_aves[2]*f_aves[2] variable volume equal vol variable n equal atoms variable n2 equal atoms*atoms variable cv equal ((${n2}*(${aveetotal2}-${ave2etotal}))/(${avetemp2})) variable cvv equal (${cv}/${volume}) print "Averages" print "--------" print "Density: ${d}" print "AveTemperature: ${avetemp}" print "Volume: ${volume}" print "HeatCapacity: ${cv}" print "HeatCapacityPerVolume: ${cvv}"
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 and . 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?
Looking at a phase diagram for the Lennard-Jones system[2], the values were chosen as follows. Liquid: Solid: Vapour:
![]() |
Looking at figure 18, it can be seen that while all three phases have a very different RDFs,it is the same for all three of them up to ca. . As the RDF represents the atom density around any molecule in the system, the RDF being 0 up to that distance indicates that no neighbouring atoms can be found in that region around the atom. This can be explained by considering the Lennard-Jones potential which was used to simulate the interatomic interactions in this system: for small values of , the potential energy becomes vary hight, making a configuration with very energetically unfavourable.
The RDF of the gas shows a single broad peak at and then shows a smooth straight line. This behaviour of the curve is produced by the very low degree of order in a gas which averages the atomic density around an atom to a straight line.
The RDF of the liquid shows three broad peaks of decreasing intensity before becoming a straight line. This indicates an increased degree of order close to the atom in a liquid compared to gas. Due to the atoms still being able to move relatively freely in a liquid, no long-range order can be achieved so that the RDF averages out to a straight line for large values of .
For the solid, the RDF is showing sharp peaks over the whole analysed distance range this indicates a high degree of order (both short and long range) with atoms repeatedly being in the same locations in all direction from the inspected atom. In this system the atoms can be considered fixed in their position of the fcc lattice so that the peaks of the RDF can be assigned to specific coordination sites in the lattice. Figure 20 shows the lattice sites that the first three peaks correspond to. From this figure, it can be seen that the lattice spacing is approximately 1.475 reduced units.
From the integral of the radial distribution function (figure 19) as well as figure 20, the coordination number for the first three peaks can be determined as 12,6 and 24 respectively.
JC: Good understanding of the RDFs for the different phases. Can you show that the positions (r) of the first three peaks in the solid RDF corresponds to the distances to the first, second and third nearest neighbours in the fcc structure?/span>
Dynamical properties and the diffusion coefficient
TASK: In the D subfolder, there is a file liq.in that will run a simulation at specified density and temperature to calculate the mean squared displacement and velocity autocorrelation function of your system. Run one of these simulations for a vapour, liquid, and solid. You have also been given some simulated data from much larger systems (approximately one million atoms). You will need these files later.
Simulations in this Section
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 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.
The diffusion coefficient can be determined using . The gradient of the MSD can be found from the plots below. As the data in the plots is in timestep units, the gradient has to be multiplied by 0.002 to make sure the units match up.
![]() |
![]() |
For the gas phase (figure 21 and 22), linear behaviour is only observed after 2000 timesteps. Before that the behaviour resembles a quadratic function. This can be explained by the atoms not colliding regularly at the beginning of the simulation but rather moving through space freely (as they are too far apart). Their displacement therefore increases linearly with time and their mean squared displacement increases squared with time.
As we are only interested in the properties of the system once it has reached a stable state and atoms collide, the gradients for the gas were determined using only timestep values greater than 2000 (figure 23 and 26).
JC: Good reasoning, no need to show a linear fit to all the data in figure 21, this is slightly confusing.
From 2000 timestep onwards for the vapour and from 0 timestep onwards for the liquid, a linear relationship between the MSD and timestep is observed (see figure 23, 24, 26 and 27). This resembles the expected behaviour of the atoms moving and colliding randomly. This behaviour is known as brownian motion. It can also be seen from the same figures that the diffusion coefficients are much higher for the gas compared to the liquid, this agrees with the idea that atoms in the gas phase can move more freely than in atoms in the liquid phase.
The diffusion coefficients for the solid are the lowest of the three phases and does not increase linearly with timestep. It rather increases rapidly and then stays more or less constant for the duration of the simulation. This agrees with the notion that atoms in a solid cannot move freely once they have reached the position of lowest potential with regards to their neighbours.
The difference between the 8000 and the 1m atom simulations (and the respective diffusion coefficients) are generally very low. This suggests that the 8000 atom simulation resembles a real physical system reasonably well.
Velocity Autocorrelation Function
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!):
Be sure to show your working in your writeup.
Stating from the equation of the position of the harmonic oscillator:
We get the velocity by taking the derivative:
Substituting into original equation:
Using the trigonometric identity we can write:
The second term
is zero as we're integrating an antisymmetric function from
to
. Hence:
JC: Good, clear derivation.
On the same graph, with x range 0 to 500, plot with 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.
From the radial distribution function of the liquid and solid in the previous section, we can see how the surroundings of an atom is different for the two systems. While in the solid the atoms are in a fixed lattice around the inspected atom (short range and long range order), in the liquid only short range order is observed. The comparatively stronger minima in the solid therefore correspond to the large change in velocity upon collision with neighbouring atoms whereas the comparatively weak initial minimum in the liquid corresponds to collision only with the ordered atoms in close proximity of the inspected atom (cf. solvation shell).
For both the liquid and the solid the VACF goes to zero over time. This is because due to repeating collisions the velocity of the atoms becomes decorrelated over time. The model of an harmonic oscillator does not account for any collisions so that the velocity does not get decorrelated over time. It therefore makes sense that the VACF does not go to zero over time; it rather oscillates around 0. The VACF of the harmonic oscillator is zero at maximum and minimum atom distance as the velocity is constant at that point in time.
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 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?
The diffusion coefficients were determined from the running integrals of the VACF after converting the timestep into time* to ensure consistent units. The formula given was .
As expected, the diffusion coefficients found from integrating the VACF are smallest for the solid, and largest for the gas. The diffusion coefficients are also reasonably similar to the ones found from the MSD above. This suggests that they both reasonable ways to calculate the diffusion coefficient.
Besides the inherent inherent error in any numerical integration method, the VACF would have to be integrated to infinity as stated in the formula above. As this is not possible for our simulation (it would require infinite computation time), the calculated diffusion coefficient will not be completely accurate. As the VACF tends to zero for our simulated system for large time, this value is however not extraordinarily high. When comparing figure 31 and 34 it can also be seen that noise in the VACF decreases with increasing number of particles. Noise can therefore also be a significant source of error when simulating small systems.
JC: Good analysis.
- ↑ Michalek, T., Kowalewski, T.A. and Sarler, B., 2005. Natural convection for anomalous density variation of water: numerical benchmark. Progress in Computational Fluid Dynamics, an International Journal, 5(3-5), pp.158-170.DOI:10.1504/PCFD.2005.006751
- ↑ Hansen, J.P. and Verlet, L., 1969. Phase transitions of the Lennard-Jones system. physical Review, 184(1), p.151.DOI:10.1103/PhysRev.184.151