From a0c4fac42842fc1cca41746d252f1ccbc7636782 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 19 Jan 2021 22:56:06 -0500 Subject: [PATCH] assume type labels begin with letter --- src/input.cpp | 1 + src/label_map.cpp | 5 ++++- src/molecule.cpp | 35 ++++++++++++++++++++--------------- src/read_data.cpp | 3 ++- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index ba38112ac8..e409111090 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -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); } diff --git a/src/label_map.cpp b/src/label_map.cpp index 5031a8fc9c..8ea9ae94e6 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -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; } } diff --git a/src/molecule.cpp b/src/molecule.cpp index ce7e97fd9a..e0a20ff6af 100755 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -727,9 +727,10 @@ 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) { - type[iatom] = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); - if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); + 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); type[iatom] += toffset; } @@ -939,9 +940,10 @@ 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) { - itype = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); - if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); + 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); atom1 = values.next_tagint(); atom2 = values.next_tagint(); @@ -1012,9 +1014,10 @@ 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) { - itype = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); - if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); + 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); atom1 = values.next_tagint(); atom2 = values.next_tagint(); @@ -1101,9 +1104,10 @@ 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) { - itype = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); - if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); + 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); atom1 = values.next_tagint(); atom2 = values.next_tagint(); @@ -1205,9 +1209,10 @@ 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) { - itype = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); - if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); + 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); atom1 = values.next_tagint(); atom2 = values.next_tagint(); diff --git a/src/read_data.cpp b/src/read_data.cpp index 9734539492..f493be0977 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1974,7 +1974,7 @@ void ReadData::typelabels(std::vector &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 &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; }