diff --git a/src/EXTRA-PAIR/pair_e3b.cpp b/src/EXTRA-PAIR/pair_e3b.cpp index a6c42c2198..a6f0e218bb 100644 --- a/src/EXTRA-PAIR/pair_e3b.cpp +++ b/src/EXTRA-PAIR/pair_e3b.cpp @@ -388,7 +388,7 @@ void PairE3B::coeff(int narg, char **arg) if (narg < 4) error->all(FLERR, "There must be at least one keyword given to pair_coeff"); if (typeO_str.size() > 0) - typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp); + typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp, 1); // clear setflag since coeff() called once with I,J = * * int n = atom->ntypes; diff --git a/src/FEP/pair_lj_cut_tip4p_long_soft.cpp b/src/FEP/pair_lj_cut_tip4p_long_soft.cpp index c9d3f6d72a..8309939227 100644 --- a/src/FEP/pair_lj_cut_tip4p_long_soft.cpp +++ b/src/FEP/pair_lj_cut_tip4p_long_soft.cpp @@ -441,10 +441,10 @@ void PairLJCutTIP4PLongSoft::coeff(int narg, char **arg) // and the types are already set and the strings are empty. if (typeO_str.size() > 0) { - typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp); - typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp); - typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp); - typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp); + typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp, 1); + typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp, 1); + typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp, 1); + typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp, 1); } PairLJCutCoulLongSoft::coeff(narg, arg); diff --git a/src/FEP/pair_tip4p_long_soft.cpp b/src/FEP/pair_tip4p_long_soft.cpp index 1ff4868928..35e2972898 100644 --- a/src/FEP/pair_tip4p_long_soft.cpp +++ b/src/FEP/pair_tip4p_long_soft.cpp @@ -398,10 +398,10 @@ void PairTIP4PLongSoft::coeff(int narg, char **arg) // and the types are already set and the strings are empty. if (typeO_str.size() > 0) { - typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp); - typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp); - typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp); - typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp); + typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp, 1); + typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp, 1); + typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp, 1); + typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp, 1); } PairCoulLongSoft::coeff(narg, arg); diff --git a/src/KSPACE/pair_lj_cut_tip4p_long.cpp b/src/KSPACE/pair_lj_cut_tip4p_long.cpp index 8a3d869595..f72e8c42f8 100644 --- a/src/KSPACE/pair_lj_cut_tip4p_long.cpp +++ b/src/KSPACE/pair_lj_cut_tip4p_long.cpp @@ -455,10 +455,10 @@ void PairLJCutTIP4PLong::coeff(int narg, char **arg) // and the types are already set and the strings are empty. if (typeO_str.size() > 0) { - typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp); - typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp); - typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp); - typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp); + typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp, 1); + typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp, 1); + typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp, 1); + typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp, 1); } PairLJCutCoulLong::coeff(narg, arg); diff --git a/src/KSPACE/pair_lj_long_tip4p_long.cpp b/src/KSPACE/pair_lj_long_tip4p_long.cpp index 9b460d9636..fe3671f21b 100644 --- a/src/KSPACE/pair_lj_long_tip4p_long.cpp +++ b/src/KSPACE/pair_lj_long_tip4p_long.cpp @@ -1472,10 +1472,10 @@ void PairLJLongTIP4PLong::coeff(int narg, char **arg) // and the types are already set and the strings are empty. if (typeO_str.size() > 0) { - typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp); - typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp); - typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp); - typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp); + typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp, 1); + typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp, 1); + typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp, 1); + typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp, 1); } PairLJLongCoulLong::coeff(narg, arg); diff --git a/src/KSPACE/pair_tip4p_long.cpp b/src/KSPACE/pair_tip4p_long.cpp index 7c290bbf8a..cd2b1f6af3 100644 --- a/src/KSPACE/pair_tip4p_long.cpp +++ b/src/KSPACE/pair_tip4p_long.cpp @@ -411,10 +411,10 @@ void PairTIP4PLong::coeff(int narg, char **arg) // and the types are already set and the strings are empty. if (typeO_str.size() > 0) { - typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp); - typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp); - typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp); - typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp); + typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp, 1); + typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp, 1); + typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp, 1); + typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp, 1); } PairCoulLong::coeff(narg, arg); diff --git a/src/MOLECULE/pair_lj_cut_tip4p_cut.cpp b/src/MOLECULE/pair_lj_cut_tip4p_cut.cpp index 7f968c1424..f4ddad5f70 100644 --- a/src/MOLECULE/pair_lj_cut_tip4p_cut.cpp +++ b/src/MOLECULE/pair_lj_cut_tip4p_cut.cpp @@ -465,10 +465,10 @@ void PairLJCutTIP4PCut::coeff(int narg, char **arg) // and the types are already set and the strings are empty. if (typeO_str.size() > 0) { - typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp); - typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp); - typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp); - typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp); + typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp, 1); + typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp, 1); + typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp, 1); + typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp, 1); } int ilo,ihi,jlo,jhi; diff --git a/src/MOLECULE/pair_tip4p_cut.cpp b/src/MOLECULE/pair_tip4p_cut.cpp index c7e21cd126..f8bced69af 100644 --- a/src/MOLECULE/pair_tip4p_cut.cpp +++ b/src/MOLECULE/pair_tip4p_cut.cpp @@ -400,10 +400,10 @@ void PairTIP4PCut::coeff(int narg, char **arg) // and the types are already set and the strings are empty. if (typeO_str.size() > 0) { - typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp); - typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp); - typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp); - typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp); + typeO = utils::expand_type_int(FLERR, typeO_str, Atom::ATOM, lmp, 1); + typeH = utils::expand_type_int(FLERR, typeH_str, Atom::ATOM, lmp, 1); + typeB = utils::expand_type_int(FLERR, typeB_str, Atom::BOND, lmp, 1); + typeA = utils::expand_type_int(FLERR, typeA_str, Atom::ANGLE, lmp, 1); } int ilo,ihi,jlo,jhi; diff --git a/src/utils.cpp b/src/utils.cpp index 27d89f1bf5..cbf2a23ae1 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -995,17 +995,42 @@ char *utils::expand_type(const char *file, int line, const std::string &str, int /* ------------------------------------------------------------------------- Expand type string to integer-valued numeric type from labelmap. - Not guaranteed to return a valid type. - For example, type <= 0 or type > Ntypes is checked in calling routine. + Not guaranteed to return a valid type if param verify = 0 (default) + In this case, type <= 0 or type > Ntypes should be checked in calling routine. ------------------------------------------------------------------------- */ int utils::expand_type_int(const char *file, int line, const std::string &str, int mode, - LAMMPS *lmp) + LAMMPS *lmp, int verify) { char *typestr = expand_type(file, line, str, mode, lmp); - int out = inumeric(file, line, typestr ? typestr : str, false, lmp); + int type = inumeric(file, line, typestr ? typestr : str, false, lmp); + if (verify) { + int errorflag = 0; + if (type <= 0) errorflag = 1; + int nmax; + switch (mode) { + case Atom::ATOM: + nmax = lmp->atom->ntypes; + break; + case Atom::BOND: + nmax = lmp->atom->nbondtypes; + break; + case Atom::ANGLE: + nmax = lmp->atom->nangletypes; + break; + case Atom::DIHEDRAL: + nmax = lmp->atom->ndihedraltypes; + break; + case Atom::IMPROPER: + nmax = lmp->atom->nimpropertypes; + break; + } + if (type > nmax) errorflag = 1; + if (errorflag) lmp->error->all(file, line, "{} type {} is out of bounds ({}-{})", + labeltypes[mode], type, 1, nmax); + } delete[] typestr; - return out; + return type; } /* ---------------------------------------------------------------------- diff --git a/src/utils.h b/src/utils.h index 3b85824a68..b7ceca4eb0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -409,7 +409,7 @@ This functions adds the following case to :cpp:func:`utils::bounds()