Skip to content

Commit 53049b7

Browse files
authored
Merge pull request #140 from deepmodeling/devel
Devel
2 parents cd2800e + ab355d0 commit 53049b7

35 files changed

+3182
-170
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "source/op/cuda/cub"]
2+
path = source/op/cuda/cub
3+
url = git://github.com/NVlabs/cub.git

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- [Include deepmd in the pair style](#include-deepmd-in-the-pair-style)
3333
- [Long-range interaction](#long-range-interaction)
3434
- [Run path-integral MD with i-PI](#run-path-integral-md-with-i-pi)
35+
- [Use deep potential with ASE](#use-deep-potential-with-ase)
3536
- [Troubleshooting](#troubleshooting)
3637

3738
# About DeePMD-kit
@@ -150,7 +151,7 @@ One should remember to activate the virtual environment every time he/she uses d
150151
Clone the DeePMD-kit source code
151152
```bash
152153
cd /some/workspace
153-
git clone https://github.com/deepmodeling/deepmd-kit.git deepmd-kit
154+
git clone --recursive https://github.com/deepmodeling/deepmd-kit.git deepmd-kit -b devel
154155
```
155156
If one downloads the .zip file from the github, then the default folder of source code would be `deepmd-kit-master` rather than `deepmd-kit`. For convenience, you may want to record the location of source to a variable, saying `deepmd_source_dir` by
156157
```bash
@@ -553,6 +554,30 @@ The option **`graph_file`** provides the file name of the frozen model.
553554

554555
The `dp_ipi` gets the atom names from an [XYZ file](https://en.wikipedia.org/wiki/XYZ_file_format) provided by **`coord_file`** (meanwhile ignores all coordinates in it), and translates the names to atom types by rules provided by **`atom_type`**.
555556

557+
## Use deep potential with ASE
558+
559+
Deep potential can be set up as a calculator with ASE to obtain potential energies and forces.
560+
```python
561+
from ase import Atoms
562+
from deepmd.calculator import DP
563+
564+
water = Atoms('H2O',
565+
positions=[(0.7601, 1.9270, 1),
566+
(1.9575, 1, 1),
567+
(1., 1., 1.)],
568+
cell=[100, 100, 100],
569+
calculator=DP(model="frozen_model.pb"))
570+
print(water.get_potential_energy())
571+
print(water.get_forces())
572+
```
573+
574+
Optimization is also available:
575+
```python
576+
from ase.optimize import BFGS
577+
dyn = BFGS(water)
578+
dyn.run(fmax=1e-6)
579+
print(water.get_positions())
580+
```
556581

557582
# Troubleshooting
558583
In consequence of various differences of computers or systems, problems may occur. Some common circumstances are listed as follows.

deepmd/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .DeepPot import DeepPot
44
from .DeepDipole import DeepDipole
55
from .DeepPolar import DeepPolar
6+
from .DeepPolar import DeepGlobalPolar
67
from .DeepWFC import DeepWFC
78

89
set_mkl()

source/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ include_directories(${TensorFlow_INCLUDE_DIRS})
170170
if (BUILD_CPP_IF)
171171
set (LIB_DEEPMD "deepmd")
172172
set (LIB_DEEPMD_OP "deepmd_op")
173+
if (USE_CUDA_TOOLKIT)
174+
set (LIB_DEEPMD_OP_CUDA "deepmd_op_cuda")
175+
else()
176+
set (LIB_DEEPMD_OP_CUDA "")
177+
endif()
173178
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9)
174179
set (LIB_DEEPMD_NATIVE "deepmd_native_md")
175180
set (LIB_DEEPMD_IPI "deepmd_ipi")

source/lib/include/NNPAtomMap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ template <typename VALUETYPE>
88
class NNPAtomMap
99
{
1010
public:
11+
NNPAtomMap();
1112
NNPAtomMap(const vector<int >::const_iterator in_begin,
1213
const vector<int >::const_iterator in_end);
1314
void forward (typename vector<VALUETYPE >::iterator out,

source/lib/include/NNPInter.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
#include "tensorflow/core/framework/op.h"
66
#include "tensorflow/core/framework/op_kernel.h"
77
#include "tensorflow/core/framework/shape_inference.h"
8-
8+
#include "NNPAtomMap.h"
99
#include <vector>
1010
#include "version.h"
1111

12+
typedef double compute_t;
1213
using namespace tensorflow;
1314
using namespace std;
1415

@@ -53,6 +54,7 @@ class NNPInter
5354
{
5455
public:
5556
NNPInter () ;
57+
~NNPInter() ;
5658
NNPInter (const string & model, const int & gpu_rank = 0);
5759
void init (const string & model, const int & gpu_rank = 0);
5860
void print_summary(const string &pre) const;
@@ -74,6 +76,7 @@ class NNPInter
7476
const vector<VALUETYPE> & box,
7577
const int nghost,
7678
const LammpsNeighborList & lmp_list,
79+
const int & ago,
7780
const vector<VALUETYPE> & fparam = vector<VALUETYPE>(),
7881
const vector<VALUETYPE> & aparam = vector<VALUETYPE>());
7982
void compute (ENERGYTYPE & ener,
@@ -96,6 +99,7 @@ class NNPInter
9699
const vector<VALUETYPE> & box,
97100
const int nghost,
98101
const LammpsNeighborList & lmp_list,
102+
const int & ago,
99103
const vector<VALUETYPE> & fparam = vector<VALUETYPE>(),
100104
const vector<VALUETYPE> & aparam = vector<VALUETYPE>());
101105
VALUETYPE cutoff () const {assert(inited); return rcut;};
@@ -118,12 +122,30 @@ class NNPInter
118122
void validate_fparam_aparam(const int & nloc,
119123
const vector<VALUETYPE> &fparam,
120124
const vector<VALUETYPE> &aparam)const ;
125+
126+
// copy neighbor list info from host
127+
bool init_nbor;
128+
std::vector<int> sec_a;
129+
compute_t *array_double;
130+
InternalNeighborList nlist;
131+
NNPAtomMap<VALUETYPE> nnpmap;
132+
unsigned long long *array_longlong;
133+
int *ilist, *jrange, *jlist, *array_int;
134+
int ilist_size, jrange_size, jlist_size;
135+
int arr_int_size, arr_ll_size, arr_dou_size;
136+
137+
// function used for neighbor list copy
138+
vector<int> get_sel_a() const;
139+
#ifdef USE_CUDA_TOOLKIT
140+
void update_nbor(const InternalNeighborList & nlist, const int nloc);
141+
#endif
121142
};
122143

123144
class NNPInterModelDevi
124145
{
125146
public:
126147
NNPInterModelDevi () ;
148+
~NNPInterModelDevi() ;
127149
NNPInterModelDevi (const vector<string> & models, const int & gpu_rank = 0);
128150
void init (const vector<string> & models, const int & gpu_rank = 0);
129151
public:
@@ -144,6 +166,7 @@ class NNPInterModelDevi
144166
const vector<VALUETYPE> & box,
145167
const int nghost,
146168
const LammpsNeighborList & lmp_list,
169+
const int & ago,
147170
const vector<VALUETYPE> & fparam = vector<VALUETYPE>(),
148171
const vector<VALUETYPE> & aparam = vector<VALUETYPE>());
149172
void compute (vector<ENERGYTYPE> & all_ener,
@@ -156,6 +179,7 @@ class NNPInterModelDevi
156179
const vector<VALUETYPE> & box,
157180
const int nghost,
158181
const LammpsNeighborList & lmp_list,
182+
const int & ago,
159183
const vector<VALUETYPE> & fparam = vector<VALUETYPE>(),
160184
const vector<VALUETYPE> & aparam = vector<VALUETYPE>());
161185
VALUETYPE cutoff () const {assert(inited); return rcut;};
@@ -176,6 +200,9 @@ class NNPInterModelDevi
176200
void compute_std_f (vector<VALUETYPE> & std,
177201
const vector<VALUETYPE> & avg,
178202
const vector<vector<VALUETYPE> >& xx);
203+
void compute_relative_std_f (vector<VALUETYPE> & std,
204+
const vector<VALUETYPE> & avg,
205+
const VALUETYPE eps);
179206
private:
180207
unsigned numb_models;
181208
vector<Session*> sessions;
@@ -193,6 +220,25 @@ class NNPInterModelDevi
193220
void validate_fparam_aparam(const int & nloc,
194221
const vector<VALUETYPE> &fparam,
195222
const vector<VALUETYPE> &aparam)const ;
223+
224+
// copy neighbor list info from host
225+
bool init_nbor;
226+
compute_t *array_double;
227+
vector<vector<int> > sec;
228+
InternalNeighborList nlist;
229+
NNPAtomMap<VALUETYPE> nnpmap;
230+
unsigned long long *array_longlong;
231+
int max_sec_size = 0, max_sec_back = 0;
232+
int *ilist, *jrange, *jlist, *array_int;
233+
int ilist_size, jrange_size, jlist_size, arr_int_size, arr_ll_size, arr_dou_size;
234+
235+
// function used for nborlist copy
236+
void get_max_sec();
237+
vector<vector<int> > get_sel() const;
238+
void cum_sum(const std::vector<std::vector<int32> > n_sel);
239+
#ifdef USE_CUDA_TOOLKIT
240+
void update_nbor(const InternalNeighborList & nlist, const int nloc);
241+
#endif
196242
};
197243

198244

source/lib/src/NNPAtomMap.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <algorithm>
44
#include <cassert>
55

6+
template <typename VALUETYPE>
7+
NNPAtomMap<VALUETYPE>::
8+
NNPAtomMap() {}
9+
610
template <typename VALUETYPE>
711
NNPAtomMap<VALUETYPE>::
812
NNPAtomMap(const vector<int >::const_iterator in_begin,

0 commit comments

Comments
 (0)