-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add LAMMPS plugin #945
Merged
Merged
add LAMMPS plugin #945
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
49212e5
add LAMMPS plugin
njzjz c097b11
fix include path
njzjz e424369
add compatibility
njzjz 4072495
add `make install` to lammps document
njzjz 4d1cffa
update document for built-in mode
njzjz 2de6748
revert troublesome
njzjz f19856b
update docs
njzjz d50523b
Update source/install/build_cc.sh
njzjz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
- [Easy installation methods](#easy-installation-methods) | ||
- [Install from source code](#install-from-source-code) | ||
- [Install i-PI](#install-i-pi) | ||
- [Install third-party packages](#install-third-party-packages) | ||
- [Building conda packages](#building-conda-packages) | ||
|
||
## Easy installation methods | ||
|
@@ -204,6 +204,7 @@ One may add the following arguments to `cmake`: | |
| -DCUDA_TOOLKIT_ROOT_DIR=<value> | Path | Detected automatically | The path to the CUDA toolkit directory. | | ||
| -DUSE_ROCM_TOOLKIT=<value> | `TRUE` or `FALSE` | `FALSE` | If `TRUE`, Build GPU support with ROCM toolkit. | | ||
| -DROCM_ROOT=<value> | Path | Detected automatically | The path to the ROCM toolkit directory. | | ||
| -LAMMPS_SOURCE_ROOT=<value> | Path | - | The path to the LAMMPS source code (later than 8Apr2021). | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't it be |
||
|
||
If the cmake has executed successfully, then | ||
```bash | ||
|
@@ -215,46 +216,40 @@ The option `-j4` means using 4 processes in parallel. You may want to use a diff | |
If everything works fine, you will have the following executable and libraries installed in `$deepmd_root/bin` and `$deepmd_root/lib` | ||
```bash | ||
$ ls $deepmd_root/bin | ||
dp_ipi | ||
dp_ipi dp_ipi_low | ||
$ ls $deepmd_root/lib | ||
libdeepmd_ipi.so libdeepmd_op.so libdeepmd.so | ||
libdeepmd_cc_low.so libdeepmd_ipi_low.so libdeepmd_lmp_low.so libdeepmd_low.so libdeepmd_op_cuda.so libdeepmd_op.so | ||
libdeepmd_cc.so libdeepmd_ipi.so libdeepmd_lmp.so libdeepmd_op_cuda_low.so libdeepmd_op_low.so libdeepmd.so | ||
``` | ||
|
||
### Install LAMMPS's DeePMD-kit module | ||
DeePMD-kit provide module for running MD simulation with LAMMPS. Now make the DeePMD-kit module for LAMMPS. | ||
```bash | ||
cd $deepmd_source_dir/source/build | ||
make lammps | ||
``` | ||
DeePMD-kit will generate a module called `USER-DEEPMD` in the `build` directory. If you need low precision version, move `env_low.sh` to `env.sh` in the directory. Now download the LAMMPS code (`29Oct2020` or later), and uncompress it: | ||
## Install third-party packages | ||
### Install LAMMPS | ||
DeePMD-kit provide module for running MD simulation with LAMMPS. | ||
|
||
DeePMD-kit will generate a module called `USER-DEEPMD` in the `build` directory. If you need low precision version, move `env_low.sh` to `env.sh` in the directory. Now download the LAMMPS code (`8Apr2021` or later), and uncompress it: | ||
```bash | ||
cd /some/workspace | ||
wget https://github.com/lammps/lammps/archive/stable_29Oct2020.tar.gz | ||
tar xf stable_29Oct2020.tar.gz | ||
``` | ||
The source code of LAMMPS is stored in directory `lammps-stable_29Oct2020`. Now go into the LAMMPS code and copy the DeePMD-kit module like this | ||
```bash | ||
cd lammps-stable_29Oct2020/src/ | ||
cp -r $deepmd_source_dir/source/build/USER-DEEPMD . | ||
wget https://github.com/lammps/lammps/archive/patch_30Jul2021.tar.gz | ||
tar xf patch_30Jul2021.tar.gz | ||
``` | ||
Now build LAMMPS | ||
The source code of LAMMPS is stored in directory `lammps-patch_30Jul2021`. Now go into the LAMMPS code and create a directory called `build` | ||
```bash | ||
make yes-kspace | ||
make yes-user-deepmd | ||
make mpi -j4 | ||
mkdir -p lammps-patch_30Jul2021/build/ | ||
cd lammps-patch_30Jul2021/build/ | ||
``` | ||
|
||
If everything works fine, you will end up with an executable `lmp_mpi`. | ||
Now build LAMMPS. Note that `PLUGIN` and `KSPACE` package must be enabled, and `BUILD_SHARED_LIBS` must be set to `yes`. | ||
```bash | ||
./lmp_mpi -h | ||
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} ../cmake | ||
make -j4 | ||
make install | ||
``` | ||
|
||
The DeePMD-kit module can be removed from LAMMPS source code by | ||
If everything works fine, you will end up with an executable `${deepmd_root}/lmp`. | ||
```bash | ||
make no-user-deepmd | ||
${deepmd_root}/lmp -h | ||
``` | ||
|
||
## Install i-PI | ||
### Install i-PI | ||
The i-PI works in a client-server model. The i-PI provides the server for integrating the replica positions of atoms, while the DeePMD-kit provides a client named `dp_ipi` that computes the interactions (including energy, force and virial). The server and client communicates via the Unix domain socket or the Internet socket. A full instruction of i-PI can be found [here](http://ipi-code.org/). The source code and a complete installation instructions of i-PI can be found [here](https://github.com/i-pi/i-pi). | ||
To use i-PI with already existing drivers, install and update using Pip: | ||
```bash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
if (DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) | ||
add_library(lammps_interface INTERFACE) | ||
if (DEFINED LAMMPS_VERSION) | ||
cmake_minimum_required(VERSION 3.11) | ||
include(FetchContent) | ||
FetchContent_Declare(lammps_download | ||
GIT_REPOSITORY https://github.com/lammps/lammps | ||
GIT_TAG ${LAMMPS_VERSION} | ||
) | ||
FetchContent_GetProperties(lammps_download) | ||
if(NOT lammps_download_POPULATED) | ||
FetchContent_Populate(lammps_download) | ||
set(LAMMPS_SOURCE_ROOT ${lammps_download_SOURCE_DIR}) | ||
endif() | ||
endif() | ||
set(LAMMPS_HEADER_DIR ${LAMMPS_SOURCE_ROOT}/src) | ||
message(STATUS "LAMMPS_HEADER_DIR is ${LAMMPS_HEADER_DIR}") | ||
|
||
target_include_directories(lammps_interface INTERFACE ${LAMMPS_HEADER_DIR}) | ||
|
||
find_package(MPI) | ||
if(MPI_FOUND) | ||
set(LAMMPS_MPI_INCLUDE_DIRS ${MPI_CXX_INCLUDE_DIRS}) | ||
target_link_libraries(lammps_interface INTERFACE MPI::MPI_CXX) | ||
else() | ||
# Use LAMMPS serial mpi.h header | ||
target_include_directories(lammps_interface INTERFACE "${LAMMPS_HEADER_DIR}/STUBS") | ||
endif() | ||
|
||
# get_lammps_version | ||
# https://github.com/lammps/lammps/blob/c2a12f97c5f665852fb38fdd4922f7dd2e77a0a1/cmake/Modules/LAMMPSUtils.cmake#L27-L46 | ||
include(${LAMMPS_SOURCE_ROOT}/cmake/Modules/LAMMPSUtils.cmake) | ||
get_lammps_version(${LAMMPS_HEADER_DIR}/version.h LAMMPS_VERSION_NUMBER) | ||
set(LAMMPS_VERSION_NUMBER ${LAMMPS_VERSION_NUMBER} PARENT_SCOPE) | ||
|
||
configure_file("../pair_deepmd.h.in" "${CMAKE_CURRENT_BINARY_DIR}/pair_deepmd.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 | ||
) | ||
|
||
function(_add_lmp_plugin_variant variant_name prec_def) | ||
set (libname "deepmd_lmp${variant_name}") | ||
|
||
add_library(${libname} MODULE ${LMP_SRC}) | ||
|
||
# link: libdeepmd libtensorflow_cc libtensorflow_framework | ||
target_link_libraries (${libname} PUBLIC | ||
lammps_interface | ||
${LIB_DEEPMD_CC}${variant_name} | ||
${TensorFlow_LIBRARY} | ||
${TensorFlowFramework_LIBRARY} | ||
) | ||
target_include_directories(${libname} PRIVATE | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
${CMAKE_CURRENT_SOURCE_DIR}/.. | ||
${TensorFlow_INCLUDE_DIRS} | ||
${LAMMPS_SOURCE_ROOT}/src/PLUGIN | ||
${LAMMPS_SOURCE_ROOT}/src/KSPACE | ||
${LAMMPS_SOURCE_ROOT}/src | ||
) | ||
|
||
set_target_properties( | ||
${libname} | ||
PROPERTIES | ||
INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}" | ||
LINK_FLAGS "-rdynamic" | ||
) | ||
target_compile_definitions(${libname} | ||
PUBLIC ${prec_def} | ||
PRIVATE "LMPPLUGIN" # fix header path | ||
PRIVATE "LAMMPS_VERSION_NUMBER=${LAMMPS_VERSION_NUMBER}" | ||
) | ||
|
||
install(TARGETS ${libname} DESTINATION lib/) | ||
|
||
endfunction() | ||
_add_lmp_plugin_variant("${HIGH_PREC_VARIANT}" "${HIGH_PREC_DEF}") | ||
_add_lmp_plugin_variant("${LOW_PREC_VARIANT}" "${LOW_PREC_DEF}") | ||
|
||
endif() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the built-in mode is not supported by this PR. Then it is a breaking change, because all lammps input scripts have to be changed.
It is ideal to support both built-in and plugin modes. We still need the built-in mode because it is easy to use, one do not need to load the shared lib in every lammps script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Note that I just removed built-in mode in the document, and I'll revert them.