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:
Via SSH: Use your terminal application
Via OnDemand: Go to ondemand
.anvil .rcac .purdue .edu → Clusters → Anvil Shell Access
Step 2: Navigate to Your Scratch Space¶
cd $SCRATCHStep 3: Create a Tutorial Directory¶
mkdir lammps_tutorial
cd lammps_tutorial
pwdThe pwd command shows your current location. You should see:
/anvil/scratch/x-username/lammps_tutorialStep 4: Create Your First LAMMPS Input File¶
We’ll use the nano text editor (simple and beginner-friendly):
nano argon.inThis 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:
Simulate millions of atoms efficiently
Run in parallel across thousands of CPU cores
Handle complex force fields (proteins, polymers, metals, etc.)
Integrate with analysis tools and visualization software
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:
Simulate millions of atoms efficiently
Run in parallel across thousands of cores
Handle complex materials (proteins, polymers, metals)
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 pWhat it does:
units real— Use real-world units: Angstroms (Å), femtoseconds (fs), kcal/mol, Kelvin (K)atom_style atomic— Simple atoms (no bonds or molecules)boundary p p p— Periodic boundaries (atoms wrap around edges)
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 gaussianWhat it does:
Creates a simulation box with ~2048 Argon atoms
lattice fcc 3.8— FCC lattice with conventional cell size 3.8 Åregion simbox block 0 8 0 8 0 8— Define a region extending 8 lattice unitscreate_box 1 simbox— Create simulation box with 1 atom typecreate_atoms 1 region simbox— Fill region with atoms on FCC latticemass 1 39.948— Argon atomic mass (amu)Gives atoms random velocities for T = 500 K
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 yesWhat it does:
lj/cut 12.0— Lennard-Jones potential with cutoff at 12.0 Åpair_coeff 1 1 0.238 3.405— For Argon:ε = 0.238 kcal/mol (well depth)
σ = 3.405 Å (atom diameter)
neighbor 2.0— Build neighbor list with 2.0 Å buffer
7. Section 4: Simulation Settings¶
Add this:
# ========================================
# SECTION 4: SIMULATION SETTINGS
# ========================================
timestep 2.0
fix 1 all nvt temp 500.0 500.0 100.0What it does:
timestep 2.0— Time advances in steps of 2.0 fs (femtoseconds)fix 1 all nvt temp 500.0 500.0 100.0— Nosé-Hoover thermostat at 500 KStart temp: 500 K
End temp: 500 K
Damping: 100 fs
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.outWhat it does:
thermo 500— Print thermodynamic data every 500 steps (= 1 ps)dump— Save atom positions/velocities every 1000 steps (= 2 ps)log thermo.out— Write output to file (for later analysis)
9. Section 6: Execution¶
Final section:
# ========================================
# SECTION 6: EXECUTION
# ========================================
run 50000
write_data final_state.dataWhat it does:
run 50000— Simulate for 50,000 timesteps = 100 ps (picoseconds)write_data— Save final configuration (for restart/continuation)
10. Save and Exit¶
Now save your file:
Press
Ctrl+O(that’s the letter O, not zero)Press
Enterto confirm filenamePress
Ctrl+Xto exit nano
Verify your file was created:
ls -lh argon.inYou should see:
-rw-r--r-- 1 username group 1.2K date argon.in11. 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:
✅ Easy to find specific results
✅ No accidentally overwriting files
✅ Clear documentation of what each simulation does
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 -lhYou should see:
drwxr-xr-x NVT_simulations/
drwxr-xr-x NPT_simulations/
-rw-r--r-- argon.inStep 2: Create Temperature Subfolders (NVT)¶
cd NVT_simulations
# Create three temperature folders
mkdir T_300K T_500K T_700K
# Check
lsOutput:
T_300K T_500K T_700KStep 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.inPaste 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.dataSave: Ctrl+O, Enter, Ctrl+X
For T_500K:
cd ../T_500K
nano argon_500K.inPaste 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.dataFor T_700K:
cd ../T_700K
nano argon_700K.inChange 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.dataStep 4: Verify NVT Folder Structure¶
cd $SCRATCH/lammps_tutorial/NVT_simulations
treeOr without tree:
ls -RYou should see:
T_300K/:
argon_300K.in
T_500K/:
argon_500K.in
T_700K/:
argon_700K.in12. 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
lsOutput:
P_1atm P_10atmStep 2: NPT Input for 1 atm¶
cd P_1atm
nano argon_npt_1atm.inPaste 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.dataStep 3: NPT Input for 10 atm¶
cd ../P_10atm
nano argon_npt_10atm.inCopy 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.dataStep 4: Verify Complete Structure¶
cd $SCRATCH/lammps_tutorial
treeOr:
find . -name "*.in" -type fYou 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.in13. Understanding Real Units vs Reduced Units¶
Why We Use Real Units in This Class¶
Real units (units real in LAMMPS):
✅ Direct: Temperature = 300 K (not T* = 2.50)
✅ Intuitive: Pressure = 1 atm (not P* = 0.002)
✅ Comparable: Can directly compare with experimental data
✅ Practical: Easy to understand physical meaning
Reduced units (units lj):
Good for theory and dimensionless comparisons
Common in older MD papers
Less intuitive for beginners
Units in LAMMPS Real Mode¶
| Quantity | Units | Example |
|---|---|---|
| Distance | Angstroms (Å) | σ = 3.405 Å |
| Time | femtoseconds (fs) | timestep = 2.0 fs |
| Energy | kcal/mol | ε = 0.238 kcal/mol |
| Temperature | Kelvin (K) | T = 500 K |
| Pressure | atmospheres (atm) | P = 1 atm |
| Mass | atomic mass units (amu) | m_Ar = 39.948 amu |
Argon Parameters (Memorize These!)¶
| Parameter | Value | Physical Meaning |
|---|---|---|
| ε | 0.238 kcal/mol | LJ well depth |
| σ | 3.405 Å | LJ atom diameter |
| mass | 39.948 amu | Atomic mass |
| Cutoff | 12.0 Å | ~3.5σ (interaction range) |
14. Summary Checklist¶
After completing this tutorial, you should have:
Created organized folder structure:
NVT_simulations/with 3 temperature foldersNPT_simulations/with 2 pressure folders
5 complete LAMMPS input files (.in files)
Understand the difference between NVT and NPT fixes
Know how to convert real units (K, atm) to reduced units
File count check:
cd $SCRATCH/lammps_tutorial
find . -name "*.in" | wc -lShould output: 5
Next Tutorial: Running these simulations on Anvil (Tutorial 8)
15. Troubleshooting¶
Problem: “mkdir: cannot create directory: File exists”
That folder already exists. Use
lsto check what’s there, or use-pflag:mkdir -p foldername
Problem: “No such file or directory”
You’re in the wrong directory. Use
pwdto check location,cdto navigate
Problem: Lost track of where you are
cd $SCRATCH/lammps_tutorial
pwd
ls -RProblem: Want to start over
cd $SCRATCH
rm -rf lammps_tutorial
# Then start from Section 11, Step 116. 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¶
LAMMPS Manual — Command reference
Anvil LAMMPS Documentation — Anvil-specific guide
LAMMPS fix npt — NPT thermostat/barostat documentation
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/bashWait 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/20210310Step 3: Run LAMMPS¶
lmp -in argon.inYou 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¶
exit12. Understanding the Output Files¶
12. Understanding the Output Files¶
After running, check what files were created:
ls -lh| File | Contents |
|---|---|
thermo.out | Temperature, pressure, energy vs. time |
argon.lammpstrj | Trajectory snapshots (for visualization) |
final_state.data | Final positions (for restart) |
log.lammps | Full LAMMPS log (warnings, timings) |
Quick check:
head -20 thermo.outLook for the temperature column — it should fluctuate around 4.17 (your target).
13. Common LAMMPS Commands Reference¶
| Command | Purpose | Example |
|---|---|---|
units | Set unit system | units lj |
boundary | Set boundary conditions | boundary p p p |
create_box | Create simulation box | create_box 1 simbox |
create_atoms | Add atoms | create_atoms 1 box |
mass | Set atom mass | mass 1 1.0 |
velocity | Set initial velocities | velocity all create 1.0 12345 |
pair_style | Choose interaction model | pair_style lj/cut 2.5 |
pair_coeff | Set interaction parameters | pair_coeff 1 1 1.0 1.0 |
timestep | Set integration timestep | timestep 0.005 |
fix | Apply thermostat/barostat | fix 1 all nvt temp 1.0 1.0 0.1 |
thermo | Output frequency | thermo 100 |
dump | Save trajectory | dump 1 all custom 1000 traj.lammpstrj |
run | Execute simulation | run 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:
You need to change TWO lines in the input file.
Hint 2: Which lines?
The
velocityline (sets initial temperature)The
fix nvtline (thermostat target)
Solution
# Copy the file
cp argon.in argon_300K.in
# Edit it
nano argon_300K.inChange these two lines:
velocity all create 2.50 87287 dist gaussian
fix 1 all nvt temp 2.50 2.50 0.5Also 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.outTest 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”
You’re not on Anvil or in a proper terminal
Problem: “Permission denied”
Make sure you’re in
$SCRATCH, not$HOME
Problem: LAMMPS crashes with “Unknown command”
Check for typos in command names
Make sure there are no extra spaces at line beginnings
Problem: “ERROR: Cannot open input script”
Check filename:
ls -lh argon.inMake sure you’re in the right directory:
pwd
17. Summary Checklist¶
After completing this tutorial, you should have:
Created
argon.inin$SCRATCH/lammps_tutorial/Successfully run LAMMPS in an interactive session
Seen
thermo.outandargon.lammpstrjfiles createdUnderstand the 6-section structure of LAMMPS input files
Next Tutorial: Running LAMMPS jobs on the cluster (Tutorial 8)
18. Further Reading¶
LAMMPS Manual — Searchable command reference
Anvil LAMMPS Documentation — Anvil-specific setup
LAMMPS Tutorials — Community tutorials
15. Further Reading¶
LAMMPS Manual — The official documentation (searchable!)
Anvil LAMMPS Documentation — Anvil-specific LAMMPS setup and modules
LAMMPS Tutorial: Argon — Mississippi State tutorial
Molecular Dynamics with LAMMPS — Community tutorials
Frenkel & Smit, Chapter 4 — Reduced units and their conversions