How to take type of a particle in a if condition?

Dear community,

I am providing an example pseudo-code below. I want to implement it in a LAMMPS script.

##Total number of particle=N

for(i=1;i<=N;i++)
{
if(type_of_particle_(i) == 1) ##Check if particle id-i is type 1
{
for(j=i;j<=N;j++)
{
r_ij = distance(i,j) ##Calculate distance between i and j

  if(r_ij<r_cut && type_of_particle_(j) == 2)  
  ##Check whether (i,j) are within cutoff and j is type 2
  { 
    type_of_particle_(j) == 1 ##convert j to type 1
  }

}

}
}

I understand it is possible to do this with a with a “LAMMPS → C analysis code → back to LAMMPS” kind of set up. I am curious if this can be achieved within LAMMPS itself.

Thanks in advance.

Not without writing some C++ code. It is similar to fix bond/create only that you don’t create a bond, but change atom type.

Please also note that your pseudo code cannot work, since in LAMMPS atoms are distributed over processors, so a loop over all particles is impossible. And also a double loop over all particles is going to be extremely slow and not a smart thing to do. Instead you would utilize a neighbor list.

Note that compute coord/atom can calculate a per-atom vector staying, for each atom, how many atoms of type j are within a certain cutoff of that atom (documentation: compute coord/atom command — LAMMPS documentation).

You can also define a group from the value of a per-atom variable (which can be set using per-atom values from a compute). Finally, you can change the types of all atoms in a group using the set command.

The details, you will have to check and implement yourself in a LAMMPS script. But it should be doable without any code writing.