diff --git a/src/group.cpp b/src/group.cpp index 4b42223646..9d070e319c 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -547,6 +547,22 @@ void Group::assign(int narg, char **arg) } } +/* ---------------------------------------------------------------------- + convenience function to allow assigning to groups from a single string +------------------------------------------------------------------------- */ + +void Group::assign(const std::string &fixcmd) +{ + std::vector args = utils::split_words(fixcmd); + char **newarg = new char*[args.size()]; + int i=0; + for (const auto &arg : args) { + newarg[i++] = (char *)arg.c_str(); + } + assign(args.size(),newarg); + delete[] newarg; +} + /* ---------------------------------------------------------------------- add flagged atoms to a new or existing group ------------------------------------------------------------------------- */ diff --git a/src/group.h b/src/group.h index ec913f98bc..9f44850d79 100644 --- a/src/group.h +++ b/src/group.h @@ -30,6 +30,7 @@ class Group : protected Pointers { Group(class LAMMPS *); ~Group(); void assign(int, char **); // assign atoms to a group + void assign(const std::string &); // convenience function void create(char *, int *); // add flagged atoms to a group int find(const char *); // lookup name in list of groups int find_or_create(const char *); // lookup name or create new group