How to Change Certain Types of Atoms Within a Group in LAMMPS

Hello Dear Developers.

I am a new user of LAMMPS and I have a question for dynamic simulations.
I grouped the alloy system. There are two types of atoms in total within these groups.
What I want to do is change the type of atoms within a certain group and of certain types.

For example:
if (group=group_1) and (type=1) then

Can I change or how do I change the types of atoms in a particular group with just an ‘if statement’ in LAMMPS?

LAMMPS Version: LAMMPS (27 May 2021)

I am appreciated for any kind of help/suggestion you could give me.

Mehmet Yılmaz

The “if” statement in LAMMPS can only be used for flow of control, not the way you are implying. This is clear from the documentation. Basically, you are making the mistake that you are trying to describe what you want in a way how you would explain it to another human and not in a way using the syntax and logic defined by the LAMMPS script language, which is all that LAMMPS understands (since it is a computer program, not a human).

However, what you are asking for can be done. You just have to look at how to do it by reversing the steps needed to figure out how it can be done.

  1. To change the type you need to use the “set” command and there you can either change individual or ranges of atoms by their atom ID, atoms that have the same type, are in the same group, have the same molecule ID, or are in the same region. So the logical step here would be that you need to define a new group that contains only the atoms of interest.
  2. To define a group that has atoms where multiple conditions apply, you have two possible approaches:
    a) if you have few conditions, then you just define a group for each condition and then define a group that is the intersection of all such “condition groups”
    b) for more complex selections, you can define a group based on a atom style variable where you can have multiple conditions. If you multiply those conditions, the resulting variable will have the value 1 only of all conditions are fulfilled and thus only those atoms will be included in the group. And then a group that is the intersection of group_1 and the type_1 group. With that group you can use the set command to change the type. It is good practice to then delete the two added groups after that, so you won’t run out of groups which are limited.

In your specific case, you would define a group that contains all type 1 atoms and then a group that is the intersection of the type_1 group and group_1. You can use the “set” command on that group.

1 Like

Thank you so much!

Mehmet Yılmaz