diff --git a/doc/src/Library_config.rst b/doc/src/Library_config.rst index 532bd5cfa0..0c1e254537 100644 --- a/doc/src/Library_config.rst +++ b/doc/src/Library_config.rst @@ -15,9 +15,6 @@ This section documents the following functions: - :cpp:func:`lammps_has_style` - :cpp:func:`lammps_style_count` - :cpp:func:`lammps_style_name` -- :cpp:func:`lammps_has_group` -- :cpp:func:`lammps_group_count` -- :cpp:func:`lammps_group_name` - :cpp:func:`lammps_has_id` - :cpp:func:`lammps_id_count` - :cpp:func:`lammps_id_name` @@ -132,21 +129,6 @@ a safer approach. ----------------------- -.. doxygenfunction:: lammps_has_group - :project: progguide - ------------------------ - -.. doxygenfunction:: lammps_group_count - :project: progguide - ------------------------ - -.. doxygenfunction:: lammps_group_name - :project: progguide - ------------------------ - .. doxygenfunction:: lammps_has_id :project: progguide diff --git a/src/library.cpp b/src/library.cpp index ebbebff2c1..3192cf4eef 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -4049,86 +4049,12 @@ int lammps_style_name(void *handle, const char *category, int idx, /* ---------------------------------------------------------------------- */ -/** Check if a group with a given name has been defined - * -\verbatim embed:rst -This function checks if a group with the provided *name* is defined -in the current LAMMPS instance. -\endverbatim - * - * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. - * \param name name of the style - * \return 1 if defined, 0 if not. - */ -int lammps_has_group(void *handle, const char *name) -{ - LAMMPS *lmp = (LAMMPS *)handle; - - int ngroup = lmp->group->ngroup; - char **groups = lmp->group->names; - - for (int i=0; i < ngroup; ++i) - if (strcmp(groups[i],name) == 0) return 1; - - return 0; -} - -/* ---------------------------------------------------------------------- */ - -/** Count the number of currently defined groups - * - * This function counts how many groups are defined in the - * current LAMMPS instance. - * - * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. - * \return number of styles in category - */ -int lammps_group_count(void *handle) -{ - LAMMPS *lmp = (LAMMPS *)handle; - - return lmp->group->ngroup; -} - -/* ---------------------------------------------------------------------- */ - -/** Look up the name of a group by index in the list of groups. - * - * This function copies the name of the group with the index *idx* into - * the provided C-style string buffer. The length of the buffer must be - * provided as *buf_size* argument. If the name of the group exceeds the - * length of the buffer, it will be truncated accordingly. If the index - * is out of range, the function returns 0 and *buffer* is set to an empty - * string, otherwise 1 is returned. - * - * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. - * \param idx index of the group in the list of groups (0 <= idx < group count) - * \param buffer string buffer to copy the name of the style to - * \param buf_size size of the provided string buffer - * \return 1 if successful, otherwise 0 - */ -int lammps_group_name(void *handle, int idx, char *buffer, int buf_size) { - LAMMPS *lmp = (LAMMPS *)handle; - - int ngroup = lmp->group->ngroup; - char **groups = lmp->group->names; - if ((idx >=0) && (idx < ngroup)) { - strncpy(buffer, groups[idx], buf_size); - return 1; - } - - buffer[0] = '\0'; - return 0; -} - -/* ---------------------------------------------------------------------- */ - /** Check if a specific ID exists in the current LAMMPS instance * \verbatim embed:rst This function checks if the current LAMMPS instance a *category* ID of the given *name* exists. Valid categories are: *compute*\ , *dump*\ , -*fix*\ , *molecule*\ , *region*\ , and *variable*\ . +*fix*\ , *group*\ , *molecule*\ , *region*\ , and *variable*\ . \endverbatim * * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. @@ -4157,6 +4083,12 @@ int lammps_has_id(void *handle, const char *category, const char *name) { for (int i=0; i < nfix; ++i) { if (strcmp(name,fix[i]->id) == 0) return 1; } + } else if (strcmp(category,"group") == 0) { + int ngroup = lmp->group->ngroup; + char **groups = lmp->group->names; + for (int i=0; i < ngroup; ++i) { + if (strcmp(groups[i],name) == 0) return 1; + } } else if (strcmp(category,"molecule") == 0) { int nmolecule = lmp->atom->nmolecule; Molecule **molecule = lmp->atom->molecules; @@ -4202,6 +4134,8 @@ int lammps_id_count(void *handle, const char *category) { return lmp->output->ndump; } else if (strcmp(category,"fix") == 0) { return lmp->modify->nfix; + } else if (strcmp(category,"group") == 0) { + return lmp->group->ngroup; } else if (strcmp(category,"molecule") == 0) { return lmp->atom->nmolecule; } else if (strcmp(category,"region") == 0) { @@ -4249,6 +4183,11 @@ int lammps_id_name(void *handle, const char *category, int idx, strncpy(buffer, lmp->modify->fix[idx]->id, buf_size); return 1; } + } else if (strcmp(category,"group") == 0) { + if ((idx >=0) && (idx < lmp->group->ngroup)) { + strncpy(buffer, lmp->group->names[idx], buf_size); + return 1; + } } else if (strcmp(category,"molecule") == 0) { if ((idx >=0) && (idx < lmp->atom->nmolecule)) { strncpy(buffer, lmp->atom->molecules[idx]->id, buf_size); diff --git a/src/library.h b/src/library.h index c365bd9210..8089e51ade 100644 --- a/src/library.h +++ b/src/library.h @@ -183,10 +183,6 @@ int lammps_has_style(void *, const char *, const char *); int lammps_style_count(void *, const char *); int lammps_style_name(void *, const char *, int, char *, int); -int lammps_has_group(void *, const char *); -int lammps_group_count(void *); -int lammps_group_name(void *, int, char *, int); - int lammps_has_id(void *, const char *, const char *); int lammps_id_count(void *, const char *); int lammps_id_name(void *, const char *, int, char *, int); diff --git a/tools/lammps-shell/lammps-shell.cpp b/tools/lammps-shell/lammps-shell.cpp index 7fa1e0f931..c1f8182535 100644 --- a/tools/lammps-shell/lammps-shell.cpp +++ b/tools/lammps-shell/lammps-shell.cpp @@ -357,12 +357,12 @@ char *group_generator(const char *text, int state) static int idx, num, len; if (!state) { idx = 0; - num = lammps_group_count(lmp); + num = lammps_id_count(lmp, "group"); len = strlen(text); } while (idx < num) { - lammps_group_name(lmp, idx, buf, buflen); + lammps_id_name(lmp, "group", idx, buf, buflen); ++idx; if ((len == 0) || (strncmp(text, buf, len) == 0)) return dupstring(buf); }