use tokenizer to read neb initial replica files

This commit is contained in:
Axel Kohlmeyer
2022-03-22 20:00:54 -04:00
parent 4c13f99b04
commit 080662683d
6 changed files with 137 additions and 180 deletions

View File

@ -32,37 +32,3 @@
31 2.2000000000000002e+00 7.1662499999999998e+00 1.0032750000000000e+01 1.4332499999999999e+00 -1.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 31 2.2000000000000002e+00 7.1662499999999998e+00 1.0032750000000000e+01 1.4332499999999999e+00 -1.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
32 2.2000000000000002e+00 1.0032750000000000e+01 1.0032750000000000e+01 1.4332499999999999e+00 -1.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 32 2.2000000000000002e+00 1.0032750000000000e+01 1.0032750000000000e+01 1.4332499999999999e+00 -1.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00

View File

@ -5,7 +5,7 @@ LAMMPS data file via write_data, version 4 Jan 2019, timestep = 0
0.0000000000000000e+00 1.1465999999999999e+01 xlo xhi 0.0000000000000000e+00 1.1465999999999999e+01 xlo xhi
0.0000000000000000e+00 1.1465999999999999e+01 ylo yhi 0.0000000000000000e+00 1.1465999999999999e+01 ylo yhi
0.0000000000000000e+00 2.8664999999999998e+00 zlo zhi -1.0000000000000000e+00 10.0664999999999998e+00 zlo zhi
Masses Masses

View File

@ -135,24 +135,24 @@ FixNEB::FixNEB(LAMMPS *lmp, int narg, char **arg) :
else procnext = -1; else procnext = -1;
uworld = universe->uworld; uworld = universe->uworld;
if (NEBLongRange) {
int *iroots = new int[nreplica]; int *iroots = new int[nreplica];
MPI_Group uworldgroup,rootgroup; MPI_Group uworldgroup,rootgroup;
if (NEBLongRange) {
for (int i=0; i<nreplica; i++) for (int i=0; i<nreplica; i++) iroots[i] = universe->root_proc[i];
iroots[i] = universe->root_proc[i];
MPI_Comm_group(uworld, &uworldgroup); MPI_Comm_group(uworld, &uworldgroup);
MPI_Group_incl(uworldgroup, nreplica, iroots, &rootgroup); MPI_Group_incl(uworldgroup, nreplica, iroots, &rootgroup);
MPI_Comm_create(uworld, rootgroup, &rootworld); MPI_Comm_create(uworld, rootgroup, &rootworld);
} if (rootgroup != MPI_GROUP_NULL) MPI_Group_free(&rootgroup);
if (uworldgroup != MPI_GROUP_NULL) MPI_Group_free(&uworldgroup);
delete [] iroots; delete [] iroots;
}
// create a new compute pe style // create a new compute pe style
// id = fix-ID + pe, compute group = all // id = fix-ID + pe, compute group = all
std::string cmd = id + std::string("_pe"); id_pe = utils::strdup(std::string(id)+"_pe");
id_pe = new char[cmd.size()+1]; modify->add_compute(std::string(id_pe)+" all pe");
strcpy(id_pe,cmd.c_str());
modify->add_compute(cmd + " all pe");
// initialize local storage // initialize local storage

View File

@ -27,6 +27,7 @@
#include "output.h" #include "output.h"
#include "thermo.h" #include "thermo.h"
#include "timer.h" #include "timer.h"
#include "tokenizer.h"
#include "universe.h" #include "universe.h"
#include "update.h" #include "update.h"
@ -173,12 +174,11 @@ void NEB::run()
else color = 1; else color = 1;
MPI_Comm_split(uworld,color,0,&roots); MPI_Comm_split(uworld,color,0,&roots);
int ineb; auto fixes = modify->get_fix_by_style("^neb$");
for (ineb = 0; ineb < modify->nfix; ineb++) if (fixes.size() != 1)
if (strcmp(modify->fix[ineb]->style,"neb") == 0) break; error->all(FLERR,"NEB requires use of exactly one fix neb instance");
if (ineb == modify->nfix) error->all(FLERR,"NEB requires use of fix neb");
fneb = (FixNEB *) modify->fix[ineb]; fneb = (FixNEB *) fixes[0];
if (verbose) numall =7; if (verbose) numall =7;
else numall = 4; else numall = 4;
memory->create(all,nreplica,numall,"neb:all"); memory->create(all,nreplica,numall,"neb:all");
@ -376,11 +376,11 @@ void NEB::run()
void NEB::readfile(char *file, int flag) void NEB::readfile(char *file, int flag)
{ {
int i,j,m,nchunk,eofflag,nlines; int i,nchunk,eofflag,nlines;
tagint tag; tagint tag;
char *eof,*start,*next,*buf; char *eof,*start,*next,*buf;
char line[MAXLINE]; char line[MAXLINE];
double xx,yy,zz,delx,dely,delz; double delx,dely,delz;
if (me_universe == 0 && universe->uscreen) if (me_universe == 0 && universe->uscreen)
fprintf(universe->uscreen,"Reading NEB coordinate file(s) ...\n"); fprintf(universe->uscreen,"Reading NEB coordinate file(s) ...\n");
@ -424,10 +424,7 @@ void NEB::readfile(char *file, int flag)
} }
char *buffer = new char[CHUNK*MAXLINE]; char *buffer = new char[CHUNK*MAXLINE];
char **values = new char*[ATTRIBUTE_PERLINE];
double fraction = ireplica/(nreplica-1.0); double fraction = ireplica/(nreplica-1.0);
double **x = atom->x; double **x = atom->x;
int nlocal = atom->nlocal; int nlocal = atom->nlocal;
@ -435,9 +432,7 @@ void NEB::readfile(char *file, int flag)
// two versions of read_lines_from_file() for world vs universe bcast // two versions of read_lines_from_file() for world vs universe bcast
// count # of atom coords changed so can check for invalid atom IDs in file // count # of atom coords changed so can check for invalid atom IDs in file
int ncount = 0; int ncount = 0, nread = 0;
int nread = 0;
while (nread < nlines) { while (nread < nlines) {
nchunk = MIN(nlines-nread,CHUNK); nchunk = MIN(nlines-nread,CHUNK);
if (flag == 0) if (flag == 0)
@ -461,10 +456,10 @@ void NEB::readfile(char *file, int flag)
for (i = 0; i < nchunk; i++) { for (i = 0; i < nchunk; i++) {
next = strchr(buf,'\n'); next = strchr(buf,'\n');
*next = '\0';
values[0] = strtok(buf," \t\n\r\f"); try {
for (j = 1; j < nwords; j++) ValueTokenizer values(buf," \t\n\r\f");
values[j] = strtok(nullptr," \t\n\r\f");
// adjust atom coord based on replica fraction // adjust atom coord based on replica fraction
// for flag = 0, interpolate for intermediate and final replicas // for flag = 0, interpolate for intermediate and final replicas
@ -476,17 +471,14 @@ void NEB::readfile(char *file, int flag)
// will be remapped back into box when simulation starts // will be remapped back into box when simulation starts
// its image flags will then be adjusted // its image flags will then be adjusted
tag = ATOTAGINT(values[0]); tag = values.next_tagint();
m = atom->map(tag); int m = atom->map(tag);
if (m >= 0 && m < nlocal) { if (m >= 0 && m < nlocal) {
ncount++; ncount++;
xx = atof(values[1]);
yy = atof(values[2]);
zz = atof(values[3]);
delx = xx - x[m][0]; delx = values.next_double() - x[m][0];
dely = yy - x[m][1]; dely = values.next_double() - x[m][1];
delz = zz - x[m][2]; delz = values.next_double() - x[m][2];
domain->minimum_image(delx,dely,delz); domain->minimum_image(delx,dely,delz);
@ -500,10 +492,11 @@ void NEB::readfile(char *file, int flag)
x[m][2] += delz; x[m][2] += delz;
} }
} }
} catch (std::exception &e) {
error->universe_one(FLERR,"Incorrectly formatted NEB file: " + std::string(e.what()));
}
buf = next + 1; buf = next + 1;
} }
nread += nchunk; nread += nchunk;
} }
@ -522,9 +515,7 @@ void NEB::readfile(char *file, int flag)
} }
// clean up // clean up
delete[] buffer; delete[] buffer;
delete [] values;
if (flag == 0) { if (flag == 0) {
if (me_universe == 0) { if (me_universe == 0) {

View File

@ -56,7 +56,7 @@ FixNEBSpin::FixNEBSpin(LAMMPS *lmp, int narg, char **arg) :
counts(nullptr), displacements(nullptr) counts(nullptr), displacements(nullptr)
{ {
if (narg < 4) error->all(FLERR,"Illegal fix neb_spin command"); if (narg < 4) error->all(FLERR,"Illegal fix neb/spin command");
kspring = utils::numeric(FLERR,arg[3],false,lmp); kspring = utils::numeric(FLERR,arg[3],false,lmp);
if (kspring <= 0.0) error->all(FLERR,"Illegal fix neb command"); if (kspring <= 0.0) error->all(FLERR,"Illegal fix neb command");
@ -77,16 +77,16 @@ FixNEBSpin::FixNEBSpin(LAMMPS *lmp, int narg, char **arg) :
int iarg = 4; int iarg = 4;
while (iarg < narg) { while (iarg < narg) {
if (strcmp(arg[iarg],"parallel") == 0) { if (strcmp(arg[iarg],"parallel") == 0) {
error->all(FLERR,"Illegal fix neb command"); error->all(FLERR,"Illegal fix neb/spin command");
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg],"perp") == 0) { } else if (strcmp(arg[iarg],"perp") == 0) {
error->all(FLERR,"Illegal fix neb command"); error->all(FLERR,"Illegal fix neb/spin command");
iarg += 2; iarg += 2;
} else if (strcmp (arg[iarg],"end") == 0) { } else if (strcmp (arg[iarg],"end") == 0) {
iarg += 3; iarg += 3;
} else if (strcmp (arg[iarg],"lattice") == 0) { } else if (strcmp (arg[iarg],"lattice") == 0) {
iarg += 2; iarg += 2;
} else error->all(FLERR,"Illegal fix neb command"); } else error->all(FLERR,"Illegal fix neb/spin command");
} }
// nreplica = number of partitions // nreplica = number of partitions
@ -107,16 +107,18 @@ FixNEBSpin::FixNEBSpin(LAMMPS *lmp, int narg, char **arg) :
else procnext = -1; else procnext = -1;
uworld = universe->uworld; uworld = universe->uworld;
if (NEBLongRange) {
int *iroots = new int[nreplica]; int *iroots = new int[nreplica];
MPI_Group uworldgroup,rootgroup; MPI_Group uworldgroup,rootgroup;
if (NEBLongRange) {
for (int i=0; i<nreplica; i++) for (int i=0; i<nreplica; i++) iroots[i] = universe->root_proc[i];
iroots[i] = universe->root_proc[i];
MPI_Comm_group(uworld, &uworldgroup); MPI_Comm_group(uworld, &uworldgroup);
MPI_Group_incl(uworldgroup, nreplica, iroots, &rootgroup); MPI_Group_incl(uworldgroup, nreplica, iroots, &rootgroup);
MPI_Comm_create(uworld, rootgroup, &rootworld); MPI_Comm_create(uworld, rootgroup, &rootworld);
} if (rootgroup != MPI_GROUP_NULL) MPI_Group_free(&rootgroup);
if (uworldgroup != MPI_GROUP_NULL) MPI_Group_free(&uworldgroup);
delete [] iroots; delete [] iroots;
}
// create a new compute pe style // create a new compute pe style
// id = fix-ID + pe, compute group = all // id = fix-ID + pe, compute group = all

View File

@ -38,6 +38,7 @@
#include "output.h" #include "output.h"
#include "thermo.h" #include "thermo.h"
#include "timer.h" #include "timer.h"
#include "tokenizer.h"
#include "universe.h" #include "universe.h"
#include "update.h" #include "update.h"
@ -147,6 +148,7 @@ void NEBSpin::command(int narg, char **arg)
verbose=false; verbose=false;
if (strcmp(arg[narg-1],"verbose") == 0) verbose=true; if (strcmp(arg[narg-1],"verbose") == 0) verbose=true;
// run the NEB calculation
run(); run();
} }
@ -166,12 +168,11 @@ void NEBSpin::run()
// search for neb_spin fix, allocate it // search for neb_spin fix, allocate it
int ineb; auto fixes = modify->get_fix_by_style("^neb/spin");
for (ineb = 0; ineb < modify->nfix; ineb++) if (fixes.size() != 1)
if (strcmp(modify->fix[ineb]->style,"neb/spin") == 0) break; error->all(FLERR,"NEBSpin requires use of exactly one fix neb/spin instance");
if (ineb == modify->nfix) error->all(FLERR,"NEBSpin requires use of fix neb/spin");
fneb = (FixNEBSpin *) modify->fix[ineb]; fneb = (FixNEBSpin *) fixes[0];
if (verbose) numall =7; if (verbose) numall =7;
else numall = 4; else numall = 4;
memory->create(all,nreplica,numall,"neb:all"); memory->create(all,nreplica,numall,"neb:all");
@ -370,12 +371,11 @@ void NEBSpin::run()
void NEBSpin::readfile(char *file, int flag) void NEBSpin::readfile(char *file, int flag)
{ {
int i,j,m,nchunk,eofflag,nlines; int i,nchunk,eofflag,nlines;
tagint tag; tagint tag;
char *eof,*start,*next,*buf; char *eof,*start,*next,*buf;
char line[MAXLINE]; char line[MAXLINE];
double xx,yy,zz; double musp,xx,yy,zz,spx,spy,spz;
double musp,spx,spy,spz;
if (me_universe == 0 && universe->uscreen) if (me_universe == 0 && universe->uscreen)
fprintf(universe->uscreen,"Reading NEBSpin coordinate file(s) ...\n"); fprintf(universe->uscreen,"Reading NEBSpin coordinate file(s) ...\n");
@ -393,10 +393,12 @@ void NEBSpin::readfile(char *file, int flag)
start = &line[strspn(line," \t\n\v\f\r")]; start = &line[strspn(line," \t\n\v\f\r")];
if (*start != '\0' && *start != '#') break; if (*start != '\0' && *start != '#') break;
} }
sscanf(line,"%d",&nlines); int rv = sscanf(line,"%d",&nlines);
if (rv != 1) nlines = -1;
} }
MPI_Bcast(&nlines,1,MPI_INT,0,uworld); MPI_Bcast(&nlines,1,MPI_INT,0,uworld);
if (nlines < 0)
error->universe_all(FLERR,"Incorrectly formatted NEB file");
} else { } else {
if (me == 0) { if (me == 0) {
if (ireplica) { if (ireplica) {
@ -407,17 +409,17 @@ void NEBSpin::readfile(char *file, int flag)
start = &line[strspn(line," \t\n\v\f\r")]; start = &line[strspn(line," \t\n\v\f\r")];
if (*start != '\0' && *start != '#') break; if (*start != '\0' && *start != '#') break;
} }
sscanf(line,"%d",&nlines); int rv = sscanf(line,"%d",&nlines);
if (rv != 1) nlines = -1;
} else nlines = 0; } else nlines = 0;
} }
MPI_Bcast(&nlines,1,MPI_INT,0,world); MPI_Bcast(&nlines,1,MPI_INT,0,world);
if (nlines < 0)
error->all(FLERR,"Incorrectly formatted NEB file");
} }
char *buffer = new char[CHUNK*MAXLINE]; char *buffer = new char[CHUNK*MAXLINE];
char **values = new char*[ATTRIBUTE_PERLINE];
double fraction = ireplica/(nreplica-1.0); double fraction = ireplica/(nreplica-1.0);
double **x = atom->x; double **x = atom->x;
double **sp = atom->sp; double **sp = atom->sp;
double spinit[3],spfinal[3]; double spinit[3],spfinal[3];
@ -427,11 +429,7 @@ void NEBSpin::readfile(char *file, int flag)
// two versions of read_lines_from_file() for world vs universe bcast // two versions of read_lines_from_file() for world vs universe bcast
// count # of atom coords changed so can check for invalid atom IDs in file // count # of atom coords changed so can check for invalid atom IDs in file
int ncount = 0; int ncount=0, nread=0, temp_flag=0, rot_flag=0;
int temp_flag,rot_flag;
temp_flag = rot_flag = 0;
int nread = 0;
while (nread < nlines) { while (nread < nlines) {
nchunk = MIN(nlines-nread,CHUNK); nchunk = MIN(nlines-nread,CHUNK);
if (flag == 0) if (flag == 0)
@ -444,7 +442,7 @@ void NEBSpin::readfile(char *file, int flag)
buf = buffer; buf = buffer;
next = strchr(buf,'\n'); next = strchr(buf,'\n');
*next = '\0'; *next = '\0';
int nwords = utils::trim_and_count_words(buf); int nwords = utils::count_words(utils::trim_comment(buf));
*next = '\n'; *next = '\n';
if (nwords != ATTRIBUTE_PERLINE) if (nwords != ATTRIBUTE_PERLINE)
@ -455,10 +453,10 @@ void NEBSpin::readfile(char *file, int flag)
for (i = 0; i < nchunk; i++) { for (i = 0; i < nchunk; i++) {
next = strchr(buf,'\n'); next = strchr(buf,'\n');
*next = '\0';
values[0] = strtok(buf," \t\n\r\f"); try {
for (j = 1; j < nwords; j++) ValueTokenizer values(buf," \t\n\r\f");
values[j] = strtok(nullptr," \t\n\r\f");
// adjust spin coord based on replica fraction // adjust spin coord based on replica fraction
// for flag = 0, interpolate for intermediate and final replicas // for flag = 0, interpolate for intermediate and final replicas
@ -471,17 +469,18 @@ void NEBSpin::readfile(char *file, int flag)
// will be remapped back into box when simulation starts // will be remapped back into box when simulation starts
// its image flags will then be adjusted // its image flags will then be adjusted
tag = ATOTAGINT(values[0]); tag = values.next_tagint();
m = atom->map(tag); int m = atom->map(tag);
if (m >= 0 && m < nlocal) { if (m >= 0 && m < nlocal) {
ncount++; ncount++;
musp = atof(values[1]);
xx = atof(values[2]); musp = values.next_double();
yy = atof(values[3]); xx = values.next_double();
zz = atof(values[4]); yy = values.next_double();
spx = atof(values[5]); zz = values.next_double();
spy = atof(values[6]); spx = values.next_double();
spz = atof(values[7]); spy = values.next_double();
spz = values.next_double();
if (flag == 0) { if (flag == 0) {
@ -520,10 +519,11 @@ void NEBSpin::readfile(char *file, int flag)
sp[m][2] = spz; sp[m][2] = spz;
} }
} }
} catch (std::exception &e) {
error->universe_one(FLERR,"Incorrectly formatted NEB file: " + std::string(e.what()));
}
buf = next + 1; buf = next + 1;
} }
nread += nchunk; nread += nchunk;
} }
@ -549,9 +549,7 @@ void NEBSpin::readfile(char *file, int flag)
} }
// clean up // clean up
delete[] buffer; delete[] buffer;
delete[] values;
if (flag == 0) { if (flag == 0) {
if (me_universe == 0) { if (me_universe == 0) {