From 72aaa9b52bdb2b46bf359b5b8baf6f0654b10b53 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 11 Aug 2021 21:21:28 -0400 Subject: [PATCH] add LAMMPS plugin (#945) * add LAMMPS plugin - Breaking changes: update fix_dplr to support lammps/lammps#2560. Old version may be not supported. No idea how to support both versions. - Feature: support LAMMPS's new plugin package. See document for details. - update document and examples for LAMMPS plugin. The old installation method will be still supported, although it's removed from documents. - LAMMPS hasn't released a stable version, but I think it will be released in one or two months. * fix include path * add compatibility * add `make install` to lammps document * update document for built-in mode * revert troublesome * update docs * Update source/install/build_cc.sh --- .github/workflows/build_cc.yml | 16 +---- doc/getting-started.md | 10 ++++ doc/install.md | 42 ++++++++++++-- examples/water/lmp/in.lammps | 2 +- examples/water/lmp/in.plugin.lammps | 28 +++++++++ source/CMakeLists.txt | 10 ---- source/install/build_cc.sh | 3 +- source/install/build_lammps.sh | 32 +--------- source/lmp/CMakeLists.txt | 7 +++ source/lmp/compute_deeptensor_atom.h | 4 ++ source/lmp/env.sh.in | 2 +- source/lmp/fix_dplr.cpp | 9 +++ source/lmp/fix_dplr.h | 5 ++ source/lmp/pair_deepmd.h.in | 4 ++ source/lmp/plugin/CMakeLists.txt | 87 ++++++++++++++++++++++++++++ source/lmp/plugin/deepmdplugin.cpp | 50 ++++++++++++++++ source/lmp/pppm_dplr.cpp | 3 +- source/lmp/pppm_dplr.h | 3 +- 18 files changed, 252 insertions(+), 65 deletions(-) create mode 100644 examples/water/lmp/in.plugin.lammps create mode 100644 source/lmp/plugin/CMakeLists.txt create mode 100644 source/lmp/plugin/deepmdplugin.cpp diff --git a/.github/workflows/build_cc.yml b/.github/workflows/build_cc.yml index d94c49d180..115bdb017f 100644 --- a/.github/workflows/build_cc.yml +++ b/.github/workflows/build_cc.yml @@ -9,14 +9,8 @@ jobs: strategy: matrix: include: - - float_prec: high - variant: cpu - - float_prec: low - variant: cpu - - float_prec: high - variant: cuda - - float_prec: low - variant: cuda + - variant: cpu + - variant: cuda steps: - uses: actions/checkout@master with: @@ -26,12 +20,6 @@ jobs: if: matrix.variant == 'cuda' - run: source/install/build_cc.sh env: - FLOAT_PREC: ${{ matrix.float_prec }} DP_VARIANT: ${{ matrix.variant }} CC: gcc-7 CXX: g++-7 - - run: source/install/build_lammps.sh - env: - FLOAT_PREC: ${{ matrix.float_prec }} - CC: gcc-7 - CXX: g++-7 diff --git a/doc/getting-started.md b/doc/getting-started.md index 607e15ed07..4b0e0a3442 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -417,6 +417,16 @@ Note that the model for MD simulations is required to be compatible with the Dee ### Run MD with LAMMPS +#### Enable DeePMD-kit plugin (plugin mode) + +If you are using the plugin mode, enable DeePMD-kit package in LAMMPS with `plugin` command: + +``` +plugin load path/to/deepmd/lib/libdeepmd_lmp.so +``` + +The built-in mode doesn't need this step. + #### pair_style `deepmd` The DeePMD-kit package provides the pair_style `deepmd` diff --git a/doc/install.md b/doc/install.md index 89c2d4ad2c..4d8168d945 100644 --- a/doc/install.md +++ b/doc/install.md @@ -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,8 @@ 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. | +| -DLAMMPS_VERSION_NUMBER=<value> | Number | `20201029` | Only neccessary for LAMMPS built-in mode. The version number of LAMMPS (yyyymmdd). | +| -DLAMMPS_SOURCE_ROOT=<value> | Path | - | Only neccessary for LAMMPS plugin mode. The path to the LAMMPS source code (later than 8Apr2021). If not assigned, the plugin mode will not be enabled. | If the cmake has executed successfully, then ```bash @@ -215,13 +217,15 @@ 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. +## Install third-party packages +### Install LAMMPS's DeePMD-kit module (built-in mode) +DeePMD-kit provide module for running MD simulation with LAMMPS. Now make the DeePMD-kit module for LAMMPS. If you want to use the plugin mode instead of the built-in mode, you can directly go to the next section. ```bash cd $deepmd_source_dir/source/build make lammps @@ -254,7 +258,33 @@ The DeePMD-kit module can be removed from LAMMPS source code by make no-user-deepmd ``` -## Install i-PI +### Install LAMMPS (plugin mode) +Starting from `8Apr2021`, LAMMPS also provides a plugin mode, allowing one build LAMMPS and a plugin separately. You can skip the section if you are using the built-in mode. + +Now download the LAMMPS code (`8Apr2021` or later), and uncompress it: +```bash +cd /some/workspace +wget https://github.com/lammps/lammps/archive/patch_30Jul2021.tar.gz +tar xf patch_30Jul2021.tar.gz +``` +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 +mkdir -p lammps-patch_30Jul2021/build/ +cd lammps-patch_30Jul2021/build/ +``` +Now build LAMMPS. Note that `PLUGIN` and `KSPACE` package 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} ../cmake +make -j4 +make install +``` + +If everything works fine, you will end up with an executable `${deepmd_root}/lmp`. +```bash +${deepmd_root}/lmp -h +``` + +### 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 diff --git a/examples/water/lmp/in.lammps b/examples/water/lmp/in.lammps index a501a5ab27..81864aad0e 100644 --- a/examples/water/lmp/in.lammps +++ b/examples/water/lmp/in.lammps @@ -12,7 +12,7 @@ mass 1 16 mass 2 2 pair_style deepmd frozen_model.pb -pair_coeff +pair_coeff * * velocity all create 330.0 23456789 diff --git a/examples/water/lmp/in.plugin.lammps b/examples/water/lmp/in.plugin.lammps new file mode 100644 index 0000000000..c27cc54d36 --- /dev/null +++ b/examples/water/lmp/in.plugin.lammps @@ -0,0 +1,28 @@ +# bulk water + +units metal +boundary p p p +atom_style atomic + +neighbor 2.0 bin +neigh_modify every 10 delay 0 check no + +read_data water.lmp +mass 1 16 +mass 2 2 + +# load the plugin at /lib/libdeepmd_lmp.so +plugin load ../../../dp/lib/libdeepmd_lmp.so + +pair_style deepmd frozen_model.pb +pair_coeff * * + +velocity all create 330.0 23456789 + +fix 1 all nvt temp 330.0 330.0 0.5 +timestep 0.0005 +thermo_style custom step pe ke etotal temp press vol +thermo 100 +dump 1 all custom 100 water.dump id type x y z + +run 1000 diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 414b5b1564..7a5600f5f9 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -146,16 +146,6 @@ if (USE_TTM) set(TTM_DEF "-DUSE_TTM") endif (USE_TTM) -# old pppm interface -if(NOT DEFINED OLD_LMP_PPPM) - set(OLD_LMP_PPPM FALSE) -endif(NOT DEFINED OLD_LMP_PPPM) -if (OLD_LMP_PPPM) - set(OLD_LMP_PPPM_DEF "-DOLD_LMP_PPPM") - message(STATUS "Use old lammps pppm interface") -endif() -add_definitions (${OLD_LMP_PPPM_DEF}) - # define build type if ((NOT DEFINED CMAKE_BUILD_TYPE) OR CMAKE_BUILD_TYPE STREQUAL "") set (CMAKE_BUILD_TYPE release) diff --git a/source/install/build_cc.sh b/source/install/build_cc.sh index dafcde7606..16a269404d 100755 --- a/source/install/build_cc.sh +++ b/source/install/build_cc.sh @@ -20,10 +20,9 @@ NPROC=$(nproc --all) BUILD_TMP_DIR=${SCRIPT_PATH}/../build mkdir -p ${BUILD_TMP_DIR} cd ${BUILD_TMP_DIR} -cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DINSTALL_TENSORFLOW=TRUE ${CUDA_ARGS} .. +cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DINSTALL_TENSORFLOW=TRUE ${CUDA_ARGS} -DLAMMPS_VERSION=patch_30Jul2021 -DUSE_TTM=TRUE .. make -j${NPROC} make install #------------------ echo "Congratulations! DeePMD-kit has been installed at ${INSTALL_PREFIX}" - diff --git a/source/install/build_lammps.sh b/source/install/build_lammps.sh index 28002dde6f..c11aa2c733 100755 --- a/source/install/build_lammps.sh +++ b/source/install/build_lammps.sh @@ -1,21 +1,5 @@ set -e -# You need to first run ./build_cc.sh - -if [ -z "$FLOAT_PREC" ] -then - FLOAT_PREC=high -fi - -if [ ${FLOAT_PREC} == "high" ]; then - PREC_DEF="-DHIGH_PREC" - PREC_SUFFIX="" -else - PREC_DEF="-DLOW_PREC" - PREC_SUFFIX="_low" -fi -#------------------ - SCRIPT_PATH=$(dirname $(realpath -s $0)) if [ -z "$INSTALL_PREFIX" ] then @@ -25,33 +9,23 @@ mkdir -p ${INSTALL_PREFIX} echo "Installing LAMMPS to ${INSTALL_PREFIX}" NPROC=$(nproc --all) -#------------------ -# copy lammps plugin -BUILD_TMP_DIR2=${SCRIPT_PATH}/../build -cd ${BUILD_TMP_DIR2} -make lammps - #------------------ BUILD_TMP_DIR=${SCRIPT_PATH}/../build_lammps mkdir -p ${BUILD_TMP_DIR} cd ${BUILD_TMP_DIR} # download LAMMMPS -LAMMPS_VERSION=stable_29Oct2020 +LAMMPS_VERSION=patch_30Jul2021 if [ ! -d "lammps-${LAMMPS_VERSION}" ] then curl -L -o lammps.tar.gz https://github.com/lammps/lammps/archive/refs/tags/${LAMMPS_VERSION}.tar.gz tar vxzf lammps.tar.gz fi -curl -L -o lammps.patch https://github.com/deepmd-kit-recipes/lammps-dp-feedstock/raw/fdd954a1af4fadabe5c0dd2f3bed260a484175a4/recipe/deepmd.patch -cd ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION} -patch -f -p1 < ../lammps.patch || true -mkdir -p ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION}/src/USER-DEEPMD -cp -r ${BUILD_TMP_DIR2}/USER-DEEPMD/* ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION}/src/USER-DEEPMD +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_USER-DEEPMD=ON -D PKG_KSPACE=ON -D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -D CMAKE_CXX_FLAGS="${PREC_DEF} -I${INSTALL_PREFIX}/include -L${INSTALL_PREFIX}/lib -Wl,--no-as-needed -lrt -ldeepmd_cc${PREC_SUFFIX} -ltensorflow_cc -ltensorflow_framework" ../cmake +cmake -C ../cmake/presets/all_off.cmake -D PKG_PLUGIN=ON -D PKG_KSPACE=ON -D BUILD_SHARED_LIBS=yes -D LAMMPS_INSTALL_RPATH=ON -D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} ../cmake make -j${NPROC} make install diff --git a/source/lmp/CMakeLists.txt b/source/lmp/CMakeLists.txt index 2c68352385..bb89a6357b 100644 --- a/source/lmp/CMakeLists.txt +++ b/source/lmp/CMakeLists.txt @@ -1,3 +1,10 @@ +add_subdirectory(plugin) +if (NOT DEFINED LAMMPS_VERSION_NUMBER) + # set the default to 29 Oct 2020 + set(LAMMPS_VERSION_NUMBER 20201029) +endif() +message(STATUS "LAMMPS version is ${LAMMPS_VERSION_NUMBER}") + file(GLOB LMP_HEADER *.h) file(GLOB LMP_SRC *.cpp) file(GLOB LMP_SHSCRIPT *.sh) diff --git a/source/lmp/compute_deeptensor_atom.h b/source/lmp/compute_deeptensor_atom.h index 2499e5fda0..60bafc5d7c 100644 --- a/source/lmp/compute_deeptensor_atom.h +++ b/source/lmp/compute_deeptensor_atom.h @@ -9,7 +9,11 @@ ComputeStyle(deeptensor/atom,ComputeDeeptensorAtom) #include "compute.h" #include "pair_deepmd.h" +#ifdef LMPPLUGIN +#include "DeepTensor.h" +#else #include "deepmd/DeepTensor.h" +#endif namespace LAMMPS_NS { diff --git a/source/lmp/env.sh.in b/source/lmp/env.sh.in index c29519913c..4bfe613f16 100644 --- a/source/lmp/env.sh.in +++ b/source/lmp/env.sh.in @@ -6,6 +6,6 @@ TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"` TF_LIBRARY_PATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -L/g"` TF_RPATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -Wl,-rpath=/g"` -NNP_INC=" -std=c++11 -D@prec_def@ @TTM_DEF@ @OLD_LMP_PPPM_DEF@ -I$TF_INCLUDE_DIRS -I$DEEPMD_ROOT/include/ " +NNP_INC=" -std=c++11 -D@prec_def@ @TTM_DEF@ -DLAMMPS_VERSION_NUMBER=@LAMMPS_VERSION_NUMBER@ -I$TF_INCLUDE_DIRS -I$DEEPMD_ROOT/include/ " NNP_PATH=" -L$TF_LIBRARY_PATH -L$DEEPMD_ROOT/lib" NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_CC@@variant_name@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib" diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index fc633190ec..bfb2b9f543 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -41,7 +41,13 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) efield_fsum_all(4, 0.0), efield_force_flag(0) { +#if LAMMPS_VERSION_NUMBER>=20210702 + // lammps/lammps#2560 + energy_global_flag = 1; + virial_global_flag = 1; +#else virial_flag = 1; +#endif if (strcmp(update->unit_style,"metal") != 0) { error->all(FLERR,"Pair deepmd requires metal unit, please set it by \"units metal\""); @@ -117,7 +123,10 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) int FixDPLR::setmask() { int mask = 0; +#if LAMMPS_VERSION_NUMBER<20210702 + // THERMO_ENERGY removed in lammps/lammps#2560 mask |= THERMO_ENERGY; +#endif mask |= POST_INTEGRATE; mask |= PRE_FORCE; mask |= POST_FORCE; diff --git a/source/lmp/fix_dplr.h b/source/lmp/fix_dplr.h index 6de055529b..cdb5b36b1f 100644 --- a/source/lmp/fix_dplr.h +++ b/source/lmp/fix_dplr.h @@ -10,8 +10,13 @@ FixStyle(dplr,FixDPLR) #include #include "fix.h" #include "pair_deepmd.h" +#ifdef LMPPLUGIN +#include "DeepTensor.h" +#include "DataModifier.h" +#else #include "deepmd/DeepTensor.h" #include "deepmd/DataModifier.h" +#endif #ifdef HIGH_PREC #define FLOAT_PREC double diff --git a/source/lmp/pair_deepmd.h.in b/source/lmp/pair_deepmd.h.in index d2716dc1d2..6c2373e114 100644 --- a/source/lmp/pair_deepmd.h.in +++ b/source/lmp/pair_deepmd.h.in @@ -8,7 +8,11 @@ PairStyle(deepmd,PairDeepMD) #define LMP_PAIR_NNP_H #include "pair.h" +#ifdef LMPPLUGIN +#include "DeepPot.h" +#else #include "deepmd/DeepPot.h" +#endif #include #include diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt new file mode 100644 index 0000000000..9cca8ca771 --- /dev/null +++ b/source/lmp/plugin/CMakeLists.txt @@ -0,0 +1,87 @@ +if (DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) + message(STATUS "enable LAMMPS plugin mode") + 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}") + +else() + message(STATUS "disable LAMMPS plugin mode") +endif() \ No newline at end of file diff --git a/source/lmp/plugin/deepmdplugin.cpp b/source/lmp/plugin/deepmdplugin.cpp new file mode 100644 index 0000000000..ace1dc93bd --- /dev/null +++ b/source/lmp/plugin/deepmdplugin.cpp @@ -0,0 +1,50 @@ +/** +* See https://docs.lammps.org/Developer_plugins.html +*/ +#include "lammpsplugin.h" +#include "version.h" +#include "pair_deepmd.h" +#include "fix_dplr.h" +#include "compute_deeptensor_atom.h" + +using namespace LAMMPS_NS; + +static Pair *pairdeepmd(LAMMPS *lmp) +{ + return new PairDeepMD(lmp); +} + +static Compute *computedeepmdtensoratom(LAMMPS *lmp, int narg, char **arg) +{ + return new ComputeDeeptensorAtom(lmp, narg, arg); +} + +static Fix *fixdplr(LAMMPS *lmp, int narg, char **arg) +{ + return new FixDPLR(lmp, narg, arg); +} + +extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) +{ + lammpsplugin_t plugin; + lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; + + plugin.version = LAMMPS_VERSION; + plugin.style = "pair"; + plugin.name = "deepmd"; + plugin.info = "deepmd pair style v2.0"; + plugin.author = "Han Wang"; + plugin.creator.v1 = (lammpsplugin_factory1 *) &pairdeepmd; + plugin.handle = handle; + (*register_plugin)(&plugin, lmp); + + plugin.style = "compute"; + plugin.info = "compute deeptensor/atom v2.0"; + plugin.creator.v1 = (lammpsplugin_factory1 *) &computedeepmdtensoratom; + (*register_plugin)(&plugin, lmp); + + plugin.style = "fix"; + plugin.info = "fix dplr v2.0"; + plugin.creator.v1 = (lammpsplugin_factory1 *) &fixdplr; + (*register_plugin)(&plugin, lmp); +} \ No newline at end of file diff --git a/source/lmp/pppm_dplr.cpp b/source/lmp/pppm_dplr.cpp index 7b2fbe6e65..cd4e7da2ba 100644 --- a/source/lmp/pppm_dplr.cpp +++ b/source/lmp/pppm_dplr.cpp @@ -28,7 +28,8 @@ enum{FORWARD_IK,FORWARD_AD,FORWARD_IK_PERATOM,FORWARD_AD_PERATOM}; /* ---------------------------------------------------------------------- */ -#ifdef OLD_LMP_PPPM +#if LAMMPS_VERSION_NUMBER<20190201 +// See lammps/lammps#1165 PPPMDPLR::PPPMDPLR(LAMMPS *lmp, int narg, char **arg) : PPPM(lmp, narg, arg) #else diff --git a/source/lmp/pppm_dplr.h b/source/lmp/pppm_dplr.h index 4f22a9c621..df436170f9 100644 --- a/source/lmp/pppm_dplr.h +++ b/source/lmp/pppm_dplr.h @@ -21,7 +21,8 @@ namespace LAMMPS_NS { class PPPMDPLR : public PPPM { public: -#ifdef OLD_LMP_PPPM +#if LAMMPS_VERSION_NUMBER<20190201 +// See lammps/lammps#1165 PPPMDPLR(class LAMMPS *, int, char **); #else PPPMDPLR(class LAMMPS *);