Openmm and metadynamics (+Plumed?)

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
User avatar
Luca Donati
Posts: 15
Joined: Tue Sep 22, 2015 3:46 am

Openmm and metadynamics (+Plumed?)

Post by Luca Donati » Thu Feb 02, 2017 3:57 am

Dear all,
I am going to start a project where I need to estimate a free energy profile by metadynamics.
I would like to use Openmm because I need to implement my own integrator, to compute some quantities "on fly", functions of the metadynamics potential Vmeta.

With openmm I know how to implement a custom force, but the metadynamics potential is a bit complicated because it is written as sum of gaussian functions and these gaussian functions are created every "n" timesteps.
To define the first gaussian, I would write something like:

meta = CustomTorsionForce("exp((theta - theta0)^2)")
meta.addPerTorsionParameter("theta0");
meta.addTorsion(4,6,8,14, (theta0)) #phi
meta.setForceGroup(1)
meta.addForce(meta)

where theta0 is the the angle at time 0.
#1) The first question is, how can I compute theta0 at time 0, directly in Openmm?

After that, I should implement inside the integrator a way to update the metadynamcs potential, i.e. to sum all the gaussians. To do this I have two problems:
#2) How to estimate theta0 at time n*delta_t inside the integrator?
#3) How can I create a sum of gaussians with different values of theta0? Basically what I need, is a vector where to store all the "theta0" that I compute during the simulation.

###############################
All these operations look to me complicated to implement in Openmm (but maybe I am wrong), the other solution would be to use plumed (that I already used with gromacs).
I have found the following tutorial:
https://github.com/peastman/openmm-plumed

But I have the following questions:
#4) Is it possible to use plumed and openmm with a CPU or I have to use CUDA/OpenCL?
#5) Assuming I have installed plumed and everything works. If I define my own integrator, is it possible to access to the gradient of the metadynamics potential? For example could I do a calculation like:
Integrator.addComputeSum("A", "f_meta*f_meta")
?

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

Re: Openmm and metadynamics (+Plumed?)

Post by Peter Eastman » Thu Feb 02, 2017 10:47 am

Plumed is definitely the easier way of doing this. You could make something work with custom forces, but Plumed is specifically designed for doing this sort of thing.
Is it possible to use plumed and openmm with a CPU or I have to use CUDA/OpenCL?
Yes, the plugin works with all platforms.
Integrator.addComputeSum("A", "f_meta*f_meta")
Put the PlumedForce in its own force group:

Code: Select all

plumedForce.setForceGroup(1)
Then you can reference the force coming from that group in your integrator:

Code: Select all

Integrator.addComputeSum("A", "f1*f1")
Peter

User avatar
Luca Donati
Posts: 15
Joined: Tue Sep 22, 2015 3:46 am

Re: Openmm and metadynamics (+Plumed?)

Post by Luca Donati » Fri Feb 03, 2017 3:55 am

I am trying to install the plumed plugin, but I am having some problems.
I have installed the following softwares:
- plumed 2.3.0
- miniconda with python 3.5 (64 bit)
- openmm 7.0.1 (trough miniconda).

Then I downloaded the plugin to patch openmm and I followed this tutorial:
https://github.com/peastman/openmm-plumed

But when I tried to do make install I got the error:
/home/ldonati/Downloads/openmm-plumed-master/openmmapi/include/PlumedForce.h:35:28: fatal error: openmm/Context.h: No such file or directory
#include "openmm/Context.h"

Thus, I decided to remove openmm from miniconda and to reinstall it manually.
Now I can run "make install" successfully and the plumed files appear in the openmm directory.

But when I do "make PythonInstall" I have the same problem as before, i.e. the program cannot find openmm:
In file included from PlumedPluginWrapper.cpp:3076:0:
/home/ldonati/Downloads/openmm-plumed-master/openmmapi/include/PlumedForce.h:35:28: fatal error: openmm/Context.h: No such file or directory
#include "openmm/Context.h"
^

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

Re: Openmm and metadynamics (+Plumed?)

Post by Peter Eastman » Fri Feb 03, 2017 11:05 am

What did you set OPENMM_DIR to? It should point to the top level of your OpenMM installation. For example, /usr/local/openmm.

User avatar
Luca Donati
Posts: 15
Joined: Tue Sep 22, 2015 3:46 am

Re: Openmm and metadynamics (+Plumed?)

Post by Luca Donati » Tue Feb 07, 2017 4:17 am

I am not sure if the installation succeed. Actually I am not sure if I have to import the plugin in somehow. I have tried a script like:

from simtk.openmm.app import *
from simtk.openmm import *
from simtk.unit import *

....

script = """
d: DISTANCE ATOMS=1,10
METAD ARG=d SIGMA=0.2 HEIGHT=0.3 PACE=500"""
PlumedForce.setForceGroup(1)
system.addForce(PlumedForce(script))

but I get the error:

NameError: name 'PlumedForce' is not defined

Do I miss something?

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

Re: Openmm and metadynamics (+Plumed?)

Post by Peter Eastman » Tue Feb 07, 2017 12:00 pm

First make sure you installed the Python wrapper with "make PythonInstall". Assuming you've done that, add this import:

Code: Select all

from openmmplumed import PlumedForce

User avatar
Luca Donati
Posts: 7
Joined: Tue May 13, 2014 2:55 am

Re: Openmm and metadynamics (+Plumed?)

Post by Luca Donati » Wed Feb 08, 2017 3:39 am

OPENMM_DIR was set correctly in cmake, but for some reason make Pythoninstall did not work.

Then, I have manually changed the file
openmm-plumed-master/build/python/setup.py (note that build/ is the build directory that I have created)

and I set the correct OPENMM_DIR

After that, inside the directory build/ I ran make Pythoninstall and it worked perfectly (no errors).

Now I tried to execute python and to import openmmplumed, but I get a new error:

>>> from openmmplumed import PlumedForce
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ldonati/miniconda3/lib/python3.5/site-packages/openmmplumed.py", line 28, in <module>
_openmmplumed = swig_import_helper()
File "/home/ldonati/miniconda3/lib/python3.5/site-packages/openmmplumed.py", line 24, in swig_import_helper
_mod = imp.load_module('_openmmplumed', fp, pathname, description)
File "/home/ldonati/miniconda3/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/home/ldonati/miniconda3/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libOpenMMPlumed.so: cannot open shared object file: No such file or directory

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

Re: Openmm and metadynamics (+Plumed?)

Post by Peter Eastman » Wed Feb 08, 2017 4:00 pm

ImportError: libOpenMMPlumed.so: cannot open shared object file: No such file or directory
We need to figure out why it isn't finding that library. First, check to see if it got installed properly. It should be in your (OPENMM_DIR)/lib directory. If it isn't there, possibly something went wrong with the "make install"? If it is there, try adding that directory to your LD_LIBRARY_PATH.

User avatar
Luca Donati
Posts: 15
Joined: Tue Sep 22, 2015 3:46 am

Re: Openmm and metadynamics (+Plumed?)

Post by Luca Donati » Thu Feb 09, 2017 3:25 am

The file libOpenMMPlumed.so is in the correct drectory, so I have updtated LD_LIBRARY_PATH.
After that I had a similar problem with the filr libplumed.so.
So I have added to LD_LIBRARY_PATH also the path to the plumed directory.
export LD_LIBRARY_PATH=:/home/ldonati/openmm/lib:/home/ldonati/plumed/lib

And finally it works, I can import the plumed plugin and I can run a simulation.

There is only one (hopefully) small problem.
If I set the force group with
PlumedForce.setForceGroup(1)

I get the error
TypeError: setForceGroup() missing 1 required positional argument: 'group'

I remark that without that line, it works, but for my project I need to manipulate the potential on the fly, so I really need to set the force group.

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

Re: Openmm and metadynamics (+Plumed?)

Post by Peter Eastman » Fri Feb 10, 2017 10:38 am

"PlumedForce" is the name of the class, so you're trying to call it as a static method. You need to call it on your object:

Code: Select all

force = PlumedForce(script)
force.setForceGroup(1)
system.addForce(force)

POST REPLY