Skip to content

Instantly share code, notes, and snippets.

View maxentile's full-sized avatar

Josh Fass maxentile

  • Relay Therapeutics
  • Cambridge, MA
View GitHub Profile
@maxentile
maxentile / shuffle_split_gmrq_example.py
Created August 4, 2016 14:30
Toy example of using shuffle-split cross-validated GMRQ
from sklearn.cross_validation import ShuffleSplit
from msmbuilder.msm import MarkovStateModel
import numpy as np
# just generating random dtrajs: replace these lines with actual data
n_states = 500
traj_length = 10000
n_trajs = 100
dtrajs = [np.random.randint(0, n_states, traj_length) for _ in range(n_trajs)]
n_threads = 32
from simtk.openmm import app
import simtk.openmm as mm
import openmmtools
from simtk.unit import *
from openmmtools.integrators import kB
import mdtraj as md
from msmbuilder.example_datasets import AlanineDipeptide
import os
@maxentile
maxentile / trajectory_index_test_case.py
Created October 18, 2016 16:40
quick check that `hmm.sample_by_observation_probabilities` isn't the culprit
import numpy as np
import numpy.random as npr
import pyemma
# generate random trajectories, where each trajectory has a random length between 100 and 1000.
# since the trajectories have different lengths, we will by likely to see an error if `hmm` somehow
# scrambles the trajectory indices.
dtrajs_A = [npr.randint(0,100,x) for x in npr.randint(100,1000,8)]
dtrajs_B = [npr.randint(100,200,x) for x in npr.randint(100,1000,9)]
dtrajs_C = [npr.randint(200,300,x) for x in npr.randint(100,1000,10)]
@maxentile
maxentile / barebones_langevin_splitting_test.py
Last active January 5, 2017 16:31
Barebones LangevinSplittingIntegrator test
import numpy
import simtk.unit
import simtk.openmm as mm
print('OpenMM version: ', mm.version.full_version)
from openmmtools.constants import kB
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from simtk.openmm import app
def get_total_energy(context):
state = context.getState(getEnergy=True)
ke, pe = state.getKineticEnergy(), state.getPotentialEnergy()
return ke + pe
def measure_shadow_work(simulation, n_steps):
'''Given a `simulation` that uses an integrator that accumulates heat exchange with bath,
apply the integrator for n_steps and return the change in energy - the heat.
'''
get_energy = lambda : get_total_energy(simulation.context)
@maxentile
maxentile / kinetic_energy_check.py
Created January 19, 2017 19:50
Troubleshooting velocity-randomization step: plotting kinetic energy distributions
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from tqdm import tqdm
from simtk import unit
from simtk import openmm as mm
from simtk.openmm import app
from openmmtools.testsystems import WaterBox
from openmmtools.integrators import GHMCIntegrator
@maxentile
maxentile / pretty_print_customintegrator.py
Created March 15, 2017 19:27
Converts an OpenMM CustomIntegrator into a readable list of computation steps
from openmmtools.integrators import GHMCIntegrator, GradientDescentMinimizationIntegrator
integrators = [GHMCIntegrator(), GradientDescentMinimizationIntegrator()]
step_type_dict = {
0 : "{target} <- {expr}",
1: "{target} <- {expr}",
2: "{target} <- sum({expr})",
3: "constrain positions",
4: "constrain velocities",
@maxentile
maxentile / cartoon.py
Created July 14, 2017 00:59
Cartoon placeholder for illustrating work measurement scheme
import numpy as np
import matplotlib.pyplot as plt
# without velocity randomization
np.random.seed(0)
plt.figure(figsize=(6,3))
protocol_length = 25
x_1 = np.arange(protocol_length)
x_2 = np.arange(protocol_length) + protocol_length
@maxentile
maxentile / autograd_able_compute_perturbed_free_energies.py
Created July 11, 2018 22:55
MBAR's computePerturbedFreeEnergies doesn't play nice with autograd. This does.
from autograd.scipy.misc import logsumexp
from autograd import grad
from autograd import numpy as np
import pymbar
def compute_perturbed_free_energies(mbar, u_ln):
states_with_samples = (mbar.N_k > 0)
log_q_k = mbar.f_k[states_with_samples] - mbar.u_kn[states_with_samples].T
log_denominator_n = logsumexp(log_q_k, b=mbar.N_k[states_with_samples], axis=1)
@maxentile
maxentile / quick_speed_test_customintegrator.py
Last active August 10, 2018 18:49
isolate contribution of random number generation (result: not a major contribution)
#!/bin/env python
"""
Benchmark DHFR in explicit solvent with minimal CustomIntegrators that include Gaussian random numbers or not.
"""
import time
from simtk import openmm, unit
from openmmtools import testsystems