diff --git a/src/MC/fix_charge_regulation.cpp b/src/MC/fix_charge_regulation.cpp index 6775b4e4ca..17d3af3e34 100644 --- a/src/MC/fix_charge_regulation.cpp +++ b/src/MC/fix_charge_regulation.cpp @@ -187,14 +187,7 @@ void FixChargeRegulation::init() { // neighbor list exclusion setup // turn off interactions between group all and the exclusion group - int narg = 4; - char **arg = new char*[narg];; - arg[0] = (char *) "exclude"; - arg[1] = (char *) "group"; - arg[2] = (char *) group_id.c_str(); - arg[3] = (char *) "all"; - neighbor->modify_params(narg,arg); - delete [] arg; + neighbor->modify_params(fmt::format("exclude group {} all",group_id)); } // check that no deletable atoms are in atom->firstgroup diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index b946615b04..ff894d976b 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -580,14 +580,7 @@ void FixGCMC::init() // neighbor list exclusion setup // turn off interactions between group all and the exclusion group - int narg = 4; - char **arg = new char*[narg];; - arg[0] = (char *) "exclude"; - arg[1] = (char *) "group"; - arg[2] = (char *) group_id.c_str(); - arg[3] = (char *) "all"; - neighbor->modify_params(narg,arg); - delete [] arg; + neighbor->modify_params(fmt::format("exclude group {} all",group_id); } // create a new group for temporary use with selected molecules diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index e898196e14..65f00811c1 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -342,14 +342,7 @@ void FixWidom::init() // neighbor list exclusion setup // turn off interactions between group all and the exclusion group - int narg = 4; - char **arg = new char*[narg];; - arg[0] = (char *) "exclude"; - arg[1] = (char *) "group"; - arg[2] = (char *) group_id.c_str(); - arg[3] = (char *) "all"; - neighbor->modify_params(narg,arg); - delete [] arg; + neighbor->modify_params(fmt::format("exclude group {} all",group_id)); } // create a new group for temporary use with selected molecules diff --git a/src/USER-MISC/fix_srp.cpp b/src/USER-MISC/fix_srp.cpp index eb57da30e9..51047dfaa6 100644 --- a/src/USER-MISC/fix_srp.cpp +++ b/src/USER-MISC/fix_srp.cpp @@ -128,20 +128,10 @@ void FixSRP::init() // bond particles do not interact with other types // type bptype only interacts with itself - char* arg1[4]; - arg1[0] = (char *) "exclude"; - arg1[1] = (char *) "type"; - char c0[20]; - char c1[20]; - for (int z = 1; z < atom->ntypes; z++) { if (z == bptype) continue; - sprintf(c0, "%d", z); - arg1[2] = c0; - sprintf(c1, "%d", bptype); - arg1[3] = c1; - neighbor->modify_params(4, arg1); + neighbor->modify_params(fmt::format("exclude type {} {}",z,bptype)); } } diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 704d94c77c..ee4226f43e 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -2356,6 +2356,22 @@ void Neighbor::modify_params(int narg, char **arg) } } +/* ---------------------------------------------------------------------- + convenience function to allow modifying parameters from a single string +------------------------------------------------------------------------- */ + +void Neighbor::modify_params(const std::string &modcmd) +{ + auto args = utils::split_words(modcmd); + char **newarg = new char*[args.size()]; + int i=0; + for (const auto &arg : args) { + newarg[i++] = (char *)arg.c_str(); + } + modify_params(args.size(),newarg); + delete[] newarg; +} + /* ---------------------------------------------------------------------- remove the first group-group exclusion matching group1, group2 ------------------------------------------------------------------------- */ diff --git a/src/neighbor.h b/src/neighbor.h index b9b40bcf1a..0babfae9ef 100644 --- a/src/neighbor.h +++ b/src/neighbor.h @@ -118,6 +118,7 @@ class Neighbor : protected Pointers { void set(int, char **); // set neighbor style and skin distance void reset_timestep(bigint); // reset of timestep counter void modify_params(int, char**); // modify params that control builds + void modify_params(const std::string &); // convenience overload void exclusion_group_group_delete(int, int); // rm a group-group exclusion int exclude_setting(); // return exclude value to accelerator pkg