openmm / openmm-plumed

OpenMM plugin to interface with PLUMED
55 stars 23 forks source link

adding ENERGY colvar #53

Open invemichele opened 2 years ago

invemichele commented 2 years ago

Hi, is it possible to have the ENERGY collective variable implemented, so that it can be biased with plumed? I would love to be able to run multithermal simulations with OPES and OpenMM, but for that I need to bias the potential energy.

From what I understand it might not be easy to do, because you need to calculate the total energy without the contribution of the PlumedForce. But I am quite new to OpenMM...

peastman commented 2 years ago

The Plumed plugin can only apply biases based on CVs computed with Plumed. There might be another way of doing what you want though. I'm not familiar with that algorithm. Can you describe how it works?

invemichele commented 2 years ago

It is a way of sampling an expanded ensemble made of a set of "overlapping" sub-ensembles, in a sense like replica exchange but based on an adaptive bias potential. The bias potential is a function of the difference in the Hamiltonians of the sub-ensembles (e.g. for multithermal ensembles the potential energy is needed) and depends on estimates of the free energy differences between the sub-ensembles. These estimates are based on a reweighting procedure and are updated on-the-fly during the simulation. (details in § IV here)

Since it is not possible to access the potential energy from PLUMED, I guess the only way to run my multithermal simulations with OPES would be to implement it directly in OpenMM. I might start by looking into the openmmtools.multistate.SAMSSampler class, which seems to me the closest one to what I want to do.

raimis commented 2 years ago

Currently the ENERGY CV isn't supported. OpenMM computes the forces (and energies) concurrently, so the potential energy is not available for the individual force objects.

@peastman is it possible to get the potential energy in CudaCalcPlumedForceKernel::beginComputation? https://github.com/openmm/openmm-plumed/blob/5406068b5a36b1208f1340180cfc5b8e4ee7aff9/platforms/cuda/src/CudaPlumedKernels.cpp#L210-L218

peastman commented 2 years ago

It's not available yet then. beginComputation() is called by a ForcePreComputation which is executed right at the start of a force/energy computation, before anything else has been done. That's so we can get Plumed started right away and have it running in parallel while all the other forces are computed.

GiovanniBussi commented 1 year ago

I noticed this issue linked from the plumed mailing list.

Gromacs has a similar issue. We solved it as follows:

In this way, with gromacs you pay for the slow down only when you use the energy as a collective variable.

I am not sure this would be easy / feasible with openmm structure. In case I can help in sorting out the correct function call