Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions doc/install/install-lammps.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ cd /some/workspace
wget https://github.com/lammps/lammps/archive/stable_2Aug2023_update1.tar.gz
tar xf stable_2Aug2023_update1.tar.gz
```
The source code of LAMMPS is stored in the directory `lammps-stable_2Aug2023_update1`. Now go into the LAMMPS code and copy the DeePMD-kit module like this
The source code of LAMMPS is stored in the directory `lammps-stable_2Aug2023_update1`.

Then, you can [build LAMMPS](https://docs.lammps.org/Build.html) with either make or CMake.

### With make

Now go into the LAMMPS code and copy the DeePMD-kit module like this
```bash
cd lammps-stable_2Aug2023_update1/src/
cp -r $deepmd_source_dir/source/build/USER-DEEPMD .
Expand All @@ -40,6 +46,35 @@ The DeePMD-kit module can be removed from the LAMMPS source code by
make no-user-deepmd
```

### With CMake

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

```bash
mkdir -p lammps-stable_2Aug2023_update1/build/
cd lammps-stable_2Aug2023_update1/build/
```

Patch the LAMMPS `CMakeLists.txt` file:

```bash
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.
```bash
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
```

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

## Install LAMMPS (plugin mode)
Starting from `8Apr2021`, LAMMPS also provides a plugin mode, allowing one to build LAMMPS and a plugin separately.

Expand All @@ -56,9 +91,9 @@ The source code of LAMMPS is stored in the directory `lammps-stable_2Aug2023_upd
mkdir -p lammps-stable_2Aug2023_update1/build/
cd lammps-stable_2Aug2023_update1/build/
```
Now build LAMMPS. Note that `PLUGIN` and `KSPACE` packages must be enabled, and `BUILD_SHARED_LIBS` must be set to `yes`. You can install any other package you want.
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.
```bash
cmake -D PKG_PLUGIN=ON -D PKG_KSPACE=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
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
```
Expand Down
2 changes: 1 addition & 1 deletion source/install/build_lammps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fi
cd ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION}
mkdir -p ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION}/build
cd ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION}/build
cmake -C ../cmake/presets/all_off.cmake -D PKG_PLUGIN=ON -D PKG_KSPACE=ON -D PKG_MOLECULE=ON -DLAMMPS_EXCEPTIONS=yes -D BUILD_SHARED_LIBS=yes -D LAMMPS_INSTALL_RPATH=ON -D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -D CMAKE_INSTALL_LIBDIR=lib -D CMAKE_INSTALL_FULL_LIBDIR=${INSTALL_PREFIX}/lib ../cmake
cmake -C ../cmake/presets/all_off.cmake -D PKG_PLUGIN=ON -D PKG_MOLECULE=ON -DLAMMPS_EXCEPTIONS=yes -D BUILD_SHARED_LIBS=yes -D LAMMPS_INSTALL_RPATH=ON -D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -D CMAKE_INSTALL_LIBDIR=lib -D CMAKE_INSTALL_FULL_LIBDIR=${INSTALL_PREFIX}/lib ../cmake

make -j${NPROC}
make install
Expand Down
31 changes: 31 additions & 0 deletions source/lmp/builtin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file should be included in the end of
# ${LAMMPS_SOURCE_DIR}/cmake/CMakeLists.txt
# include(/path/to/deepmd_source/source/lmp/builtin.cmake)

# assume LAMMPS CMake file has been executed, so these target/variables exist:
# lammps LAMMPS_SOURCE_DIR get_lammps_version

get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION_NUMBER)

configure_file("${CMAKE_CURRENT_LIST_DIR}/deepmd_version.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/deepmd_version.h" @ONLY)

file(GLOB DEEPMD_LMP_SRC ${CMAKE_CURRENT_LIST_DIR}/*.cpp)

find_package(DeePMD REQUIRED)
target_sources(
lammps
PRIVATE ${DEEPMD_LMP_SRC}
${LAMMPS_SOURCE_DIR}/KSPACE/pppm.cpp # for pppm_dplr
${LAMMPS_SOURCE_DIR}/KSPACE/fft3d.cpp
${LAMMPS_SOURCE_DIR}/KSPACE/fft3d_wrap.cpp
${LAMMPS_SOURCE_DIR}/KSPACE/remap.cpp
${LAMMPS_SOURCE_DIR}/KSPACE/remap_wrap.cpp
${LAMMPS_SOURCE_DIR}/EXTRA-FIX/fix_ttm.cpp # for ttm
)
target_link_libraries(lammps PUBLIC DeePMD::deepmd_c)
target_include_directories(
lammps PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}
${LAMMPS_SOURCE_DIR}/KSPACE ${LAMMPS_SOURCE_DIR}/EXTRA-FIX)
target_compile_definitions(
lammps PRIVATE "LAMMPS_VERSION_NUMBER=${LAMMPS_VERSION_NUMBER}")
13 changes: 10 additions & 3 deletions source/lmp/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION)
configure_file("../deepmd_version.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/deepmd_version.h" @ONLY)

file(GLOB LMP_SRC deepmdplugin.cpp ../*.cpp
${LAMMPS_SOURCE_ROOT}/src/kspace.cpp # for pppm_dplr
${LAMMPS_SOURCE_ROOT}/src/KSPACE/pppm.cpp)
file(
GLOB
LMP_SRC
deepmdplugin.cpp
../*.cpp
${LAMMPS_SOURCE_ROOT}/src/KSPACE/pppm.cpp # for pppm_dplr
${LAMMPS_SOURCE_ROOT}/src/KSPACE/fft3d.cpp
${LAMMPS_SOURCE_ROOT}/src/KSPACE/fft3d_wrap.cpp
${LAMMPS_SOURCE_ROOT}/src/KSPACE/remap.cpp
${LAMMPS_SOURCE_ROOT}/src/KSPACE/remap_wrap.cpp)
if(LAMMPS_VERSION_NUMBER GREATER 20210831)
list(APPEND LMP_SRC ${LAMMPS_SOURCE_ROOT}/src/EXTRA-FIX/fix_ttm.cpp
)# for ttm
Expand Down