diff --git a/src/atom.cpp b/src/atom.cpp index d269fb8c2a..7b0ca8d0c6 100644 --- a/src/atom.cpp +++ b/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; diff --git a/src/label_map.cpp b/src/label_map.cpp index 72c20e56ac..4aeb4f29a1 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -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, diff --git a/unittest/commands/test_labelmap.cpp b/unittest/commands/test_labelmap.cpp index 53a72a010f..15344b45bb 100644 --- a/unittest/commands/test_labelmap.cpp +++ b/unittest/commands/test_labelmap.cpp @@ -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"););