Building LAMMPS using CMAKE with OpenMPI on Rocky Linux 8

What is LAMMPS (briefly)?

LAMMPS is a classical molecular dynamics code with a focus on materials modeling. It’s an acronym for Large-scale Atomic/Molecular Massively Parallel Simulator. More Information on the software, do take a look at https://www.lammps.org/

Where to Download?

You can download the latest stable from Download LAMMPS

Step 1: Ensure Prerequisites are present

Step 2: Download and build LAMMPS

For more information, do take a look at https://docs.lammps.org/Install_tarball.html

$ tar -zxvf lammps-stable.tar.gz
$ cd lammps-2Aug203
$ mkdir build
$ touch setup.sh
$ vim setup.sh

Inside the setup.sh

cmake   -C ../cmake/presets/most.cmake ../cmake             \
-D CMAKE_INSTALL_PREFIX=/usr/local/lammps-2Aug2023 \
-D BUILD_MPI=on \
-D BUILD_SHARED_LIBS=yes \
-D FFT=FFTW3 \
-D FFTW3_INCLUDE_DIRS=${FFTW_INC} \
-D FFTW3_LIBRARIES=${FFTW_LIB}/libfftw3_mpi.a

Notes:
The -C ../cmake/presets/most.cmake command adds the packages that don’t need extra libraries.

Make and Compile……

$ make -j 16 
$ make install

References:

  1. Compiling LAMMPS and using it with Python
  2. Building LAMMPS using CMake

Compiling USER-GFMD to LAMMPS-10Mar21 with OpenMPI and GNU

Prerequisites

  • openmpi-3.1.4
  • gnu-6.5
  • m4-1.4.18
  • gmp-6.1.0
  • mpfr-3.1.4
  • mpc-1.0.3
  • isl-0.18
  • gsl-2.1
  • python-3.6.9
  • fftw-3.3.8

Download the lammps.10Mar2021.tar.gz from https://download.lammps.org/tars/

Step 1: Untar LAMMPS

% tar -zxvf lammps-10Mar2021.tar.gz

Step 2: Go to $LAMMPS_HOME/src. Make Packages. I will only need kspace and USER-GFMD.

% make yes-kspace
% make pi
% make ps

Step 3: Preparing Green’s function molecular dynamics (GFMD) code on LAMMPS. For more information on the website, https://github.com/Atomistica/user-gfmd

% cd $LAMMPS_HOME
% git clone https://github.com/Atomistica/user-gfmd.git

You should see a directory called user-gfmd in your $LAMMPS_HOME. Rename it to uppercase

% mv user-gfmd USER-GFMD

Copy the USER-GDMD to the $LAMMPS_HOME/src and
Make the package

% cp USER-GFMD to src
% make yes-user-gfmd

Step 4: Edit the Makefile.g++_openmpi

% vim $LAMMPS_HOME/src/MAKE/OPTIONS/Makefile.g++_openmpi
FFT_INC =       -DFFT_FFTW3 -I/usr/local/fftw-3.3.8-gcc6/include
FFT_PATH =      -L/usr/local/fftw-3.3.8-gcc6/lib
FFT_LIB =        -lfftw3

The -DFFT_FFTW3 was important or I will get error like

mpicxx -std=c++11 -g -O3 -DLAMMPS_GZIP -DGFMD_FFTW3 -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1 -I/usr/local/fftw-3.3.8-gcc6/include -c ../nonperiodic_stiffness.cpp
../nonperiodic_stiffness.cpp:199:4: error: #error NonperiodicStiffnessKernel requires FFTW3
#error NonperiodicStiffnessKernel requires FFTW3
^~~~~
make[1]: *** [nonperiodic_stiffness.o] Error 1

Step 5: Compile LAMMPS

% make clean-all
% make g++_openmpi

You should have binary called lmp_g++_openmpi. Do a softlink

% ln -s lmp_g++_openmpi lammps

Make and Run USER-GFMD Units Tests

% cd src/USER-GFMD/
% make unittests
% ./unittests
[==========] Running 23 tests from 5 test cases.
[----------] Global test environment set-up.
[----------] 5 tests from CrystalSurfaceTest
[ RUN      ] CrystalSurfaceTest.fcc100
[       OK ] CrystalSurfaceTest.fcc100 (0 ms)
[ RUN      ] CrystalSurfaceTest.fcc100_supercell
[       OK ] CrystalSurfaceTest.fcc100_supercell (11 ms)
[ RUN      ] CrystalSurfaceTest.reverse_indices
[       OK ] CrystalSurfaceTest.reverse_indices (0 ms)
[ RUN      ] CrystalSurfaceTest.fcc100_3nn
[       OK ] CrystalSurfaceTest.fcc100_3nn (0 ms)
[ RUN      ] CrystalSurfaceTest.fcc100_neighbor_shells
[       OK ] CrystalSurfaceTest.fcc100_neighbor_shells (0 ms)
[----------] 5 tests from CrystalSurfaceTest (12 ms total)
.....
.....
.....

Run Tests

% cd src/USER-GFMD/tests
% sh run_tests.sh ../../lmp_g++_openmpi

I had some errors, but it did not look critical. Tests were run without failures

.....
.....
TEST_Hertz_sc100_128x128_a0_1.3
eval.py:83: RuntimeWarning: invalid value encountered in sqrt
  pa_xy = np.where(r_xy<a, p0*np.sqrt(1-(r_xy/a)**2), np.zeros_like(r_xy))
.ok.
TEST_restart
.ok.
Ran 20 tests; 0 failures, 20 successes.

Error: Too many elements extracted from the MEAM Library on LAMMPS

If you encounter an errors similar

ERROR: Too many elements extracted from MEAM library (current limit:5 ). Increase 'maxelt' in meam.h and recompile. 
Last command: pair_coeff     * * library.alloy2.meam .............................

Move to /usr/local/lammps-29Oct20/src/USER-MEAMC/meam.h and /usr/local/lammps-29Oct20/src/meam.h. Edit line 22. The default value is #define maxelt 5

#definte maxelt 6

Recompile the lammps. Go to /usr/local/lammps-29Oct20/src

% make clean-all
% make g++_openmpi -j 16

References

  1. Compiling LAMMPS-15Jun20 with GNU 6 and OpenMPI 3

No MEAM parameter file in pair coefficients Errors in LAMMPS

If you are encountering errors like, you may want to check

ERROR: No MEAM parameter file in pair coefficients (../pair_meamc.cpp:243)

When a pair_coeff command using a potential file is specified, LAMMPS looks for the potential file in 2 places. First it looks in the location specified. E.g. if the file is specified as “niu3.eam”, it is looked for in the current working directory. If it is specified as “../potentials/niu3.eam”, then it is looked for in the potentials directory, assuming it is a sister directory of the current working directory. If the file is not found, it is then looked for in one of the directories specified by the LAMMPS_POTENTIALS environment variable. Thus if this is set to the potentials directory in the LAMMPS distribution, then you can use those files from anywhere on your system, without copying them into your working directory. Environment variables are set in different ways for different shells. Here are example settings for

 export LAMMPS_POTENTIALS=/path/to/lammps/potentials

For more information, do read LAMMPS Documentation https://docs.lammps.org/stable/pair_coeff.html

KIM_SimulatorHeaders.h: No such file or directory during compilation of lammps

If you encounter an error such as the one below during compilation for lammps such as written in Compiling LAMMPS-15Jun20 with GNU 6 and OpenMPI 3

After running the command,

% make g++_openmpi -j 16

you may encounter

In file included from ../style_pair.h:112:0,
                 from ../force.cpp:20:
../pair_kim.h:70:34: fatal error: KIM_SimulatorHeaders.h: No such file or directory
 #include "KIM_SimulatorHeaders.h"

This is due to one of the a header file not found at /usr/local/lammps-29Oct20/src/pair_kim.h. At line 70, modify the actual location of KIM_SimulatorHeaders.h

/* #include "KIM_SimulatorHeaders.h" */
#include "/usr/local/lammps-29Oct20/lib/kim/kim-api-2.1.3/build/installed-kim-api-2.1.3/include/kim-api/KIM_SimulatorHeaders.h"

Again, after running the command,

% make g++_openmpi -j 16

you may encounter

mpicxx -g -O3  -DLAMMPS_GZIP -I../../lib/colvars -DLMP_USER_OMP -I../../lib/voronoi/includelink -DLMP_PYTHON -I../../lib/poems -DLMP_MPIIO -I../../lib/message/cslib/src -I../../lib/latte/includelink -DLMP_KOKKOS  -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1     -I/usr/include/python2.7 -I/usr/include/python2.7   -I./ -I../../lib/kokkos/core/src -I../../lib/kokkos/containers/src -I../../lib/kokkos/algorithms/src --std=c++11 -fopenmp -I./ -I../../lib/kokkos/core/src -I../../lib/kokkos/containers/src -I../../lib/kokkos/algorithms/src   -DLMP_KIM_CURL   -c ../kim_param.cpp
../kim_param.cpp:73:34: fatal error: KIM_SimulatorHeaders.h: No such file or directory
 #include "KIM_SimulatorHeaders.h"

This is due to one of the a header file not found at /usr/local/lammps-29Oct20/src/kim_param.cpp. At line 73, modify the actual location of KIM_SimulatorHeaders.h

/* #include "KIM_SimulatorHeaders.h" */
#include "/usr/local/lammps-29Oct20/lib/kim/kim-api-2.1.3/build/installed-kim-api-2.1.3/include/kim-api/KIM_SimulatorHeaders.h"

There might be the same issue for kim_init.cpp, fix_store_kim.cpp, pair.kim.h etc

voro++.hh: No such file or directory during compilation of lammps with voronoi

If you encounter an error such as the one below during compilation for lammps such as written in Compiling LAMMPS-15Jun20 with GNU 6 and OpenMPI 3

../compute_voronoi_atom.h:24:21: fatal error: voro++.hh: No such file or directory

This is due to one of the a header file not found at /usr/local/lammps-29Oct20/src/compute_voronoi_atom.cpp. To resolve the issue, do take a look at Line 23 or 24 and edit to the path where you place voro++.hh

/* #include <voro++.hh> */
#include "/usr/local/lammps-29Oct20/lib/voronoi/voro++-0.4.6/src/voro++.hh"

References:

  1. https://sourceforge.net/p/lammps/mailman/message/31832584/

Compiling LAMMPS-15Jun20 with GNU 6 and OpenMPI 3

Prerequisites

openmpi-3.1.4
gnu-6.5
m4-1.4.18
gmp-6.1.0
mpfr-3.1.4
mpc-1.0.3
isl-0.18
gsl-2.1
lammps-15Jun20

Download the latest tar.gz from https://lammps.sandia.gov/

Step 1: Untar LAMMPS

% tar -zxvf lammps-stable.tar.gz

Step 2: Go to $LAMMPS_HOME/src. Make Standard Packages

% cd src
% make yes-standard
% make no-gpu
% make no-mscg

Step 3: Compile message libraries

% cd lammps-15Jun20/lib/message/cslib/src
% make lib_parallel zmq=no

Copy and rename the produced cslib/src/libcsmpi.a or libscnompi.a file to cslib/src/libmessage.a

% cp cslib/src/libcsmpi.a cslib/src/libmessage.a

Copy either lammps-15Jun20/lib/message/Makefile.lammps.zmq or Makefile.lammps.nozmq to lib/message/Makefile.lammps

% cp Makefile.lammps.nozmq Makefile.lammps

Step 4: Compile poems

% cd lammps-15Jun20/lib/poems
% make -f Makefile.g++

Step 5: Compile latte
Download LATTE code and unpack the tarball either in this /lib/latte directory

% git clone https://github.com/lanl/LATTE

Inside lammps-15Jun20/lib/latte/LATTE
Modify the makefile.CHOICES according to your system architecture and compilers

% cd lammps-15Jun20/lib/latte/LATTE
% cp makefile.CHOICES makefile.CHOICES.gfort
% make
% cd lammps-15Jun20/lib/latte
% ln -s ./LATTE/src includelink
% ln -s ./LATTE liblink
% ln -s ./LATTE/src/latte_c_bind.o filelink.o
% cp Makefile.lammps.gfortran Makefile.lammps

Step 6. Compile Voronoi

Download voro++-0.4.6.tar.gz from http://math.lbl.gov/voro++/download/
Untar the voro++-0.4.6.tar.gz inside lammps-15Jun20/lib/voronoi/

% tar -zxvf voro++-0.4.6.tar.gz
% cd lammps-15Jun20/lib/voronoi/voro++-0.4.6
% make

Step 7: Compile kim

Download kim from https://openkim.org/doc/usage/obtaining-models . The current version is  kim-api-2.1.3.txz

Download at /lammps-15Jun20/lib/kim

% cd lammps-15Jun20/lib/kim
% tar Jxvf kim-api-2.1.3.txz
% cd kim-api-2.1.3
% mkdir build
% cd build
% cmake .. -DCMAKE_INSTALL_PREFIX=${PWD}/../../installed-kim-api-2.1.3
% make -j2
% make install
% cd /lammps-15Jun20/lib/kim/installed-kim-api-2.1.3/
% source ${PWD}/kim-api-X2.1.3/bin/kim-api-activate
% kim-api-collections-management install system EAM_ErcolessiAdams_1994_Al__MO_324507536345_002

Step 8: Compile USER-COLVARS

% cd lammps-15Jun/lib/colvars
% make -f Makefile.g++

Step 9: Check Packages Status

% make package-status
[root@hpc-gekko1 src]# make package-status
Installed YES: package ASPHERE
Installed YES: package BODY
Installed YES: package CLASS2
Installed YES: package COLLOID
Installed YES: package COMPRESS
Installed YES: package CORESHELL
Installed YES: package DIPOLE
Installed  NO: package GPU
Installed YES: package GRANULAR
Installed YES: package KIM
.....
.....

Step 9a: To Activate Standard Package

% make yes-standard

Step 9b: To activate USER-COLVARS, USER-OMP

% make yes-user-colvars
% make yes-user-omp

Step 9c: To deactivate GPGPU

% make no-gpu

Step 10: Finally Compile LAMMPS

% cd lammps-15Jun20/src
% make g++_openmpi -j 16

You should have binary called lmp_g++_openmpi
Do a softlink

ln -s lmp_g++_openmpi lammps