Hello everyone,
I have a linear molecule, where I have defined, in the molecule file, the atom types of the linear molecule to be in consecutive order, and I have a NVT simulation containing and only containing multiple copies of this linear molecule, where the endpoints of each copy are held stationary.
I want to implement a harmonic force to restrain the total length of the molecule to a certain length, l. Let 1 be the atom type of one endpoint of the molecule, and n be the atom type of the other endpoint of the molecule.
For atom types 1 through n - 1, this restraining force will have a positive contribution of k times (total length of the molecule the given atom belongs to / l - 1) times (position vector of given atom minus position vector of successor atom / distance between the given atom and its successor), where k is a scaling constant.
For atom types 2 through n, this restraining force will have a negative contribution of k times (total length of the molecule the given atom belongs to / l - 1) times (position vector of given atom minus position vector of predecessor atom / distance between the given atom and its predecessor). k here is the same as in the previous paragraph.
Several problems with implementing this immediately arise:
-
Because I am trying to restrain the total length of a molecule, instead of constraining the length of specific bonds, this means that fix shake goes out the window.
-
For fix addforce, implementing this force is simple if only one copy of the molecule exists in the system: I can use compute bond/local to calculate the magnitude and components of the bond lengths of said molecule, sum up the magnitude of the bond lengths to get the total length of the molecule, and then feed this information into an atom-style vector for fix addforce.
-
However, if multiple copies of the molecule exist in the system, because the restraining force on any atom cannot depend on the total lengths of any molecule the atom does not belong to, this would require me to explicitly define a group for every copy of the molecule that exists in the system - which obviously would not scale well.
-
I’ve taken a look at compute chunk/spread/atom to see if I could use it to distribute the total lengths of each molecule to their respective atoms, and it would not actually work because it would require a reduce/chunk of the bond distances, but reduce/chunk requires a atom style variable as an input and compute bond/local, which can give me the bond distances of every bond in the system, does not return an atom style input. This isn’t the only obstacle I’ve encountered so far with trying to implement this using only LAMMPS script commands.
-
The option that my PI wants me to pursue is to write a custom fix and/or bond source file for LAMMPS. However, there are several facts that I do not know how to deal with: the fact that different atoms of the same molecule can be locally owned by different processes, and reassigning forces back to their respective atoms across the different processes (the fact that this is my first time working with MPICH doesn’t help my situation here)
This leads me to my question: Is it possible to implement the harmonic length restraint, as I have described above, entirely in the LAMMPS script (without sacrificing too much parallel performance)? If not, how should I be structuring my source file for this harmonic length restraint?