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');
|
next = strchr(buf,'\n');
|
||||||
if (!next) error->all(FLERR, "Missing data in Atoms section of data file");
|
if (!next) error->all(FLERR, "Missing data in Atoms section of data file");
|
||||||
*next = '\0';
|
*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';
|
*next = '\n';
|
||||||
|
|
||||||
if ((nwords != avec->size_data_atom) && (nwords != avec->size_data_atom + 3))
|
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');
|
next = strchr(buf,'\n');
|
||||||
if (!next) error->all(FLERR, "Missing data in Atoms section of data file");
|
if (!next) error->all(FLERR, "Missing data in Atoms section of data file");
|
||||||
*next = '\0';
|
*next = '\0';
|
||||||
auto values = Tokenizer(utils::trim_comment(buf)).as_vector();
|
auto values = Tokenizer(buf).as_vector();
|
||||||
if (values.size() == 0) {
|
int nvalues = values.size();
|
||||||
|
if ((nvalues == 0) || (utils::strmatch(values[0],"^#.*"))) {
|
||||||
// skip over empty or comment lines
|
// 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));
|
error->all(FLERR, "Incorrect atom format in data file: {}", utils::trim(buf));
|
||||||
} else {
|
} else {
|
||||||
int imx = 0, imy = 0, imz = 0;
|
int imx = 0, imy = 0, imz = 0;
|
||||||
|
|||||||
@ -138,9 +138,9 @@ void LabelMap::modify_lmap(int narg, char **arg)
|
|||||||
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(arg[iarg++]);
|
||||||
if (isdigit(slabel[0]))
|
if (isdigit(slabel[0]) || (slabel[0] == '#') || (slabel[0] == '*'))
|
||||||
error->all(FLERR, "Label {} for {} type {} must not start with a number", slabel, tlabel,
|
error->all(FLERR, "Label {} for {} type {} must not start with a number, a '#', or a '*'",
|
||||||
itype);
|
slabel, tlabel, itype);
|
||||||
int found = search(slabel, (*labels_map));
|
int found = search(slabel, (*labels_map));
|
||||||
if ((found != -1) && (found != itype))
|
if ((found != -1) && (found != itype))
|
||||||
error->all(FLERR, "The {} type label {} is already in use for type {}", tlabel, slabel,
|
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"););
|
command("labelmap atom 5 C1"););
|
||||||
TEST_FAILURE(".*ERROR: Label 1C for atom type 1 must not start with a number.*",
|
TEST_FAILURE(".*ERROR: Label 1C for atom type 1 must not start with a number.*",
|
||||||
command("labelmap atom 1 1C"););
|
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.*",
|
TEST_FAILURE(".*ERROR: The atom type label N2 is already in use for type 2.*",
|
||||||
command("labelmap atom 1 N2"););
|
command("labelmap atom 1 N2"););
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user