Dynamically assign particles of a certain type to a group

Dear LAMMPS users,

I’m running a simulation in which, due to fix bond/create (fix bond/create command — LAMMPS documentation), the type of some atoms changes from 1 to 2 during the simulation. I would like all atoms of type 1 to be in a certain group and all atoms of type 2 to be in another at all times, which as far as I understand requires using dynamic groups (group command — LAMMPS documentation).

From the manual page of the group command, I found that it is possible to dynamically define groups based on variables using the “var” keyword:

If the var keyword is used, the variable name must be an atom-style or atomfile-style variable. The variable is evaluated and atoms whose per-atom values are 0.0, are removed from the dynamic group.

I have thus created a variable containing the type of each atom:

variable atom_type atom type

From here, however, it is not entirely clear to me how to use this variable to define a dynamic group. I have tried with

group mono dynamic all var atom_type every 1
group poly dynamic all var atom_type every 1

which does not result in an error, but clearly does not do what I want to achieve. In particular, I am confused by the sentence “The variable is evaluated and atoms whose per-atom values are 0.0, are removed from the dynamic group”. Does this mean that I have to write a formula using my variable atom_type so that the result is 0 if the atom does not have the correct type for the group? Also, does this only allow to remove atoms from a group or also to add them?

Any help is appreciated, and sorry in advance if I’m missing something obvious!

Best regards,

The variable must result in a 1/0 value depending on whether the atom should be included or excluded in the group. That means you need to have a logical expression representing that. For example:

variable atom_type atom type==1

to select atoms that are of type 1.

Dear Axel,

Thank you very much, this works.

Do you think it might be helpful to add this as an example to the manual page for the group command? I thought that this could be useful, as changing particle type is something that can happen when using fix bond/create.

If you think this is useful, I could draft the text (never proposed additions to the manual so I’m not sure if there is an official way to do so).

All the best,

All changes to the LAMMPS distribution are made through pull requests on GitHub. 8.6.2. LAMMPS GitHub tutorial — LAMMPS documentation