LAMMPS
- pagelastupdated
2023-02-08
LAMMPS is a classical molecular dynamics simulation code with a focus on materials modeling.
Building a basic version of LAMMPS
LAMMPS is typically built based on the specific needs of the simulation. When building LAMMPS one can enable and disable various different packages that enable commands when LAMMPS is run.
LAMMPS has an extensive guide on how to build LAMMPS. The recommended way of building LAMMPS is with CMake.
Below are instructions on how to do a basic build of LAMMPS with OpenMP and MPI parallelizations enabled.
One can obtain LAMMPS source code either from LAMMPS download page or from LAMMPS source repository. Here we’ll be using the version 22Jun2022.
# Obtain source code and go to the code folder
wget https://download.lammps.org/tars/lammps-23Jun2022.tar.gz
tar xf lammps-23Jun2022.tar.gz
cd lammps-23Jun2022
# Create a build folder and go to it
mkdir build
cd build
# Activate CMake and OpenMPI modules needed by LAMMPS
module load cmake gcc/8.4.0 openmpi/4.0.5
# Configure LAMMPS packages and set install folder
cmake ../cmake -D BUILD_MPI=yes -D BUILD_OMP=yes -D CMAKE_INSTALL_PREFIX=../../lammps-mpi-23Jun2022
# Build LAMMPS
make -j 2
# Install LAMMPS
make install
# Go back to starting folder
cd ../..
# Add installed LAMMPS to the executable search path
export PATH=$PATH:$PWD/lammps-mpi-23Jun2022/bin
Now we can verify that we have a working LAMMPS installation with the following command:
echo "info configuration" | srun lmp
The output should look something like this:
srun: job 11839786 queued and waiting for resources
srun: job 11839786 has been allocated resources
LAMMPS (23 Jun 2022 - 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
Info-Info-Info-Info-Info-Info-Info-Info-Info-Info-Info
Printed on Thu Jan 19 17:20:21 2023
LAMMPS version: 23 Jun 2022 / 20220623
OS information: Linux "CentOS Linux 7 (Core)" 3.10.0-1160.71.1.el7.x86_64 x86_64
sizeof(smallint): 32-bit
sizeof(imageint): 32-bit
sizeof(tagint): 32-bit
sizeof(bigint): 64-bit
Compiler: GNU C++ 8.4.0 with OpenMP 4.5
C++ standard: C++11
Active compile time flags:
-DLAMMPS_GZIP
-DLAMMPS_PNG
-DLAMMPS_SMALLBIG
Available compression formats:
Extension: .gz Command: gzip
Extension: .bz2 Command: bzip2
Extension: .xz Command: xz
Extension: .lzma Command: xz
Extension: .lz4 Command: lz4
Installed packages:
Info-Info-Info-Info-Info-Info-Info-Info-Info-Info-Info
Total wall time: 0:00:00
Building a version of LAMMPS with most packages
Many packages in LAMMPS need other external libraries such as BLAS and FFTW libraries. These extra libraries can be given to LAMMPS via flags mentioned in this documentation, but in most cases loading the appropriate modules from the module system is enough for CMake to find the libraries.
To include extra packages in the build one can either use flags mentioned in this documentation or one can use developer maintained CMake presets for installing a collection of packages.
Below is an example that installs LAMMPS with “most packages”-collection enabled:
# Obtain source code and go to the code folder
wget https://download.lammps.org/tars/lammps-23Jun2022.tar.gz
tar xf lammps-23Jun2022.tar.gz
cd lammps-23Jun2022
# Create a build folder and go to it
mkdir build
cd build
# Activate CMake and OpenMPI modules needed by LAMMPS
module load cmake gcc/8.4.0 openmpi/4.0.5 fftw/3.3.10-openmpi-openmp openblas/0.3.17-openmp eigen/3.4.0 ffmpeg/4.3.2 voropp/0.4.6 zstd/1.5.0
# Configure LAMMPS packages and set install folder
cmake ../cmake -C ../cmake/presets/most.cmake -D BUILD_MPI=yes -D BUILD_OMP=yes -D CMAKE_INSTALL_PREFIX=../../lammps-mpi-most-23Jun2022
# Build LAMMPS
make -j 2
# Install LAMMPS
make install
# Go back to starting folder
cd ../..
# Add installed LAMMPS to the executable search path
export PATH=$PATH:$PWD/lammps-mpi-most-23Jun2022/bin
Now we can verify that we have a working LAMMPS installation with the following command:
echo "info configuration" | srun lmp
The output should look something like this:
srun: job 13235690 queued and waiting for resources
srun: job 13235690 has been allocated resources
LAMMPS (23 Jun 2022 - 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
Info-Info-Info-Info-Info-Info-Info-Info-Info-Info-Info
Printed on Tue Feb 07 11:41:05 2023
LAMMPS version: 23 Jun 2022 / 20220623
OS information: Linux "CentOS Linux 7 (Core)" 3.10.0-1160.71.1.el7.x86_64 x86_64
sizeof(smallint): 32-bit
sizeof(imageint): 32-bit
sizeof(tagint): 32-bit
sizeof(bigint): 64-bit
Compiler: GNU C++ 8.4.0 with OpenMP 4.5
C++ standard: C++11
Active compile time flags:
-DLAMMPS_GZIP
-DLAMMPS_PNG
-DLAMMPS_FFMPEG
-DLAMMPS_SMALLBIG
Available compression formats:
Extension: .gz Command: gzip
Extension: .bz2 Command: bzip2
Extension: .xz Command: xz
Extension: .lzma Command: xz
Extension: .lz4 Command: lz4
Installed packages:
ASPHERE BOCS BODY BPM BROWNIAN CG-DNA CG-SDK CLASS2 COLLOID COLVARS COMPRESS
CORESHELL DIELECTRIC DIFFRACTION DIPOLE DPD-BASIC DPD-MESO DPD-REACT
DPD-SMOOTH DRUDE EFF ELECTRODE EXTRA-COMPUTE EXTRA-DUMP EXTRA-FIX
EXTRA-MOLECULE EXTRA-PAIR FEP GRANULAR INTERLAYER KSPACE MACHDYN MANYBODY MC
MEAM MISC ML-IAP ML-SNAP MOFFF MOLECULE OPENMP OPT ORIENT PERI PHONON PLUGIN
POEMS QEQ REACTION REAXFF REPLICA RIGID SHOCK SPH SPIN SRD TALLY UEF VORONOI
YAFF
Info-Info-Info-Info-Info-Info-Info-Info-Info-Info-Info
Total wall time: 0:00:00
Examples
LAMMPS indent-example
Let’s run a simple example from LAMMPS examples. This specific model represents a spherical indenter into a 2D solid.
First, we need to get the example:
# Obtain source code and go to the code folder
wget https://download.lammps.org/tars/lammps-23Jun2022.tar.gz
tar xf lammps-23Jun2022.tar.gz
cd lammps-23Jun2022/examples/indent/
After this we can launch LAMMPS with a slurm script like this:
#!/bin/bash
#SBATCH --time=01:00:00
#SBATCH --mem=2G
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=4
#SBATCH --output=lammps_indent.out
# Load modules used for building the LAMMPS binary
module load cmake gcc/8.4.0 openmpi/4.0.5 fftw/3.3.10-openmpi-openmp openblas/0.3.17-openmp eigen/3.4.0 ffmpeg/4.3.2 voropp/0.4.6 zstd/1.5.0
# Set path to LAMMPS executable
export PATH=$PATH:$PWD/../../../lammps-mpi-most-23Jun2022/bin
# Run simulation
srun lmp < in.indent