stricter matching of header items and skip comments right away
This commit is contained in:
@ -1927,10 +1927,11 @@ void Molecule::read(int flag)
|
|||||||
|
|
||||||
readline(line);
|
readline(line);
|
||||||
|
|
||||||
// trim comments. if line is blank, continue
|
// trim comments. if line is blank or comment, continue
|
||||||
|
|
||||||
auto text = utils::trim(utils::trim_comment(line));
|
auto text = utils::trim(utils::trim_comment(line));
|
||||||
if (text.empty()) continue;
|
if (text.empty()) continue;
|
||||||
|
if (utils::strmatch(text, "^\\s*#")) continue;
|
||||||
|
|
||||||
// search line for header keywords and set corresponding variable
|
// search line for header keywords and set corresponding variable
|
||||||
try {
|
try {
|
||||||
@ -1938,31 +1939,31 @@ void Molecule::read(int flag)
|
|||||||
|
|
||||||
int nmatch = values.count();
|
int nmatch = values.count();
|
||||||
int nwant = 0;
|
int nwant = 0;
|
||||||
if (values.matches("^\\s*\\d+\\s+atoms")) {
|
if (values.matches("^\\s*\\d+\\s+atoms\\s*$")) {
|
||||||
natoms = values.next_int();
|
natoms = values.next_int();
|
||||||
nwant = 2;
|
nwant = 2;
|
||||||
has_atoms = true;
|
has_atoms = true;
|
||||||
} else if (values.matches("^\\s*\\d+\\s+bonds")) {
|
} else if (values.matches("^\\s*\\d+\\s+bonds\\s*$")) {
|
||||||
nbonds = values.next_int();
|
nbonds = values.next_int();
|
||||||
nwant = 2;
|
nwant = 2;
|
||||||
} else if (values.matches("^\\s*\\d+\\s+angles")) {
|
} else if (values.matches("^\\s*\\d+\\s+angles\\s*$")) {
|
||||||
nangles = values.next_int();
|
nangles = values.next_int();
|
||||||
nwant = 2;
|
nwant = 2;
|
||||||
} else if (values.matches("^\\s*\\d+\\s+dihedrals")) {
|
} else if (values.matches("^\\s*\\d+\\s+dihedrals\\s*$")) {
|
||||||
ndihedrals = values.next_int();
|
ndihedrals = values.next_int();
|
||||||
nwant = 2;
|
nwant = 2;
|
||||||
} else if (values.matches("^\\s*\\d+\\s+impropers")) {
|
} else if (values.matches("^\\s*\\d+\\s+impropers\\s*$")) {
|
||||||
nimpropers = values.next_int();
|
nimpropers = values.next_int();
|
||||||
nwant = 2;
|
nwant = 2;
|
||||||
} else if (values.matches("^\\s*\\d+\\s+fragments")) {
|
} else if (values.matches("^\\s*\\d+\\s+fragments\\s*$")) {
|
||||||
nfragments = values.next_int();
|
nfragments = values.next_int();
|
||||||
nwant = 2;
|
nwant = 2;
|
||||||
} else if (values.matches("^\\s*\\f+\\s+mass")) {
|
} else if (values.matches("^\\s*\\f+\\s+mass\\s*$")) {
|
||||||
massflag = 1;
|
massflag = 1;
|
||||||
masstotal = values.next_double();
|
masstotal = values.next_double();
|
||||||
nwant = 2;
|
nwant = 2;
|
||||||
masstotal *= sizescale * sizescale * sizescale;
|
masstotal *= sizescale * sizescale * sizescale;
|
||||||
} else if (values.matches("^\\s*\\f+\\s+\\f+\\s+\\f+\\s+com")) {
|
} else if (values.matches("^\\s*\\f+\\s+\\f+\\s+\\f+\\s+com\\s*$")) {
|
||||||
comflag = 1;
|
comflag = 1;
|
||||||
com[0] = values.next_double();
|
com[0] = values.next_double();
|
||||||
com[1] = values.next_double();
|
com[1] = values.next_double();
|
||||||
@ -1973,7 +1974,7 @@ void Molecule::read(int flag)
|
|||||||
com[2] *= sizescale;
|
com[2] *= sizescale;
|
||||||
if ((domain->dimension == 2) && (com[2] != 0.0))
|
if ((domain->dimension == 2) && (com[2] != 0.0))
|
||||||
error->all(FLERR, fileiarg, "Molecule file z center-of-mass must be 0.0 for 2d systems");
|
error->all(FLERR, fileiarg, "Molecule file z center-of-mass must be 0.0 for 2d systems");
|
||||||
} else if (values.matches("^\\s*\\f+\\s+\\f+\\s+\\f+\\s+\\f+\\s+\\f+\\s+\\f+\\s+inertia")) {
|
} else if (values.matches("^\\s*\\f+\\s+\\f+\\s+\\f+\\s+\\f+\\s+\\f+\\s+\\f+\\s+inertia\\s*$")) {
|
||||||
inertiaflag = 1;
|
inertiaflag = 1;
|
||||||
itensor[0] = values.next_double();
|
itensor[0] = values.next_double();
|
||||||
itensor[1] = values.next_double();
|
itensor[1] = values.next_double();
|
||||||
@ -1989,7 +1990,7 @@ void Molecule::read(int flag)
|
|||||||
itensor[3] *= scale5;
|
itensor[3] *= scale5;
|
||||||
itensor[4] *= scale5;
|
itensor[4] *= scale5;
|
||||||
itensor[5] *= scale5;
|
itensor[5] *= scale5;
|
||||||
} else if (values.matches("^\\s*\\d+\\s+\\d+\\s+body")) {
|
} else if (values.matches("^\\s*\\d+\\s+\\d+\\s+body\\s*$")) {
|
||||||
bodyflag = 1;
|
bodyflag = 1;
|
||||||
avec_body = dynamic_cast<AtomVecBody *>(atom->style_match("body"));
|
avec_body = dynamic_cast<AtomVecBody *>(atom->style_match("body"));
|
||||||
if (!avec_body) error->all(FLERR, fileiarg, "Molecule file requires atom style body");
|
if (!avec_body) error->all(FLERR, fileiarg, "Molecule file requires atom style body");
|
||||||
@ -1999,15 +2000,15 @@ void Molecule::read(int flag)
|
|||||||
} else {
|
} else {
|
||||||
// unknown header keyword
|
// unknown header keyword
|
||||||
if (values.matches("^\\s*\\f+\\s+\\S+")) {
|
if (values.matches("^\\s*\\f+\\s+\\S+")) {
|
||||||
error->one(FLERR, fileiarg, "Unknown keyword or incorrectly formatted header line: {}",
|
error->all(FLERR, fileiarg, "Unknown keyword or incorrectly formatted header line: {}",
|
||||||
line);
|
line);
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (nmatch != nwant)
|
if (nmatch != nwant)
|
||||||
error->one(FLERR, fileiarg, "Invalid header line format in molecule file");
|
error->all(FLERR, fileiarg, "Invalid header line format in molecule file: {}", line);
|
||||||
} catch (TokenizerException &e) {
|
} catch (TokenizerException &e) {
|
||||||
error->one(FLERR, fileiarg, "Invalid header in molecule file: {}", e.what());
|
error->all(FLERR, fileiarg, "Invalid header in molecule file: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user