Tutorial 1 - Running your first LAMMPS simulation

1. Install Ubuntu (Linux)

Using a linux environment for LAMMPS provides a good place to run your initial simulations and learn transferable skills that will work on most computing clusters and high performance computers. Several shell commands are available within LAMMPS that allow for better data management and simple bash scripting can help create a better workflow when running multiple simulations.

If you have a linux workstation - Great! If you have a mac - Great! If you have a windows machine.... you're in luck if you have Windows 10.

A tutorial for installing Ubuntu on windows can be found here: https://tutorials.ubuntu.com/tutorial/tutorial-ubuntu-on-windows#0.

If you are working on an older Windows version, I previously used Cygwin and preferred it to dual-booting . It is not as straight forward, but it will get you there in the end.

2. Download LAMMPS

For most simple simulations, the "lammps-daily" option is probably the easiest. A pre-built LAMMPS executable can be grabbed by issuing the following commands:

sudo add-apt-repository ppa:gladky-anton/lammps

sudo apt-get update

sudo apt-get install lammps-daily

This portion of the tutorial was written in 2019 and some aspect may have changed regarding getting this executable. For the latest details please reference: https://lammps.sandia.gov/doc/Install_linux.html.

For other linux distributions you might find an available executable at: https://lammps.sandia.gov/doc/Install_linux.html#ubuntu .

You can check to see if everything is working properly by calling the executable "lmp_daily" (lmp_stable as of Oct 2020) which should now be located in "/usr/bin/" and can be accessed from any directory by typing "lmp_daily" in the command line and pressing enter. This should put you in an interactive LAMMPS session that will look like this:

LAMMPS (8 Feb 2019)

using 1 OpenMP thread(s) per MPI task

To exit this session, simply type "quit".

If you get a message "OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:87)", don't worry! This won't affect your simulation. If you would rather not see this then you can enter:

export OMP_NUM_THREADS=1

If you are interested in using multiple threads in the future, you can start by looking here: https://lammps.sandia.gov/doc/Run_basics.html

3. Getting a potential

There are many different repositories where interatomic potentials can be located. One of the most user-friendly locations is the NIST potential repository : https://www.ctcms.nist.gov/potentials/ . Here you can search the periodic table for an element and download potentials into the folder you plan to work in. For this first example we will be working with Copper, specifically the 2001 Mishin Potential named "2001--Mishin-Y-Mehl-M-J-Papaconstantopoulos-D-A-et-al--Cu-1" on the site. You can right click the link above and open in a new tab. From there, scroll down to the files section and open "Cu01.eam.alloy " as a new tab as well. Right click on the page and select "save as." If you are given a choice it is generally a good idea to save the file type as "All Files." This should help some issues with LAMMPS not being able to find your potential due to some file systems (primarily windows) adding ".txt" to the end of the file name with an unknown type.

Alternatively, this potential can also be found in the potentials folder of the standard distribution. If you are using the "lammps-daily" executable you might not have these files on your system yet. To get them you will need to download a tarball containing the source code and documentation (which is a good thing to have handy anyways). The download page for this is: https://lammps.sandia.gov/download.html . Here you will scroll down to the "download a tarball " section and select " LAMMPS --- Stable version " , then click "Download Now". This should be ~ 400 MB, so it might take a little while to finish downloading. Once downloaded, you can use your file explorer to move the tarball into your desired working folder (I typically name mine something like "lammps"). In order to extract the compressed files, type the following and press enter:

tar -xvf lammps.tar.gz

This will extract everything into a folder that will be named something like "lammps-29Mar19". The date is added here to help keep track of what version you are working with in case you run into trouble. Notice that the lammps-daily version is usually different, here printing out "LAMMPS (8 Feb 2019)" (as of writing this tutorial) when you first entered interactive mode. This is the version of LAMMPS you are running and is the most often forgotten piece of information forgotten when asking questions on the LAMMPS mailing list: https://lammps.sandia.gov/mail.html . Back to the potential. Within the primary folder (lammps-version) there is a potentials subfolder. The corresponding potential is "Cu_mishin1.eam.alloy". Depending on which potential you select there will be a specific line in the input file that will need to directly correspond to this file name and its location.

4. The Input File

This input script was run using the 8 Feb 2019 version of LAMMPS. It is possible that a newer LAMMPS version will change some of the commands slightly. and changes to your own input script will have to be changed accordingly. Open your favorite text editor (my personal suggestion is Notepad++) and copy and paste the code below . Then save the file as "in.fcc_Cu_eval.sh". in your working folder A common standard for LAMMPS is that your input files should begin with "in", but this is not enforced by LAMMPS in any way, - it is simply an easy way to keep track of your input files. I often append a ".sh" to the end of my input files; Notepad++ will automatically selectively color different parts of the code, helping you keep track of comments, variable, numbers, etc.

The input code:

# Find lattice parameter and cohesive energy 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 4

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 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 ===

min_style cg

minimize 1e-10 1e-10 10000 20000


# === Gather and Print Outputs ===

variable length equal "lx/v_cubelength"

variable engcoh equal "pe/atoms"


print " "

print "Simulation Summary"

print "Lattice parameter (Angstoms) = ${length}"

print "Cohesive energy (eV) = ${engcoh}"

print " "

print "Job's Done"

5. Running LAMMPS

Now that you have your input file and potential file in the same place, it is time to run your first script. As a quick first check, you can type "ls" into your command line and press enter. The result should look something like this:

Cu01.eam.alloy in.fcc_Cu_eval.sh lammps-29Mar19

This is just a quick double check to make sure that everything is in place and named correctly. Windows is a particularly bad culprit here, enjoying to add ".txt" to files seemingly at random.

To run the simulation you will type the following and press enter:

lmp_daily -in in.fcc_Cu_eval.sh -log log.fcc_Cu_eval

Here "lmp_daily" is your LAMMPS executable, "-in" specifies an input script follows, and "-log" defines the name of the output log. The default log name is "log.lammps". If there is already a log file in your directory with the same name, it will be overwritten. In the future it will be critical that you make sure a valuable log file is not overwritten.

Using "-in" is preferable to using "<" because it helps LAMMPS store the name of the input file, which can be referenced by other commands in the future.

If everything goes to plan, you should see some numbers quickly scroll by and then the message "Job's done" followed by the total elapsed time. Right above this you can find the screen output of the simulation that we specified:

Simulation Summary

Lattice parameter (Angstoms) = 3.61500005821842

Cohesive energy (eV) = -3.53999996838069

6. What is the script actually doing?

Let's break down this simple script into its basic parts. If you have questions, a great place to start is the LAMMPS manual, which can be found here: https://lammps.sandia.gov/doc/Manual.html. If you want to find a specific command quickly, the first result of a google search of "LAMMPS command" is usually the manual page you are looking for!

# Find lattice parameter and cohesive energy of fcc system

# Eric Hahn, 2019

These first two commands are comments, denoted by the "#" and LAMMPS will skip over them.

# === Simulation Setup ===

clear

units metal

dimension 3

boundary p p p

atom_style atomic

This is where the simulation is first set up. "clear" clears the memory. "units" specifies the units of the simulation, ie. Angstroms, eV, picoseconds, etc. "dimension" sets the system dimensions, in this case a 3D system. "boundary" specifies what type of boundaries the system will employ, here using "p p p" tells the simulation that each of the boundaries are periodic. "atom_style" tells LAMMPS what attributes the atoms will have, with atomic being the most basic.

Next the simulation box is defined and atoms are created.

# === Define Simulation Box and Create Atoms ===

lattice fcc 4

variable cubelength equal 2

region box block 0 ${cubelength} 0 ${cubelength} 0 ${cubelength} units lattice

create_box 1 box

create_atoms 1 box

The "lattice" command species the type of lattice we are going to create (fcc, bcc, hpc, diamond, etc.) and the trailing number defines the lattice parameter of the system, used in several following commands. The "region" command defines a volume, here a rectangular "block" that spans 0 to a defined number of cube lengths, defined above with the variable command in "units lattice". "units lattice" specifies that the 2 lengths in each dimension will be multiplied by the lattice parameter defined in the "lattice" command preceding it.

"create_box" will then create the simulation box and "create_atoms" will fill the new simulation box with atoms of the prescribed lattice type.

# === Define Interatomic Potential ===

pair_style eam/alloy

pair_coeff * * Cu01.eam.alloy Cu

This section defines the pair_style we will be using and then defines the corresponding pair coefficients from the potential we downloaded. More details about how to handle multiple atom types will be included in future tutorials.

# === 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

A couple of run settings are defined here, namely the "fix .. box/relax" which allows for the system volume to change during the upcoming minimization. Next a few lines define the frequency of the "thermo" output. Here the value of 10 lets LAMMPS know how often you would like to evaluate and print its output, ie every 10 timesteps. The "thermo-style" allows you to choose what outputs you would like to see! More options can be found here: https://lammps.sandia.gov/doc/thermo_style.html .

Next we inform LAMMPS that we would like to run a conjugate gradient minimization with the "min_style" command.

# === Run Minimization ===

min_style cg

minimize 1e-10 1e-10 10000 20000

Minimization is actually performed by issuing the "minimize" command with stopping conditions specified by the given four number entries. More on what these are actually doing later! Simply, we are allowing the volume of the system to change (the "fix ... box/relax" command above) in order to find the lowest energy possible. This is what is allowing us to find the preferred lattice parameter of the simulation along with the corresponding cohesive energy.

After the minimization is complete, we would like to figure out what these two values actually are!

# === Gather and Print Outputs ===

variable length equal "lx/v_cubelength"

variable engcoh equal "pe/atoms"

These two variable commands gather several of the final thermo outputs along with the defined number of lattice lengths we set when defining the simulation.

print " "

print "Simulation Summary"

print "Lattice parameter (Angstoms) = ${length}"

print "Cohesive energy (eV) = ${engcoh}"

print " "

print "Job's Done"

Finally, we print these values with some descriptions to the screen and the log file. Note: we use some blank "print" commands to make everything look a little cleaner.

Congratulations on running your first simulation!

Next Tutorial

Evaluating Pressure-Volume Type Relationships.

Return to main LAMMPS Tutorials page.

Changing Things Up

Lets try changing the input file to call a potential from a different folder. If when you listed your files (ls) your list was similar to the one shown above, we can call the other potential by substituting the following code snippet into the input file (make sure you save before you run the executable again).

# === Define Interatomic Potential ===

pair_style eam/alloy

pair_coeff * * ./lammps-29Mar19/potentials/Cu_mishin1.eam.alloy Cu

The final result is:

Simulation Summary

Lattice parameter (Angstoms) = 3.61492506589063

Cohesive energy (eV) = -3.54021833020495

Note that even though both potentials reference the same paper, they give slightly different results due to how they were converted into the setfl format. Most use scenarios may not notice a difference. If you are new to Molecular Dynamics simulations, let this serve as your first warning that not all potentials are created equal!