Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] SAMS samplers and documentation #214

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Rework MCMCSampler usage to match openmmtools.mcmc
jchodera committed Jun 5, 2017
commit e366db535438f93aa0d5004c9016e1a076618ab2
1 change: 0 additions & 1 deletion openmmtools/mcmc.py
Original file line number Diff line number Diff line change
@@ -291,7 +291,6 @@ def minimize(self, tolerance=1.0*unit.kilocalories_per_mole/unit.angstroms,

timer.report_timing()


# =============================================================================
# MCMC MOVE CONTAINERS
# =============================================================================
59 changes: 22 additions & 37 deletions openmmtools/samplers/sams/testsystems.py
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
from openmmtools import testsystems
from openmmtools.states import ThermodynamicState, SamplerState
from openmmtools.mcmc import MCMCSampler, GHMCMove, LangevinDynamicsMove
from openmmtools.samplers.sams import ExpandedEnsembleSampler, SAMSSampler
from openmmtools.samplers.sams import ExpandedEnsemble, SAMS

################################################################################
# CONSTANTS
@@ -97,10 +97,10 @@ class SAMSTestSystem(object):
Themodynamic states for each environment
mcmc_samplers : dict of MCMCSampler objects
MCMCSampler objects for environments
exen_samplers : dict of ExpandedEnsembleSampler objects
ExpandedEnsembleSampler objects for environments
sams_samplers : dict of SAMSSampler objects
SAMSSampler objects for environments
exen_samplers : dict of ExpandedEnsemble objects
ExpandedEnsemble objects for environments
sams_samplers : dict of SAMS objects
SAMS objects for environments

"""
def __init__(self, netcdf_filename=None):
@@ -141,6 +141,7 @@ def __init__(self, **kwargs):
mass = 39.948 * unit.amu # 3D harmonic oscillator particle mass
period = 2.0 * np.pi * unit.sqrt(mass / K) # harmonic oscillator period
timestep = 0.01 * period
collision_rate = 1.0 / (100 * timestep)
testsystem = HarmonicOscillator(K=K, mass=mass)
self.topology = testsystem.topology
self.positions = testsystem.positions
@@ -164,16 +165,11 @@ def __init__(self, **kwargs):
thermodynamic_state_index = 0 # initial thermodynamic state index
thermodynamic_state = self.thermodynamic_states[thermodynamic_state_index]
sampler_state = SamplerState(positions=self.positions)
self.mcmc_sampler = MCMCSampler(sampler_state=sampler_state, thermodynamic_state=thermodynamic_state, ncfile=self.ncfile)
self.mcmc_sampler.pdbfile = open('output.pdb', 'w')
self.mcmc_sampler.topology = self.topology
self.mcmc_sampler.timestep = timestep
self.mcmc_sampler.collision_rate = 1.0 / (100 * timestep)
self.mcmc_sampler.nsteps = 1000
self.mcmc_sampler.verbose = True
self.exen_sampler = ExpandedEnsembleSampler(self.mcmc_sampler, self.thermodynamic_states)
mcmc_move = LangevinDynamicsMove(timestep=timestep, collision_rate=collision_rate, n_steps=1000)
self.mcmc_sampler = MCMCSampler(thermodynamic_state, sampler_state, move=mcmc_move)
self.exen_sampler = ExpandedEnsemble(self.mcmc_sampler, self.thermodynamic_states)
self.exen_sampler.verbose = True
self.sams_sampler = SAMSSampler(self.exen_sampler, update_stages='two-stage', update_method='optimal')
self.sams_sampler = SAMS(self.exen_sampler, update_stages='two-stage', update_method='optimal')
self.sams_sampler.verbose = True


@@ -221,14 +217,11 @@ def __init__(self, **kwargs):
thermodynamic_state_index = 0 # initial thermodynamic state index
thermodynamic_state = self.thermodynamic_states[thermodynamic_state_index]
sampler_state = SamplerState(positions=self.positions)
self.mcmc_sampler = MCMCSampler(sampler_state=sampler_state, thermodynamic_state=thermodynamic_state, ncfile=self.ncfile)
self.mcmc_sampler.pdbfile = open('output.pdb', 'w')
self.mcmc_sampler.topology = self.topology
self.mcmc_sampler.nsteps = 500 # reduce number of steps for testing
self.mcmc_sampler.verbose = True
self.exen_sampler = ExpandedEnsembleSampler(self.mcmc_sampler, self.thermodynamic_states)
mcmc_move = LangevinDynamicsMove(n_steps=500)
self.mcmc_sampler = MCMCSampler(thermodynamic_state, sampler_state, mcmc_move)
self.exen_sampler = ExpandedEnsemble(self.mcmc_sampler, self.thermodynamic_states)
self.exen_sampler.verbose = True
self.sams_sampler = SAMSSampler(self.exen_sampler)
self.sams_sampler = SAMS(self.exen_sampler)
self.sams_sampler.verbose = True

class AlanineDipeptideExplicitSimulatedTempering(SAMSTestSystem):
@@ -287,15 +280,11 @@ def __init__(self, **kwargs):
thermodynamic_state_index = 0 # initial thermodynamic state index
thermodynamic_state = self.thermodynamic_states[thermodynamic_state_index]
sampler_state = SamplerState(positions=self.positions)
self.mcmc_sampler = MCMCSampler(sampler_state=sampler_state, thermodynamic_state=thermodynamic_state, ncfile=self.ncfile)
#self.mcmc_sampler.pdbfile = open('output.pdb', 'w')
self.mcmc_sampler.topology = self.topology
self.mcmc_sampler.nsteps = 500
self.mcmc_sampler.timestep = 2.0 * unit.femtoseconds
self.mcmc_sampler.verbose = True
self.exen_sampler = ExpandedEnsembleSampler(self.mcmc_sampler, self.thermodynamic_states)
mcmc_move = LangevinDynamicsMove(timestep=2.0*unit.femtoseconds, n_steps=500)
self.mcmc_sampler = MCMCSampler(thermodynamic_state, sampler_state=sampler_state)
self.exen_sampler = ExpandedEnsemble(self.mcmc_sampler, self.thermodynamic_states)
self.exen_sampler.verbose = True
self.sams_sampler = SAMSSampler(self.exen_sampler)
self.sams_sampler = SAMS(self.exen_sampler)
self.sams_sampler.verbose = True

class AlchemicalSAMSTestSystem(SAMSTestSystem):
@@ -386,15 +375,11 @@ def __init__(self, alchemical_protocol='two-phase', nlambda=50, **kwargs):
thermodynamic_state_index = 0 # initial thermodynamic state index
thermodynamic_state = self.thermodynamic_states[thermodynamic_state_index]
sampler_state = SamplerState(positions=self.positions)
self.mcmc_sampler = MCMCSampler(sampler_state=sampler_state, thermodynamic_state=thermodynamic_state, ncfile=self.ncfile)
self.mcmc_sampler.timestep = 2.0 * unit.femtoseconds
self.mcmc_sampler.nsteps = 500
#self.mcmc_sampler.pdbfile = open('output.pdb', 'w')
self.mcmc_sampler.topology = self.topology
self.mcmc_sampler.verbose = True
self.exen_sampler = ExpandedEnsembleSampler(self.mcmc_sampler, self.thermodynamic_states)
mcmc_move = LangevinDynamicsMove(timestep=2.0*unit.femtoseconds, n_steps=500)
self.mcmc_sampler = MCMCSampler(thermodynamic_state, sampler_state=sampler_state)
self.exen_sampler = ExpandedEnsemble(self.mcmc_sampler, self.thermodynamic_states)
self.exen_sampler.verbose = True
self.sams_sampler = SAMSSampler(self.exen_sampler)
self.sams_sampler = SAMS(self.exen_sampler)
self.sams_sampler.verbose = True

# DEBUG: Write PDB of initial frame