assume type labels begin with letter

This commit is contained in:
Jacob Gissinger
2021-01-19 22:56:06 -05:00
parent 739dc46fab
commit a0c4fac428
4 changed files with 27 additions and 17 deletions

View File

@ -1560,6 +1560,7 @@ void Input::labelmap()
{
if (domain->box_exist == 0)
error->all(FLERR,"Labelmap command before simulation box is defined");
if (!atom->labelmapflag) atom->add_label_map();
atom->lmap->modify_lmap(narg,arg);
}

View File

@ -100,10 +100,13 @@ void LabelMap::modify_lmap(int narg, char **arg)
int itype;
int iarg = 1;
char *charlabel;
while (iarg < narg) {
itype = utils::inumeric(FLERR,arg[iarg++],false,lmp);
charlabel = arg[iarg++];
if (itype > ntypes) error->all(FLERR,"Topology type exceeds system topology type");
(*labels)[itype-1] = arg[iarg++];
if (!isalpha(charlabel[0])) error->all(FLERR,"Type labels must begin with a letter");
(*labels)[itype-1] = charlabel;
}
}

View File

@ -727,7 +727,8 @@ void Molecule::types(char *line)
if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Types section in molecule file");
count[iatom]++;
typestr = values.next_string();
if (atom->labelmapflag) {
if (isalpha(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file");
type[iatom] = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes);
if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file");
} else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
@ -939,7 +940,8 @@ void Molecule::bonds(int flag, char *line)
if (values.count() != 4) error->one(FLERR,"Invalid Bonds section in molecule file");
values.next_int();
typestr = values.next_string();
if (atom->labelmapflag) {
if (isalpha(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file");
itype = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes);
if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file");
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
@ -1012,7 +1014,8 @@ void Molecule::angles(int flag, char *line)
if (values.count() != 5) error->one(FLERR,"Invalid Angles section in molecule file");
values.next_int();
typestr = values.next_string();
if (atom->labelmapflag) {
if (isalpha(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file");
itype = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes);
if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file");
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
@ -1101,7 +1104,8 @@ void Molecule::dihedrals(int flag, char *line)
if (values.count() != 6) error->one(FLERR,"Invalid Dihedrals section in molecule file");
values.next_int();
typestr = values.next_string();
if (atom->labelmapflag) {
if (isalpha(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file");
itype = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes);
if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file");
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
@ -1205,7 +1209,8 @@ void Molecule::impropers(int flag, char *line)
if (values.count() != 6) error->one(FLERR,"Invalid Impropers section in molecule file");
values.next_int();
typestr = values.next_string();
if (atom->labelmapflag) {
if (isalpha(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file");
itype = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes);
if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file");
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);

View File

@ -1974,7 +1974,7 @@ void ReadData::typelabels(std::vector<std::string> &mytypelabel, int myntypes, i
char *buf = new char[myntypes*MAXLINE];
labelflag = 1;
if (atom->labelmapflag == 0) atom->add_label_map();
if (!atom->labelmapflag) atom->add_label_map();
int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf);
if (eof) error->all(FLERR,"Unexpected end of data file");
@ -1984,6 +1984,7 @@ void ReadData::typelabels(std::vector<std::string> &mytypelabel, int myntypes, i
next = strchr(buf,'\n');
*next = '\0';
sscanf(buf,"%*d %s",typelabel);
if (!isalpha(typelabel[0])) error->all(FLERR,"Type labels must begin with a letter");
mytypelabel[i] = typelabel;
buf = next + 1;
}