randomly choose atoms to form a group

Dear LAMMPS users,

Is there any good method in LAMMPS to randomly choose many atoms in the entire supercell to form a group? I want to do it many times in one simulation, so it would be great if there is a simple method.

Thanks in advance.

Zhao

Dear LAMMPS users,

Is there any good method in LAMMPS to randomly choose many atoms in the
entire supercell to form a group? I want to do it many times in one
simulation, so it would be great if there is a simple method.

define an atom style variable that takes a random number and rounds it
to either 0 or 1
use then this variable to define a group (containing all atoms that
have a non-zero value of the variable).

axel.

Thanks, Axel, very much for your advice.

If use this method, is it possible for the atom style variable has constant number of 0 or 1 each time and I can set how many 0 it contains? That is, each time the atom number in the group containing the atoms chosen randomly is constant.

It seems I can use atomfile style variable. But if my supercell is very big and I need to randomly choose atoms many times, I will need to write a big file to store values? Thus I want to if there is better method?

Thanks,
Zhao

Thanks, Axel, very much for your advice.

If use this method, is it possible for the atom style variable has constant
number of 0 or 1 each time and I can set how many 0 it contains? That is,
each time the atom number in the group containing the atoms chosen randomly
is constant.

if you use code like below, you can set the fraction of atoms being selected:

variable fract atom random(0,1,9876)<=0.2
group part variable fract
print "fraction of atoms $(count(part)/atoms)"

you may construct other ways to randomly flag atoms. it is
conceptually rather complicated to pick the exact same number of
randomly selected atoms in parallel and efficiently.
the scheme from above is efficient, but cannot guarantee and exact
number of selected atoms.

It seems I can use atomfile style variable. But if my supercell is very big
and I need to randomly choose atoms many times, I will need to write a big
file to store values? Thus I want to if there is better method?

i already suggested something. if you want something else, you have to
look at alternatives. as mentioned above you have to consider what you
want more: exact number of randomly selected particles or efficient
parallel execution. i don't see a simple way to do both.

axel.

... and to point out the obvious. the larger the number of particles
in total, the smaller the relative error, when you don't get the exact
number of atoms.

axel.

Thanks, Axel, very much for your good suggestion. I will try.
Zhao