How to change the type of atoms?

dear lammpser
Hello, I have a model where the atomic types are already defined. However, I want to change the atomic types within a specific region. In this region, there are two types, and I hope to exchange type 1 and type 2. How should I write the program? I’ve looked through the manual but don’t have a clear idea.

region myregion cylinder z 6 9 1 0 6.7

Thank you very much
Li

You have to define two groups, each containing the atom type that you want to manipulate. Then, change the atom type. Here the list of commands for the swapping of atom types 1 and 2 in myregion:

group gr region myregion # all the atoms inside myregion.
group g1 type 1 # all atoms of type 1.
group g2 type 2
group a1 intersect gr g1 # atom type 1 in myregion.
group a2 intersect gr g2
set group a1 type 2 # assign a new atom type to the atoms in this group.
set group a2 type 1
1 Like

Note that, because set supports region selection and per-atom variables, you can do something much more hacky:

variable newtype atom 3-type
set region myregion type v_newtype

This only works if you are interchanging types 1 and 2 and can guarantee that there are no other atom types in that region (you can write a more complicated atom variable for more complicated permutations).

1 Like

That’s so cool!