removing force from system

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
Daniel Konstantinovsky
Posts: 77
Joined: Tue Jun 11, 2019 12:21 pm

removing force from system

Post by Daniel Konstantinovsky » Fri Jan 28, 2022 1:03 pm

Hi OpenMM,
Is there a way to remove a custom force from a system once it's added or do I have to create a new system and simulation object? Alternatively, is there a way to modify the parameters of a force, for example between two bonds BondForce, after it's added to the system? I have an application where I need to turn on and off restraints over and over again and run short simulations each time.
Thanks!
Dan

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

Re: removing force from system

Post by Peter Eastman » Fri Jan 28, 2022 1:22 pm

You can do both. To remove the force, call removeForce() on the System. Note that this won't affect any existing Contexts unless you call reinitialize() on them. Until you do that, they'll continue to apply the force.

All force classes have methods to modify their parameters. For example, you can call setBondParameters() on a HarmonicBondForce to change the parameters of a single bond. This too will not affect existing Contexts unless you reinitialize them, or alternatively call updateParametersInContext() on the Force. The latter is much less expensive.

POST REPLY