allow '#' character in type labels. support also when reading Atoms section
This commit is contained in:
17
src/atom.cpp
17
src/atom.cpp
@ -1057,7 +1057,14 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,
|
||||
next = strchr(buf,'\n');
|
||||
if (!next) error->all(FLERR, "Missing data in Atoms section of data file");
|
||||
*next = '\0';
|
||||
int nwords = utils::trim_and_count_words(buf);
|
||||
auto values = Tokenizer(buf).as_vector();
|
||||
int nwords = 0;
|
||||
for (std::size_t i = 0; i < values.size(); ++i) {
|
||||
if (utils::strmatch(values[i], "^#")) {
|
||||
nwords = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*next = '\n';
|
||||
|
||||
if ((nwords != avec->size_data_atom) && (nwords != avec->size_data_atom + 3))
|
||||
@ -1135,10 +1142,12 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,
|
||||
next = strchr(buf,'\n');
|
||||
if (!next) error->all(FLERR, "Missing data in Atoms section of data file");
|
||||
*next = '\0';
|
||||
auto values = Tokenizer(utils::trim_comment(buf)).as_vector();
|
||||
if (values.size() == 0) {
|
||||
auto values = Tokenizer(buf).as_vector();
|
||||
int nvalues = values.size();
|
||||
if ((nvalues == 0) || (utils::strmatch(values[0],"^#.*"))) {
|
||||
// skip over empty or comment lines
|
||||
} else if ((int)values.size() != nwords) {
|
||||
} else if ((nvalues < nwords) ||
|
||||
((nvalues > nwords) && (!utils::strmatch(values[nwords],"^#")))) {
|
||||
error->all(FLERR, "Incorrect atom format in data file: {}", utils::trim(buf));
|
||||
} else {
|
||||
int imx = 0, imy = 0, imz = 0;
|
||||
|
||||
@ -138,9 +138,9 @@ void LabelMap::modify_lmap(int narg, char **arg)
|
||||
if ((itype < 1) || (itype > ntypes))
|
||||
error->all(FLERR, "Labelmap {} type {} must be within 1-{}", tlabel, itype, ntypes);
|
||||
std::string slabel(arg[iarg++]);
|
||||
if (isdigit(slabel[0]))
|
||||
error->all(FLERR, "Label {} for {} type {} must not start with a number", slabel, tlabel,
|
||||
itype);
|
||||
if (isdigit(slabel[0]) || (slabel[0] == '#') || (slabel[0] == '*'))
|
||||
error->all(FLERR, "Label {} for {} type {} must not start with a number, a '#', or a '*'",
|
||||
slabel, tlabel, itype);
|
||||
int found = search(slabel, (*labels_map));
|
||||
if ((found != -1) && (found != itype))
|
||||
error->all(FLERR, "The {} type label {} is already in use for type {}", tlabel, slabel,
|
||||
|
||||
@ -119,6 +119,10 @@ TEST_F(SetTest, NoBoxAtoms)
|
||||
command("labelmap atom 5 C1"););
|
||||
TEST_FAILURE(".*ERROR: Label 1C for atom type 1 must not start with a number.*",
|
||||
command("labelmap atom 1 1C"););
|
||||
TEST_FAILURE(".*ERROR: Label #C for atom type 1 must not start with a number, a '#', or.*",
|
||||
command("labelmap atom 1 '#C'"););
|
||||
TEST_FAILURE(".*ERROR: Label \\*C for atom type 1 must not start with a number, a '#', or.*",
|
||||
command("labelmap atom 1 *C"););
|
||||
TEST_FAILURE(".*ERROR: The atom type label N2 is already in use for type 2.*",
|
||||
command("labelmap atom 1 N2"););
|
||||
|
||||
|
||||
Reference in New Issue
Block a user