From faa1dbc19d91a79e00dd29b9a6e3409fd56e912c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 14 Jun 2025 11:48:11 -0400 Subject: [PATCH] add missing type check and setting of ntypes for json data molecules --- src/molecule.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/molecule.cpp b/src/molecule.cpp index fdfbe8fce8..c59dca424d 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -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,