Set types of an exact fraction of atoms


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

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:)

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:

Would anyone know of a better way?


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.