improve error messages
This commit is contained in:
@ -222,26 +222,37 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
std::string val;
|
||||
if (moldata.contains("application")) {
|
||||
if (moldata["application"] != "LAMMPS")
|
||||
error->all(FLERR, Error::NOLASTLINE, "JSON data is for incompatible application: {}",
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: JSON data is for incompatible application: {}", id,
|
||||
std::string(moldata["application"]));
|
||||
} else {
|
||||
error->all(FLERR, Error::NOLASTLINE, "JSON data does not contain required 'application' field");
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: JSON data does not contain required 'application' field", id);
|
||||
}
|
||||
if (moldata.contains("format")) {
|
||||
if (moldata["format"] != "molecule")
|
||||
error->all(FLERR, Error::NOLASTLINE, "JSON data is not for a molecule: {}",
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: JSON data is not for a molecule: {}", id,
|
||||
std::string(moldata["format"]));
|
||||
} else {
|
||||
error->all(FLERR, Error::NOLASTLINE, "JSON data does not contain required 'format' field");
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: JSON data does not contain required 'format' field", id);
|
||||
}
|
||||
if (moldata.contains("revision")) {
|
||||
int rev = moldata["revision"];
|
||||
if ((rev < 1) || (rev > 1))
|
||||
error->all(FLERR, Error::NOLASTLINE, "JSON molecule data with unsupported revision {}", rev);
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: JSON molecule data with unsupported revision {}", id, rev);
|
||||
} else {
|
||||
error->all(FLERR, Error::NOLASTLINE, "JSON data does not contain required 'revision' field");
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: JSON data does not contain required 'revision' field", id);
|
||||
}
|
||||
|
||||
// length of types data list determines the number of atoms in the template and is thus required
|
||||
if (!moldata.contains("types"))
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: JSON data does not contain required 'types' field", id);
|
||||
|
||||
// optional fields
|
||||
|
||||
// check for compatible units
|
||||
@ -274,23 +285,31 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
flagvar = 0; \
|
||||
if (!moldata[#field].contains("format")) \
|
||||
error->all(FLERR, Error::NOLASTLINE, \
|
||||
"JSON molecule data does not contain required 'format' field for '{}'", #field); \
|
||||
"Molecule template {}: JSON molecule data does not contain required 'format' " \
|
||||
"field for '{}'", \
|
||||
id, #field); \
|
||||
if (moldata[#field].contains("data")) { \
|
||||
flagvar = 1; \
|
||||
sizevar = moldata[#field]["data"].size(); \
|
||||
} else { \
|
||||
error->all(FLERR, Error::NOLASTLINE, \
|
||||
"JSON molecule data does not contain required 'data' field for '{}'", #field); \
|
||||
"Molecule template {}: JSON molecule data does not contain required 'data' " \
|
||||
"field for '{}'", \
|
||||
id, #field); \
|
||||
} \
|
||||
if (sizevar < 1) \
|
||||
error->all(FLERR, Error::NOLASTLINE, "No {} in JSON data for molecule", #field); \
|
||||
error->all(FLERR, Error::NOLASTLINE, \
|
||||
"Molecule template {}: No {} entries in JSON data for molecule", id, #field); \
|
||||
} else { \
|
||||
if (required) \
|
||||
error->all(FLERR, Error::NOLASTLINE, \
|
||||
"JSON data for molecule does not contain required '{}' field", #field); \
|
||||
error->all( \
|
||||
FLERR, Error::NOLASTLINE, \
|
||||
"Molecule template {}: JSON data for molecule does not contain required '{}' field", id, \
|
||||
#field); \
|
||||
} \
|
||||
if (sizecheck && (sizecheck != sizevar)) \
|
||||
error->all(FLERR, Error::NOLASTLINE, "Found {} instead of {} data entries for '{}'", sizevar, \
|
||||
error->all(FLERR, Error::NOLASTLINE, \
|
||||
"Molecule template {}: Found {} instead of {} data entries for '{}'", id, sizevar, \
|
||||
sizecheck, #field);
|
||||
|
||||
JSON_INIT_FIELD(types, natoms, typeflag, true, 0);
|
||||
@ -340,7 +359,8 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
const double scale5 = powint(sizescale, 5);
|
||||
avec_body = dynamic_cast<AtomVecBody *>(atom->style_match("body"));
|
||||
if (!avec_body)
|
||||
error->all(FLERR, Error::NOLASTLINE, "JSON molecule data requires atom style body");
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: JSON molecule data requires atom style body", id);
|
||||
nibody = moldata["body"][0];
|
||||
ndbody = moldata["body"][1];
|
||||
}
|
||||
@ -349,7 +369,8 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
|
||||
if ((domain->dimension == 2) && (com[2] != 0.0))
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule data z center-of-mass must be 0.0 for 2d systems");
|
||||
"Molecule template {}: Molecule data z center-of-mass must be 0.0 for 2d systems",
|
||||
id);
|
||||
|
||||
// allocate required storage
|
||||
|
||||
@ -363,8 +384,10 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
std::vector<std::string> secfmt;
|
||||
|
||||
// coords
|
||||
if (xflag) {
|
||||
for (int i = 0; i < 4; ++i) secfmt.push_back(moldata["coords"]["format"][i]);
|
||||
if ((secfmt[0] == "atom-id") && (secfmt[1] == "x") && (secfmt[2] == "y") && (secfmt[3] == "z")) {
|
||||
if ((secfmt[0] == "atom-id") && (secfmt[1] == "x") && (secfmt[2] == "y") &&
|
||||
(secfmt[3] == "z")) {
|
||||
|
||||
memset(count, 0, natoms * sizeof(int));
|
||||
for (const auto &c : moldata["coords"]["data"]) {
|
||||
@ -374,17 +397,17 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
"Molecule template {}: missing data in \"coords\" section of molecule JSON data: {}",
|
||||
id, to_string(c));
|
||||
if (!c[0].is_number_integer())
|
||||
error->all(
|
||||
FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: invalid atom-id in \"coords\" section of molecule JSON data: {}",
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: invalid atom-id in \"coords\" section of molecule JSON "
|
||||
"data: {}",
|
||||
id, to_string(c[0]));
|
||||
|
||||
const int iatom = int(c[0]) - 1;
|
||||
if ((iatom < 0) || (iatom >= natoms))
|
||||
error->all(
|
||||
FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: invalid atom-id {} in coords section of molecule JSON data", id,
|
||||
iatom + 1);
|
||||
"Molecule template {}: invalid atom-id {} in coords section of molecule JSON data",
|
||||
id, iatom + 1);
|
||||
count[iatom]++;
|
||||
x[iatom][0] = c[1];
|
||||
x[iatom][1] = c[2];
|
||||
@ -406,8 +429,8 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
for (int i = 0; i < natoms; i++) {
|
||||
if (x[i][2] != 0.0) {
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: Z coord for atom {} must be 0.0 for 2d-simulation", id,
|
||||
i + 1);
|
||||
"Molecule template {}: Z coord for atom {} must be 0.0 for 2d-simulation",
|
||||
id, i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -417,8 +440,9 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
"but found [\"{}\",\"{}\",\"{}\",\"{}\"]",
|
||||
id, secfmt[0], secfmt[1], secfmt[2], secfmt[3]);
|
||||
}
|
||||
}
|
||||
|
||||
// types
|
||||
// types (is a required section and we tested for it above)
|
||||
|
||||
secfmt.clear();
|
||||
for (int i = 0; i < 2; ++i) secfmt.push_back(moldata["types"]["format"][i]);
|
||||
@ -438,8 +462,10 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
|
||||
id, to_string(c[0]));
|
||||
const int iatom = int(c[0]) - 1;
|
||||
if ((iatom < 0) || (iatom >= natoms))
|
||||
error->all(FLERR, Error::NOLASTLINE,
|
||||
"Invalid atom-id {} in types section of molecule JSON data", iatom + 1);
|
||||
error->all(
|
||||
FLERR, Error::NOLASTLINE,
|
||||
"Molecule template {}: invalid atom-id {} in types section of molecule JSON data", id,
|
||||
iatom + 1);
|
||||
if (c[1].is_number_integer()) { // numeric type
|
||||
type[iatom] = int(c[1]) + toffset;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user