read_data: bond, etc. direct label support

This commit is contained in:
Jacob Gissinger
2021-11-07 00:51:55 -04:00
parent 062b880661
commit 3fc47a9366
4 changed files with 80 additions and 37 deletions

View File

@ -53,6 +53,7 @@ using namespace MathConst;
#define DELTA 1
#define DELTA_PERATOM 64
#define EPSILON 1.0e-6
#define MAXLINE 256
/* ---------------------------------------------------------------------- */
@ -1198,9 +1199,9 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,
if (id_offset) tag[nlocal-1] += id_offset;
if (mol_offset) molecule[nlocal-1] += mol_offset;
if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file");
if (!atom->labelmapflag) error->one(FLERR,"Invalid Atoms section in data file");
type[nlocal-1] = atom->find_label(typestr,Atom::ATOM);
if (type[nlocal-1] == -1) error->one(FLERR,"Invalid Types section in molecule file");
if (type[nlocal-1] == -1) error->one(FLERR,"Invalid Atoms section in data file");
} else {
type[nlocal-1] = utils::inumeric(FLERR,typestr.c_str(),true,lmp);
if (labelflag) type[nlocal-1] = ilabel[type[nlocal-1]-1];
@ -1275,20 +1276,30 @@ void Atom::data_bonds(int n, char *buf, int *count, tagint id_offset,
int m,tmp,itype,rv;
tagint atom1,atom2;
char *next;
char typechar[MAXLINE];
std::string typestr;
int newton_bond = force->newton_bond;
for (int i = 0; i < n; i++) {
next = strchr(buf,'\n');
*next = '\0';
rv = sscanf(buf,"%d %d " TAGINT_FORMAT " " TAGINT_FORMAT,
&tmp,&itype,&atom1,&atom2);
rv = sscanf(buf,"%d %s " TAGINT_FORMAT " " TAGINT_FORMAT,
&tmp,typechar,&atom1,&atom2);
if (rv != 4)
error->one(FLERR,"Incorrect format of Bonds section in data file");
if (id_offset) {
atom1 += id_offset;
atom2 += id_offset;
}
if (labelflag) itype = ilabel[itype-1];
typestr = typechar;
if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in data file");
itype = atom->find_label(typestr,Atom::BOND);
if (itype == -1) error->one(FLERR,"Invalid Bonds section in data file");
} else {
itype = utils::inumeric(FLERR,typechar,true,lmp);
if (labelflag) itype = ilabel[itype-1];
}
itype += type_offset;
if ((atom1 <= 0) || (atom1 > map_tag_max) ||
@ -1333,13 +1344,15 @@ void Atom::data_angles(int n, char *buf, int *count, tagint id_offset,
int m,tmp,itype,rv;
tagint atom1,atom2,atom3;
char *next;
char typechar[MAXLINE];
std::string typestr;
int newton_bond = force->newton_bond;
for (int i = 0; i < n; i++) {
next = strchr(buf,'\n');
*next = '\0';
rv = sscanf(buf,"%d %d " TAGINT_FORMAT " " TAGINT_FORMAT " " TAGINT_FORMAT,
&tmp,&itype,&atom1,&atom2,&atom3);
rv = sscanf(buf,"%d %s " TAGINT_FORMAT " " TAGINT_FORMAT " " TAGINT_FORMAT,
&tmp,typechar,&atom1,&atom2,&atom3);
if (rv != 5)
error->one(FLERR,"Incorrect format of Angles section in data file");
if (id_offset) {
@ -1347,7 +1360,15 @@ void Atom::data_angles(int n, char *buf, int *count, tagint id_offset,
atom2 += id_offset;
atom3 += id_offset;
}
if (labelflag) itype = ilabel[itype-1];
typestr = typechar;
if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in data file");
itype = atom->find_label(typestr,Atom::ANGLE);
if (itype == -1) error->one(FLERR,"Invalid Angles section in data file");
} else {
itype = utils::inumeric(FLERR,typechar,true,lmp);
if (labelflag) itype = ilabel[itype-1];
}
itype += type_offset;
if ((atom1 <= 0) || (atom1 > map_tag_max) ||
@ -1406,14 +1427,16 @@ void Atom::data_dihedrals(int n, char *buf, int *count, tagint id_offset,
int m,tmp,itype,rv;
tagint atom1,atom2,atom3,atom4;
char *next;
char typechar[MAXLINE];
std::string typestr;
int newton_bond = force->newton_bond;
for (int i = 0; i < n; i++) {
next = strchr(buf,'\n');
*next = '\0';
rv = sscanf(buf,"%d %d " TAGINT_FORMAT " " TAGINT_FORMAT
rv = sscanf(buf,"%d %s " TAGINT_FORMAT " " TAGINT_FORMAT
" " TAGINT_FORMAT " " TAGINT_FORMAT,
&tmp,&itype,&atom1,&atom2,&atom3,&atom4);
&tmp,typechar,&atom1,&atom2,&atom3,&atom4);
if (rv != 6)
error->one(FLERR,"Incorrect format of Dihedrals section in data file");
if (id_offset) {
@ -1422,7 +1445,15 @@ void Atom::data_dihedrals(int n, char *buf, int *count, tagint id_offset,
atom3 += id_offset;
atom4 += id_offset;
}
if (labelflag) itype = ilabel[itype-1];
typestr = typechar;
if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in data file");
itype = atom->find_label(typestr,Atom::DIHEDRAL);
if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in data file");
} else {
itype = utils::inumeric(FLERR,typechar,true,lmp);
if (labelflag) itype = ilabel[itype-1];
}
itype += type_offset;
if ((atom1 <= 0) || (atom1 > map_tag_max) ||
@ -1498,14 +1529,16 @@ void Atom::data_impropers(int n, char *buf, int *count, tagint id_offset,
int m,tmp,itype,rv;
tagint atom1,atom2,atom3,atom4;
char *next;
char typechar[MAXLINE];
std::string typestr;
int newton_bond = force->newton_bond;
for (int i = 0; i < n; i++) {
next = strchr(buf,'\n');
*next = '\0';
rv = sscanf(buf,"%d %d "
rv = sscanf(buf,"%d %s "
TAGINT_FORMAT " " TAGINT_FORMAT " " TAGINT_FORMAT " " TAGINT_FORMAT,
&tmp,&itype,&atom1,&atom2,&atom3,&atom4);
&tmp,typechar,&atom1,&atom2,&atom3,&atom4);
if (rv != 6)
error->one(FLERR,"Incorrect format of Impropers section in data file");
if (id_offset) {
@ -1514,7 +1547,15 @@ void Atom::data_impropers(int n, char *buf, int *count, tagint id_offset,
atom3 += id_offset;
atom4 += id_offset;
}
if (labelflag) itype = ilabel[itype-1];
typestr = typechar;
if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in data file");
itype = atom->find_label(typestr,Atom::IMPROPER);
if (itype == -1) error->one(FLERR,"Invalid Impropers section in data file");
} else {
itype = utils::inumeric(FLERR,typechar,true,lmp);
if (labelflag) itype = ilabel[itype-1];
}
itype += type_offset;
if ((atom1 <= 0) || (atom1 > map_tag_max) ||