type offsets are only applied to numeric types

This commit is contained in:
Axel Kohlmeyer
2022-09-04 22:12:59 -04:00
parent 53d82056ce
commit fc738ea239
3 changed files with 20 additions and 35 deletions

View File

@ -89,6 +89,12 @@ molecule file. E.g. if *toff* = 2, and the file uses atom types
individual values will be ignored if the molecule template does not individual values will be ignored if the molecule template does not
use that attribute (e.g. no bonds). use that attribute (e.g. no bonds).
.. note::
Offsets are **ignored** if the molecule file lines using type labels,
as the type labels will determine the actual types depending on the
current :doc:`labelmap <labelmap>` settings.
The *scale* keyword scales the size of the molecule. This can be The *scale* keyword scales the size of the molecule. This can be
useful for modeling polydisperse granular rigid bodies. The scale useful for modeling polydisperse granular rigid bodies. The scale
factor is applied to each of these properties in the molecule file, if factor is applied to each of these properties in the molecule file, if
@ -183,6 +189,7 @@ type labels have been defined, either by the :doc:`labelmap
Type Labels, Angle Type Labels, etc. See the :doc:`Howto type labels Type Labels, Angle Type Labels, etc. See the :doc:`Howto type labels
<Howto_type_labels>` doc page for the allowed syntax of 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. and a general discussion of how type labels can be used.
When using type labels, any values specified as *offset* are ignored.
If a Bonds section is specified then the Special Bond Counts and If a Bonds section is specified then the Special Bond Counts and
Special Bonds sections can also be used, if desired, to explicitly Special Bonds sections can also be used, if desired, to explicitly

View File

@ -164,6 +164,12 @@ other types already exist. All five offset values must be specified,
but individual values will be ignored if the data file does not use but individual values will be ignored if the data file does not use
that attribute (e.g. no bonds). that attribute (e.g. no bonds).
.. note::
Offsets are **ignored** for any data file lines using type labels, as
the type labels will determine the actual types depending on the
current :doc:`labelmap <labelmap>` settings.
The *shift* keyword can be used to specify an (Sx, Sy, Sz) The *shift* keyword can be used to specify an (Sx, Sy, Sz)
displacement applied to the coordinates of each atom. Sz must be 0.0 displacement applied to the coordinates of each atom. Sz must be 0.0
for a 2d simulation. This is a mechanism for adding structured for a 2d simulation. This is a mechanism for adding structured

View File

@ -1188,11 +1188,10 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,
typestr = utils::utf8_subst(typestr); typestr = utils::utf8_subst(typestr);
if (id_offset) tag[nlocal-1] += id_offset; if (id_offset) tag[nlocal-1] += id_offset;
if (mol_offset) molecule[nlocal-1] += mol_offset; if (mol_offset) molecule[nlocal-1] += mol_offset;
// clang-format on
switch (utils::is_type(typestr)) {
switch (utils::is_type(typestr)) {
case 0: { // numeric case 0: { // numeric
int itype = utils::inumeric(FLERR, typestr, true, lmp); int itype = utils::inumeric(FLERR, typestr, true, lmp) + type_offset;
if ((itype < 1) || (itype > ntypes)) if ((itype < 1) || (itype > ntypes))
error->one(FLERR, "Invalid atom type {} in {}: {}", itype, location, error->one(FLERR, "Invalid atom type {} in {}: {}", itype, location,
utils::trim(buf)); utils::trim(buf));
@ -1200,7 +1199,6 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,
if (labelflag) type[nlocal - 1] = ilabel[itype - 1]; if (labelflag) type[nlocal - 1] = ilabel[itype - 1];
break; break;
} }
case 1: { // type label case 1: { // type label
if (!atom->labelmapflag) if (!atom->labelmapflag)
error->one(FLERR, "Invalid line in {}: {}", location, utils::trim(buf)); error->one(FLERR, "Invalid line in {}: {}", location, utils::trim(buf));
@ -1209,13 +1207,11 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,
error->one(FLERR, "Invalid line in {}: {}", location, utils::trim(buf)); error->one(FLERR, "Invalid line in {}: {}", location, utils::trim(buf));
break; break;
} }
default: // invalid default: // invalid
error->one(FLERR, "Invalid line in {}: {}", location, utils::trim(buf)); error->one(FLERR, "Invalid line in {}: {}", location, utils::trim(buf));
break; break;
} }
// clang-format off
if (type_offset) type[nlocal-1] += type_offset;
if (type[nlocal-1] <= 0 || type[nlocal-1] > ntypes) if (type[nlocal-1] <= 0 || type[nlocal-1] > ntypes)
error->one(FLERR,"Invalid atom type {} in {}", location, typestr); error->one(FLERR,"Invalid atom type {} in {}", location, typestr);
} }
@ -1300,30 +1296,24 @@ void Atom::data_bonds(int n, char *buf, int *count, tagint id_offset,
atom2 += id_offset; atom2 += id_offset;
} }
// clang-format on
switch (utils::is_type(typestr)) { switch (utils::is_type(typestr)) {
case 0: { // numeric case 0: { // numeric
itype = utils::inumeric(FLERR, typestr, false, lmp); itype = utils::inumeric(FLERR, typestr, false, lmp) + type_offset;
if ((itype < 1) || (itype > nbondtypes)) if ((itype < 1) || (itype > nbondtypes))
error->all(FLERR, "Invalid bond type {} in {}: {}", itype, location, utils::trim(buf)); error->all(FLERR, "Invalid bond type {} in {}: {}", itype, location, utils::trim(buf));
if (labelflag) itype = ilabel[itype - 1]; if (labelflag) itype = ilabel[itype - 1];
break; break;
} }
case 1: { // type label case 1: { // type label
if (!atom->labelmapflag) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf)); if (!atom->labelmapflag) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf));
itype = lmap->find(typestr, Atom::BOND); itype = lmap->find(typestr, Atom::BOND);
if (itype == -1) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf)); if (itype == -1) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf));
break; break;
} }
default: // invalid default: // invalid
error->one(FLERR, "Invalid {}: {}", location, utils::trim(buf)); error->one(FLERR, "Invalid {}: {}", location, utils::trim(buf));
break; break;
} }
itype += type_offset;
// clang-format off
if ((atom1 <= 0) || (atom1 > map_tag_max) || if ((atom1 <= 0) || (atom1 > map_tag_max) ||
(atom2 <= 0) || (atom2 > map_tag_max) || (atom1 == atom2)) (atom2 <= 0) || (atom2 > map_tag_max) || (atom1 == atom2))
@ -1399,30 +1389,24 @@ void Atom::data_angles(int n, char *buf, int *count, tagint id_offset,
atom3 += id_offset; atom3 += id_offset;
} }
// clang-format on
switch (utils::is_type(typestr)) { switch (utils::is_type(typestr)) {
case 0: { // numeric case 0: { // numeric
itype = utils::inumeric(FLERR, typestr, false, lmp); itype = utils::inumeric(FLERR, typestr, false, lmp) + type_offset;
if ((itype < 1) || (itype > nangletypes)) if ((itype < 1) || (itype > nangletypes))
error->all(FLERR, "Invalid angle type {} in {}: {}", itype, location, utils::trim(buf)); error->all(FLERR, "Invalid angle type {} in {}: {}", itype, location, utils::trim(buf));
if (labelflag) itype = ilabel[itype - 1]; if (labelflag) itype = ilabel[itype - 1];
break; break;
} }
case 1: { // type label case 1: { // type label
if (!atom->labelmapflag) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf)); if (!atom->labelmapflag) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf));
itype = lmap->find(typestr, Atom::ANGLE); itype = lmap->find(typestr, Atom::ANGLE);
if (itype == -1) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf)); if (itype == -1) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf));
break; break;
} }
default: // invalid default: // invalid
error->one(FLERR, "Invalid {}: {}", location, utils::trim(buf)); error->one(FLERR, "Invalid {}: {}", location, utils::trim(buf));
break; break;
} }
itype += type_offset;
// clang-format off
if ((atom1 <= 0) || (atom1 > map_tag_max) || if ((atom1 <= 0) || (atom1 > map_tag_max) ||
(atom2 <= 0) || (atom2 > map_tag_max) || (atom2 <= 0) || (atom2 > map_tag_max) ||
@ -1514,31 +1498,25 @@ void Atom::data_dihedrals(int n, char *buf, int *count, tagint id_offset,
atom4 += id_offset; atom4 += id_offset;
} }
// clang-format on
switch (utils::is_type(typestr)) { switch (utils::is_type(typestr)) {
case 0: { // numeric case 0: { // numeric
itype = utils::inumeric(FLERR, typestr, false, lmp); itype = utils::inumeric(FLERR, typestr, false, lmp) + type_offset;
if ((itype < 1) || (itype > ndihedraltypes)) if ((itype < 1) || (itype > ndihedraltypes))
error->all(FLERR, "Invalid dihedral type {} in {}: {}", itype, location, error->all(FLERR, "Invalid dihedral type {} in {}: {}", itype, location,
utils::trim(buf)); utils::trim(buf));
if (labelflag) itype = ilabel[itype - 1]; if (labelflag) itype = ilabel[itype - 1];
break; break;
} }
case 1: { // type label case 1: { // type label
if (!atom->labelmapflag) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf)); if (!atom->labelmapflag) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf));
itype = lmap->find(typestr, Atom::DIHEDRAL); itype = lmap->find(typestr, Atom::DIHEDRAL);
if (itype == -1) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf)); if (itype == -1) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf));
break; break;
} }
default: // invalid default: // invalid
error->one(FLERR, "Invalid {}: {}", location, utils::trim(buf)); error->one(FLERR, "Invalid {}: {}", location, utils::trim(buf));
break; break;
} }
itype += type_offset;
// clang-format off
if ((atom1 <= 0) || (atom1 > map_tag_max) || if ((atom1 <= 0) || (atom1 > map_tag_max) ||
(atom2 <= 0) || (atom2 > map_tag_max) || (atom2 <= 0) || (atom2 > map_tag_max) ||
@ -1646,31 +1624,25 @@ void Atom::data_impropers(int n, char *buf, int *count, tagint id_offset,
atom4 += id_offset; atom4 += id_offset;
} }
// clang-format on
switch (utils::is_type(typestr)) { switch (utils::is_type(typestr)) {
case 0: { // numeric case 0: { // numeric
itype = utils::inumeric(FLERR, typestr, false, lmp); itype = utils::inumeric(FLERR, typestr, false, lmp) + type_offset;
if ((itype < 1) || (itype > nimpropertypes)) if ((itype < 1) || (itype > nimpropertypes))
error->all(FLERR, "Invalid improper type {} in {}: {}", itype, location, error->all(FLERR, "Invalid improper type {} in {}: {}", itype, location,
utils::trim(buf)); utils::trim(buf));
if (labelflag) itype = ilabel[itype - 1]; if (labelflag) itype = ilabel[itype - 1];
break; break;
} }
case 1: { // type label case 1: { // type label
if (!atom->labelmapflag) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf)); if (!atom->labelmapflag) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf));
itype = lmap->find(typestr, Atom::IMPROPER); itype = lmap->find(typestr, Atom::IMPROPER);
if (itype == -1) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf)); if (itype == -1) error->all(FLERR, "Invalid {}: {}", location, utils::trim(buf));
break; break;
} }
default: // invalid default: // invalid
error->one(FLERR, "Invalid {}: {}", location, utils::trim(buf)); error->one(FLERR, "Invalid {}: {}", location, utils::trim(buf));
break; break;
} }
itype += type_offset;
// clang-format off
if ((atom1 <= 0) || (atom1 > map_tag_max) || if ((atom1 <= 0) || (atom1 > map_tag_max) ||
(atom2 <= 0) || (atom2 > map_tag_max) || (atom2 <= 0) || (atom2 > map_tag_max) ||