Skip to content

Commit 745452e

Browse files
authored
implementation of esolver_dp and esolver_lj (#1406)
* feature: make dir for HS matrix output in md * refactor: add para istep for afterscf() * feature: md output HS matrix in a subdir * fix: fix typo * Refactor: use esolver_lj to classic MD * fix: fix esolver_lj * feature: esolver_dp for MD * update makefile for DP potential * fix: fix Makefile and DP virial * fix: fix memory leak of DP * update Makefile for DP * fix: update head file for DP * update CmakeLists.txt for DP potential * remove useless functions and __LCAO in module_md * add para for DP model * fix: fix init of ESolver_DP * update docs and tests for esolver lj and dp * docs: update docs for esolver_dp
1 parent f2d1913 commit 745452e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3133
-12510
lines changed

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ if(ENABLE_LIBXC)
249249
endif()
250250
endif()
251251

252+
if(DEFINED DeePMD_DIR)
253+
add_compile_definitions(
254+
__DPMD
255+
HIGH_PREC
256+
)
257+
add_compile_options(-Wl,--no-as-needed)
258+
find_package(DeePMD REQUIRED)
259+
include_directories(${DeePMD_DIR}/include)
260+
target_link_libraries(${ABACUS_BIN_NAME}
261+
DeePMD::deepmd_cc
262+
DeePMD::deepmd_op
263+
DeePMD::deepmd_op_cuda
264+
DeePMD::tensorflow_cc
265+
)
266+
if(NOT DEFINED TensorFlow_DIR)
267+
message(FATAL_ERROR "Please define TensorFlow_DIR!")
268+
endif()
269+
endif()
270+
271+
if(DEFINED TensorFlow_DIR)
272+
include_directories(${TensorFlow_DIR}/include)
273+
if(NOT DEFINED DeePMD_DIR)
274+
message(FATAL_ERROR "Please define DeePMD_DIR!")
275+
endif()
276+
endif()
277+
252278
add_compile_definitions(
253279
__EXX
254280
__FFTW3

docs/advanced/input_files/input-main.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
- [Molecular dynamics](#molecular-dynamics)
4444

45-
[md_type](#md_type) | [md_nstep](#md_nstep) | [md_ensolver](#md_ensolver) | [md_restart](#md_restart) | [md_dt](#md_dt) | [md_tfirst, md_tlast](#md_tfirst-md_tlast) | [md_dumpfreq](#md_dumpfreq) | [md_restartfreq](#md_restartfreq) | [md_seed](#md_seed) | [md_tfreq](#md_tfreq) | [md_mnhc](#md_mnhc) | [lj_rcut](#lj_rcut) | [lj_epsilon](#lj_epsilon) | [lj_sigma](#lj_sigma) | [msst_direction](#msst_direction) | [msst_vel](#msst_vel) | [msst_vis](#msst_vis) | [msst_tscale](#msst_tscale) | [msst_qmass](#msst_qmass) | [md_damp](#md_damp)
45+
[md_type](#md_type) | [md_nstep](#md_nstep) | [md_ensolver](#md_ensolver) | [md_restart](#md_restart) | [md_dt](#md_dt) | [md_tfirst, md_tlast](#md_tfirst-md_tlast) | [md_dumpfreq](#md_dumpfreq) | [md_restartfreq](#md_restartfreq) | [md_seed](#md_seed) | [md_tfreq](#md_tfreq) | [md_mnhc](#md_mnhc) | [lj_rcut](#lj_rcut) | [lj_epsilon](#lj_epsilon) | [lj_sigma](#lj_sigma) | [pot_file](#pot_file) | [msst_direction](#msst_direction) | [msst_vel](#msst_vel) | [msst_vis](#msst_vis) | [msst_tscale](#msst_tscale) | [msst_qmass](#msst_qmass) | [md_damp](#md_damp)
4646

4747
- [vdW correction](#vdw-correction)
4848

@@ -1380,6 +1380,12 @@ temperature will fluctuate violently; if it is too small, the temperature will t
13801380
- **Description**: The value of sigma for Leonard Jones potential (angstrom).
13811381
- **Default**: 3.405 (for He)
13821382
1383+
### pot_file
1384+
1385+
- **Type**: String
1386+
- **Description**: The filename of potential files for CMD such as DP.
1387+
- **Default**: graph.pb
1388+
13831389
### msst_direction
13841390
13851391
- **Type**: Integer

docs/advanced/install.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ If DeePKS feature is requied for [DeePKS-kit](https://github.com/deepmodeling/de
2626
cmake -B build -DENABLE_DEEPKS=1 -DTorch_DIR=~/libtorch/share/cmake/Torch/ -Dlibnpy_INCLUDE_DIR=~/libnpy/include
2727
```
2828

29+
## Build with DeePMD-kit
30+
If the Deep Potential model is employed in Molecule Dynamics calculations, the following prerequisites and steps are needed:
31+
32+
### Extra prerequisites
33+
34+
- [DeePMD-kit](https://github.com/deepmodeling/deepmd-kit)
35+
- [TensorFlow](https://www.tensorflow.org/)
36+
37+
```bash
38+
cmake -B build -DDeePMD_DIR=~/deepmd-kit -DTensorFlow_DIR=~/tensorflow
39+
```
40+
2941
## Build Unit Tests
3042
To build tests for ABACUS, define `BUILD_TESTING` flag. You can also specify path to local installation of [Googletest](https://github.com/google/googletest) by setting `GTEST_DIR` flags. If not found in local, the configuration process will try to download it automatically.
3143

@@ -60,6 +72,10 @@ CC = mpiicpc
6072
# g++: compile gnu serial version
6173
# make: FFTW_DIR, OPENBLAS_LIB_DIR, SCALAPACK_LIB_DIR, ELPA_DIR, ELPA_INCLUDE_DIR, CEREAL_DIR must also be set.
6274
# make pw: FFTW_DIR, OPENBLAS_LIB_DIR must be set.
75+
76+
# GPU = OFF #We do not support GPU yet
77+
# OFF: do not use GPU
78+
# CUDA: use CUDA
6379
#======================================================================
6480

6581
#------- FOR INTEL COMPILER ------------
@@ -96,6 +112,17 @@ CEREAL_DIR = /public/soft/cereal
96112
# LIBXC_DIR = /public/soft/libxc
97113
# directory of libxc(>5.1.7), which contains include and lib/libxc.a
98114
# add LIBXC_DIR to use libxc to compile ABACUS
115+
116+
# DeePMD_DIR = ${deepmd_root}
117+
# TensorFlow_DIR = ${tensorflow_root}
118+
# add them to use DEEPMD
119+
120+
# NP = 14 # It is not supported. use make -j14 or make -j to parallelly compile
121+
122+
# DEBUG = OFF
123+
# Only for developers
124+
# ON: use gnu compiler and check segmental defaults
125+
# OFF: nothing
99126
#======================================================================
100127
```
101128

@@ -164,3 +191,11 @@ To compile ABACUS with DEEPKS, you need to define `LIBTORCH_DIR` and `LIBNPY_DIR
164191
make LIBTORCH_DIR=/opt/libtorch/ LIBNPY_DIR=/opt/libnpy/
165192
```
166193
directly.
194+
195+
### Add DeePMD-kit Support
196+
197+
To compile ABACUS with DeePMD-kit, you need to define `DeePMD_DIR` and `TensorFlow_DIR` in the file `Makefile.vars` or use
198+
```makefile
199+
make DeePMD_DIR=~/deepmd-kit TensorFlow_DIR=~/tensorflow
200+
```
201+
directly.

docs/advanced/md.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ By setting `calculation` to be `md` or `sto-md`, ABACUS currently provides six d
1313

1414
Furthermore, ABACUS also provides a [list of keywords](./input_files/input-main.md#molecular-dynamics) to control relevant parmeters used in MD simulations.
1515

16+
To employ CMD calculations, `md_ensolver` should be set to be `LJ` or `DP`.
17+
If DP model is selected, the filename of DP model is specified by keyword `pot_file`.
18+
1619
[Examples](https://github.com/deepmodeling/abacus-develop/tree/develop/examples/md/lcao_gammaonly_Sn64) of MD simulations are also provided.
1720
There are six INPUT files corresponding to six different MD evolution methods in the directory.
1821
For examlpe, `INPUT_0` shows how to employ the NVE simulation.

modules/FindDeePMD.cmake

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
###############################################################################
2+
# - Find DeePMD
3+
# Find the native DeePMD headers and libraries.
4+
#
5+
# DeePMD_FOUND - True if lib is found.
6+
# DeePMD_LIBRARIES - List of libraries
7+
# DeePMD_INCLUDE_DIR - Where to find DeePMD headers.
8+
#
9+
10+
find_path(DeePMD_INCLUDE_DIR
11+
deepmd/DeepPot.h
12+
HINTS ${DeePMD_DIR}
13+
PATH_SUFFIXES "include"
14+
)
15+
find_library(deepmd_cc
16+
NAMES deepmd_cc
17+
HINTS ${DeePMD_DIR}
18+
PATH_SUFFIXES "lib"
19+
)
20+
find_library(deepmd_op
21+
NAMES deepmd_op
22+
HINTS ${DeePMD_DIR}
23+
PATH_SUFFIXES "lib"
24+
)
25+
find_library(deepmd_op_cuda
26+
NAMES deepmd_op_cuda
27+
HINTS ${DeePMD_DIR}
28+
PATH_SUFFIXES "lib"
29+
)
30+
find_library(tensorflow_cc
31+
NAMES tensorflow_cc
32+
HINTS ${DeePMD_DIR}
33+
PATH_SUFFIXES "lib"
34+
)
35+
36+
# Handle the QUIET and REQUIRED arguments and
37+
# set DeePMD_FOUND to TRUE if all variables are non-zero.
38+
include(FindPackageHandleStandardArgs)
39+
find_package_handle_standard_args(DeePMD DEFAULT_MSG deepmd_cc deepmd_op deepmd_op_cuda tensorflow_cc DeePMD_INCLUDE_DIR)
40+
41+
# Copy the results to the output variables and target.
42+
if(DeePMD_FOUND)
43+
#set(DeePMD_LIBRARIES ${DeePMD_LIBRARY})
44+
set(DeePMD_INCLUDE_DIR ${DeePMD_INCLUDE_DIR})
45+
46+
if(NOT TARGET DeePMD::deepmd_cc)
47+
add_library(DeePMD::deepmd_cc UNKNOWN IMPORTED)
48+
set_target_properties(DeePMD::deepmd_cc PROPERTIES
49+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
50+
IMPORTED_LOCATION "${deepmd_cc}"
51+
INTERFACE_INCLUDE_DIRECTORIES "${DeePMD_INCLUDE_DIR}")
52+
endif()
53+
if(NOT TARGET DeePMD::deepmd_op)
54+
add_library(DeePMD::deepmd_op UNKNOWN IMPORTED)
55+
set_target_properties(DeePMD::deepmd_op PROPERTIES
56+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
57+
IMPORTED_LOCATION "${deepmd_op}"
58+
INTERFACE_INCLUDE_DIRECTORIES "${DeePMD_INCLUDE_DIR}")
59+
endif()
60+
if(NOT TARGET DeePMD::deepmd_op_cuda)
61+
add_library(DeePMD::deepmd_op_cuda UNKNOWN IMPORTED)
62+
set_target_properties(DeePMD::deepmd_op_cuda PROPERTIES
63+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
64+
IMPORTED_LOCATION "${deepmd_op_cuda}"
65+
INTERFACE_INCLUDE_DIRECTORIES "${DeePMD_INCLUDE_DIR}")
66+
endif()
67+
if(NOT TARGET DeePMD::tensorflow_cc)
68+
add_library(DeePMD::tensorflow_cc UNKNOWN IMPORTED)
69+
set_target_properties(DeePMD::tensorflow_cc PROPERTIES
70+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
71+
IMPORTED_LOCATION "${tensorflow_cc}"
72+
INTERFACE_INCLUDE_DIRECTORIES "${DeePMD_INCLUDE_DIR}")
73+
endif()
74+
endif()
75+
76+
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${DeePMD_INCLUDE_DIR})
77+
78+
mark_as_advanced(DeePMD_INCLUDE_DIR deepmd_cc deepmd_op deepmd_op_cuda tensorflow_cc)

source/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ ifdef LIBTORCH_DIR
115115
endif
116116
endif
117117

118+
ifdef DeePMD_DIR
119+
HONG += -D__DPMD -DHIGH_PREC
120+
OPTS += -Wl,--no-as-needed
121+
##==========================
122+
## DeePMD-kit package
123+
##==========================
124+
DeeP_LIB_DIR = ${DeePMD_DIR}/lib
125+
LIBS += -L${DeeP_LIB_DIR} -ldeepmd_cc -ldeepmd_op -ldeepmd_op_cuda -Wl,-rpath=${DeeP_LIB_DIR}
126+
DeeP_INCLUDE_DIR = ${DeePMD_DIR}/include
127+
INCLUDES += -I${DeeP_INCLUDE_DIR}
128+
129+
#==========================
130+
# TensorFlow package
131+
#==========================
132+
TensorFlow_LIB_DIR = ${TensorFlow_DIR}/lib
133+
LIBS += -L${TensorFlow_LIB_DIR} -ltensorflow_cc -Wl,-rpath=${TensorFlow_LIB_DIR}
134+
TensorFlow_INCLUDE_DIR = ${TensorFlow_DIR}/include
135+
INCLUDES += -I${TensorFlow_INCLUDE_DIR}
136+
endif
137+
118138
include Makefile.Objects
119139

120140
#==========================

source/Makefile.vars

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ CC = mpiicpc
2121

2222

2323
#------- FOR INTEL COMPILER ------------
24-
ELPA_DIR = /pubilc/soft/elpa_21.05.002
24+
ELPA_DIR = /public/soft/elpa_21.05.002
2525
ELPA_INCLUDE_DIR = ${ELPA_DIR}/include/elpa-2021.05.002
2626
# directory of elpa, which contains include and lib/libelpa.a
2727

28-
CEREAL_DIR = /pubilc/soft/cereal
28+
CEREAL_DIR = /public/soft/cereal
2929
# directory of cereal, which contains a include directory in it.
3030

3131
#------- FOR GNU COMPILER ---------------
32-
# FFTW_DIR = /pubilc/soft/fftw
32+
# FFTW_DIR = /public/soft/fftw_3.3.8
3333
# # directory of fftw package, which contains lib/libfftw3.a. Only used when CC = mpicxx/g++
3434

35-
# OPENBLAS_LIB_DIR = /pubilc/soft/openblas/lib
35+
# OPENBLAS_LIB_DIR = /public/soft/openblas/lib
3636
# # directory of libopenblas.a, only used when CC = mpicxx/g++
3737

38-
# SCALAPACK_LIB_DIR = /pubilc/soft/openblas/lib
38+
# SCALAPACK_LIB_DIR = /public/soft/openblas/lib
3939
# # directory of libscalapack.a, only used when CC = mpicxx/g++
4040

41-
# ELPA_DIR = /pubilc/soft/elpa_21.05.002
41+
# ELPA_DIR = /public/soft/elpa_21.05.002
4242
# ELPA_INCLUDE_DIR = ${ELPA_DIR}/include/elpa-2021.05.002
4343
# # directory of elpa, which contains include and lib/libelpa.a
4444

45-
# CEREAL_DIR = /pubilc/soft/cereal
45+
# CEREAL_DIR = /public/soft/cereal
4646
# # directory of cereal, which contains a include directory in it.
4747

4848

@@ -52,10 +52,14 @@ CEREAL_DIR = /pubilc/soft/cereal
5252
# LIBNPY_DIR = /usr/local
5353
# add them to use DEEPKS
5454

55-
# LIBXC_DIR = /pubilc/soft/libxc
55+
# LIBXC_DIR = /public/soft/libxc
5656
# directory of libxc(5.1.7), which contains include and lib/libxc.a
5757
# add LIBXC_DIR to use libxc to compile ABACUS
5858

59+
# DeePMD_DIR = ${deepmd_root}
60+
# TensorFlow_DIR = ${tensorflow_root}
61+
# add them to use DEEPMD
62+
5963
# NP = 14 # It is not supported. use make -j14 or make -j to parallelly compile
6064

6165
# DEBUG = OFF

source/driver_run.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "src_io/print_info.h"
77
#include "src_lcao/run_md_lcao.h"
88
#include "src_pw/run_md_pw.h"
9+
#include "module_md/run_md_classic.h"
910

1011
// This is the driver function which defines the workflow of ABACUS calculations
1112
// It relies on the class Esolver, which is a class that organizes workflows of single point calculations.
@@ -56,6 +57,11 @@ void Driver::driver_run()
5657
run_md_lcao.opt_ions(p_esolver);
5758
#endif
5859
}
60+
else if(INPUT.mdp.md_ensolver == "LJ" || INPUT.mdp.md_ensolver == "DP")
61+
{
62+
Run_MD_CLASSIC run_md_classic;
63+
run_md_classic.classic_md_line(GlobalC::ucell, p_esolver);
64+
}
5965
else if(GlobalV::CALCULATION == "md" || GlobalV::CALCULATION == "sto-md")
6066
{
6167
Run_MD_PW run_md_pw;

source/input.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <stdio.h>
1919
#include <string.h>
2020
#include <vector>
21+
#include <unistd.h>
2122
Input INPUT;
2223

2324
void Input::Init(const std::string &fn)
@@ -1257,6 +1258,10 @@ bool Input::Read(const std::string &fn)
12571258
{
12581259
read_value(ifs, mdp.md_damp);
12591260
}
1261+
else if (strcmp("pot_file", word) == 0)
1262+
{
1263+
read_value(ifs, mdp.pot_file);
1264+
}
12601265
//----------------------------------------------------------
12611266
// efield and dipole correction
12621267
// Yu Liu add 2022-05-18
@@ -2204,6 +2209,7 @@ void Input::Bcast()
22042209
Parallel_Common::bcast_double(mdp.msst_tscale);
22052210
Parallel_Common::bcast_double(mdp.md_tfreq);
22062211
Parallel_Common::bcast_double(mdp.md_damp);
2212+
Parallel_Common::bcast_string(mdp.pot_file);
22072213
// Yu Liu add 2022-05-18
22082214
Parallel_Common::bcast_bool(efield_flag);
22092215
Parallel_Common::bcast_bool(dip_cor_flag);
@@ -2547,6 +2553,13 @@ void Input::Check(void)
25472553
ModuleBase::WARNING_QUIT("Input::Check", "msst_qmass must be greater than 0!");
25482554
}
25492555
}
2556+
if(mdp.md_ensolver == "DP")
2557+
{
2558+
if (access(mdp.pot_file.c_str(), 0) == -1)
2559+
{
2560+
ModuleBase::WARNING_QUIT("Input::Check", "Can not find DP model !");
2561+
}
2562+
}
25502563
// if(mdp.md_tfirst!=mdp.md_tlast)
25512564
// {
25522565
// std::ifstream file1;

source/module_esolver/esolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace ModuleESolver
9090
}
9191
else if (esolver_type == "dp_pot")
9292
{
93-
p_esolver = new ESolver_DP();
93+
p_esolver = new ESolver_DP(INPUT.mdp.pot_file);
9494
}
9595
}
9696

0 commit comments

Comments
 (0)