small tweaks to support type labels with single and double quotes. add tests

This commit is contained in:
Axel Kohlmeyer
2022-09-03 19:04:24 -04:00
parent b143f87d10
commit bb45137b1a
4 changed files with 14 additions and 4 deletions

View File

@ -1834,8 +1834,8 @@ void Atom::set_mass(const char *file, int line, int /*narg*/, char **arg)
{ {
if (mass == nullptr) error->all(file,line, "Cannot set atom mass for atom style {}", atom_style); if (mass == nullptr) error->all(file,line, "Cannot set atom mass for atom style {}", atom_style);
if (!isdigit(arg[0][0]) && arg[0][0] != '*') { std::string typestr = utils::trim(arg[0]);
std::string typestr(arg[0]); if (!isdigit(typestr[0]) && typestr[0] != '*') {
int itype = lmap->find(typestr,Atom::ATOM); int itype = lmap->find(typestr,Atom::ATOM);
if (itype == -1) error->all(file,line,"Invalid type for mass set"); if (itype == -1) error->all(file,line,"Invalid type for mass set");
mass[itype] = utils::numeric(FLERR,arg[1],false,lmp); mass[itype] = utils::numeric(FLERR,arg[1],false,lmp);

View File

@ -728,7 +728,7 @@ int Input::readtype(char *&str, int mode)
int type,max,max2; int type,max,max2;
char typechar[256]; char typechar[256];
std::string labelstr(str); std::string labelstr = utils::trim(str);
type = atom->lmap->find(labelstr,mode); type = atom->lmap->find(labelstr,mode);
if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str)); if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str));

View File

@ -137,7 +137,7 @@ void LabelMap::modify_lmap(int narg, char **arg)
int itype = utils::inumeric(FLERR, arg[iarg++], false, lmp); int itype = utils::inumeric(FLERR, arg[iarg++], false, lmp);
if ((itype < 1) || (itype > ntypes)) if ((itype < 1) || (itype > ntypes))
error->all(FLERR, "Labelmap {} type {} must be within 1-{}", tlabel, itype, ntypes); error->all(FLERR, "Labelmap {} type {} must be within 1-{}", tlabel, itype, ntypes);
std::string slabel(arg[iarg++]); std::string slabel = utils::trim(arg[iarg++]);
if (isdigit(slabel[0]) || (slabel[0] == '#') || (slabel[0] == '*')) if (isdigit(slabel[0]) || (slabel[0] == '#') || (slabel[0] == '*'))
error->all(FLERR, "Label {} for {} type {} must not start with a number, a '#', or a '*'", error->all(FLERR, "Label {} for {} type {} must not start with a number, a '#', or a '*'",
slabel, tlabel, itype); slabel, tlabel, itype);

View File

@ -153,6 +153,16 @@ TEST_F(SetTest, NoBoxAtoms)
ASSERT_FALSE(atom->lmap->is_complete(Atom::ATOM)); ASSERT_FALSE(atom->lmap->is_complete(Atom::ATOM));
ASSERT_EQ(atom->lmap->find("C1", Atom::ATOM), 3); ASSERT_EQ(atom->lmap->find("C1", Atom::ATOM), 3);
ASSERT_EQ(atom->lmap->find("N2", Atom::ATOM), 2); ASSERT_EQ(atom->lmap->find("N2", Atom::ATOM), 2);
BEGIN_HIDE_OUTPUT();
command("labelmap clear");
command("labelmap atom 1 \"C1'\" 2 'C2\"' 3 \"\"\"C1'-C2\" \"\"\" 4 \"\"\" C2\"-C1'\"\"\"");
END_HIDE_OUTPUT();
ASSERT_TRUE(atom->lmap->is_complete(Atom::ATOM));
ASSERT_EQ(atom->lmap->find("C1'", Atom::ATOM), 1);
ASSERT_EQ(atom->lmap->find("C2\"", Atom::ATOM), 2);
ASSERT_EQ(atom->lmap->find("C1'-C2\"", Atom::ATOM), 3);
ASSERT_EQ(atom->lmap->find("C2\"-C1'", Atom::ATOM), 4);
} }
} // namespace LAMMPS_NS } // namespace LAMMPS_NS