2.5. Install LAMMPS#

An AI agent can build LAMMPS with the DeePMD-kit module and Kokkos. DPA4/SeZM and DPA4C use pair_style deepmd/kk; compressed native-spin DPA4C models use pair_style dpa4spin/kk. See Install with an AI agent.

There are two ways to install LAMMPS: the built-in mode and the plugin mode. The built-in mode builds LAMMPS along with the DeePMD-kit and DeePMD-kit will be loaded automatically when running LAMMPS. The plugin mode builds LAMMPS and a plugin separately, so one needs to use plugin load command to load the DeePMD-kit’s LAMMPS plugin library.

2.5.1. Install LAMMPS’s DeePMD-kit module (built-in mode)#

Before following this section, DeePMD-kit C++ interface should have be installed.

DeePMD-kit provides a module for running MD simulations with LAMMPS. Now make the DeePMD-kit module for LAMMPS.

cd $deepmd_source_dir/source/build
make lammps

DeePMD-kit will generate a module called USER-DEEPMD in the build directory, which supports either double or single float precision interface. Now download the LAMMPS code, and uncompress it.

cd /some/workspace
wget https://github.com/lammps/lammps/archive/stable_22Jul2025_update2.tar.gz
tar xf stable_22Jul2025_update2.tar.gz

The source code of LAMMPS is stored in the directory lammps-stable_22Jul2025_update2.

Then, you can build LAMMPS with either make or CMake.

2.5.1.1. With make#

Now go into the LAMMPS code and copy the DeePMD-kit module like this

cd lammps-stable_22Jul2025_update2/src/
cp -r $deepmd_source_dir/source/build/USER-DEEPMD .
make yes-kspace
make yes-extra-fix
make yes-user-deepmd

You can enable any other package you want. Now build LAMMPS

make mpi -j4

If everything works fine, you will end up with an executable lmp_mpi.

./lmp_mpi -h

The DeePMD-kit module can be removed from the LAMMPS source code by

make no-user-deepmd

2.5.1.2. With CMake#

Now go into the LAMMPS directory and create a directory called build:

mkdir -p lammps-stable_22Jul2025_update2/build/
cd lammps-stable_22Jul2025_update2/build/

Patch the LAMMPS CMakeLists.txt file:

echo "include(${deepmd_source_dir}/source/lmp/builtin.cmake)" >> ../cmake/CMakeLists.txt

It’s expected to see one extra line in the end of CMakeLists.txt.

Now build LAMMPS. You can install any other package you want.

cmake -D LAMMPS_INSTALL_RPATH=ON -D BUILD_SHARED_LIBS=yes -D CMAKE_INSTALL_PREFIX=${deepmd_root} -DCMAKE_PREFIX_PATH=${deepmd_root} ../cmake
make -j4
make install

To build the GPU-resident pair styles deepmd/kk and dpa4spin/kk, enable the LAMMPS Kokkos package. The pair styles use the DeePMD C API:

cmake -D PKG_KOKKOS=ON \
    -D LAMMPS_INSTALL_RPATH=ON -D BUILD_SHARED_LIBS=yes \
    -D CMAKE_INSTALL_PREFIX=${deepmd_root} \
    -D CMAKE_PREFIX_PATH=${deepmd_root} ../cmake

If everything works fine, you will end up with an executable ${deepmd_root}/bin/lmp.

${deepmd_root}/bin/lmp -h

2.5.2. Install LAMMPS (plugin mode)#

Starting from 8Apr2021, LAMMPS also provides a plugin mode, allowing one to build LAMMPS and a plugin separately.

Now download the LAMMPS code (8Apr2021 or later), and uncompress it:

cd /some/workspace
wget https://github.com/lammps/lammps/archive/stable_22Jul2025_update2.tar.gz
tar xf stable_22Jul2025_update2.tar.gz

The source code of LAMMPS is stored in the directory lammps-stable_22Jul2025_update2. The directory of the source code should be specified as the CMAKE argument LAMMPS_SOURCE_ROOT during installation of the DeePMD-kit C++ interface. Now go into the LAMMPS directory and create a directory called build

mkdir -p lammps-stable_22Jul2025_update2/build/
cd lammps-stable_22Jul2025_update2/build/

Now build LAMMPS. Note that PLUGIN must be enabled, and BUILD_SHARED_LIBS must be set to yes. You can install any other package you want.

cmake -D PKG_PLUGIN=ON -D LAMMPS_INSTALL_RPATH=ON -D BUILD_SHARED_LIBS=yes -D CMAKE_INSTALL_PREFIX=${deepmd_root} -D CMAKE_INSTALL_LIBDIR=lib -D CMAKE_INSTALL_FULL_LIBDIR=${deepmd_root}/lib ../cmake
make -j4
make install

Configure LAMMPS with PKG_KOKKOS=ON, then configure the DeePMD plugin with DEEPMD_LAMMPS_KOKKOS=ON and Kokkos_DIR pointing to the Kokkos package exported by the LAMMPS build. This registers the GPU-resident pair styles deepmd/kk and dpa4spin/kk; the plugin and built-in integrations use the same C API device-graph interface.

If everything works fine, you will end up with an executable ${deepmd_root}/bin/lmp.

${deepmd_root}/bin/lmp -h

Note

If ${tensorflow_root}, ${deepmd_root}, or the path to TensorFlow Python package if applicable is different from the prefix of LAMMPS, you need to append the library path to RUNPATH of liblammps.so. For example, use patchelf >= 0.13

patchelf --add-rpath "${tensorflow_root}/lib" liblammps.so

2.5.3. MPI for runs on several GPUs#

With the KOKKOS package, each MPI rank of LAMMPS uses one GPU and keeps its atom data in GPU memory, and the ranks exchange atom data at every step. Build LAMMPS and the DeePMD-kit C++ interface against the same MPI library, one that can access GPU memory (CUDA-aware MPI), such as Open MPI with UCX. When LAMMPS detects an MPI library without CUDA support, such as the MPICH package of conda-forge, it turns GPU-aware communication off and copies the positions and forces through host memory at every step. An MPI library that LAMMPS cannot identify is assumed to support CUDA; if it does not, run LAMMPS with -pk kokkos gpu/aware off.

The Open MPI package of conda-forge is built with CUDA support but disables it by default; ompi_info --all | grep opal_built_with_cuda_support shows whether an Open MPI installation was built with it. Install the package in an environment of its own:

conda create -n openmpi -c conda-forge openmpi ucx

Configure LAMMPS and the DeePMD-kit C++ interface in new build directories with both compiler wrappers of that environment, -D MPI_C_COMPILER=${mpi_root}/bin/mpicc -D MPI_CXX_COMPILER=${mpi_root}/bin/mpicxx, where ${mpi_root} is its prefix; CMake finds the MPI of each language separately. Launch a run on several GPUs with the mpirun of that installation, enabling its CUDA support for the launch:

mpirun --mca opal_cuda_support 1 -x UCX_MEMTYPE_CACHE=n -np 2 lmp -k on g 2 -sf kk -in in.lammps

With UCX_MEMTYPE_CACHE=n, UCX queries the memory type of every buffer instead of taking it from a cache that can report a GPU buffer as host memory and make UCX abort.

Launch a run on a single MPI rank without these options: it exchanges no atom data, and the CUDA support adds a memory-type query to every MPI call, which can lengthen the step of a small system by more than 10%.