Skip to content

Commit

Permalink
use a local context cache instead of a global one (#849)
Browse files Browse the repository at this point in the history
* use a local context cache instead of a global one

* fix import and location of context_cache argument
  • Loading branch information
mikemhenry authored Aug 27, 2021
1 parent ba3e04e commit 82dd766
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
16 changes: 9 additions & 7 deletions perses/app/relative_point_mutation_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class PointMutationExecutor(object):
n_restart_attempts=20,
splitting="V R R R O R R R V",
constraint_tolerance=1e-06),
hybrid_factory=htf, online_analysis_interval=10)
hybrid_factory=htf,
online_analysis_interval=10,
context_cache=cache.ContextCache(capacity=None, time_to_live=None))
hss.setup(n_states=n_states, temperature=300*unit.kelvin, storage_file=reporter, lambda_protocol=lambda_protocol, endstates=False)
hss.extend(n_cycles)
Expand Down Expand Up @@ -385,7 +387,7 @@ def _get_ion_and_water_parameters(self, system, topology, positive_ion_name="NA"
'''
Get the charge, sigma, and epsilon for the positive and negative ions. Also get the charge of the water atoms. Set
these parameters as class variables.
Parameters
----------
system : simtk.openmm.System
Expand All @@ -398,9 +400,9 @@ def _get_ion_and_water_parameters(self, system, topology, positive_ion_name="NA"
the residue name of each negative ion
water_name : str, "HOH"
the residue name of each water
'''

# Get the indices
pos_index = None
neg_index = None
Expand All @@ -419,8 +421,8 @@ def _get_ion_and_water_parameters(self, system, topology, positive_ion_name="NA"
assert pos_index is not None, f"Error occurred when trying to turn a water into an ion: No positive ions with residue name {positive_ion_name} found"
assert neg_index is not None, f"Error occurred when trying to turn a water into an ion: No negative ions with residue name {negative_ion_name} found"
assert O_index is not None, f"Error occurred when trying to turn a water into an ion: No O atoms with residue name {water_name} and atom name O found"
assert H_index is not None, f"Error occurred when trying to turn a water into an ion: No water atoms with residue name {water_name} and atom name H1 found"
assert H_index is not None, f"Error occurred when trying to turn a water into an ion: No water atoms with residue name {water_name} and atom name H1 found"

# Get parameters from nonbonded force
force_dict = {i.__class__.__name__: i for i in system.getForces()}
if 'NonbondedForce' in [i for i in force_dict.keys()]:
Expand All @@ -429,7 +431,7 @@ def _get_ion_and_water_parameters(self, system, topology, positive_ion_name="NA"
neg_charge, neg_sigma, neg_epsilon = nbf.getParticleParameters(neg_index)
O_charge, _, _ = nbf.getParticleParameters(O_index)
H_charge, _, _ = nbf.getParticleParameters(H_index)

self._pos_charge = pos_charge
self._pos_sigma = pos_sigma
self._pos_epsilon = pos_epsilon
Expand Down
10 changes: 6 additions & 4 deletions perses/app/setup_relative_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from perses.app.relative_setup import RelativeFEPSetup
from perses.annihilation.lambda_protocol import LambdaProtocol

from openmmtools import mcmc
from openmmtools import mcmc, cache
from openmmtools.multistate import MultiStateReporter
from perses.utils.smallmolecules import render_atom_mapping
from perses.tests.utils import validate_endstate_energies
Expand Down Expand Up @@ -640,7 +640,8 @@ def run_setup(setup_options, serialize_systems=True, build_samplers=True):
collision_rate=1.0 / unit.picosecond,
n_steps=n_steps_per_move_application,
reassign_velocities=False,
n_restart_attempts=20,constraint_tolerance=1e-06),
n_restart_attempts=20,constraint_tolerance=1e-06,
context_cache=cache.ContextCache(capacity=None, time_to_live=None)),
hybrid_factory=htf[phase], online_analysis_interval=setup_options['offline-freq'],
online_analysis_minimum_iterations=10,flatness_criteria=setup_options['flatness-criteria'],
gamma0=setup_options['gamma0'])
Expand All @@ -650,8 +651,9 @@ def run_setup(setup_options, serialize_systems=True, build_samplers=True):
collision_rate=1.0 / unit.picosecond,
n_steps=n_steps_per_move_application,
reassign_velocities=False,
n_restart_attempts=20,constraint_tolerance=1e-06),
hybrid_factory=htf[phase],online_analysis_interval=setup_options['offline-freq'])
n_restart_attempts=20,constraint_tolerance=1e-06,
context_cache=cache.ContextCache(capacity=None, time_to_live=None)),
hybrid_factory=htf[phase],online_analysis_interval=setup_options['offline-freq'],)
hss[phase].setup(n_states=n_states, temperature=temperature,storage_file=reporter,lambda_protocol=lambda_protocol,endstates=endstates)
else:
_logger.info(f"omitting sampler construction")
Expand Down
4 changes: 3 additions & 1 deletion perses/dispersed/feptasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import copy

import openmmtools.mcmc as mcmc
from openmmtools import cache
import openmmtools.integrators as integrators
import openmmtools.states as states
import numpy as np
Expand Down Expand Up @@ -884,7 +885,8 @@ def run_equilibrium(task):
n_atoms = subset_topology.n_atoms

#construct the MCMove:
mc_move = mcmc.LangevinSplittingDynamicsMove(n_steps=inputs['nsteps_equil'], splitting=inputs['splitting'], timestep = inputs['timestep'])
mc_move = mcmc.LangevinSplittingDynamicsMove(n_steps=inputs['nsteps_equil'],
splitting=inputs['splitting'], timestep = inputs['timestep'], context_cache=cache.ContextCache(capacity=None, time_to_live=None))
mc_move.n_restart_attempts = 10

#create a numpy array for the trajectory
Expand Down
4 changes: 3 additions & 1 deletion perses/dispersed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import copy

from openmmtools import cache
import openmmtools.mcmc as mcmc
import openmmtools.integrators as integrators
import openmmtools.states as states
Expand Down Expand Up @@ -307,7 +308,8 @@ def run_equilibrium(task):
n_atoms = subset_topology.n_atoms

#construct the MCMove:
mc_move = mcmc.LangevinSplittingDynamicsMove(n_steps=inputs['nsteps_equil'], splitting=inputs['splitting'], timestep = inputs['timestep'])
mc_move = mcmc.LangevinSplittingDynamicsMove(n_steps=inputs['nsteps_equil'],
splitting=inputs['splitting'], timestep = inputs['timestep'], context_cache = cache.ContextCache(capacity=None, time_to_live=None))
mc_move.n_restart_attempts = 10

#create a numpy array for the trajectory
Expand Down

0 comments on commit 82dd766

Please sign in to comment.