Openmm and metadynamics (+Plumed?)
- Luca Donati
- Posts: 15
- Joined: Tue Sep 22, 2015 3:46 am
Openmm and metadynamics (+Plumed?)
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")
?
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")
?
- Peter Eastman
- Posts: 2541
- Joined: Thu Aug 09, 2007 1:25 pm
Re: Openmm and metadynamics (+Plumed?)
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.
Then you can reference the force coming from that group in your integrator:
Peter
Yes, the plugin works with all platforms.Is it possible to use plumed and openmm with a CPU or I have to use CUDA/OpenCL?
Put the PlumedForce in its own force group:Integrator.addComputeSum("A", "f_meta*f_meta")
Code: Select all
plumedForce.setForceGroup(1)
Code: Select all
Integrator.addComputeSum("A", "f1*f1")
- Luca Donati
- Posts: 15
- Joined: Tue Sep 22, 2015 3:46 am
Re: Openmm and metadynamics (+Plumed?)
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"
^
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"
^
- Peter Eastman
- Posts: 2541
- Joined: Thu Aug 09, 2007 1:25 pm
Re: Openmm and metadynamics (+Plumed?)
What did you set OPENMM_DIR to? It should point to the top level of your OpenMM installation. For example, /usr/local/openmm.
- Luca Donati
- Posts: 15
- Joined: Tue Sep 22, 2015 3:46 am
Re: Openmm and metadynamics (+Plumed?)
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?
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?
- Peter Eastman
- Posts: 2541
- Joined: Thu Aug 09, 2007 1:25 pm
Re: Openmm and metadynamics (+Plumed?)
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
- Luca Donati
- Posts: 7
- Joined: Tue May 13, 2014 2:55 am
Re: Openmm and metadynamics (+Plumed?)
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
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
- Peter Eastman
- Posts: 2541
- Joined: Thu Aug 09, 2007 1:25 pm
Re: Openmm and metadynamics (+Plumed?)
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.ImportError: libOpenMMPlumed.so: cannot open shared object file: No such file or directory
- Luca Donati
- Posts: 15
- Joined: Tue Sep 22, 2015 3:46 am
Re: Openmm and metadynamics (+Plumed?)
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.
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.
- Peter Eastman
- Posts: 2541
- Joined: Thu Aug 09, 2007 1:25 pm
Re: Openmm and metadynamics (+Plumed?)
"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)