use of type labels in set commands
This commit is contained in:
@ -28,18 +28,18 @@ Syntax
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
*type* value = atom type
|
||||
*type* value = atom type or type label
|
||||
value can be an atom-style variable (see below)
|
||||
*type/fraction* values = type fraction seed
|
||||
type = new atom type
|
||||
type = new atom type or type label
|
||||
fraction = approximate fraction of selected atoms to set to new atom type
|
||||
seed = random # seed (positive integer)
|
||||
*type/ratio* values = type fraction seed
|
||||
type = new atom type
|
||||
type = new atom type or type label
|
||||
fraction = exact fraction of selected atoms to set to new atom type
|
||||
seed = random # seed (positive integer)
|
||||
*type/subset* values = type Nsubset seed
|
||||
type = new atom type
|
||||
type = new atom type or type label
|
||||
Nsubset = exact number of selected atoms to set to new atom type
|
||||
seed = random # seed (positive integer)
|
||||
*mol* value = molecule ID
|
||||
@ -107,10 +107,10 @@ Syntax
|
||||
*image* nx ny nz
|
||||
nx,ny,nz = which periodic image of the simulation box the atom is in
|
||||
any of nx,ny,nz can be an atom-style variable (see below)
|
||||
*bond* value = bond type for all bonds between selected atoms
|
||||
*angle* value = angle type for all angles between selected atoms
|
||||
*dihedral* value = dihedral type for all dihedrals between selected atoms
|
||||
*improper* value = improper type for all impropers between selected atoms
|
||||
*bond* value = bond type or bond type label for all bonds between selected atoms
|
||||
*angle* value = angle type or angle type label for all angles between selected atoms
|
||||
*dihedral* value = dihedral type or dihedral type label for all dihedrals between selected atoms
|
||||
*improper* value = improper type or improper type label for all impropers between selected atoms
|
||||
*sph/e* value = energy of SPH particles (need units)
|
||||
value can be an atom-style variable (see below)
|
||||
*sph/cv* value = heat capacity of SPH particles (need units)
|
||||
@ -145,15 +145,19 @@ Examples
|
||||
.. code-block:: LAMMPS
|
||||
|
||||
set group solvent type 2
|
||||
set group solvent type C
|
||||
set group solvent type/fraction 2 0.5 12393
|
||||
set group solvent type/fraction C 0.5 12393
|
||||
set group edge bond 4
|
||||
set region half charge 0.5
|
||||
set type 3 charge 0.5
|
||||
set type H charge 0.5
|
||||
set type 1*3 charge 0.5
|
||||
set atom * charge v_atomfile
|
||||
set atom 100*200 x 0.5 y 1.0
|
||||
set atom 100 vx 0.0 vy 0.0 vz -1.0
|
||||
set atom 1492 type 3
|
||||
set atom 1492 type H
|
||||
set atom * i_myVal 5
|
||||
set atom * d2_Sxyz[1] 6.4
|
||||
|
||||
@ -184,8 +188,8 @@ This section describes how to select which atoms to change
|
||||
the properties of, via the *style* and *ID* arguments.
|
||||
|
||||
The style *atom* selects all the atoms in a range of atom IDs. The
|
||||
style *type* selects all the atoms in a range of types. The style
|
||||
*mol* selects all the atoms in a range of molecule IDs.
|
||||
style *type* selects all the atoms in a range of types or type labels.
|
||||
The style *mol* selects all the atoms in a range of molecule IDs.
|
||||
|
||||
In each of the range cases, the range can be specified as a single
|
||||
numeric value, or a wildcard asterisk can be used to specify a range
|
||||
@ -237,24 +241,27 @@ from a file.
|
||||
such as the molecule ID, then the floating point value is truncated to
|
||||
its integer portion, e.g. a value of 2.6 would become 2.
|
||||
|
||||
Keyword *type* sets the atom type for all selected atoms. The
|
||||
specified value must be from 1 to ntypes, where ntypes was set by the
|
||||
:doc:`create_box <create_box>` command or the *atom types* field in the
|
||||
Keyword *type* sets the atom type or atom type label for all selected atoms.
|
||||
For atom type, specified value must be from 1 to ntypes, where ntypes was set
|
||||
by the :doc:`create_box <create_box>` command or the *atom types* field in the
|
||||
header of the data file read by the :doc:`read_data <read_data>`
|
||||
command.
|
||||
command. In the case of the specified type label, it must have been defined
|
||||
before use via an alphanumeric type label. See the
|
||||
:doc:`Howto type labels <Howto_type_labels>` doc page for the allowed syntax
|
||||
of type labels and a general discussion of how type labels can be used.
|
||||
|
||||
Keyword *type/fraction* sets the atom type for a fraction of the
|
||||
selected atoms. The actual number of atoms changed is not guaranteed
|
||||
Keyword *type/fraction* sets the atom type or atom type label for a fraction
|
||||
of the selected atoms. The actual number of atoms changed is not guaranteed
|
||||
to be exactly the specified fraction (0 <= *fraction* <= 1), but
|
||||
should be statistically close. Random numbers are used in such a way
|
||||
that a particular atom is changed or not changed, regardless of how
|
||||
many processors are being used. This keyword does not allow use of an
|
||||
atom-style variable.
|
||||
|
||||
Keywords *type/ratio* and *type/subset* also set the atom type for a
|
||||
fraction of the selected atoms. The actual number of atoms changed
|
||||
will be exactly the requested number. For *type/ratio* the specified
|
||||
fraction (0 <= *fraction* <= 1) determines the number. For
|
||||
Keywords *type/ratio* and *type/subset* also set the atom type or atom
|
||||
type label for a fraction of the selected atoms. The actual number of
|
||||
atoms changed will be exactly the requested number. For *type/ratio* the
|
||||
specified fraction (0 <= *fraction* <= 1) determines the number. For
|
||||
*type/subset*, the specified *Nsubset* is the number. An iterative
|
||||
algorithm is used which ensures the correct number of atoms are
|
||||
selected, in a perfectly random fashion. Which atoms are selected
|
||||
@ -465,7 +472,10 @@ molecule which straddles the periodic box.
|
||||
|
||||
Keywords *bond*, *angle*, *dihedral*, and *improper*, set the bond type
|
||||
(angle type, etc) of all bonds (angles, etc) of selected atoms to the
|
||||
specified value from 1 to nbondtypes (nangletypes, etc). All atoms in a
|
||||
specified value from 1 to nbondtypes (nangletypes, etc). One can also use
|
||||
a specified type label. See the :doc:`Howto type labels <Howto_type_labels>`
|
||||
doc page for the allowed syntax of type labels and a general discussion of
|
||||
how type labels can be used. All atoms in a
|
||||
particular bond (angle, etc) must be selected atoms in order for the
|
||||
change to be made. The value of nbondtype (nangletypes, etc) was set by
|
||||
the *bond types* (\ *angle types*, etc) field in the header of the data
|
||||
|
||||
24
src/set.cpp
24
src/set.cpp
@ -93,12 +93,18 @@ void Set::command(int narg, char **arg)
|
||||
if (strcmp(arg[iarg],"type") == 0) {
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set type", error);
|
||||
if (utils::strmatch(arg[iarg+1],"^v_")) varparse(arg[iarg+1],1);
|
||||
else ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
else {
|
||||
char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ATOM,lmp);
|
||||
if (typestr) arg[iarg+1] = typestr;
|
||||
ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
}
|
||||
set(TYPE);
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"type/fraction") == 0) {
|
||||
if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "set type/fraction", error);
|
||||
char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ATOM,lmp);
|
||||
if (typestr) arg[iarg+1] = typestr;
|
||||
newtype = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
fraction = utils::numeric(FLERR,arg[iarg+2],false,lmp);
|
||||
ivalue = utils::inumeric(FLERR,arg[iarg+3],false,lmp);
|
||||
@ -113,6 +119,8 @@ void Set::command(int narg, char **arg)
|
||||
|
||||
} else if (strcmp(arg[iarg],"type/ratio") == 0) {
|
||||
if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "set type/ratio", error);
|
||||
char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ATOM,lmp);
|
||||
if (typestr) arg[iarg+1] = typestr;
|
||||
newtype = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
fraction = utils::numeric(FLERR,arg[iarg+2],false,lmp);
|
||||
ivalue = utils::inumeric(FLERR,arg[iarg+3],false,lmp);
|
||||
@ -127,6 +135,8 @@ void Set::command(int narg, char **arg)
|
||||
|
||||
} else if (strcmp(arg[iarg],"type/subset") == 0) {
|
||||
if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "set type/subset", error);
|
||||
char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ATOM,lmp);
|
||||
if (typestr) arg[iarg+1] = typestr;
|
||||
newtype = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
nsubset = utils::bnumeric(FLERR,arg[iarg+2],false,lmp);
|
||||
ivalue = utils::inumeric(FLERR,arg[iarg+3],false,lmp);
|
||||
@ -477,6 +487,8 @@ void Set::command(int narg, char **arg)
|
||||
|
||||
} else if (strcmp(arg[iarg],"bond") == 0) {
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set bond", error);
|
||||
char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::BOND,lmp);
|
||||
if (typestr) arg[iarg+1] = typestr;
|
||||
ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
if (atom->avec->bonds_allow == 0)
|
||||
error->all(FLERR,"Cannot set attribute {} for atom style {}", arg[iarg], atom->get_style());
|
||||
@ -487,6 +499,8 @@ void Set::command(int narg, char **arg)
|
||||
|
||||
} else if (strcmp(arg[iarg],"angle") == 0) {
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set angle", error);
|
||||
char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ANGLE,lmp);
|
||||
if (typestr) arg[iarg+1] = typestr;
|
||||
ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
if (atom->avec->angles_allow == 0)
|
||||
error->all(FLERR,"Cannot set attribute {} for atom style {}", arg[iarg], atom->get_style());
|
||||
@ -497,6 +511,8 @@ void Set::command(int narg, char **arg)
|
||||
|
||||
} else if (strcmp(arg[iarg],"dihedral") == 0) {
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set dihedral", error);
|
||||
char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::DIHEDRAL,lmp);
|
||||
if (typestr) arg[iarg+1] = typestr;
|
||||
ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
if (atom->avec->dihedrals_allow == 0)
|
||||
error->all(FLERR,"Cannot set attribute {} for atom style {}", arg[iarg], atom->get_style());
|
||||
@ -507,6 +523,8 @@ void Set::command(int narg, char **arg)
|
||||
|
||||
} else if (strcmp(arg[iarg],"improper") == 0) {
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set improper", error);
|
||||
char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::IMPROPER,lmp);
|
||||
if (typestr) arg[iarg+1] = typestr;
|
||||
ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
if (atom->avec->impropers_allow == 0)
|
||||
error->all(FLERR,"Cannot set attribute {} for atom style {}", arg[iarg], atom->get_style());
|
||||
@ -722,6 +740,8 @@ void Set::selection(int n)
|
||||
if (style == ATOM_SELECT) {
|
||||
if (atom->tag_enable == 0)
|
||||
error->all(FLERR,"Cannot use set atom with no atom IDs defined");
|
||||
char *typestr = utils::expand_type(FLERR,id,Atom::ATOM,lmp);
|
||||
if (typestr) id = typestr;
|
||||
bigint nlobig,nhibig;
|
||||
utils::bounds(FLERR,id,1,MAXTAGINT,nlobig,nhibig,error);
|
||||
|
||||
@ -742,6 +762,8 @@ void Set::selection(int n)
|
||||
else select[i] = 0;
|
||||
|
||||
} else if (style == TYPE_SELECT) {
|
||||
char *typestr = utils::expand_type(FLERR, id, Atom::ATOM, lmp);
|
||||
if (typestr) id = typestr;
|
||||
utils::bounds(FLERR,id,1,atom->ntypes,nlo,nhi,error);
|
||||
|
||||
int *type = atom->type;
|
||||
|
||||
@ -206,6 +206,16 @@ TEST_F(SetTest, StylesTypes)
|
||||
sum += (atom->type[i] == 2) ? 1 : 0;
|
||||
ASSERT_EQ(sum, 4);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("labelmap atom 1 C 2 H");
|
||||
command("set group all type C");
|
||||
command("set group all type/fraction H 0.5 453246");
|
||||
END_HIDE_OUTPUT();
|
||||
sum = 0;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
sum += (atom->type[i] == 2) ? 1 : 0;
|
||||
ASSERT_EQ(sum, 4);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set group all type 1");
|
||||
command("set group all type/ratio 2 0.5 5784536");
|
||||
@ -224,6 +234,15 @@ TEST_F(SetTest, StylesTypes)
|
||||
sum += (atom->type[i] == 2) ? 1 : 0;
|
||||
ASSERT_EQ(sum, 4);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set group all type C");
|
||||
command("set group all type/subset H 5 784536");
|
||||
END_HIDE_OUTPUT();
|
||||
sum = 0;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
sum += (atom->type[i] == 2) ? 1 : 0;
|
||||
ASSERT_EQ(sum, 5);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Numeric index 9 is out of bounds .1-8.*", command("set type 9 x 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Invalid range string: 3:10.*", command("set type 3:10 x 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Could not find set group ID nope.*", command("set group nope x 0.0"););
|
||||
@ -247,6 +266,34 @@ TEST_F(SetTest, PosVelCharge)
|
||||
ASSERT_EQ(atom->q[6], -1);
|
||||
ASSERT_EQ(atom->q[7], -1);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("labelmap atom 1 C 2 H");
|
||||
command("set region right type H");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
ASSERT_EQ(atom->type[0], 1);
|
||||
ASSERT_EQ(atom->type[1], 2);
|
||||
ASSERT_EQ(atom->type[2], 1);
|
||||
ASSERT_EQ(atom->type[3], 2);
|
||||
ASSERT_EQ(atom->type[4], 1);
|
||||
ASSERT_EQ(atom->type[5], 2);
|
||||
ASSERT_EQ(atom->type[6], 1);
|
||||
ASSERT_EQ(atom->type[7], 2);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set type C charge 1.25");
|
||||
command("set type H charge -1.25");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
ASSERT_EQ(atom->q[0], 1.25);
|
||||
ASSERT_EQ(atom->q[1], -1.25);
|
||||
ASSERT_EQ(atom->q[2], 1.25);
|
||||
ASSERT_EQ(atom->q[3], -1.25);
|
||||
ASSERT_EQ(atom->q[4], 1.25);
|
||||
ASSERT_EQ(atom->q[5], -1.25);
|
||||
ASSERT_EQ(atom->q[6], 1.25);
|
||||
ASSERT_EQ(atom->q[7], -1.25);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("variable xpos atom 0.5-x");
|
||||
command("variable ypos atom y*0.5");
|
||||
|
||||
Reference in New Issue
Block a user