Questions / Comments
Please contact me if you have any questions or comments pertaining to this tutorial
Email: Eric Hahn, ericnhahn@gmail.com
We will be using the same LAMMPS executable and potential from the previous tutorial (Tutorial 1a - First Simulation). This time, we will be using a bash script and a tiny workflow to generate a pressure-volume curve. In the same folder you have been working in, copy the following three code boxes into new files and save them with the names found above each box. You should have three new files: pv_curve.sh in.fcc_Cu_min.sh in.fcc_Cu_pv.sh. Note that when you save these (if you are using notepad++) make sure to have Unix Mode on. This option can be found in the bottom right hand corner and should say "Unix (LF)". If it is set on Windows or Mac, you can right click this option to change.
Bash script (pv_curve.sh):
#!/bin/bash
lmp_daily -in in.fcc_Cu_min.sh
alattice=$(head -n 1 minfcclat.txt)
rm pv_fcc.txt
for scale in `seq 0.875 .0125 1.125` ; do
lmp_daily -var scale ${scale} -var alattice ${alattice} -in in.fcc_Cu_pv.sh
done
LAMMPS input script (in.fcc_Cu_min.sh):
# Find minimum energy lattice parameter of a fcc system
# Eric Hahn, 2019
# === Simulation Setup ===
clear
units metal
dimension 3
boundary p p p
atom_style atomic
# === Define Simulation Box and Create Atoms ===
lattice fcc 3.5
variable cubelength equal 2
region box block 0 ${cubelength} 0 ${cubelength} 0 ${cubelength} units lattice
create_box 1 box
create_atoms 1 box
# === Define Interatomic Potential ===
pair_style eam/alloy
pair_coeff * * Cu01.eam.alloy Cu
# === Define Computes ===
compute eng all pe/atom
# === Define Run Setting ===
fix volumerelax all box/relax iso 0
thermo 10
thermo_style custom step pe lx ly lz vol pxx pyy pzz press atoms
min_style cg
# === Run Minimization ===
minimize 1e-10 1e-10 10000 20000
# === Gather and Print Outputs ===
variable length equal "lx/v_cubelength"
variable engcoh equal "pe/atoms"
print "${length}" file minfcclat.txt
print " "
print "Simulation Summary"
print "Lattice parameter (Angstoms) = ${length}"
print "Cohesive energy (eV) = ${engcoh}"
print " "
print "Job's Done"
LAMMPS input script (in.fcc_Cu_pv.sh):
# Evaluate properties at a specific lattice parameter
# Eric Hahn, 2019
# === Simulation Setup ===
clear
units metal
dimension 3
boundary p p p
atom_style atomic
# === Define Simulation Box and Create Atoms ===
variable makelattice equal "((v_alattice^3)*v_scale)^(1/3)"
lattice fcc ${makelattice}
print "${makelattice}"
variable cubelength equal 2
region box block 0 ${cubelength} 0 ${cubelength} 0 ${cubelength} units lattice
create_box 1 box
create_atoms 1 box
# === Define Interatomic Potential ===
pair_style eam/alloy
pair_coeff * * Cu01.eam.alloy Cu
# === Define Computes ===
compute eng all pe/atom
# === Define Run Setting ===
fix volumerelax all box/relax iso 0
thermo 10
thermo_style custom step pe lx ly lz vol pxx pyy pzz press atoms
# === Run Minimization ===
run 0
# === Gather and Print Outputs ===
variable length equal "lx/v_cubelength"
variable engcoh equal "pe/atoms"
variable hpress equal "press/10000"
variable avol equal "(v_length^3)/4" #4 atoms per fcc unit cell
print "${hpress} ${avol} ${length} ${engcoh}" append pv_fcc.txt
print "Job's Done"
Now that you have all your input files and (executable + potential file) in the same place, it is time to run the bash script. Its as simple as:
./pv_curve.sh
Followed by an enter.
If all goes to plan, you should have three new files: log.lammps pv_fcc.txt minfcclat.txt.
Within "pv_fcc.txt" you should now have the following results!
24.4754519267733 10.3341078000638 3.45762316854501 -3.4405019834256
21.1294307141847 10.4817379114932 3.47401025301304 -3.46149162961157
18.0433273921468 10.6293680229227 3.49024418155862 -3.47952054348826
15.1881392221276 10.7769981343522 3.50632848332225 -3.49481397827449
12.5424107414177 10.9246282457817 3.52226655910217 -3.50757463424449
10.0858082609564 11.0722583572111 3.53806168768571 -3.51798608259076
7.79886501890603 11.2198884686406 3.55371703178846 -3.5262135599958
5.66309092943076 11.3675185800701 3.56923564363025 -3.5324047910811
3.66129046523013 11.5151486914996 3.58462047017467 -3.53669102603909
1.77800427205162 11.6627788029291 3.59987435805634 -3.53918844294827
-3.36762362108694e-10 11.8104089143586 3.61500005821842 -3.53999996838069
-1.69906854441165 11.9580390257881 3.63000023028056 -3.5392125315774
-3.33620135456193 12.1056691372175 3.64487744665631 -3.53688781850153
-4.90788950192891 12.253299248647 3.6596341964371 -3.53308444093935
-6.40978652302134 12.4009293600764 3.67427288905868 -3.52786465897977
-7.83723349746692 12.548559471506 3.68879585776468 -3.52129491835946
-9.18575742809725 12.6961895829354 3.7032053628807 -3.51344591506926
-10.4515754138394 12.843819694365 3.71750359491149 -3.50439218186207
-11.6320037488047 12.9914498057944 3.73169267747248 -3.49421126110488
-12.725593505429 13.1390799172239 3.74577467006662 -3.48298260429429
-13.7322846875356 13.2867100286534 3.75975157071591 -3.47078635680224
Lets first take a look at the BASH script (pv_curve.sh).
#!/bin/bash
This first line specifies where to find your bash executable is. Bin is a standard place, but it might be elsewhere on your system.
lmp_daily -in in.fcc_Cu_min.sh
This line runs the first LAMMPS input file. This input file is nearly identical to the "1a" input file with the following change:
print "${length}" file minfcclat.txt
Instead of previous "print" commands that sent the input to the screen and the log file, this print command sends the "length" variable (which corresponds to the minimum lattice parameter) to the file "minfcclat.txt". From the command line you can enter "more minfcclat.txt" and you should now see "3.61500005821842" as the response.
alattice=$(head -n 1 minfcclat.txt)
This next bash command does nearly this. It assigns the first line of the file (head -n 1) to the variable "alattice".
Next we clean our desired output text file, we do this in case it has data in it from a previous run. A note about this further below.
rm pv_fcc.txt
Next we use a FOR loop to sequentially cover a range of contractions and expansions for our system. Here we are going between 0.875 and 1.125 in steps of 0.0125.
for scale in `seq 0.875 .0125 1.125` ; do
lmp_daily -var scale ${scale} -var alattice ${alattice} -in in.fcc_Cu_pv.sh
done
In between our executable (lmp_daily) and calling our input (-in in.fcc_Cu_pv.sh), we carry two variables from our command line input into the run. Lets look at the sequence "-var scale ${scale}". Here we specify that we are sending a variable named scale with a value of ${scale} to LAMMPS. Within LAMMPS, if we call "v_scale" this is take the value we entered from the command line. I have found that this process is more straightforward when the variable name your are sending and the variable name you are calling are the same, but they don't have to be! The following example FOR loop will work just as well.
for i in `seq 0.875 .0125 1.125` ; do
lmp_daily -var scale ${i} -var alattice ${alattice} -in in.fcc_Cu_pv.sh
done
The definition of "scale" as the variable name that LAMMPS receives is still the same, so the following snippet from inside "in.fcc_Cu_pv.sh" works just as well:
variable makelattice equal "((v_alattice^3)*v_scale)^(1/3)"
If we want to make a plot of the Volume and Pressure relationship, it is important to scale things properly. Because we are interested in scaling the volume and we output the equilibrium lattice parameter, we can get our correct scaling using a variable command such as this.
Since we want to evaluate the properties at this new lattice parameter we don't want to minimize the system as before. We still want to evaluate the variables though. LAMMPS's way of making this happen is by issuing a "run 0" command.
We add a couple of new variables to calculate things and then print the results to a new file:
variable hpress equal "press/10000"
variable avol equal "(v_length^3)/4" #4 atoms per fcc unit cell
print "${hpress} ${avol} ${length} ${engcoh}" append pv_fcc.txt
Quick things to note. The default pressure units for "units metal" (that we specified at the very top of the file) is in bars, to convert to GPa we divide by 10000. To calculate how much volume each atom is occupying we use our knowledge of the FCC unit cell and take the cube of the lattice parameter divided by four atoms per unit cell (note again that we are making several assumptions here about our system remaining FCC). Finally, we have an output file with four columns that we can plot and evaluate for other purposes!
In the example plot shown to the right, Column 1 is plotted against Column 2 normalized by the equilibrium volume/atom of "11.81", resulting in a standard P vs V/V0 chart, often referred to as the "cold curve" since the calculations we ran were at T= 0 Kelvin!
Tutorial 2 ... coming soon ...
Plotting Tutorial ... coming soon...
Return to main LAMMPS Tutorials page.