Skip to content

Commit

Permalink
Merge pull request #140 from deepmodeling/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
amcadmus authored Dec 20, 2019
2 parents cd2800e + ab355d0 commit 53049b7
Show file tree
Hide file tree
Showing 35 changed files with 3,182 additions and 170 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "source/op/cuda/cub"]
path = source/op/cuda/cub
url = git://github.com/NVlabs/cub.git
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [Include deepmd in the pair style](#include-deepmd-in-the-pair-style)
- [Long-range interaction](#long-range-interaction)
- [Run path-integral MD with i-PI](#run-path-integral-md-with-i-pi)
- [Use deep potential with ASE](#use-deep-potential-with-ase)
- [Troubleshooting](#troubleshooting)

# About DeePMD-kit
Expand Down Expand Up @@ -150,7 +151,7 @@ One should remember to activate the virtual environment every time he/she uses d
Clone the DeePMD-kit source code
```bash
cd /some/workspace
git clone https://github.com/deepmodeling/deepmd-kit.git deepmd-kit
git clone --recursive https://github.com/deepmodeling/deepmd-kit.git deepmd-kit -b devel
```
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
```bash
Expand Down Expand Up @@ -553,6 +554,30 @@ The option **`graph_file`** provides the file name of the frozen model.

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`**.

## Use deep potential with ASE

Deep potential can be set up as a calculator with ASE to obtain potential energies and forces.
```python
from ase import Atoms
from deepmd.calculator import DP

water = Atoms('H2O',
positions=[(0.7601, 1.9270, 1),
(1.9575, 1, 1),
(1., 1., 1.)],
cell=[100, 100, 100],
calculator=DP(model="frozen_model.pb"))
print(water.get_potential_energy())
print(water.get_forces())
```

Optimization is also available:
```python
from ase.optimize import BFGS
dyn = BFGS(water)
dyn.run(fmax=1e-6)
print(water.get_positions())
```

# Troubleshooting
In consequence of various differences of computers or systems, problems may occur. Some common circumstances are listed as follows.
Expand Down
1 change: 1 addition & 0 deletions deepmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .DeepPot import DeepPot
from .DeepDipole import DeepDipole
from .DeepPolar import DeepPolar
from .DeepPolar import DeepGlobalPolar
from .DeepWFC import DeepWFC

set_mkl()
Expand Down
5 changes: 5 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ include_directories(${TensorFlow_INCLUDE_DIRS})
if (BUILD_CPP_IF)
set (LIB_DEEPMD "deepmd")
set (LIB_DEEPMD_OP "deepmd_op")
if (USE_CUDA_TOOLKIT)
set (LIB_DEEPMD_OP_CUDA "deepmd_op_cuda")
else()
set (LIB_DEEPMD_OP_CUDA "")
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9)
set (LIB_DEEPMD_NATIVE "deepmd_native_md")
set (LIB_DEEPMD_IPI "deepmd_ipi")
Expand Down
1 change: 1 addition & 0 deletions source/lib/include/NNPAtomMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ template <typename VALUETYPE>
class NNPAtomMap
{
public:
NNPAtomMap();
NNPAtomMap(const vector<int >::const_iterator in_begin,
const vector<int >::const_iterator in_end);
void forward (typename vector<VALUETYPE >::iterator out,
Expand Down
48 changes: 47 additions & 1 deletion source/lib/include/NNPInter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"

#include "NNPAtomMap.h"
#include <vector>
#include "version.h"

typedef double compute_t;
using namespace tensorflow;
using namespace std;

Expand Down Expand Up @@ -53,6 +54,7 @@ class NNPInter
{
public:
NNPInter () ;
~NNPInter() ;
NNPInter (const string & model, const int & gpu_rank = 0);
void init (const string & model, const int & gpu_rank = 0);
void print_summary(const string &pre) const;
Expand All @@ -74,6 +76,7 @@ class NNPInter
const vector<VALUETYPE> & box,
const int nghost,
const LammpsNeighborList & lmp_list,
const int & ago,
const vector<VALUETYPE> & fparam = vector<VALUETYPE>(),
const vector<VALUETYPE> & aparam = vector<VALUETYPE>());
void compute (ENERGYTYPE & ener,
Expand All @@ -96,6 +99,7 @@ class NNPInter
const vector<VALUETYPE> & box,
const int nghost,
const LammpsNeighborList & lmp_list,
const int & ago,
const vector<VALUETYPE> & fparam = vector<VALUETYPE>(),
const vector<VALUETYPE> & aparam = vector<VALUETYPE>());
VALUETYPE cutoff () const {assert(inited); return rcut;};
Expand All @@ -118,12 +122,30 @@ class NNPInter
void validate_fparam_aparam(const int & nloc,
const vector<VALUETYPE> &fparam,
const vector<VALUETYPE> &aparam)const ;

// copy neighbor list info from host
bool init_nbor;
std::vector<int> sec_a;
compute_t *array_double;
InternalNeighborList nlist;
NNPAtomMap<VALUETYPE> nnpmap;
unsigned long long *array_longlong;
int *ilist, *jrange, *jlist, *array_int;
int ilist_size, jrange_size, jlist_size;
int arr_int_size, arr_ll_size, arr_dou_size;

// function used for neighbor list copy
vector<int> get_sel_a() const;
#ifdef USE_CUDA_TOOLKIT
void update_nbor(const InternalNeighborList & nlist, const int nloc);
#endif
};

class NNPInterModelDevi
{
public:
NNPInterModelDevi () ;
~NNPInterModelDevi() ;
NNPInterModelDevi (const vector<string> & models, const int & gpu_rank = 0);
void init (const vector<string> & models, const int & gpu_rank = 0);
public:
Expand All @@ -144,6 +166,7 @@ class NNPInterModelDevi
const vector<VALUETYPE> & box,
const int nghost,
const LammpsNeighborList & lmp_list,
const int & ago,
const vector<VALUETYPE> & fparam = vector<VALUETYPE>(),
const vector<VALUETYPE> & aparam = vector<VALUETYPE>());
void compute (vector<ENERGYTYPE> & all_ener,
Expand All @@ -156,6 +179,7 @@ class NNPInterModelDevi
const vector<VALUETYPE> & box,
const int nghost,
const LammpsNeighborList & lmp_list,
const int & ago,
const vector<VALUETYPE> & fparam = vector<VALUETYPE>(),
const vector<VALUETYPE> & aparam = vector<VALUETYPE>());
VALUETYPE cutoff () const {assert(inited); return rcut;};
Expand All @@ -176,6 +200,9 @@ class NNPInterModelDevi
void compute_std_f (vector<VALUETYPE> & std,
const vector<VALUETYPE> & avg,
const vector<vector<VALUETYPE> >& xx);
void compute_relative_std_f (vector<VALUETYPE> & std,
const vector<VALUETYPE> & avg,
const VALUETYPE eps);
private:
unsigned numb_models;
vector<Session*> sessions;
Expand All @@ -193,6 +220,25 @@ class NNPInterModelDevi
void validate_fparam_aparam(const int & nloc,
const vector<VALUETYPE> &fparam,
const vector<VALUETYPE> &aparam)const ;

// copy neighbor list info from host
bool init_nbor;
compute_t *array_double;
vector<vector<int> > sec;
InternalNeighborList nlist;
NNPAtomMap<VALUETYPE> nnpmap;
unsigned long long *array_longlong;
int max_sec_size = 0, max_sec_back = 0;
int *ilist, *jrange, *jlist, *array_int;
int ilist_size, jrange_size, jlist_size, arr_int_size, arr_ll_size, arr_dou_size;

// function used for nborlist copy
void get_max_sec();
vector<vector<int> > get_sel() const;
void cum_sum(const std::vector<std::vector<int32> > n_sel);
#ifdef USE_CUDA_TOOLKIT
void update_nbor(const InternalNeighborList & nlist, const int nloc);
#endif
};


4 changes: 4 additions & 0 deletions source/lib/src/NNPAtomMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <algorithm>
#include <cassert>

template <typename VALUETYPE>
NNPAtomMap<VALUETYPE>::
NNPAtomMap() {}

template <typename VALUETYPE>
NNPAtomMap<VALUETYPE>::
NNPAtomMap(const vector<int >::const_iterator in_begin,
Expand Down
Loading

0 comments on commit 53049b7

Please sign in to comment.