Can "fix" command implement in molecule id style?

Hi lammps users,

Is there any way to implement "fix command " something in “molecule id” style not the “group id” style? Just like the form:

fix ID molecule ID style args

The reason is because I have 50 molecule in the box, and I want them to be vibrational equilibrium (by removing translational and rotational velocities of each molecule). To do this, I can do following operation:

group group_1 molecule 1

group group_2 molecule 2

group group_50 molecule 50

fix 1 group_1 momentum 100 linear 1 1 1 angular

fix 2 group_2 momentum 100 linear 1 1 1 angular

fix 50 group_50 momentum 100 linear 1 1 1 angular

Then, each of molecule’s translational and rotational velocities will be removed. However, there is a limit (32) for group numbers, and I know it is very difficult to extend max group number after search on LAMMPS Mailing Archives.

I am wondering if I can only fix is in molecule ID style by LAMMPS or by minor changes? Or I can do this with other way?Otherwise I should write a total new fix, with will difficult without using “group” class.

Thank you in advance.

Jiang Xiao

Hi lammps users,

Is there any way to implement "fix command " something in “molecule id” style not the “group id” style? Just like the form:

fix ID molecule ID style args

no. the use of a group ID as the second argument to the fix command is rooted deep in how fixes are created and cannot be changed.

The reason is because I have 50 molecule in the box, and I want them to be vibrational equilibrium (by removing translational and rotational velocities of each molecule). To do this, I can do following operation:

group group_1 molecule 1

group group_2 molecule 2

group group_50 molecule 50

fix 1 group_1 momentum 100 linear 1 1 1 angular

fix 2 group_2 momentum 100 linear 1 1 1 angular

fix 50 group_50 momentum 100 linear 1 1 1 angular

using 50(!) fix instances is a very bad idea. for each fix instance you need to do multiple collective communications, which will have a significant negative impact on the parallel performance of LAMMPS.

Then, each of molecule’s translational and rotational velocities will be removed. However, there is a limit (32) for group numbers, and I know it is very difficult to extend max group number after search on LAMMPS Mailing Archives.

I am wondering if I can only fix is in molecule ID style by LAMMPS or by minor changes? Or I can do this with other way?Otherwise I should write a total new fix, with will difficult without using “group” class.

if you want momentum removal for other partitioning than groups, you need to implement a new fix. In that case, however, I would strongly recommend to make this based on the “chunk” methodology in LAMMPS. You would then have something like:

compute molchunk all chunk/atom molecule
fix momz all momentum/chunk molchunk 100 linear 1 1 1 angular

then you would follow the same flow of control as in fix momentum, only that instead of collecting data globally for the entire group, you would collect it per-chunk and then could use the collective communications across the per-chunk arrays and thus saving many of those non-parallelizing global communications.

If the purpose is to retain the molecules in place while allowing them to be thermally excited, have you considered using fix spring/self?

Axel.

1 Like

Dear Axel,

Thanks for your valuable suggestion, your “chunk” is really work well. I’m now sharing this new fix code to whom may also face this problems. They can implement this fix as:

compute ID1 group-ID chunk/atom chunkID

compute ID2 group-ID com/chunk chunkID

compute ID3 group-ID vcm/chunk chunkID

compute ID4 group-ID omega/chunk chunkID

fix ID group-ID momentum/chunk N ID1 ID2 ID3 ID4 keyword

keyword = linear or angular or both

After such implementation, the translational and rotational velocity could be removed for each chunk. The following is one of example:

compute molchunk all chunk/atom molecule

compute comchunk all com/chunk molchunk

compute vcmchunk all vcm/chunk molchunk

compute omegachunk all omega/chunk molchunk

fix restrain all momentum/chunk 100 molchunk comchunk vcmchunk omegachunk linear angular

As for using command “fix spring/self” from your suggest, I’m not sure this command may induce some additional energy, due to its additional force K*r may add more potential energy when we fix or unfix this command.

Best Regards,

Jiang Xiao

fix_my_momrot_chunk.cpp (6.33 KB)

fix_my_momrot_chunk.h (1.99 KB)

Dear Axel,

Thanks for your valuable suggestion, your “chunk” is really work well. I’m now sharing this new fix code to whom may also face this problems. They can implement this fix as:

thanks for sharing the code. I will see, if it can be integrated into the distribution. I would make one modification, though, and set it up so that the com/chunk, vcm/chunk and omega/chunk are created internally by the fix, so the API for the fix command is simpler.

compute ID1 group-ID chunk/atom chunkID

compute ID2 group-ID com/chunk chunkID

compute ID3 group-ID vcm/chunk chunkID

compute ID4 group-ID omega/chunk chunkID

fix ID group-ID momentum/chunk N ID1 ID2 ID3 ID4 keyword

keyword = linear or angular or both

[…]

As for using command “fix spring/self” from your suggest, I’m not sure this command may induce some additional energy, due to its additional force K*r may add more potential energy when we fix or unfix this command.

please note, however, that you are systematically removing kinetic energy of the system doing it this way. that is why the “rescale” keyword was added to fix momentum, so that after removing momentum the velocities are rescaled to make certain that energy is conserved.

using fix sprint/self will not “add” any potential energy, when the system is at rest when the fix is issued. there are advantages and drawbacks for either approach. ultimately, the question of which one is the better choice depends on the specifics of the simulation and why the manipulation of the system is required in the first place.

axel.

Dear Axel,

Many thanks for your patience and valuable answer .

Best Regards,

Jiang Xiao

FYI your code has been generalized to have the same interface and options as fix momentum. It only needs the ID of compute chunk in addition and submitted for inclusion into the LAMMPS distribution: https://github.com/lammps/lammps/pull/2295

Axel.

Dear Axel.

Thanks for your improvement, your code is much more concise and robust!

Best Regards,

Jiang Xiao