Merge branch 'master' of https://github.com/lammps/lammps into lammps-master

This commit is contained in:
Jacob Gissinger
2021-04-27 14:46:33 -04:00
4905 changed files with 257534 additions and 191333 deletions

View File

@ -11,10 +11,6 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
// lmptype.h must be first b/c this file uses MAXBIGINT and includes mpi.h
// due to OpenMPI bug which sets INT64_MAX via its mpi.h
// before lmptype.h can set flags to insure it is done correctly
#include "read_data.h"
#include "angle.h"
@ -67,15 +63,15 @@ const char *suffixes[] = {"/cuda","/gpu","/opt","/omp","/kk",
/* ---------------------------------------------------------------------- */
ReadData::ReadData(LAMMPS *lmp) : Pointers(lmp)
ReadData::ReadData(LAMMPS *lmp) : Command(lmp)
{
MPI_Comm_rank(world,&me);
line = new char[MAXLINE];
keyword = new char[MAXLINE];
style = new char[MAXLINE];
buffer = new char[CHUNK*MAXLINE];
narg = maxarg = 0;
arg = nullptr;
ncoeffarg = maxcoeffarg = 0;
coeffarg = nullptr;
fp = nullptr;
// customize for new sections
@ -99,7 +95,7 @@ ReadData::~ReadData()
delete [] keyword;
delete [] style;
delete [] buffer;
memory->sfree(arg);
memory->sfree(coeffarg);
for (int i = 0; i < nfix; i++) {
delete [] fix_header[i];
@ -223,7 +219,7 @@ void ReadData::command(int narg, char **arg)
iarg += 2;
} else if (strcmp(arg[iarg],"extra/bond/per/atom") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal read_data command");
if (! atom->molecular)
if (atom->molecular == Atom::ATOMIC)
error->all(FLERR,"No bonds allowed with this atom style");
atom->extra_bond_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
if (atom->extra_bond_per_atom < 0)
@ -231,7 +227,7 @@ void ReadData::command(int narg, char **arg)
iarg += 2;
} else if (strcmp(arg[iarg],"extra/angle/per/atom") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal read_data command");
if (! atom->molecular)
if (atom->molecular == Atom::ATOMIC)
error->all(FLERR,"No angles allowed with this atom style");
atom->extra_angle_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
if (atom->extra_angle_per_atom < 0)
@ -239,7 +235,7 @@ void ReadData::command(int narg, char **arg)
iarg += 2;
} else if (strcmp(arg[iarg],"extra/dihedral/per/atom") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal read_data command");
if (! atom->molecular)
if (atom->molecular == Atom::ATOMIC)
error->all(FLERR,"No dihedrals allowed with this atom style");
atom->extra_dihedral_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
if (atom->extra_dihedral_per_atom < 0)
@ -247,7 +243,7 @@ void ReadData::command(int narg, char **arg)
iarg += 2;
} else if (strcmp(arg[iarg],"extra/improper/per/atom") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal read_data command");
if (! atom->molecular)
if (atom->molecular == Atom::ATOMIC)
error->all(FLERR,"No impropers allowed with this atom style");
atom->extra_improper_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
if (atom->extra_improper_per_atom < 0)
@ -255,7 +251,7 @@ void ReadData::command(int narg, char **arg)
iarg += 2;
} else if (strcmp(arg[iarg],"extra/special/per/atom") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal read_data command");
if (! atom->molecular)
if (atom->molecular == Atom::ATOMIC)
error->all(FLERR,"No bonded interactions allowed with this atom style");
force->special_extra = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
if (force->special_extra < 0)
@ -280,14 +276,8 @@ void ReadData::command(int narg, char **arg)
if (fix_index[nfix] < 0)
error->all(FLERR,"Fix ID for read_data does not exist");
if (strcmp(arg[iarg+2],"NULL") == 0) fix_header[nfix] = nullptr;
else {
int n = strlen(arg[iarg+2]) + 1;
fix_header[nfix] = new char[n];
strcpy(fix_header[nfix],arg[iarg+2]);
}
int n = strlen(arg[iarg+3]) + 1;
fix_section[nfix] = new char[n];
strcpy(fix_section[nfix],arg[iarg+3]);
else fix_header[nfix] = utils::strdup(arg[iarg+2]);
fix_section[nfix] = utils::strdup(arg[iarg+3]);
nfix++;
iarg += 4;
@ -316,6 +306,12 @@ void ReadData::command(int narg, char **arg)
extra_dihedral_types || extra_improper_types))
error->all(FLERR,"Cannot use read_data extra with add flag");
// check if data file is available and readable
if (!utils::file_is_readable(arg[0]))
error->all(FLERR,fmt::format("Cannot open file {}: {}",
arg[0], utils::getsyserror()));
// first time system initialization
if (addflag == NONE) {
@ -345,6 +341,12 @@ void ReadData::command(int narg, char **arg)
Dihedral *saved_dihedral = nullptr;
Improper *saved_improper = nullptr;
KSpace *saved_kspace = nullptr;
char *saved_pair_style = nullptr;
char *saved_bond_style = nullptr;
char *saved_angle_style = nullptr;
char *saved_dihedral_style = nullptr;
char *saved_improper_style = nullptr;
char *saved_kspace_style = nullptr;
if (coeffflag == 0) {
char *coeffs[2];
@ -352,33 +354,45 @@ void ReadData::command(int narg, char **arg)
coeffs[1] = (char *) "nocoeff";
saved_pair = force->pair;
saved_pair_style = force->pair_style;
force->pair = nullptr;
force->pair_style = nullptr;
force->create_pair("zero",0);
if (force->pair) force->pair->settings(2,coeffs);
coeffs[0] = coeffs[1];
saved_bond = force->bond;
saved_bond_style = force->bond_style;
force->bond = nullptr;
force->bond_style = nullptr;
force->create_bond("zero",0);
if (force->bond) force->bond->settings(1,coeffs);
saved_angle = force->angle;
saved_angle_style = force->angle_style;
force->angle = nullptr;
force->angle_style = nullptr;
force->create_angle("zero",0);
if (force->angle) force->angle->settings(1,coeffs);
saved_dihedral = force->dihedral;
saved_dihedral_style = force->dihedral_style;
force->dihedral = nullptr;
force->dihedral_style = nullptr;
force->create_dihedral("zero",0);
if (force->dihedral) force->dihedral->settings(1,coeffs);
saved_improper = force->improper;
saved_improper_style = force->improper_style;
force->improper = nullptr;
force->improper_style = nullptr;
force->create_improper("zero",0);
if (force->improper) force->improper->settings(1,coeffs);
saved_kspace = force->kspace;
saved_kspace_style = force->kspace_style;
force->kspace = nullptr;
force->kspace_style = nullptr;
}
// -----------------------------------------------------------------
@ -843,7 +857,7 @@ void ReadData::command(int narg, char **arg)
special.build();
}
// for atom style template systems, count total bonds,angles,etc
// for atom style template just count total bonds, etc. from template(s)
if (atom->molecular == Atom::TEMPLATE) {
Molecule **onemols = atom->avec->onemols;
@ -871,13 +885,6 @@ void ReadData::command(int narg, char **arg)
MPI_Allreduce(&ndihedrals,&atom->ndihedrals,1,MPI_LMP_BIGINT,MPI_SUM,world);
MPI_Allreduce(&nimpropers,&atom->nimpropers,1,MPI_LMP_BIGINT,MPI_SUM,world);
if (!force->newton_bond) {
atom->nbonds /= 2;
atom->nangles /= 3;
atom->ndihedrals /= 4;
atom->nimpropers /= 4;
}
if (me == 0) {
std::string mesg;
@ -941,20 +948,26 @@ void ReadData::command(int narg, char **arg)
if (coeffflag == 0) {
if (force->pair) delete force->pair;
force->pair = saved_pair;
force->pair_style = saved_pair_style;
if (force->bond) delete force->bond;
force->bond = saved_bond;
force->bond_style = saved_bond_style;
if (force->angle) delete force->angle;
force->angle = saved_angle;
force->angle_style = saved_angle_style;
if (force->dihedral) delete force->dihedral;
force->dihedral = saved_dihedral;
force->dihedral_style = saved_dihedral_style;
if (force->improper) delete force->improper;
force->improper = saved_improper;
force->improper_style = saved_improper_style;
force->kspace = saved_kspace;
force->kspace_style = saved_kspace_style;
}
// total time
@ -1283,7 +1296,7 @@ void ReadData::atoms()
while (nread < natoms) {
nchunk = MIN(natoms-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (tlabelflag && !lmap->is_complete(Atom::ATOM))
error->all(FLERR,"Label map is incomplete. "
@ -1343,7 +1356,7 @@ void ReadData::velocities()
while (nread < natoms) {
nchunk = MIN(natoms-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
atom->data_vels(nchunk,buffer,id_offset);
nread += nchunk;
@ -1385,7 +1398,7 @@ void ReadData::bonds(int firstpass)
while (nread < nbonds) {
nchunk = MIN(nbonds-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (blabelflag && !lmap->is_complete(Atom::BOND))
error->all(FLERR,"Label map is incomplete. "
@ -1463,7 +1476,7 @@ void ReadData::angles(int firstpass)
while (nread < nangles) {
nchunk = MIN(nangles-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (alabelflag && !lmap->is_complete(Atom::ANGLE))
error->all(FLERR,"Label map is incomplete. "
@ -1541,7 +1554,7 @@ void ReadData::dihedrals(int firstpass)
while (nread < ndihedrals) {
nchunk = MIN(ndihedrals-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (dlabelflag && !lmap->is_complete(Atom::DIHEDRAL))
error->all(FLERR,"Label map is incomplete. "
@ -1619,7 +1632,7 @@ void ReadData::impropers(int firstpass)
while (nread < nimpropers) {
nchunk = MIN(nimpropers-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (ilabelflag && !lmap->is_complete(Atom::IMPROPER))
error->all(FLERR,"Label map is incomplete. "
@ -1690,7 +1703,7 @@ void ReadData::bonus(bigint nbonus, AtomVec *ptr, const char *type)
while (nread < natoms) {
nchunk = MIN(natoms-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
atom->data_bonus(nchunk,buffer,ptr,id_offset);
nread += nchunk;
@ -1817,7 +1830,7 @@ void ReadData::mass()
char *next;
char *buf = new char[ntypes*MAXLINE];
int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf);
int eof = utils::read_lines_from_file(fp,ntypes,MAXLINE,buf,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (tlabelflag && !lmap->is_complete(Atom::ATOM))
error->all(FLERR,"Label map is incomplete. "
@ -1840,7 +1853,7 @@ void ReadData::paircoeffs()
char *next;
char *buf = new char[ntypes*MAXLINE];
int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf);
int eof = utils::read_lines_from_file(fp,ntypes,MAXLINE,buf,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (tlabelflag && !lmap->is_complete(Atom::ATOM))
@ -1853,9 +1866,9 @@ void ReadData::paircoeffs()
*next = '\0';
parse_coeffs(buf,nullptr,1,2,toffset,tlabelflag,
lmap->lmap2lmap.atom);
if (narg == 0)
if (ncoeffarg == 0)
error->all(FLERR,"Unexpected empty line in PairCoeffs section");
force->pair->coeff(narg,arg);
force->pair->coeff(ncoeffarg,coeffarg);
buf = next + 1;
}
delete [] original;
@ -1871,7 +1884,7 @@ void ReadData::pairIJcoeffs()
int nsq = ntypes * (ntypes+1) / 2;
char *buf = new char[nsq * MAXLINE];
int eof = comm->read_lines_from_file(fp,nsq,MAXLINE,buf);
int eof = utils::read_lines_from_file(fp,nsq,MAXLINE,buf,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (tlabelflag && !lmap->is_complete(Atom::ATOM))
@ -1885,9 +1898,9 @@ void ReadData::pairIJcoeffs()
*next = '\0';
parse_coeffs(buf,nullptr,0,2,toffset,tlabelflag,
lmap->lmap2lmap.atom);
if (narg == 0)
if (ncoeffarg == 0)
error->all(FLERR,"Unexpected empty line in PairCoeffs section");
force->pair->coeff(narg,arg);
force->pair->coeff(ncoeffarg,coeffarg);
buf = next + 1;
}
delete [] original;
@ -1902,7 +1915,7 @@ void ReadData::bondcoeffs()
char *next;
char *buf = new char[nbondtypes*MAXLINE];
int eof = comm->read_lines_from_file(fp,nbondtypes,MAXLINE,buf);
int eof = utils::read_lines_from_file(fp,nbondtypes,MAXLINE,buf,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (blabelflag && !lmap->is_complete(Atom::BOND))
@ -1914,9 +1927,9 @@ void ReadData::bondcoeffs()
next = strchr(buf,'\n');
*next = '\0';
parse_coeffs(buf,nullptr,0,1,boffset,blabelflag,lmap->lmap2lmap.bond);
if (narg == 0)
if (ncoeffarg == 0)
error->all(FLERR,"Unexpected empty line in BondCoeffs section");
force->bond->coeff(narg,arg);
force->bond->coeff(ncoeffarg,coeffarg);
buf = next + 1;
}
delete [] original;
@ -1931,7 +1944,7 @@ void ReadData::anglecoeffs(int which)
char *next;
char *buf = new char[nangletypes*MAXLINE];
int eof = comm->read_lines_from_file(fp,nangletypes,MAXLINE,buf);
int eof = utils::read_lines_from_file(fp,nangletypes,MAXLINE,buf,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (alabelflag && !lmap->is_complete(Atom::ANGLE))
@ -1948,8 +1961,8 @@ void ReadData::anglecoeffs(int which)
lmap->lmap2lmap.angle);
else if (which == 2) parse_coeffs(buf,"ba",0,1,aoffset,alabelflag,
lmap->lmap2lmap.angle);
if (narg == 0) error->all(FLERR,"Unexpected empty line in AngleCoeffs section");
force->angle->coeff(narg,arg);
if (ncoeffarg == 0) error->all(FLERR,"Unexpected empty line in AngleCoeffs section");
force->angle->coeff(ncoeffarg,coeffarg);
buf = next + 1;
}
delete [] original;
@ -1964,7 +1977,7 @@ void ReadData::dihedralcoeffs(int which)
char *next;
char *buf = new char[ndihedraltypes*MAXLINE];
int eof = comm->read_lines_from_file(fp,ndihedraltypes,MAXLINE,buf);
int eof = utils::read_lines_from_file(fp,ndihedraltypes,MAXLINE,buf,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (dlabelflag && !lmap->is_complete(Atom::DIHEDRAL))
@ -1987,9 +2000,9 @@ void ReadData::dihedralcoeffs(int which)
lmap->lmap2lmap.dihedral);
else if (which == 5) parse_coeffs(buf,"bb13",0,1,doffset,dlabelflag,
lmap->lmap2lmap.dihedral);
if (narg == 0)
if (ncoeffarg == 0)
error->all(FLERR,"Unexpected empty line in DihedralCoeffs section");
force->dihedral->coeff(narg,arg);
force->dihedral->coeff(ncoeffarg,coeffarg);
buf = next + 1;
}
delete [] original;
@ -2004,7 +2017,7 @@ void ReadData::impropercoeffs(int which)
char *next;
char *buf = new char[nimpropertypes*MAXLINE];
int eof = comm->read_lines_from_file(fp,nimpropertypes,MAXLINE,buf);
int eof = utils::read_lines_from_file(fp,nimpropertypes,MAXLINE,buf,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
if (ilabelflag && !lmap->is_complete(Atom::IMPROPER))
@ -2019,8 +2032,8 @@ void ReadData::impropercoeffs(int which)
lmap->lmap2lmap.improper);
else if (which == 1) parse_coeffs(buf,"aa",0,1,ioffset,ilabelflag,
lmap->lmap2lmap.improper);
if (narg == 0) error->all(FLERR,"Unexpected empty line in ImproperCoeffs section");
force->improper->coeff(narg,arg);
if (ncoeffarg == 0) error->all(FLERR,"Unexpected empty line in ImproperCoeffs section");
force->improper->coeff(ncoeffarg,coeffarg);
buf = next + 1;
}
delete [] original;
@ -2073,7 +2086,7 @@ void ReadData::fix(int ifix, char *keyword)
bigint nread = 0;
while (nread < nline) {
nchunk = MIN(nline-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world);
if (eof) error->all(FLERR,"Unexpected end of data file");
modify->fix[ifix]->read_data_section(keyword,nchunk,buffer,id_offset);
nread += nchunk;
@ -2101,13 +2114,12 @@ int ReadData::reallocate(int **pcount, int cmax, int amax)
void ReadData::open(char *file)
{
compressed = 0;
char *suffix = file + strlen(file) - 3;
if (suffix > file && strcmp(suffix,".gz") == 0) compressed = 1;
if (!compressed) fp = fopen(file,"r");
else {
if (utils::strmatch(file,"\\.gz$")) {
compressed = 1;
#ifdef LAMMPS_GZIP
std::string gunzip = fmt::format("gzip -c -d {}",file);
auto gunzip = fmt::format("gzip -c -d {}",file);
#ifdef _WIN32
fp = _popen(gunzip.c_str(),"rb");
#else
@ -2115,8 +2127,11 @@ void ReadData::open(char *file)
#endif
#else
error->one(FLERR,"Cannot open gzipped file: " + utils::getsyserror());
error->one(FLERR,"Cannot open gzipped file without gzip support");
#endif
} else {
compressed = 0;
fp = fopen(file,"r");
}
if (fp == nullptr)
@ -2211,7 +2226,7 @@ void ReadData::skip_lines(bigint n)
}
/* ----------------------------------------------------------------------
parse a line of coeffs into words, storing them in narg,arg
parse a line of coeffs into words, storing them in ncoeffarg,coeffarg
trim anything from '#' onward
word strings remain in line, are not copied
if addstr != nullptr, add addstr as extra arg for class2 angle/dihedral/improper
@ -2229,35 +2244,40 @@ void ReadData::parse_coeffs(char *line, const char *addstr, int dupflag,
char *ptr;
if ((ptr = strchr(line,'#'))) *ptr = '\0';
narg = 0;
char *word = strtok(line," \t\n\r\f");
while (word) {
if (narg == maxarg) {
maxarg += DELTA;
arg = (char **)
memory->srealloc(arg,maxarg*sizeof(char *),"read_data:arg");
ncoeffarg = 0;
char *word = line;
char *end = line + strlen(line)+1;
while (word < end) {
word += strspn(word," \t\r\n\f");
word[strcspn(word," \t\r\n\f")] = '\0';
if (strlen(word) == 0) break;
if (ncoeffarg == maxcoeffarg) {
maxcoeffarg += DELTA;
coeffarg = (char **)
memory->srealloc(coeffarg,maxcoeffarg*sizeof(char *),"read_data:coeffarg");
}
if (addstr && narg == 1 && !islower(word[0])) arg[narg++] = (char *) addstr;
arg[narg++] = word;
if (addstr && narg == 2 && islower(word[0])) arg[narg++] = (char *) addstr;
if (dupflag && narg == 1) arg[narg++] = word;
word = strtok(nullptr," \t\n\r\f");
if (addstr && ncoeffarg == 1 && !islower(word[0])) coeffarg[ncoeffarg++] = (char *) addstr;
coeffarg[ncoeffarg++] = word;
if (addstr && ncoeffarg == 2 && islower(word[0])) coeffarg[ncoeffarg++] = (char *) addstr;
if (dupflag && ncoeffarg == 1) coeffarg[ncoeffarg++] = word;
word += strlen(word)+1;
}
// to avoid segfaults on empty lines
if (narg == 0) return;
if (ncoeffarg == 0) return;
if (noffset) {
int value = utils::inumeric(FLERR,arg[0],false,lmp);
int value = utils::inumeric(FLERR,coeffarg[0],false,lmp);
if (labelmode) value = ilabel[value-1];
sprintf(argoffset1,"%d",value+offset);
arg[0] = argoffset1;
coeffarg[0] = argoffset1;
if (noffset == 2) {
value = utils::inumeric(FLERR,arg[1],false,lmp);
value = utils::inumeric(FLERR,coeffarg[1],false,lmp);
if (labelmode) value = ilabel[value-1];
sprintf(argoffset2,"%d",value+offset);
arg[1] = argoffset2;
coeffarg[1] = argoffset2;
}
}
}