Commit 9c4766f0 authored by ljmartin's avatar ljmartin
Browse files

Get and scale velocities during simulated tempering using numpy, for speed

parent 5aa19c2d
...@@ -48,6 +48,11 @@ try: ...@@ -48,6 +48,11 @@ try:
have_gzip = True have_gzip = True
except: have_gzip = False except: have_gzip = False
try:
import numpy
have_numpy = True
except: have_numpy = False
class SimulatedTempering(object): class SimulatedTempering(object):
"""SimulatedTempering implements the simulated tempering algorithm for accelerated sampling. """SimulatedTempering implements the simulated tempering algorithm for accelerated sampling.
...@@ -214,6 +219,9 @@ class SimulatedTempering(object): ...@@ -214,6 +219,9 @@ class SimulatedTempering(object):
# Rescale the velocities. # Rescale the velocities.
scale = math.sqrt(self.temperatures[j]/self.temperatures[self.currentTemperature]) scale = math.sqrt(self.temperatures[j]/self.temperatures[self.currentTemperature])
if have_numpy:
velocities = scale*state.getVelocities(asNumpy=True).value_in_unit(unit.nanometers/unit.picoseconds)
else:
velocities = [v*scale for v in state.getVelocities().value_in_unit(unit.nanometers/unit.picoseconds)] velocities = [v*scale for v in state.getVelocities().value_in_unit(unit.nanometers/unit.picoseconds)]
self.simulation.context.setVelocities(velocities) self.simulation.context.setVelocities(velocities)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment