Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Tutorial 8: LAMMPS Input Files — Building Your First Simulation

Objective: Learn to write LAMMPS input scripts by building a simple Argon gas simulation from scratch.


1. Getting Started: Creating Your Workspace

Before we write any LAMMPS code, let’s set up a proper workspace on Anvil.

Step 1: Log in to Anvil

Open a terminal on Anvil:

Step 2: Navigate to Your Scratch Space

cd $SCRATCH

Step 3: Create a Tutorial Directory

mkdir lammps_tutorial
cd lammps_tutorial
pwd

The pwd command shows your current location. You should see:

/anvil/scratch/x-username/lammps_tutorial

Step 4: Create Your First LAMMPS Input File

We’ll use the nano text editor (simple and beginner-friendly):

nano argon.in

This opens a blank file. You’ll see a text editor with a menu at the bottom.

Keep nano open — we’ll fill it with LAMMPS commands in the next section!


2. What is LAMMPS?

LAMMPS (Large-scale Atomic/Molecular Massively Parallel Simulator) is one of the most widely-used molecular dynamics codes in the world. Unlike our Python toy models, LAMMPS is production-grade software designed to:

LAMMPS is command-driven. You write a text file (the “input script”) that tells LAMMPS what to do, step by step. This tutorial will teach you the structure of that file.


2. What is LAMMPS?

LAMMPS (Large-scale Atomic/Molecular Massively Parallel Simulator) is production-grade MD software used worldwide. Unlike our Python toy model, LAMMPS can:

How it works: You write a text file (input script) telling LAMMPS what to do, step by step.


3. Building Your Input File: Section by Section

Now let’s fill in the argon.in file you have open in nano. Copy each section below.

The Six-Section Structure

Every LAMMPS input follows this template:

# SECTION 1: INITIALIZATION - Define the "universe"
# SECTION 2: SYSTEM DEFINITION - Create atoms
# SECTION 3: FORCE FIELD - Define interactions
# SECTION 4: SIMULATION SETTINGS - Timestep, thermostat
# SECTION 5: OUTPUT - What to save
# SECTION 6: EXECUTION - Run!

4. Section 1: Initialization

Copy this into nano:

# ========================================
# SECTION 1: INITIALIZATION
# ========================================
units           real
atom_style      atomic
boundary        p p p

What it does:


5. Section 2: System Definition

Add this to your file:

# ========================================
# SECTION 2: SYSTEM DEFINITION
# ========================================
# FCC lattice with 3.8 Angstrom conventional cell
lattice         fcc 3.8
# Simulation box: 8 lattice units per edge
region          simbox block 0 8 0 8 0 8
create_box      1 simbox
create_atoms    1 region simbox
mass            1 39.948
velocity        all create 500.0 87287 dist gaussian

What it does:


6. Section 3: Force Field

Add this:

# ========================================
# SECTION 3: FORCE FIELD
# ========================================
pair_style      lj/cut 12.0
pair_coeff      1 1 0.238 3.405
neighbor        2.0 bin
neigh_modify    every 1 delay 0 check yes

What it does:


7. Section 4: Simulation Settings

Add this:

# ========================================
# SECTION 4: SIMULATION SETTINGS
# ========================================
timestep        2.0
fix             1 all nvt temp 500.0 500.0 100.0

What it does:


8. Section 5: Output

Add this:

# ========================================
# SECTION 5: OUTPUT
# ========================================
thermo_style    custom step temp press pe ke etotal density
thermo          500
dump            1 all custom 1000 argon.lammpstrj id type x y z vx vy vz
dump_modify     1 sort id
log             thermo.out

What it does:


9. Section 6: Execution

Final section:

# ========================================
# SECTION 6: EXECUTION
# ========================================
run             50000
write_data      final_state.data

What it does:


10. Save and Exit

Now save your file:

  1. Press Ctrl+O (that’s the letter O, not zero)

  2. Press Enter to confirm filename

  3. Press Ctrl+X to exit nano

Verify your file was created:

ls -lh argon.in

You should see:

-rw-r--r-- 1 username group 1.2K date argon.in

11. Creating an Organized Folder Structure

Professional MD simulations require good organization. Let’s create a proper folder structure for running multiple simulations.

Why Folder Structure Matters

When you run multiple simulations (different temperatures, ensembles, parameters), you need:

The Standard Structure

We’ll create this hierarchy:

lammps_tutorial/
├── NVT_simulations/
│   ├── T_300K/
│   ├── T_500K/
│   └── T_700K/
└── NPT_simulations/
    ├── P_1atm/
    └── P_10atm/

Step 1: Create the Main Directories

cd $SCRATCH/lammps_tutorial

# Create top-level folders
mkdir -p NVT_simulations
mkdir -p NPT_simulations

# Verify
ls -lh

You should see:

drwxr-xr-x  NVT_simulations/
drwxr-xr-x  NPT_simulations/
-rw-r--r--  argon.in

Step 2: Create Temperature Subfolders (NVT)

cd NVT_simulations

# Create three temperature folders
mkdir T_300K T_500K T_700K

# Check
ls

Output:

T_300K  T_500K  T_700K

Step 3: Copy Input Files for Each Temperature

We’ll create three versions of the input file, one per temperature.

For T_300K:

cd T_300K
nano argon_300K.in

Paste this complete input file:

# ========================================
# Argon NVT Simulation at 300 K
# ========================================

# ========================================
# SECTION 1: INITIALIZATION
# ========================================
units           real
atom_style      atomic
boundary        p p p

# ========================================
# SECTION 2: SYSTEM DEFINITION
# ========================================
lattice         fcc 3.8
region          simbox block 0 8 0 8 0 8
create_box      1 simbox
create_atoms    1 region simbox
mass            1 39.948
velocity        all create 300.0 87287 dist gaussian

# ========================================
# SECTION 3: FORCE FIELD
# ========================================
pair_style      lj/cut 12.0
pair_coeff      1 1 0.238 3.405
neighbor        2.0 bin
neigh_modify    every 1 delay 0 check yes

# ========================================
# SECTION 4: SIMULATION SETTINGS
# ========================================
timestep        2.0
fix             1 all nvt temp 300.0 300.0 100.0

# ========================================
# SECTION 5: OUTPUT
# ========================================
thermo_style    custom step temp press pe ke etotal density
thermo          500
dump            1 all custom 1000 argon_300K.lammpstrj id type x y z vx vy vz
dump_modify     1 sort id
log             thermo_300K.out

# ========================================
# SECTION 6: EXECUTION
# ========================================
run             50000
write_data      final_300K.data

Save: Ctrl+O, Enter, Ctrl+X

For T_500K:

cd ../T_500K
nano argon_500K.in

Paste the same file BUT change these lines:

# Header comment: "Argon NVT Simulation at 500 K"
velocity        all create 500.0 87287 dist gaussian
fix             1 all nvt temp 500.0 500.0 100.0
dump            1 all custom 1000 argon_500K.lammpstrj id type x y z vx vy vz
log             thermo_500K.out
write_data      final_500K.data

For T_700K:

cd ../T_700K
nano argon_700K.in

Change to 700 K:

# Header comment: "Argon NVT Simulation at 700 K"
velocity        all create 700.0 87287 dist gaussian
fix             1 all nvt temp 700.0 700.0 100.0
dump            1 all custom 1000 argon_700K.lammpstrj id type x y z vx vy vz
log             thermo_700K.out
write_data      final_700K.data

Step 4: Verify NVT Folder Structure

cd $SCRATCH/lammps_tutorial/NVT_simulations
tree

Or without tree:

ls -R

You should see:

T_300K/:
argon_300K.in

T_500K/:
argon_500K.in

T_700K/:
argon_700K.in

12. Creating NPT Simulation Inputs

NPT simulations control both temperature AND pressure. Let’s create two pressure conditions.

Step 1: Create Pressure Subfolders

cd $SCRATCH/lammps_tutorial/NPT_simulations

mkdir P_1atm P_10atm

ls

Output:

P_1atm  P_10atm

Step 2: NPT Input for 1 atm

cd P_1atm
nano argon_npt_1atm.in

Paste this:

# ========================================
# Argon NPT Simulation at 1 atm
# T = 500 K, P = 1 atm
# ========================================

# ========================================
# INITIALIZATION
# ========================================
units           real
atom_style      atomic
boundary        p p p

# ========================================
# SYSTEM DEFINITION
# ========================================
lattice         fcc 3.8
region          simbox block 0 8 0 8 0 8
create_box      1 simbox
create_atoms    1 region simbox
mass            1 39.948
velocity        all create 500.0 87287 dist gaussian

# ========================================
# FORCE FIELD
# ========================================
pair_style      lj/cut 12.0
pair_coeff      1 1 0.238 3.405
neighbor        2.0 bin
neigh_modify    every 1 delay 0 check yes

# ========================================
# SIMULATION SETTINGS (NPT!)
# ========================================
timestep        2.0
fix             1 all npt temp 500.0 500.0 100.0 iso 1.0 1.0 1000.0

# ========================================
# OUTPUT
# ========================================
thermo_style    custom step temp press pe ke etotal vol density
thermo          500
dump            1 all custom 2000 argon_npt_1atm.lammpstrj id type x y z
dump_modify     1 sort id
log             thermo_npt_1atm.out

# ========================================
# EXECUTION
# ========================================
run             100000
write_data      final_npt_1atm.data

Step 3: NPT Input for 10 atm

cd ../P_10atm
nano argon_npt_10atm.in

Copy the 1 atm file but change:

# Header: "Argon NPT Simulation at 10 atm"
# T = 500 K, P = 10 atm
fix             1 all npt temp 500.0 500.0 100.0 iso 10.0 10.0 1000.0
dump            1 all custom 2000 argon_npt_10atm.lammpstrj id type x y z
log             thermo_npt_10atm.out
write_data      final_npt_10atm.data

Step 4: Verify Complete Structure

cd $SCRATCH/lammps_tutorial
tree

Or:

find . -name "*.in" -type f

You should see all 5 input files:

./NVT_simulations/T_300K/argon_300K.in
./NVT_simulations/T_500K/argon_500K.in
./NVT_simulations/T_700K/argon_700K.in
./NPT_simulations/P_1atm/argon_npt_1atm.in
./NPT_simulations/P_10atm/argon_npt_10atm.in

13. Understanding Real Units vs Reduced Units

Why We Use Real Units in This Class

Real units (units real in LAMMPS):

Reduced units (units lj):

Units in LAMMPS Real Mode

QuantityUnitsExample
DistanceAngstroms (Å)σ = 3.405 Å
Timefemtoseconds (fs)timestep = 2.0 fs
Energykcal/molε = 0.238 kcal/mol
TemperatureKelvin (K)T = 500 K
Pressureatmospheres (atm)P = 1 atm
Massatomic mass units (amu)m_Ar = 39.948 amu

Argon Parameters (Memorize These!)

ParameterValuePhysical Meaning
ε0.238 kcal/molLJ well depth
σ3.405 ÅLJ atom diameter
mass39.948 amuAtomic mass
Cutoff12.0 Å~3.5σ (interaction range)

14. Summary Checklist

After completing this tutorial, you should have:

File count check:

cd $SCRATCH/lammps_tutorial
find . -name "*.in" | wc -l

Should output: 5

Next Tutorial: Running these simulations on Anvil (Tutorial 8)


15. Troubleshooting

Problem: “mkdir: cannot create directory: File exists”

Problem: “No such file or directory”

Problem: Lost track of where you are

cd $SCRATCH/lammps_tutorial
pwd
ls -R

Problem: Want to start over

cd $SCRATCH
rm -rf lammps_tutorial
# Then start from Section 11, Step 1

16. Class Examples

Pre-made complete folder structures are available:

ls /anvil/projects/x-chm250117/class_examples/

If you get stuck, you can copy the complete structure:

cd $SCRATCH
cp -r /anvil/projects/x-chm250117/class_examples/lammps_tutorial ./

17. Further Reading

Let’s make sure your input file works before submitting a job.

Step 1: Request Interactive Session

srun -p shared -A chm250117 --nodes=1 --ntasks=4 --time=00:10:00 --pty /bin/bash

Wait for the prompt to change (30 seconds to 2 minutes). When you see a new prompt, you’re on a compute node.

Step 2: Load LAMMPS

module load gcc/11.2.0 openmpi/4.0.6
module load lammps/20210310

Step 3: Run LAMMPS

lmp -in argon.in

You should see output scrolling by:

LAMMPS (10 Mar 2021)
...
Step Temp Press PotEng KinEng TotEng Density
0 4.1700000 16.503422 -2.6604462 6.2487500 3.5883038 0.8000000
100 4.0523344 15.341847 -2.5327691 6.0722148 3.5394457 0.8000000
...

If you see this, success! Your input file works.

Step 4: Exit Interactive Session

exit

12. Understanding the Output Files

12. Understanding the Output Files

After running, check what files were created:

ls -lh
FileContents
thermo.outTemperature, pressure, energy vs. time
argon.lammpstrjTrajectory snapshots (for visualization)
final_state.dataFinal positions (for restart)
log.lammpsFull LAMMPS log (warnings, timings)

Quick check:

head -20 thermo.out

Look for the temperature column — it should fluctuate around 4.17 (your target).


13. Common LAMMPS Commands Reference

CommandPurposeExample
unitsSet unit systemunits lj
boundarySet boundary conditionsboundary p p p
create_boxCreate simulation boxcreate_box 1 simbox
create_atomsAdd atomscreate_atoms 1 box
massSet atom massmass 1 1.0
velocitySet initial velocitiesvelocity all create 1.0 12345
pair_styleChoose interaction modelpair_style lj/cut 2.5
pair_coeffSet interaction parameterspair_coeff 1 1 1.0 1.0
timestepSet integration timesteptimestep 0.005
fixApply thermostat/barostatfix 1 all nvt temp 1.0 1.0 0.1
thermoOutput frequencythermo 100
dumpSave trajectorydump 1 all custom 1000 traj.lammpstrj
runExecute simulationrun 10000

14. Exercise: Modify the Temperature

Challenge: Create a second input file for Argon at 300 K instead of 500 K.

Hint 1: What needs to change?

Calculate the reduced temperature:

T^* = \frac{T}{T_\epsilon} = \frac{300 \text{ K}}{119.8 \text{ K}} = 2.50

You need to change TWO lines in the input file.

Hint 2: Which lines?
  1. The velocity line (sets initial temperature)

  2. The fix nvt line (thermostat target)

Solution
# Copy the file
cp argon.in argon_300K.in

# Edit it
nano argon_300K.in

Change these two lines:

velocity        all create 2.50 87287 dist gaussian
fix             1 all nvt temp 2.50 2.50 0.5

Also update the output filenames to avoid overwriting:

dump            1 all custom 500 argon_300K.lammpstrj id type x y z vx vy vz
log             thermo_300K.out

Test it in an interactive session!


15. Class Examples Directory

Pre-made example files are available:

ls /anvil/projects/x-chm250117/class_examples/

Copy an example to your directory:

cp /anvil/projects/x-chm250117/class_examples/argon_example.in ./

16. Troubleshooting

Problem: “nano: command not found”

Problem: “Permission denied”

Problem: LAMMPS crashes with “Unknown command”

Problem: “ERROR: Cannot open input script”


17. Summary Checklist

After completing this tutorial, you should have:

Next Tutorial: Running LAMMPS jobs on the cluster (Tutorial 8)


18. Further Reading


15. Further Reading