Is it possible to specify each atom with a different group id via loop

Hi LAMMPS developers,

I have started to use lammps recently and the LAMMPS documentation is really helpful for me to learn myself as a beginner. I am struggling to solve a simple problem of using group-id properly. I am trying to update the forces on each of the atoms in my system by using ‘fix addforce’ command. I need to update different forces on each atom, where the forces are variables run by ‘loop’ across all the 76 atoms in my system.

variable nFx file Fx.txt #Forces

variable nFy file Fy.txt

variable nFz file Fz.txt

variable nid loop 76

group sub id ${nid}

fix 2 sub setforce 0.0 0.0 0.0

fix 3 sub addforce ${nFx} ${nFy} ${nFz} every 1

next nFx nFy nFz

next nid

When I use the above commands, the forces on all of the atoms are being replaced by the forces of the last (76th) atom. I think this is due to the ‘group-id’ which is being 76 in the last iteration. Is it possible to update the corresponding forces on each atom properly by means of atom-id or group-id ?

Thanks a lot for reading about my problem. I hope I made my explanation clear and would get some help from you. Thanks again!

There are multiple problems with your input.

  • there is no loop and no loop indexing
  • the group command adds atoms to existing groups. To replace them, you need to delete the group and recreate it
  • you cannot switch group definitions for existing commands and retain existing assignments
  • using this many fix commands is highly inefficient since the all loop over all atoms and will do that sequentially.

This all said, there is a much simpler approach. Create atomfile style variables for your per-atom forces and then a single fix addforce instance will do.

Hi Axel Kohlmeyer!

Thank you so much for your reply. I could solve my problem by following your suggestion of defining my per-atom forces by variables of atomfile style. I could update all the forces at once by just using ‘fix addforce’ command just once. Thanks again!