Skip to content

Commit b688b6b

Browse files
author
Han Wang
committed
implement scale. spline5 as smoothing function. fix bug of empty region
1 parent 1edbecc commit b688b6b

File tree

7 files changed

+81
-17
lines changed

7 files changed

+81
-17
lines changed

source/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ project(DeePMD)
33

44
find_package(Git)
55
if(GIT_FOUND)
6+
execute_process(
7+
COMMAND git describe --tags --dirty
8+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
9+
OUTPUT_VARIABLE GIT_SUMM
10+
OUTPUT_STRIP_TRAILING_WHITESPACE
11+
)
612
execute_process(
713
COMMAND git log -1 --format=%h
814
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}

source/lib/include/ComputeDescriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ void compute_descriptor_norot (vector<double > & descrpt_a,
968968
double inr4 = inr2 * inr2;
969969
double inr3 = inr4 * nr;
970970
double sw, dsw;
971-
cos_switch(sw, dsw, nr, rmin, rmax);
971+
spline5_switch(sw, dsw, nr, rmin, rmax);
972972
int idx_deriv = nei_iter * 4 * 3; // 4 components time 3 directions
973973
int idx_value = nei_iter * 4; // 4 components
974974
// 4 value components

source/lib/include/version.h.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ const string global_float_prec="float";
1010
#endif
1111

1212
const string global_install_prefix="@CMAKE_INSTALL_PREFIX@";
13+
const string global_git_summ="@GIT_SUMM@";
1314
const string global_git_hash="@GIT_HASH@";
1415
const string global_git_date="@GIT_DATE@";
1516
const string global_git_branch="@GIT_BRANCH@";
1617
const string global_tf_include_dir="@TensorFlow_INCLUDE_DIRS@";
17-
const string global_tf_lib_dir="@TensorFlow_LIBRARY_PATH@";
18+
const string global_tf_lib="@TensorFlow_LIBRARY@";

source/lib/src/NNPInter.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ run_model (ENERGYTYPE & dener,
293293
{
294294
unsigned nloc = nnpmap.get_type().size();
295295
unsigned nall = nloc + nghost;
296+
if (nloc == 0) {
297+
dener = 0;
298+
dforce_.clear();
299+
dvirial.resize(9);
300+
fill(dvirial.begin(), dvirial.end(), 0.0);
301+
return;
302+
}
296303

297304
std::vector<Tensor> output_tensors;
298305

@@ -335,6 +342,15 @@ run_model (ENERGYTYPE & dener,
335342
{
336343
unsigned nloc = nnpmap.get_type().size();
337344
unsigned nall = nloc + nghost;
345+
if (nloc == 0) {
346+
dener = 0;
347+
dforce_.clear();
348+
dvirial.resize(9);
349+
fill(dvirial.begin(), dvirial.end(), 0.0);
350+
datom_energy_.clear();
351+
datom_virial_.clear();
352+
return;
353+
}
338354

339355
std::vector<Tensor> output_tensors;
340356

@@ -418,12 +434,13 @@ NNPInter::
418434
print_summary(const string &pre) const
419435
{
420436
cout << pre << "installed to: " + global_install_prefix << endl;
437+
cout << pre << "source: " + global_git_summ << endl;
421438
cout << pre << "source brach: " + global_git_branch << endl;
422439
cout << pre << "source commit: " + global_git_hash << endl;
423440
cout << pre << "source commit at: " + global_git_date << endl;
424441
cout << pre << "build float prec: " + global_float_prec << endl;
425442
cout << pre << "build with tf inc: " + global_tf_include_dir << endl;
426-
cout << pre << "build with tf lib: " + global_tf_lib_dir << endl;
443+
cout << pre << "build with tf lib: " + global_tf_lib << endl;
427444
}
428445

429446

source/lmp/pair_nnp.cpp

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ PairNNP::PairNNP(LAMMPS *lmp)
4545
cutoff = 0.;
4646
numb_models = 0;
4747
out_freq = 0;
48+
scale = NULL;
4849

4950
// set comm size needed by this Pair
5051
comm_reverse = 1;
@@ -61,12 +62,13 @@ PairNNP::print_summary(const string pre) const
6162
nnp_inter.print_summary(pre);
6263
cout << pre << ">>> Info of lammps module:" << endl;
6364
cout << pre << "use deepmd-kit at: " << STR_DEEPMD_ROOT << endl;
65+
cout << pre << "source: " << STR_GIT_SUMM << endl;
6466
cout << pre << "source branch: " << STR_GIT_BRANCH << endl;
6567
cout << pre << "source commit: " << STR_GIT_HASH << endl;
6668
cout << pre << "source commit at: " << STR_GIT_DATE << endl;
6769
cout << pre << "build float prec: " << STR_FLOAT_PREC << endl;
6870
cout << pre << "build with tf inc: " << STR_TensorFlow_INCLUDE_DIRS << endl;
69-
cout << pre << "build with tf lib: " << STR_TensorFlow_LIBRARY_PATH << endl;
71+
cout << pre << "build with tf lib: " << STR_TensorFlow_LIBRARY << endl;
7072
}
7173
}
7274

@@ -76,6 +78,7 @@ PairNNP::~PairNNP()
7678
if (allocated) {
7779
memory->destroy(setflag);
7880
memory->destroy(cutsq);
81+
memory->destroy(scale);
7982
}
8083
}
8184

@@ -342,19 +345,19 @@ void PairNNP::compute(int eflag, int vflag)
342345
// get force
343346
for (int ii = 0; ii < nall; ++ii){
344347
for (int dd = 0; dd < 3; ++dd){
345-
f[ii][dd] += dforce[3*ii+dd];
348+
f[ii][dd] += scale[1][1] * dforce[3*ii+dd];
346349
}
347350
}
348351

349352
// accumulate energy and virial
350-
if (eflag) eng_vdwl += dener;
353+
if (eflag) eng_vdwl += scale[1][1] * dener;
351354
if (vflag) {
352-
virial[0] += 1.0 * dvirial[0];
353-
virial[1] += 1.0 * dvirial[4];
354-
virial[2] += 1.0 * dvirial[8];
355-
virial[3] += 1.0 * dvirial[3];
356-
virial[4] += 1.0 * dvirial[6];
357-
virial[5] += 1.0 * dvirial[7];
355+
virial[0] += 1.0 * dvirial[0] * scale[1][1];
356+
virial[1] += 1.0 * dvirial[4] * scale[1][1];
357+
virial[2] += 1.0 * dvirial[8] * scale[1][1];
358+
virial[3] += 1.0 * dvirial[3] * scale[1][1];
359+
virial[4] += 1.0 * dvirial[6] * scale[1][1];
360+
virial[5] += 1.0 * dvirial[7] * scale[1][1];
358361
}
359362
}
360363

@@ -372,6 +375,7 @@ void PairNNP::allocate()
372375
setflag[i][i] = 1;
373376

374377
memory->create(cutsq,n+1,n+1,"pair:cutsq");
378+
memory->create(scale,n+1,n+1,"pair:scale");
375379
}
376380

377381
void PairNNP::settings(int narg, char **arg)
@@ -425,6 +429,28 @@ void PairNNP::coeff(int narg, char **arg)
425429
if (!allocated) {
426430
allocate();
427431
}
432+
433+
int n = atom->ntypes;
434+
int ilo,ihi,jlo,jhi;
435+
ilo = 0;
436+
jlo = 0;
437+
ihi = n;
438+
jhi = n;
439+
if (narg == 2) {
440+
force->bounds(FLERR,arg[0],atom->ntypes,ilo,ihi);
441+
force->bounds(FLERR,arg[1],atom->ntypes,jlo,jhi);
442+
if (ilo != 0 || jlo != 0 || ihi != n || jhi != n) {
443+
error->all(FLERR,"deepmd requires that the scale should be set to all atom types, i.e. pair_coeff * *.");
444+
}
445+
}
446+
for (int i = ilo; i <= ihi; i++) {
447+
for (int j = MAX(jlo,i); j <= jhi; j++) {
448+
if (i == j) {
449+
setflag[i][i] = 1;
450+
}
451+
scale[i][j] = 1.0;
452+
}
453+
}
428454
}
429455

430456

@@ -439,6 +465,9 @@ void PairNNP::init_style()
439465

440466
double PairNNP::init_one(int i, int j)
441467
{
468+
if (setflag[i][j] == 0) scale[i][j] = 1.0;
469+
scale[j][i] = scale[i][j];
470+
442471
return cutoff;
443472
}
444473

@@ -480,7 +509,13 @@ void PairNNP::unpack_reverse_comm(int n, int *list, double *buf)
480509

481510
void *PairNNP::extract(const char *str, int &dim)
482511
{
483-
dim = 0;
484-
if (strcmp(str,"cut_coul") == 0) return (void *) &cutoff;
512+
if (strcmp(str,"cut_coul") == 0) {
513+
dim = 0;
514+
return (void *) &cutoff;
515+
}
516+
if (strcmp(str,"scale") == 0) {
517+
dim = 2;
518+
return (void *) scale;
519+
}
485520
return NULL;
486521
}

source/lmp/pair_nnp.h.in

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PairStyle(deepmd,PairNNP)
2525
#include <iostream>
2626
#include <fstream>
2727

28+
#define GIT_SUMM @GIT_SUMM@
2829
#define GIT_HASH @GIT_HASH@
2930
#define GIT_BRANCH @GIT_BRANCH@
3031
#define GIT_DATE @GIT_DATE@
@@ -35,16 +36,17 @@ PairStyle(deepmd,PairNNP)
3536
#endif
3637
#define DEEPMD_ROOT @CMAKE_INSTALL_PREFIX@
3738
#define TensorFlow_INCLUDE_DIRS @TensorFlow_INCLUDE_DIRS@
38-
#define TensorFlow_LIBRARY_PATH @TensorFlow_LIBRARY_PATH@
39+
#define TensorFlow_LIBRARY @TensorFlow_LIBRARY@
3940
#define DPMD_CVT_STR(x) #x
4041
#define DPMD_CVT_ASSTR(X) DPMD_CVT_STR(X)
42+
#define STR_GIT_SUMM DPMD_CVT_ASSTR(GIT_SUMM)
4143
#define STR_GIT_HASH DPMD_CVT_ASSTR(GIT_HASH)
4244
#define STR_GIT_BRANCH DPMD_CVT_ASSTR(GIT_BRANCH)
4345
#define STR_GIT_DATE DPMD_CVT_ASSTR(GIT_DATE)
4446
#define STR_FLOAT_PREC DPMD_CVT_ASSTR(FLOAT_PREC)
4547
#define STR_DEEPMD_ROOT DPMD_CVT_ASSTR(DEEPMD_ROOT)
4648
#define STR_TensorFlow_INCLUDE_DIRS DPMD_CVT_ASSTR(TensorFlow_INCLUDE_DIRS)
47-
#define STR_TensorFlow_LIBRARY_PATH DPMD_CVT_ASSTR(TensorFlow_LIBRARY_PATH)
49+
#define STR_TensorFlow_LIBRARY DPMD_CVT_ASSTR(TensorFlow_LIBRARY)
4850

4951
namespace LAMMPS_NS {
5052

@@ -55,7 +57,7 @@ class PairNNP : public Pair {
5557
virtual void compute(int, int);
5658
virtual void *extract(const char *, int &);
5759
void settings(int, char **);
58-
void coeff(int, char **);
60+
virtual void coeff(int, char **);
5961
void init_style();
6062
double init_one(int i, int j);
6163
int pack_reverse_comm(int, int, double *);
@@ -64,6 +66,7 @@ class PairNNP : public Pair {
6466

6567
protected:
6668
virtual void allocate();
69+
double **scale;
6770

6871
private:
6972
NNPInter nnp_inter;

source/train/RunOptions.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ else :
2020
global_float_prec = 'float'
2121

2222
global_install_prefix='@CMAKE_INSTALL_PREFIX@'
23+
global_git_summ='@GIT_SUMM@'
2324
global_git_hash='@GIT_HASH@'
2425
global_git_date='@GIT_DATE@'
2526
global_git_branch='@GIT_BRANCH@'
@@ -166,6 +167,7 @@ class RunOptions (object) :
166167
msg = ""
167168
msg += "---Summary of the training---------------------------------------\n"
168169
msg += 'installed to: %s\n' % global_install_prefix
170+
msg += 'source : %s\n' % global_git_summ
169171
msg += 'source brach: %s\n' % global_git_branch
170172
msg += 'source commit: %s\n' % global_git_hash
171173
msg += 'source commit at: %s\n' % global_git_date

0 commit comments

Comments
 (0)