diff --git a/doc/src/fix_shake.rst b/doc/src/fix_shake.rst index 73caa9c668..4129dcd9af 100644 --- a/doc/src/fix_shake.rst +++ b/doc/src/fix_shake.rst @@ -27,9 +27,9 @@ Syntax .. parsed-literal:: - *b* values = one or more bond types - *a* values = one or more angle types - *t* values = one or more atom types + *b* values = one or more bond types (may use type labels) + *a* values = one or more angle types (may use type labels) + *t* values = one or more atom types (may use type labels) *m* value = one or more mass values * zero or more keyword/value pairs may be appended @@ -137,7 +137,17 @@ constrained (within a fudge factor of MASSDELTA specified in both bonds in the angle are constrained then the angle will also be constrained if its type is in the list. -For all constraints, a particular bond is only constrained if both +.. versionchanged:: TBD + +The types may be given as type labels *only* if there is no atom, bond, +or angle type label named *b*, *a*, *t*, or *m* defined in the +simulation. If that is the case, type labels cannot be used as +constraint type index with these two fixes, because the type labels +would be incorrectly treated as a new type of constraint instead. +Thus, LAMMPS will print a warning and type label handling is disabled +and numeric types must be used. + +For all constraints, a particular bond is only constrained if *both* atoms in the bond are in the group specified with the SHAKE fix. The degrees-of-freedom removed by SHAKE bonds and angles are accounted diff --git a/doc/src/neigh_modify.rst b/doc/src/neigh_modify.rst index 3ec6578b3f..63d7221c70 100644 --- a/doc/src/neigh_modify.rst +++ b/doc/src/neigh_modify.rst @@ -32,7 +32,7 @@ Syntax group-ID = only build pair neighbor lists for atoms in this group *exclude* values: *type* M N - M,N = exclude if one atom in pair is type M, other is type N + M,N = exclude if one atom in pair is type M, other is type N (M and N may be type labels) *group* group1-ID group2-ID group1-ID,group2-ID = exclude if one atom is in 1st group, other in 2nd *molecule/intra* group-ID @@ -159,15 +159,19 @@ sample scenarios where this is useful: * When one or more rigid bodies are specified, interactions within each body can be turned off to save needless computation. See the :doc:`fix rigid ` command for more details. -The *exclude type* option turns off the pairwise interaction if one -atom is of type M and the other of type N. M can equal N. The -*exclude group* option turns off the interaction if one atom is in the -first group and the other is the second. Group1-ID can equal -group2-ID. The *exclude molecule/intra* option turns off the -interaction if both atoms are in the specified group and in the same -molecule, as determined by their molecule ID. The *exclude -molecule/inter* turns off the interaction between pairs of atoms that -have different molecule IDs and are both in the specified group. +.. versionchanged:: TBD + + Support for type labels was added. + +The *exclude type* option turns off the pairwise interaction if one atom +is of type M and the other of type N. M can equal N. The *exclude +group* option turns off the interaction if one atom is in the first +group and the other is the second. Group1-ID can equal group2-ID. The +*exclude molecule/intra* option turns off the interaction if both atoms +are in the specified group and in the same molecule, as determined by +their molecule ID. The *exclude molecule/inter* turns off the +interaction between pairs of atoms that have different molecule IDs and +are both in the specified group. Each of the exclude options can be specified multiple times. The *exclude type* option is the most efficient option to use; it requires @@ -219,34 +223,34 @@ atom can have. The *binsize* option allows you to specify what size of bins will be used in neighbor list construction to sort and find neighboring atoms. By default, for :doc:`neighbor style bin `, LAMMPS uses bins -that are 1/2 the size of the maximum pair cutoff. For :doc:`neighbor style multi `, -the bins are 1/2 the size of the collection interaction cutoff. -Typically these are good values for minimizing the time for -neighbor list construction. This setting overrides the default. -If you make it too big, there is little overhead due to +that are 1/2 the size of the maximum pair cutoff. For :doc:`neighbor +style multi `, the bins are 1/2 the size of the collection +interaction cutoff. Typically these are good values for minimizing the +time for neighbor list construction. This setting overrides the +default. If you make it too big, there is little overhead due to looping over bins, but more atoms are checked. If you make it too -small, the optimal number of atoms is checked, but bin overhead goes -up. If you set the binsize to 0.0, LAMMPS will use the default -binsize of 1/2 the cutoff. +small, the optimal number of atoms is checked, but bin overhead goes up. +If you set the binsize to 0.0, LAMMPS will use the default binsize of +1/2 the cutoff. The *collection/type* option allows you to define collections of atom -types, used by the *multi* neighbor mode. By grouping atom types with -similar physical size or interaction cutoff lengths, one may be able -to improve performance by reducing -overhead. You must first specify the number of collections N to be -defined followed by N lists of types. Each list consists of a series of type -ranges separated by commas. The range can be specified as a -single numeric value, or a wildcard asterisk can be used to specify a range -of values. This takes the form "\*" or "\*n" or "n\*" or "m\*n". For -example, if M = the number of atom types, then an asterisk with no numeric -values means all types from 1 to M. A leading asterisk means all types -from 1 to n (inclusive). A trailing asterisk means all types from n to M -(inclusive). A middle asterisk means all types from m to n (inclusive). -Note that all atom types must be included in exactly one of the N collections. +types, used by the *multi* neighbor mode. By grouping atom types with +similar physical size or interaction cutoff lengths, one may be able to +improve performance by reducing overhead. You must first specify the +number of collections N to be defined followed by N lists of types. +Each list consists of a series of type ranges separated by commas. The +range can be specified as a single numeric value, or a wildcard asterisk +can be used to specify a range of values. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". For example, if M = the number of atom types, +then an asterisk with no numeric values means all types from 1 to M. A +leading asterisk means all types from 1 to n (inclusive). A trailing +asterisk means all types from n to M (inclusive). A middle asterisk +means all types from m to n (inclusive). Note that all atom types must +be included in exactly one of the N collections. The *collection/interval* option provides a similar capability. This command allows a user to define collections by specifying a series of -cutoff intervals. LAMMPS will automatically sort atoms into these +cutoff intervals. LAMMPS will automatically sort atoms into these intervals based on their type-dependent cutoffs or their finite size. You must first specify the number of collections N to be defined followed by N values representing the upper cutoff of each interval. diff --git a/python/lammps/core.py b/python/lammps/core.py index dbadebe7f2..97bcb5157d 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -992,7 +992,7 @@ class lammps(object): return None dim = self.extract_pair_dimension(name) - if dim == None: + if dim is None: return None elif dim == 0: self.lib.lammps_extract_pair.restype = POINTER(c_double) diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index ac71ea01a6..41708823bb 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -21,6 +21,7 @@ #include "comm.h" #include "domain.h" #include "error.h" +#include "label_map.h" #include "fix_respa.h" #include "force.h" #include "group.h" @@ -98,6 +99,7 @@ FixShake::FixShake(LAMMPS *lmp, int narg, char **arg) : comm_forward = 3; // parse SHAKE args + auto mystyle = fmt::format("fix {}", style); if (narg < 8) utils::missing_cmd_args(FLERR, mystyle, error); @@ -106,6 +108,21 @@ FixShake::FixShake(LAMMPS *lmp, int narg, char **arg) : max_iter = utils::inumeric(FLERR, arg[4], false, lmp); output_every = utils::inumeric(FLERR, arg[5], false, lmp); + // check if any typelabels conflict with fix shake arguments. + + bool allow_typelabels = (atom->labelmapflag != 0); + if (allow_typelabels) { + for (int i = Atom::ATOM; i < Atom::DIHEDRAL; ++i) { + if ((atom->lmap->find("b", i) >= 0) || + (atom->lmap->find("a", i) >= 0) || + (atom->lmap->find("t", i) >= 0) || + (atom->lmap->find("m", i) >= 0)) allow_typelabels = false; + } + if (!allow_typelabels && (comm->me == 0)) + error->warning(FLERR, "At least one typelabel conflicts with a fix shake option: " + "support for typelabels is disabled."); + } + // parse SHAKE args for bond and angle types // will be used by find_clusters // store args for "b" "a" "t" as flags in (1:n) list for fast access @@ -124,6 +141,7 @@ FixShake::FixShake(LAMMPS *lmp, int narg, char **arg) : char mode = '\0'; int next = 6; while (next < narg) { + int i = -1; if (strcmp(arg[next],"b") == 0) mode = 'b'; else if (strcmp(arg[next],"a") == 0) mode = 'a'; else if (strcmp(arg[next],"t") == 0) mode = 't'; @@ -131,33 +149,40 @@ FixShake::FixShake(LAMMPS *lmp, int narg, char **arg) : mode = 'm'; atom->check_mass(FLERR); - // break if keyword that is not b,a,t,m + // break if known optional keyword - } else if (isalpha(arg[next][0])) break; + } else if ((strcmp(arg[next], "mol") == 0) || (strcmp(arg[next], "kbond") == 0)) { + break; - // read numeric args of b,a,t,m + // get numeric types for b, a, t, or m keywords. + + } else if (mode == 'b') { + if (allow_typelabels) i = utils::expand_type_int(FLERR, arg[next], Atom::BOND, lmp); + else i = utils::inumeric(FLERR, arg[next], false, lmp); - else if (mode == 'b') { - int i = utils::inumeric(FLERR,arg[next],false,lmp); if (i < 1 || i > atom->nbondtypes) - error->all(FLERR,"Invalid bond type index for {}", mystyle); + error->all(FLERR,"Invalid bond type {} index for {}", arg[next], mystyle); bond_flag[i] = 1; } else if (mode == 'a') { - int i = utils::inumeric(FLERR,arg[next],false,lmp); + if (allow_typelabels) i = utils::expand_type_int(FLERR, arg[next], Atom::ANGLE, lmp); + else i = utils::inumeric(FLERR, arg[next], false, lmp); + if (i < 1 || i > atom->nangletypes) - error->all(FLERR,"Invalid angle type index for {}", mystyle); + error->all(FLERR,"Invalid angle type {} for {}", arg[next], mystyle); angle_flag[i] = 1; } else if (mode == 't') { - int i = utils::inumeric(FLERR,arg[next],false,lmp); + if (allow_typelabels) i = utils::expand_type_int(FLERR, arg[next], Atom::ATOM, lmp); + else i = utils::inumeric(FLERR, arg[next], false, lmp); + if (i < 1 || i > atom->ntypes) - error->all(FLERR,"Invalid atom type index for {}", mystyle); + error->all(FLERR,"Invalid atom type {} for {}", arg[next], mystyle); type_flag[i] = 1; } else if (mode == 'm') { - double massone = utils::numeric(FLERR,arg[next],false,lmp); - if (massone == 0.0) error->all(FLERR,"Invalid atom mass for {}", mystyle); + double massone = utils::numeric(FLERR, arg[next], false, lmp); + if (massone == 0.0) error->all(FLERR,"Invalid atom mass {} for {}", arg[next], mystyle); if (nmass == atom->ntypes) error->all(FLERR,"Too many masses for {}", mystyle); mass_list[nmass++] = massone; diff --git a/src/neighbor.cpp b/src/neighbor.cpp index a1c8979ca7..072240b482 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1,4 +1,4 @@ - // clang-format off +// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -2705,8 +2705,8 @@ void Neighbor::modify_params(int narg, char **arg) memory->grow(ex1_type,maxex_type,"neigh:ex1_type"); memory->grow(ex2_type,maxex_type,"neigh:ex2_type"); } - ex1_type[nex_type] = utils::inumeric(FLERR,arg[iarg+2],false,lmp); - ex2_type[nex_type] = utils::inumeric(FLERR,arg[iarg+3],false,lmp); + ex1_type[nex_type] = utils::expand_type_int(FLERR, arg[iarg+2], Atom::ATOM, lmp); + ex2_type[nex_type] = utils::expand_type_int(FLERR, arg[iarg+3], Atom::ATOM, lmp); nex_type++; iarg += 4; } else if (strcmp(arg[iarg+1],"group") == 0) {