Set types of an exact fraction of atoms

Hi!

I need to set the type of an exact fraction of atoms, and not just
probabilistically.

This is necessary because it is a restricted simulation, given these
parameters. For an otherwise accurate simulation of bulk, I will have to
consider not just type fluctuations, but also number fluctuations, and hence a
grand-canonical simulation. (I'm saying this becasue I read the other thread
where arguments were presented against an exact type determination:)

https://sourceforge.net/p/lammps/mailman/lammps-users/thread/CABebqjxQZSyHNEGq73bN22nx_mGJwg32Qvt00qoxzGP5iQggJw%40mail.gmail.com/

What would be the best way to acheive this?

I do not want to use the solution presented there, of choosing a seed that
gives me a specific ratio, because that prevents spatial variations in type
assignment, across configurations in the ensemble. Of course, a random
velocity assignment does mean that this isn't too much of an issue, but still.

The only way I can think of doing this is through the usage of python's
shuffle() function, as suggested here:
https://sourceforge.net/p/lammps/mailman/message/32903010/

Would anyone know of a better way?

Thanks!
Vishnu

I've done what I need in the following manner:

    variable FRACTION index 0.5
    variable part equal "round(atoms * v_FRACTION)"
    group fract id > \{part\}     set group fract type 2   <initialise rest of the system for a run>     variable SEED index 1880637847     fix shuffle all atom/swap 1 (atoms) ${SEED} 1000.0 types 1 2
    run 1

I set exatly what I need to type 2, and then use the MC package' swap to
shuffle atom type. I use a high-temperature because then Metropolis implies
that every swap will be accepted.

Vishnu