Skip to content

Commit 8c92b50

Browse files
author
Han Wang
committed
correct type behavior with lammps
1 parent 798777b commit 8c92b50

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

source/lib/include/NNPInter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class NNPInter
9090
const vector<VALUETYPE> & box,
9191
const int nghost,
9292
const LammpsNeighborList & lmp_list);
93-
VALUETYPE cutoff () const {return rcut;};
93+
VALUETYPE cutoff () const {assert(inited); return rcut;};
94+
int numb_types () const {assert(inited); return ntypes;};
9495
private:
9596
Session* session;
9697
int num_intra_nthreads, num_inter_nthreads;
@@ -135,7 +136,8 @@ class NNPInterModelDevi
135136
const vector<VALUETYPE> & box,
136137
const int nghost,
137138
const LammpsNeighborList & lmp_list);
138-
VALUETYPE cutoff () const {return rcut;};
139+
VALUETYPE cutoff () const {assert(inited); return rcut;};
140+
int numb_types () const {assert(inited); return ntypes;};
139141
#ifndef HIGH_PREC
140142
void compute_avg (ENERGYTYPE & dener,
141143
const vector<ENERGYTYPE > & all_energy);

source/lmp/pair_nnp.cpp

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ PairNNP::PairNNP(LAMMPS *lmp)
4343
respa_enable = 0;
4444
writedata = 0;
4545
cutoff = 0.;
46+
numb_types = 0;
4647
numb_models = 0;
4748
out_freq = 0;
4849
scale = NULL;
@@ -368,14 +369,23 @@ void PairNNP::allocate()
368369
int n = atom->ntypes;
369370

370371
memory->create(setflag,n+1,n+1,"pair:setflag");
371-
for (int i = 1; i <= n; i++)
372-
for (int j = i; j <= n; j++)
373-
setflag[i][j] = 0;
374-
for (int i = 1; i <= n; i++)
375-
setflag[i][i] = 1;
376-
377372
memory->create(cutsq,n+1,n+1,"pair:cutsq");
378373
memory->create(scale,n+1,n+1,"pair:scale");
374+
375+
for (int i = 1; i <= n; i++){
376+
for (int j = i; j <= n; j++){
377+
setflag[i][j] = 0;
378+
scale[i][j] = 0;
379+
}
380+
}
381+
for (int i = 1; i <= numb_types; ++i) {
382+
if (i > n) continue;
383+
for (int j = i; j <= numb_types; ++j) {
384+
if (j > n) continue;
385+
setflag[i][j] = 1;
386+
scale[i][j] = 1;
387+
}
388+
}
379389
}
380390

381391
void PairNNP::settings(int narg, char **arg)
@@ -385,6 +395,7 @@ void PairNNP::settings(int narg, char **arg)
385395
if (narg == 1) {
386396
nnp_inter.init (arg[0]);
387397
cutoff = nnp_inter.cutoff ();
398+
numb_types = nnp_inter.numb_types();
388399
numb_models = 1;
389400
}
390401
else {
@@ -401,6 +412,7 @@ void PairNNP::settings(int narg, char **arg)
401412

402413
nnp_inter_model_devi.init(models);
403414
cutoff = nnp_inter_model_devi.cutoff();
415+
numb_types = nnp_inter_model_devi.numb_types();
404416
numb_models = models.size();
405417
if (comm->me == 0){
406418
fp.open (out_file);
@@ -416,6 +428,24 @@ void PairNNP::settings(int narg, char **arg)
416428
<< endl;
417429
}
418430
}
431+
432+
if (comm->me == 0){
433+
string pre = " ";
434+
cout << pre << ">>> Info of model(s):" << endl
435+
<< pre << "using " << setw(3) << numb_models << " model(s): ";
436+
if (narg == 1) {
437+
cout << arg[0] << " ";
438+
}
439+
else {
440+
for (int ii = 0; ii < narg-2; ++ii){
441+
cout << arg[ii] << " ";
442+
}
443+
}
444+
cout << endl
445+
<< pre << "rcut in model: " << cutoff << endl
446+
<< pre << "ntypes in model: " << numb_types << endl;
447+
}
448+
419449
comm_reverse = numb_models * 3;
420450
all_force.resize(numb_models);
421451
}
@@ -445,12 +475,15 @@ void PairNNP::coeff(int narg, char **arg)
445475
}
446476
for (int i = ilo; i <= ihi; i++) {
447477
for (int j = MAX(jlo,i); j <= jhi; j++) {
448-
if (i == j) {
449-
setflag[i][i] = 1;
450-
}
478+
setflag[i][j] = 1;
451479
scale[i][j] = 1.0;
480+
if (i > numb_types || j > numb_types) {
481+
char warning_msg[1024];
482+
sprintf(warning_msg, "Interaction between types %d and %d is set with deepmd, but will be ignored.\n Deepmd model has only %d types, it only computes the mulitbody interaction of types: 1-%d.", i, j, numb_types, numb_types);
483+
error->warning(FLERR, warning_msg);
484+
}
452485
}
453-
}
486+
}
454487
}
455488

456489

@@ -465,6 +498,12 @@ void PairNNP::init_style()
465498

466499
double PairNNP::init_one(int i, int j)
467500
{
501+
if (i > numb_types || j > numb_types) {
502+
char warning_msg[1024];
503+
sprintf(warning_msg, "Interaction between types %d and %d is set with deepmd, but will be ignored.\n Deepmd model has only %d types, it only computes the mulitbody interaction of types: 1-%d.", i, j, numb_types, numb_types);
504+
error->warning(FLERR, warning_msg);
505+
}
506+
468507
if (setflag[i][j] == 0) scale[i][j] = 1.0;
469508
scale[j][i] = scale[i][j];
470509

source/lmp/pair_nnp.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private:
7373
NNPInterModelDevi nnp_inter_model_devi;
7474
unsigned numb_models;
7575
double cutoff;
76+
int numb_types;
7677
vector<vector<double > > all_force;
7778
ofstream fp;
7879
int out_freq;

0 commit comments

Comments
 (0)