Skip to content

Commit 1edbecc

Browse files
author
Han Wang
committed
system ener is always double. print code version and info of building in train and md
1 parent fccbacd commit 1edbecc

File tree

18 files changed

+240
-148
lines changed

18 files changed

+240
-148
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- [Install tensorflow's C++ interface](#install-tensorflows-c-interface)
1616
- [Install xdrfile](#install-xdrfile)
1717
- [Install DeePMD-kit](#install-deepmd-kit)
18-
- [Install LAMMPS's DeePMD-kit module](#install-lammps-deepmd-kit-module)
18+
- [Install LAMMPS's DeePMD-kit module](#install-lammpss-deepmd-kit-module)
1919
- [Build DeePMD-kit with GPU support](#build-deepmd-kit-with-gpu-support)
2020
- [Use DeePMD-kit](#use-deepmd-kit)
2121
- [Prepare data](#prepare-data)
@@ -323,7 +323,11 @@ $ cat force.raw
323323
```
324324
This `force.raw` contains 3 frames with each frame having the forces of 2 atoms, thus it has 3 lines and 6 columns. Each line provides all the 3 force components of 2 atoms in 1 frame. The first three numbers are the 3 force components of the first atom, while the second three numbers are the 3 force components of the second atom. The coordinate file `coord.raw` is organized similarly. In `box.raw`, the 9 components of the box vectors should be provided on each line. In `virial.raw`, the 9 components of the virial tensor should be provided on each line. The number of lines of all raw files should be identical.
325325

326-
We assume that the atom types do not change in all frames. It is provided by `type.raw`, which has one line with the types of atoms written one by one. The atom types should be integers.
326+
We assume that the atom types do not change in all frames. It is provided by `type.raw`, which has one line with the types of atoms written one by one. The atom types should be integers. For example the `tyep.raw` of a system that has 2 atoms with 0 and 1:
327+
```bash
328+
$ cat type.raw
329+
0 1
330+
```
327331

328332
The second format is the data sets of `numpy` binary data that are directly used by the training program. User can use the script `$deepmd_source_dir/data/raw/raw_to_set.sh` to convert the prepared raw files to data sets. For example, if we have a raw file that contains 6000 frames,
329333
```bash

data/raw/raw_to_set.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ if test $# -ge 1; then
77
fi
88

99
rm -fr set.*
10-
echo nframe is `cat energy.raw | wc -l`
10+
echo nframe is `cat box.raw | wc -l`
1111
echo nline per set is $nline_per_set
1212

1313
split box.raw -l $nline_per_set -d -a 3 box.raw
1414
split coord.raw -l $nline_per_set -d -a 3 coord.raw
1515
test -f energy.raw && split energy.raw -l $nline_per_set -d -a 3 energy.raw
1616
test -f force.raw && split force.raw -l $nline_per_set -d -a 3 force.raw
1717
test -f virial.raw && split virial.raw -l $nline_per_set -d -a 3 virial.raw
18+
test -f atom_ener.raw && split atom_ener.raw -l $nline_per_set -d -a 3 atom_ener.raw
1819

1920
nset=`ls | grep box.raw[0-9] | wc -l`
2021
nset_1=$(($nset-1))
@@ -30,6 +31,7 @@ do
3031
test -f energy.raw$pi && mv energy.raw$pi set.$pi/energy.raw
3132
test -f force.raw$pi && mv force.raw$pi set.$pi/force.raw
3233
test -f virial.raw$pi && mv virial.raw$pi set.$pi/virial.raw
34+
test -f atom_ener.raw$pi && mv atom_ener.raw$pi set.$pi/atom_ener.raw
3335

3436
cd set.$pi
3537
python -c 'import numpy as np; data = np.loadtxt("box.raw" ); data = data.astype (np.float32); np.save ("box", data)'
@@ -54,6 +56,13 @@ if os.path.isfile("virial.raw"):
5456
data = np.loadtxt("virial.raw");
5557
data = data.astype (np.float32);
5658
np.save ("virial", data)
59+
'
60+
python -c \
61+
'import numpy as np; import os.path;
62+
if os.path.isfile("atom_ener.raw"):
63+
data = np.loadtxt("atom_ener.raw");
64+
data = data.astype (np.float32);
65+
np.save ("atom_ener", data)
5766
'
5867
rm *.raw
5968
cd ../

examples/train/water.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"with_distrib": false,
23
"_comment": " model parameters",
34
"use_smooth": false,
45
"sel_a": [16, 32],
@@ -35,8 +36,8 @@
3536
"_comment": " frequencies counted in batch",
3637
"disp_file": "lcurve.out",
3738
"disp_freq": 100,
38-
"numb_test": 100,
39-
"save_freq": 100,
39+
"numb_test": 10,
40+
"save_freq": 1000,
4041
"save_ckpt": "model.ckpt",
4142
"load_ckpt": "model.ckpt",
4243
"disp_training": true,

examples/train/water_smth.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"_comment": " frequencies counted in batch",
3535
"disp_file": "lcurve.out",
3636
"disp_freq": 100,
37-
"numb_test": 50,
38-
"save_freq": 100,
37+
"numb_test": 10,
38+
"save_freq": 1000,
3939
"save_ckpt": "model.ckpt",
4040
"load_ckpt": "model.ckpt",
4141
"disp_training": true,

source/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
cmake_minimum_required(VERSION 3.0)
22
project(DeePMD)
33

4+
find_package(Git)
5+
if(GIT_FOUND)
6+
execute_process(
7+
COMMAND git log -1 --format=%h
8+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
9+
OUTPUT_VARIABLE GIT_HASH
10+
OUTPUT_STRIP_TRAILING_WHITESPACE
11+
)
12+
execute_process(
13+
COMMAND git rev-parse --abbrev-ref HEAD
14+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
15+
OUTPUT_VARIABLE GIT_BRANCH
16+
OUTPUT_STRIP_TRAILING_WHITESPACE
17+
)
18+
execute_process(
19+
COMMAND git show -s --format=%ci ${GIT_HASH}
20+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
21+
OUTPUT_VARIABLE GIT_DATE
22+
OUTPUT_STRIP_TRAILING_WHITESPACE
23+
)
24+
endif(GIT_FOUND)
25+
426
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
527
# set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
628

29+
# global defines
730
list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/)
831
list (APPEND CMAKE_CXX_FLAGS "-std=c++11 -Wno-ignored-attributes")
932

@@ -61,6 +84,7 @@ set (LIB_DEEPMD_OP "deepmd_op")
6184
set (LIB_DEEPMD_NATIVE "deepmd_native_md")
6285
set (LIB_DEEPMD_IPI "deepmd_ipi")
6386

87+
include_directories(${CMAKE_BINARY_DIR}/lib/)
6488
add_subdirectory (lib/)
6589
add_subdirectory (op/)
6690
add_subdirectory (train/)

source/cmake/cmake_lammps.cmake.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ file (
1515
TYPE FILE
1616
FILES "@CMAKE_BINARY_DIR@/lmp/env.sh"
1717
)
18+
19+
file (
20+
INSTALL DESTINATION "${LMP_INSTALL_PREFIX}"
21+
TYPE FILE
22+
FILES "@CMAKE_BINARY_DIR@/lmp/pair_nnp.h"
23+
)

source/ipi/driver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int main(int argc, char * argv[])
192192
for (unsigned dd = 0; dd < dbox.size(); ++dd) dbox_[dd] = dbox[dd];
193193
vector<float> dforce_(dforce.size(), 0);
194194
vector<float> dvirial_(dvirial.size(), 0);
195-
float dener_ = 0;
195+
double dener_ = 0;
196196
nnp_inter.compute (dener_, dforce_, dvirial_, dcoord_, dtype, dbox_);
197197
for (unsigned dd = 0; dd < dforce.size(); ++dd) dforce_tmp[dd] = dforce_[dd];
198198
for (unsigned dd = 0; dd < dvirial.size(); ++dd) dvirial[dd] = dvirial_[dd];

source/lib/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
set (libname ${LIB_DEEPMD})
44

5+
configure_file(
6+
${CMAKE_CURRENT_SOURCE_DIR}/include/version.h.in
7+
version.h
8+
@ONLY
9+
)
10+
511
file(GLOB LIB_SRC src/*.cc src/*.cpp)
6-
file(GLOB INC_SRC include/*.h)
7-
# include_directories ("include/")
12+
file(GLOB INC_SRC include/*.h ${CMAKE_CURRENT_BINARY_DIR}/version.h)
813

914
add_library(${libname} SHARED ${LIB_SRC})
1015

source/lib/include/NNPInter.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
#include "tensorflow/core/framework/shape_inference.h"
88

99
#include <vector>
10+
#include "version.h"
1011

1112
using namespace tensorflow;
1213
using namespace std;
1314

1415
#ifdef HIGH_PREC
1516
typedef double VALUETYPE;
17+
typedef double ENERGYTYPE;
1618
#else
1719
typedef float VALUETYPE;
20+
typedef double ENERGYTYPE;
1821
#endif
1922

2023
struct LammpsNeighborList
@@ -52,31 +55,32 @@ class NNPInter
5255
NNPInter () ;
5356
NNPInter (const string & model);
5457
void init (const string & model);
58+
void print_summary(const string &pre) const;
5559
public:
56-
void compute (VALUETYPE & ener,
60+
void compute (ENERGYTYPE & ener,
5761
vector<VALUETYPE> & force,
5862
vector<VALUETYPE> & virial,
5963
const vector<VALUETYPE> & coord,
6064
const vector<int> & atype,
6165
const vector<VALUETYPE> & box,
6266
const int nghost = 0);
63-
void compute (VALUETYPE & ener,
67+
void compute (ENERGYTYPE & ener,
6468
vector<VALUETYPE> & force,
6569
vector<VALUETYPE> & virial,
6670
const vector<VALUETYPE> & coord,
6771
const vector<int> & atype,
6872
const vector<VALUETYPE> & box,
6973
const int nghost,
7074
const LammpsNeighborList & lmp_list);
71-
void compute (VALUETYPE & ener,
75+
void compute (ENERGYTYPE & ener,
7276
vector<VALUETYPE> & force,
7377
vector<VALUETYPE> & virial,
7478
vector<VALUETYPE> & atom_energy,
7579
vector<VALUETYPE> & atom_virial,
7680
const vector<VALUETYPE> & coord,
7781
const vector<int> & atype,
7882
const vector<VALUETYPE> & box);
79-
void compute (VALUETYPE & ener,
83+
void compute (ENERGYTYPE & ener,
8084
vector<VALUETYPE> & force,
8185
vector<VALUETYPE> & virial,
8286
vector<VALUETYPE> & atom_energy,
@@ -105,22 +109,22 @@ class NNPInterModelDevi
105109
NNPInterModelDevi (const vector<string> & models);
106110
void init (const vector<string> & models);
107111
public:
108-
void compute (VALUETYPE & ener,
112+
void compute (ENERGYTYPE & ener,
109113
vector<VALUETYPE> & force,
110114
vector<VALUETYPE> & virial,
111115
vector<VALUETYPE> & model_devi,
112116
const vector<VALUETYPE> & coord,
113117
const vector<int> & atype,
114118
const vector<VALUETYPE> & box);
115-
void compute (vector<VALUETYPE> & all_ener,
119+
void compute (vector<ENERGYTYPE> & all_ener,
116120
vector<vector<VALUETYPE> > & all_force,
117121
vector<vector<VALUETYPE> > & all_virial,
118122
const vector<VALUETYPE> & coord,
119123
const vector<int> & atype,
120124
const vector<VALUETYPE> & box,
121125
const int nghost,
122126
const LammpsNeighborList & lmp_list);
123-
void compute (vector<VALUETYPE> & all_ener,
127+
void compute (vector<ENERGYTYPE> & all_ener,
124128
vector<vector<VALUETYPE> > & all_force,
125129
vector<vector<VALUETYPE> > & all_virial,
126130
vector<vector<VALUETYPE> > & all_atom_energy,
@@ -131,13 +135,14 @@ class NNPInterModelDevi
131135
const int nghost,
132136
const LammpsNeighborList & lmp_list);
133137
VALUETYPE cutoff () const {return rcut;};
138+
#ifndef HIGH_PREC
139+
void compute_avg (ENERGYTYPE & dener,
140+
const vector<ENERGYTYPE > & all_energy);
141+
#endif
134142
void compute_avg (VALUETYPE & dener,
135143
const vector<VALUETYPE > & all_energy);
136-
void compute_avg (vector<VALUETYPE> & avg,
144+
void compute_avg (vector<VALUETYPE> & avg,
137145
const vector<vector<VALUETYPE> > & xx);
138-
void compute_std (VALUETYPE & std,
139-
const VALUETYPE & avg,
140-
const vector<VALUETYPE >& xx);
141146
void compute_std_e (vector<VALUETYPE> & std,
142147
const vector<VALUETYPE> & avg,
143148
const vector<vector<VALUETYPE> >& xx);

source/lib/include/version.h.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <string>
4+
using namespace std;
5+
6+
#ifdef HIGH_PREC
7+
const string global_float_prec="double";
8+
#else
9+
const string global_float_prec="float";
10+
#endif
11+
12+
const string global_install_prefix="@CMAKE_INSTALL_PREFIX@";
13+
const string global_git_hash="@GIT_HASH@";
14+
const string global_git_date="@GIT_DATE@";
15+
const string global_git_branch="@GIT_BRANCH@";
16+
const string global_tf_include_dir="@TensorFlow_INCLUDE_DIRS@";
17+
const string global_tf_lib_dir="@TensorFlow_LIBRARY_PATH@";

0 commit comments

Comments
 (0)