SSAGESLabs/PySAGES

New Example: OpenMM+Umbrella Sampling

meschw04 opened this issue · 3 comments

Hello!
I am trying to run OpenMM with umbrella sampling on just a very simple system, then move up to classical alanine dipeptide methods (both via umbrella sampling). I am fairly used to using OpenMM, although I am learning hoomd as well. Below is the system I am trying to run with (originally from Laio 2004):

import pysages
from pysages.collective_variables import Component
from pysages.methods import UmbrellaIntegration, ABF
import numpy as np
from openmm import *
from openmm.app import *
from openmm.unit import *

GLOB_TEMP = 0.12028 #Set such that $\beta = 1$
system = System()
system.addParticle(1)
force = CustomExternalForce('-5*e^(-(x/1.75)^2)')
force.addGlobalParameter("e", math.e)
integrator = LangevinIntegrator(GLOB_TEMP,0.0005,0.1)

force.addParticle(0,[])
system.addForce(force)
topology = Topology()
chain = topology.addChain()
residue = topology.addResidue('BAH',chain)
topology.addAtom('C',element.carbon,residue)
simulation = Simulation(topology,system,integrator)

cv1 = CustomExternalForce('x')
cv1.addParticle(0,[])
x = BiasVariable(cv1,-4,4,biasWidth=0.2,periodic=True,gridWidth=100)

cvs = np.array([Component([0], 0)])
method = UmbrellaIntegration(cvs)

centers = list(np.linspace(-4,4,10))
result = method.run(simulation, int(1e5), centers, \
                    50., int(50), int(1e-4))

Right now, if I try running this I get:
TypeError: 'Simulation' object is not callable
I am by no means an expert in OpenMM, but upon reviewing the ABF+OpenMM example, I thought that this should work with calling the Simulation object. Should I not be introducing a BiasVariable via OpenMM for the potential?
Thanks so much,
Marcus Schwarting

Hey Marcus, thanks for trying out OpenMM and with Pysages.

We have to take down the code example from the readme. It is not upto date anymore.
Instead, try to work with the examples. For OpenMM we have an up-to-date example for the ABF method.

The general scheme is changed in a way, that we need to generate the simulation context with a user function.
And this user function is the first argument that method.run() takes.
So just wrap your lines 9-21 in a function and let this function return the simulation object.
And this function is the first argument than.

In the mean time, I will submit a PR that changes the README.

Take a look at #98 we are updating the README to make that more clear.

Thank you for trying pysages Marcus. A more complete and up-to-date set of examples can be found within the examples folder, including one of alanine dipeptide.