Implementation of temporary restraints

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
Greg Smith
Posts: 6
Joined: Sat Aug 17, 2024 2:33 pm

Implementation of temporary restraints

Post by Greg Smith » Mon Sep 02, 2024 10:13 am

Greetings, I'm an open-mm rookie and I have another question.

The system I'm attempting to run is a liquid crystal simulation. The beginning of the simulation requires position restraints on the molecules and restraints on the molecular orientation while the simulation comes to equilibrium.

From the documentation, it looks like I can use CustomExternalForce to implement these restraints. However, I'm not certain how I would turn these forces off again once I reach the equilibrium point for beginning the production simulation. How do I turn on and off these sorts of forces depending on the phase of the simulation? Should I literally do it as two separate simulations where I reload the force field without the restraint force on the final geometry (and velocities) of the previous simulation? Forgive my naivety.

Thanks!
Greg Smith

User avatar
Peter Eastman
Posts: 2593
Joined: Thu Aug 09, 2007 1:25 pm

Re: Implementation of temporary restraints

Post by Peter Eastman » Mon Sep 02, 2024 6:43 pm

There are a couple of ways you could do it. One is to make the restraint force proportional to a global parameter. To turn off the restraint, set the parameter to 0. It will still compute the force every step and therefore this has a bit of overhead, but it's usually negligible.

Another option is to remove the force by calling removeForce() on the System, then reinitialize the Context by calling reinitialize(True) on it. This avoids calculating the force at all once you start the production simulation. It only works if the restraint force does not define any global parameters. If it does, reinitialize(True) will throw an exception. You could instead call reinitialize(False), but then it's up to you to copy over all state information.

User avatar
Greg Smith
Posts: 6
Joined: Sat Aug 17, 2024 2:33 pm

Re: Implementation of temporary restraints

Post by Greg Smith » Tue Sep 03, 2024 10:38 am

Forgive me, I'm trying to make certain I understand the usage of a global parameter. Coming from Gromacs, I'm not intuitively familiar with how these are accessible. I know this is going to be a stupid question and I apologize.

If I create a global parameter in the definition of an external force, does this mean that the parameter can then be set from the python script I'm using to run open-mm? Say, I just call the parameter in the python script and assign it a new value: variable = 0. This is as opposed to "exporting" values like I would if I were setting a global variable in a bash script.

User avatar
Peter Eastman
Posts: 2593
Joined: Thu Aug 09, 2007 1:25 pm

Re: Implementation of temporary restraints

Post by Peter Eastman » Tue Sep 03, 2024 12:17 pm

Correct. Global parameters are stored in the Context, allowing them to be changed at any time. To set the value of a parameter "foo", call

Code: Select all

simulation.context.setParameter("foo", value)

POST REPLY