Skip to content

Commit

Permalink
Add support for DeePMD
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudac7 committed Jan 4, 2024
1 parent 0904149 commit 969d126
Show file tree
Hide file tree
Showing 23 changed files with 968 additions and 64 deletions.
9 changes: 9 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ Calls to `offload_dgemm` also accept pointers on GPU or a combination of them.
- See <https://brehm-research.de> for more information.
-->

### 2y. DeePMD-kit (optional, wider range of interaction potentials)

DeePMD-kit - Deep Potential Molecular Dyanmics. Support for DeePMD-kit can be enabled via the flag
`-D__DEEPMD`.

- DeePMD-kit C interface can be downloaded from
<https://docs.deepmodeling.com/projects/deepmd/en/master/install/install-from-c-library.html>
- For more information see <https://github.com/deepmodeling/deepmd-kit.git>.

## 3. Compile

### 3a. ARCH files
Expand Down
Binary file added data/DeePMD/W.pb
Binary file not shown.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ list(
ct_methods.F
ct_types.F
debug_os_integrals.F
deepmd_wrapper.F
dft_plus_u.F
dgemm_counter_types.F
distribution_2d_types.F
Expand Down Expand Up @@ -310,6 +311,7 @@ list(
lri_optimize_ri_basis_types.F
ls_matrix_exp.F
manybody_eam.F
manybody_deepmd.F
manybody_gal21.F
manybody_gal.F
manybody_allegro.F
Expand Down
82 changes: 81 additions & 1 deletion src/common/bibliography.F
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ MODULE bibliography
cp2kqs2020, Behler2007, Behler2011, Schran2020a, Schran2020b, &
Rycroft2009, Thomas2015, Brehm2018, Brehm2020, Shigeta2001, Heinecke2016, &
Brehm2021, Bussy2021a, Bussy2021b, Ditler2021, Ditler2022, Mattiat2019, Mattiat2022, &
Belleflamme2023, Knizia2013, Musaelian2023, Eriksen2020, Graml2023, Bussy2023
Belleflamme2023, Knizia2013, Musaelian2023, Eriksen2020, Graml2023, Bussy2023, Wang2018, Zeng2023

CONTAINS

Expand Down Expand Up @@ -4904,6 +4904,86 @@ SUBROUTINE add_all_references()
"ER"), &
DOI="10.48550/arXiv.2306.16066")

CALL add_reference(key=Wang2018, ISI_record=s2a( &
"TY JOUR", &
"PT J", &
"AU Wang, Han", &
" Zhang, Linfeng", &
" Han, Jiequn", &
" E, Weinan", &
"TI DeePMD-kit: A Deep Learning Package for Many-body", &
" Potential Energy Representation and Molecular Dynamics", &
"SO Computer Physics Communications", &
"JF Computer Physics Communications", &
"JO Computer Physics Communications", &
"SN 178-184", &
"IS 7", &
"PY 2018", &
"VL 228", &
"DI 10.1016/j.cpc.2018.03.016", &
"ER"), &
DOI="10.1016/j.cpc.2018.03.016")

CALL add_reference(key=Zeng2023, ISI_record=s2a( &
"TY JOUR", &
"PT J", &
"AU Zeng, Jinzhe", &
" Zhang, Duo", &
" Lu, Denghui", &
" Mo, Pinghui", &
" Li, Zeyu", &
" Chen, Yixiao", &
" Rynik, Marián", &
" Huang, Li'ang", &
" Li, Ziyao", &
" Shi, Shaochen", &
" Wang, Yingze", &
" Ye, Haotian", &
" Tuo, Ping", &
" Yang, Jiabin", &
" Ding, Ye", &
" Li, Yifan", &
" Tisi, Davide", &
" Zeng, Qiyu", &
" Bao, Han", &
" Xia, Yu", &
" Huang, Jiameng", &
" Muraoka, Koki", &
" Wang, Yibo", &
" Chang, Junhan", &
" Yuan, Fengbo", &
" Bore, Sigbjørn Løland", &
" Cai, Chun", &
" Lin, Yinnian", &
" Wang, Bo", &
" Xu, Jiayan", &
" Zhu, Jia-Xin", &
" Luo, Chenxing", &
" Zhang, Yuzhi", &
" Goodall, Rhys E. A.", &
" Liang, Wenshuo", &
" Singh, Anurag Kumar", &
" Yao, Sikai", &
" Zhang, Jingchao", &
" Wentzcovitch, Renata", &
" Han, Jiequn", &
" Liu, Jie", &
" Jia, Weile", &
" York, Darrin M.", &
" E, Weinan", &
" Car, Roberto", &
" Zhang, Linfeng", &
" Wang, Han", &
"TI DeePMD-kit v2: A software package for deep potential models", &
"SO The Journal of Chemical Physics", &
"JF The Journal of Chemical Physics", &
"JO The Journal of Chemical Physics", &
"PY 2023", &
"VL 159", &
"DI 10.1063/5.0155600", &
"ER"), &
DOI="10.1063/5.0155600")

END SUBROUTINE add_all_references

END MODULE bibliography
5 changes: 5 additions & 0 deletions src/cp2k_info.F
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,14 @@ FUNCTION cp2k_flags() RESULT(flags)
flags = TRIM(flags)//" patched_cufft_70"
#endif

#if defined(__DEEPMD)
flags = TRIM(flags)//" deepmd"
#endif

#if defined(__PW_FPGA)
flags = TRIM(flags)//" pw_fpga"
#endif

#if defined(__PW_FPGA_SP)
flags = TRIM(flags)//" pw_fpga_sp"
#endif
Expand Down
144 changes: 144 additions & 0 deletions src/deepmd_wrapper.F
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!

! **************************************************************************************************
!> \brief Interface to the DeePMD-kit or a c++ wrapper.
!> \par History
!> 07.2019 created [Yongbin Zhuang]
!> 06.2021 refactored [Yunpei Liu]
!> 10.2023 adapt to DeePMD-kit C Interface [Yunpei Liu]
!> \author Yongbin Zhuang
! **************************************************************************************************

MODULE deepmd_wrapper

USE ISO_C_BINDING, ONLY: C_CHAR,&
C_DOUBLE,&
C_INT,&
C_LOC,&
C_NULL_CHAR,&
C_NULL_PTR,&
C_PTR
#include "./base/base_uses.f90"

IMPLICIT NONE
PRIVATE
PUBLIC :: dp_deep_pot, dp_deep_pot_compute, deepmd_model_release

#if(__DEEPMD)
INTERFACE
FUNCTION dp_deep_pot_c(c_model) BIND(C, name="DP_NewDeepPot")
USE ISO_C_BINDING, ONLY: C_PTR, &
C_CHAR, &
C_DOUBLE, &
C_INT, &
C_NULL_CHAR, &
C_LOC
CHARACTER(LEN=1, KIND=C_CHAR) :: c_model(*)
TYPE(C_PTR) :: dp_deep_pot_c

END FUNCTION

SUBROUTINE dp_deep_pot_compute_c(dp, natom, &
coord, atype, cell, &
energy, force, virial, &
atomic_energy, atomic_virial) BIND(C, name="DP_DeepPotCompute")
USE ISO_C_BINDING, ONLY: C_PTR, &
C_INT, &
C_CHAR, &
C_DOUBLE
TYPE(C_PTR), VALUE :: dp
INTEGER(C_INT), VALUE :: natom
REAL(C_DOUBLE), DIMENSION(natom, 3), INTENT(IN) :: coord
INTEGER(C_INT), DIMENSION(natom), INTENT(IN) :: atype
REAL(C_DOUBLE), DIMENSION(9), INTENT(IN) :: cell
REAL(C_DOUBLE), INTENT(OUT) :: energy
REAL(C_DOUBLE), DIMENSION(natom, 3), INTENT(OUT) :: force
REAL(C_DOUBLE), DIMENSION(9), INTENT(OUT) :: virial
REAL(C_DOUBLE), DIMENSION(natom), INTENT(OUT) :: atomic_energy
REAL(C_DOUBLE), DIMENSION(natom, 9), INTENT(OUT) :: atomic_virial

END SUBROUTINE
END INTERFACE
#endif

CONTAINS

! **************************************************************************************************
!> \brief Load DP from a model file.
!> \param model Path to the model file.
!> \return Pointer to the DP model.
! **************************************************************************************************

FUNCTION dp_deep_pot(model) RESULT(pot)
CHARACTER(len=*), INTENT(INOUT) :: model
TYPE(C_PTR) :: pot

#if(__DEEPMD)
pot = dp_deep_pot_c(c_model=TRIM(model)//C_NULL_CHAR)
#else
pot = C_NULL_PTR
#endif
END FUNCTION dp_deep_pot

! **************************************************************************************************
!> \brief Compute energy, force and virial from DP.
!> \param dp Pointer to the DP model.
!> \param natom Number of atoms.
!> \param coord Coordinates of the atoms.
!> \param atype Atom types.
!> \param cell Cell vectors.
!> \param energy Potential energy.
!> \param force Forces.
!> \param virial Virial tensor.
!> \param atomic_energy Atomic energies.
!> \param atomic_virial Atomic virial tensors.
! **************************************************************************************************

SUBROUTINE dp_deep_pot_compute(dp, natom, coord, atype, cell, energy, force, virial, atomic_energy, atomic_virial)
USE, INTRINSIC :: ISO_C_BINDING
TYPE(C_PTR), VALUE :: dp
INTEGER(C_INT), VALUE :: natom
REAL(C_DOUBLE), DIMENSION(natom, 3), INTENT(IN) :: coord
INTEGER(C_INT), DIMENSION(natom), INTENT(IN) :: atype
REAL(C_DOUBLE), DIMENSION(9), INTENT(IN), OPTIONAL :: cell
REAL(C_DOUBLE), INTENT(OUT), OPTIONAL :: energy
REAL(C_DOUBLE), DIMENSION(natom, 3), INTENT(OUT), OPTIONAL :: force
REAL(C_DOUBLE), DIMENSION(9), INTENT(OUT), OPTIONAL :: virial
REAL(C_DOUBLE), DIMENSION(natom), INTENT(OUT), OPTIONAL :: atomic_energy
REAL(C_DOUBLE), DIMENSION(natom, 9), INTENT(OUT), OPTIONAL :: atomic_virial

#if(__DEEPMD)
CALL dp_deep_pot_compute_c(dp, natom, coord, atype, cell, energy, force, virial, atomic_energy, atomic_virial)
#else
CPABORT("CP2K was compiled without libdeepmd_c library.")
MARK_USED(dp)
MARK_USED(natom)
MARK_USED(coord)
MARK_USED(atype)
MARK_USED(cell)
MARK_USED(energy)
MARK_USED(force)
MARK_USED(virial)
MARK_USED(atomic_energy)
MARK_USED(atomic_virial)
#endif
END SUBROUTINE

! **************************************************************************************************
!> \brief Releases a deepmd model and all its ressources.
!> \param model Pointer to the DP model.
! **************************************************************************************************
SUBROUTINE deepmd_model_release(model)
USE ISO_C_BINDING, ONLY: C_PTR, &
C_NULL_PTR
TYPE(C_PTR), INTENT(INOUT) :: model

model = C_NULL_PTR
END SUBROUTINE deepmd_model_release

END MODULE deepmd_wrapper

0 comments on commit 969d126

Please sign in to comment.