add missing type check and setting of ntypes for json data molecules

This commit is contained in:
Axel Kohlmeyer
2025-06-14 11:48:11 -04:00
parent ea23af48d3
commit faa1dbc19d

View File

@ -483,11 +483,18 @@ void Molecule::from_json(const std::string &molid, const json &moldata)
count[iatom]++;
}
// checks
ntypes = 0;
for (int i = 0; i < natoms; i++) {
if (count[i] == 0) {
error->all(FLERR, Error::NOLASTLINE,
"Molecule template {}: atom {} missing in \"types\" JSON section", id, i + 1);
}
for (int i = 0; i < natoms; i++) {
if ((type[i] <= 0) || (domain->box_exist && (type[i] > atom->ntypes)))
error->all(FLERR, fileiarg, "Invalid atom type {} for atom {} in molecule file", type[i],
i + 1);
ntypes = MAX(ntypes, type[i]);
}
}
} else {
error->all(FLERR, Error::NOLASTLINE,