Can we have a new fix spring?

Dear Lammps Developers,

I wonder If it is possible for a new “fix spring” for a group of atoms, in which the atoms in the group is tethered to the group’s COM (instantly changed with time). The force is applied on each atom when its initial relative distance to the group’s COM changed.

This may be called “fix spring/com” is as analog to “fix spring/self”, but instead of tethering the atom to its initial position, this fix tether atom to its “initial relative distance to the group’s COM” and perform independently on x-, y-, z-direction.

That is really up to you. 3. Modifying & extending LAMMPS — LAMMPS documentation

Dear Prof. @akohlmey,

Thank you for your reply.
I wish I can do that :slight_smile:

Most of LAMMPS has come into existence this way, that is someone had a need and programmed it and then contributed the result. It is rather straightforward in this case, since you can use an existing style as template.

The alternative would be to submit a feature request issue on GitHub and hope that somebody else considers this interesting or useful enough to spend the time. Of course you can also actively look for a collaborator that is willing to do the required programming on your behalf.

How about:

compute clump_com clump com

variable dx_clump atom x-c_clump_com[1]
variable dy_clump atom y-c_clump_com[2]
variable dz_clump atom z-c_clump_com[3]

variable fx_clump atom -1.2*v_dx_clump
variable fy_clump atom -1.2*v_dy_clump
variable fz_clump atom -1.2*v_dz_clump

fix spring_clump_com clump addforce fx_clump fy_clump fz_clump

I’m calling your group of interest “clump” because presumably this additional force would clump up the group. Please be very sure that you understand what every line is doing (I’m sure I’ve made at least one small mistake while typing out the code – this will motivate you to check the documentation if it doesn’t work), and be sure you know what your system is supposed to do from a physical standpoint so that you can double check the code is doing what you want it to do.


Dear Prof. Axel and @srtee,

Thank you so much for your kindly instructions.
I learn so much from your instructions.

I temporarily deal with such a problem using Lammps + fix Plumed. But still, hope to see someone have a better solution in the future patch of Lammps.

Thank you so much