Introduction to LAMMPS

by Ulf R. Pedersen

LAMMPS Documentation

LAMMPS melt example

On simon LAMMPS example script can be found at /usr/share/lammps/examples

A simple LJ simulation: examples/melt/in.melt. The input file for in.melt (always in.SOMETHING):

# 3d Lennard-Jones melt

units       lj
atom_style  atomic

lattice     fcc 0.8442
region      box block 0 10 0 10 0 10
create_box  1 box
create_atoms    1 box
mass        1 1.0

velocity    all create 3.0 87287 loop geom

pair_style  lj/cut 2.5
pair_coeff  1 1 1.0 1.0 2.5

neighbor    0.3 bin
neigh_modify    every 20 delay 0 check no

fix     1 all nve

#dump       id all atom 50 dump.melt

#dump       2 all image 25 image.*.jpg type type &
#       axes yes 0.8 0.02 view 60 -30
#dump_modify    2 pad 3

#dump       3 all movie 25 movie.mpg type type &
#       axes yes 0.8 0.02 view 60 -30
#dump_modify    3 pad 3

thermo      50
run     250

Run on simon at RUC

In this exercise we will run the melt example on simon. It is assumed that you have access to simon.

  1. Login to simon
ssh -X simon
  1. Create, and move into a new folder for your first simulation
mkdir my_first_lammps
cd my_first_lammps
  1. Copy the in.melt input file into the current directory
cp /usr/share/lammps/examples/melt/in.melt .
  1. Run the simulation on a single core (on front node)
lmp -in in.melt
  1. Investigate files in directory
# List files
ls

# Input script
less in.melt
# Log file (same as send to standard output)
  1. Inspect the output and note timesteps/s for this run. The output should look something like.
LAMMPS (29 Sep 2021 - Update 2)
OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98)
  using 1 OpenMP thread(s) per MPI task
Lattice spacing in x,y,z = 1.6795962 1.6795962 1.6795962
Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (16.795962 16.795962 16.795962)
  1 by 1 by 1 MPI processor grid
Created 4000 atoms
  using lattice units in orthogonal box = (0.0000000 0.0000000 0.0000000) to (16.795962 16.795962 16.795962)
  create_atoms CPU = 0.002 seconds
Neighbor list info ...
  update every 20 steps, delay 0 steps, check no
  max neighbors/atom: 2000, page size: 100000
  master list distance cutoff = 2.8
  ghost atom cutoff = 2.8
  binsize = 1.4, bins = 12 12 12
  1 neighbor lists, perpetual/occasional/extra = 1 0 0
  (1) pair lj/cut, perpetual
      attributes: half, newton on
      pair build: half/bin/atomonly/newton
      stencil: half/bin/3d
      bin: standard
Setting up Verlet run ...
  Unit style    : lj
  Current step  : 0
  Time step     : 0.005
Per MPI rank memory allocation (min/avg/max) = 3.222 | 3.222 | 3.222 Mbytes
Step Temp E_pair E_mol TotEng Press 
       0            3   -6.7733681            0   -2.2744931   -3.7033504 
      50    1.6842865   -4.8082494            0   -2.2824513    5.5666131 
     100    1.6712577   -4.7875609            0    -2.281301    5.6613913 
     150    1.6444751   -4.7471034            0   -2.2810074    5.8614211 
     200    1.6471542   -4.7509053            0   -2.2807916    5.8805431 
     250    1.6645597   -4.7774327            0   -2.2812174    5.7526089 
Loop time of 1.70512 on 1 procs for 250 steps with 4000 atoms

Performance: 63338.761 tau/day, 146.618 timesteps/s
99.7% CPU use with 1 MPI tasks x 1 OpenMP threads

MPI task timing breakdown:
Section |  min time  |  avg time  |  max time  |%varavg| %total
---------------------------------------------------------------
Pair    | 1.466      | 1.466      | 1.466      |   0.0 | 85.97
Neigh   | 0.14421    | 0.14421    | 0.14421    |   0.0 |  8.46
Comm    | 0.042494   | 0.042494   | 0.042494   |   0.0 |  2.49
Output  | 0.00065868 | 0.00065868 | 0.00065868 |   0.0 |  0.04
Modify  | 0.039628   | 0.039628   | 0.039628   |   0.0 |  2.32
Other   |            | 0.01217    |            |       |  0.71

Nlocal:        4000.00 ave        4000 max        4000 min
Histogram: 1 0 0 0 0 0 0 0 0 0
Nghost:        5506.00 ave        5506 max        5506 min
Histogram: 1 0 0 0 0 0 0 0 0 0
Neighs:        151788.0 ave      151788 max      151788 min
Histogram: 1 0 0 0 0 0 0 0 0 0

Total # of neighbors = 151788
Ave neighs/atom = 37.947000
Neighbor list builds = 12
Dangerous builds not checked
Total wall time: 0:00:01
  1. Run the simulation in parrallel (on front node) and note timesteps/s for this run. Dissuss findings.
mpirun -np 4 lmp -in in.melt
  1. Open an interactive job with 18 cores, and run simulation in parrallel. Note timesteps/s for this run, and discuss related to previous finding.
qsub -I -l nodes=1:ppn=18 -d`pwd`
mpirun -np 18 lmp -in in.melt
exit  # exit interactive job 
  1. Run with OpenMP multithreading (utilize full power of machine)
qsub -I -l nodes=1:ppn=72 -d`pwd`
export OMP_NUM_THREADS=2
mpirun -np 36 lmp -in in.melt
exit
  1. Run with a job script, job.sh, and send to que.
echo '#!/bin/bash
#PBS -N lammps
#PBS -l nodes=1:ppn=72
export OMP_NUM_THREADS=2
cd $PBS_O_WORKDIR
mpirun -np 36 lmp -in in.melt
' > job.sh

qsub job.sh
qstat

Edit the LAMMPS input script

Below, when you are asked to edit a file, you can use nano;

# Hint: You can edit the file with nano
nano in.melt

Save trajectory to disk

  1. In in.melt, uncomment the line (remove the #)
dump           id all atom 50 dump.melt
  1. Run using one of the above methods.
lmp -in in.melt
  1. From Open the dump file with Ovito or VMD (if installed)
ovito dump.melt

Note: This is LAMMPS own dump format. Other dump formats are avalible, like the xyz-format.

Run from final configuration

  1. Add the following line after the run command (the last one) in in.melt
write_data      data.equilibrated
  1. Run in.melt
lmp -in in.melt
  1. Confirm that data.equilibrated was created
ls data.equilibrated
  1. Create a new LAMMPS script that read information in the data file
echo '# Continue simulation

units           lj
atom_style      atomic

pair_style  lj/cut 2.5
read_data       data.equilibrated

neighbor        0.3 bin
neigh_modify    every 20 delay 0 check no

fix             1 all nve

thermo          50
run             250

write_data      data.final
' > in.continue
  1. Continue simulation with something like
lmp -in in.continue

Compute radial distrubution function (rdf)

  1. Copy the script from before
cp in.continue in.rdf
  1. Modify in.rdf: Add the following lines after neigh_modif ... and before fix 1 all nve. See docs.lammps.org/compute_rdf.html and docs.lammps.org/fix_ave_time.html for details.
compute         rdf all rdf 100 1 1 cutoff 2.5
fix             2 all ave/time 1 50 50 c_rdf[*] file rdf.dat mode vector
  1. Run in.rdf
lmp -in in.rdf
  1. Plot RDF (last)
tail -n 100 rdf.dat > rdf_last.dat
xmgrace -block rdf_last.dat -bxy 2:3

Build you own LAMMPS

Note that LAMMPS comes with a lot of packages that may not be included in the build on simon, and that it may not be the latest version. Thus, you may need to make your own build, including the packages you want. See docs.lammps.org/Build.html for a detailed description of how to do this. Here is a quick method for a build on simon with a selection of packages. Start the following commands on Debye (mid-way we move to simon)

# Create and move into a directory for your LAMMPS build
mkdir /net/debye/$USER/programs
cd /net/debye/$USER/programs

# Clone newest source code, and rename using date
git clone https://github.com/lammps/lammps
dir=lammps_`date +%F`
mv lammps $dir

# Start interactive job on simon and move into source dir:
ssh simon
qsub -I -l nodes=1:ppn=72
cd programs/lammps_`date +%F`
cd src

# Make desired packages 
make -j yes-molecule yes-kspace yes-rigid yes-manybody yes-intel yes-extra-fix yes-extra-pair yes-extra-compute
make package-status


# Build for mpi run 
make -j mpi

# You should now have an exicutible in the `src` dir
ls lmp_mpi