Skip to content

Instantly share code, notes, and snippets.

View kyleabeauchamp's full-sized avatar

Kyle Beauchamp kyleabeauchamp

View GitHub Profile
@kyleabeauchamp
kyleabeauchamp / mle_test.py
Created November 1, 2012 04:25
Test driver for new mle_code
from msmbuilder import io
from msmbuilder import MSMLib
ass = io.loadh("~/dat/redesign/NTL9/Ward-2500/Assignments.Fixed.h5")["Data"]
c = MSMLib.get_count_matrix_from_assignments(ass)
m = MSMLib.reversible_MLE_estimator(c)
u = m.optimize()
c0 = c + c.transpose()
c.data[:] = 1.
c3 = MSMLib.mle_reversible_count_matrix(c,initial_guess=c0)
@kyleabeauchamp
kyleabeauchamp / gist:5393024
Last active December 16, 2015 06:39
LH5 Reporter
"""
LH5reporter.py: Output a trajectory in MSMBuilder LH5 format.
This class is for use with the Python OpenMM App. This class allows OpenMM to directly write an MSMBuilder2 LH5 Trajectory.
Example: After preparing a simulation in OpenMM, the following code allows OpenMM to directly write to a *h5 file.
R1=Trajectory.Trajectory.LoadFromPDB('native.pdb')
simulation.reporters.append(LH5Reporter.LH5Reporter('Trajectories/trj0.lh5', 2000,R1))
"""
@kyleabeauchamp
kyleabeauchamp / cluster_tani.py
Last active December 17, 2015 10:29
Example of Wards Clustering
import matplotlib.pyplot as plt
import scipy.cluster
import numpy as np
import fastcluster
num_samples = 1000
similarities = np.loadtxt("./TanimotoMatrix0-1998")
distances0 = -1 * np.log(similarities / 1000.)
distances = scipy.cluster.hierarchy.distance.squareform(distances0)
@kyleabeauchamp
kyleabeauchamp / 3cti.pdb
Last active December 17, 2015 11:29
Learning MD with Gromacs
MODEL 1
ATOM 1 N ARG A 1 4.346 7.563 -9.808 1.00 0.00 N
ATOM 2 CA ARG A 1 4.638 6.110 -9.659 1.00 0.00 C
ATOM 3 C ARG A 1 5.735 5.902 -8.620 1.00 0.00 C
ATOM 4 O ARG A 1 6.406 4.889 -8.593 1.00 0.00 O
ATOM 5 CB ARG A 1 5.074 5.498 -11.002 1.00 0.00 C
ATOM 6 CG ARG A 1 6.311 6.214 -11.563 1.00 0.00 C
ATOM 7 CD ARG A 1 6.633 5.650 -12.951 1.00 0.00 C
ATOM 8 NE ARG A 1 5.490 5.938 -13.863 1.00 0.00 N
ATOM 9 CZ ARG A 1 5.575 5.623 -15.127 1.00 0.00 C
@kyleabeauchamp
kyleabeauchamp / do_everything.py
Last active June 1, 2016 21:42
Fetch and simulate PDB in openmm.
from sys import stdout
import simtk.openmm as mm
import simtk.openmm.app as app
import simtk.unit as u
import urllib
def write_pdb(pdb_id):
url = 'http://www.rcsb.org/pdb/files/%s.pdb' % pdb_id
pdb_text = urllib.urlopen(url).read()
file_handle = open("%s.pdb" % pdb_id, 'w')
@kyleabeauchamp
kyleabeauchamp / 2it7.pdb
Last active December 17, 2015 17:39
Simulate 2it7 in gromacs 4.6
ATOM 1 N GLY A 1 -11.791 0.397 -6.281 1.00 0.00 N
ATOM 2 CA GLY A 1 -10.447 1.020 -6.222 1.00 0.00 C
ATOM 3 C GLY A 1 -9.768 0.819 -4.872 1.00 0.00 C
ATOM 4 O GLY A 1 -10.326 0.200 -3.964 1.00 0.00 O
ATOM 5 H1 GLY A 1 -11.723 -0.596 -6.123 1.00 0.00 H
ATOM 6 H2 GLY A 1 -12.393 0.795 -5.577 1.00 0.00 H
ATOM 7 H3 GLY A 1 -12.205 0.552 -7.186 1.00 0.00 H
ATOM 8 HA2 GLY A 1 -9.814 0.587 -6.997 1.00 0.00 H
ATOM 9 HA3 GLY A 1 -10.539 2.092 -6.405 1.00 0.00 H
ATOM 10 N CYS A 2 -8.548 1.349 -4.721 1.00 0.00 N
@kyleabeauchamp
kyleabeauchamp / pandas_traj.py
Created July 24, 2013 22:04
Pandas Trajectory Container
import mdtraj, mdtraj.geometry
import pandas as pd
import numpy as np
r = mdtraj.load(filename)
data = []
for atom in r.top.atoms:
data.append((atom.index, atom.name, atom.residue.index, atom.residue.name, atom.residue.chain.index))
@kyleabeauchamp
kyleabeauchamp / atom_pair_distances.py
Last active July 20, 2021 13:10
Calculate specific atom pair distances with MDTraj
import itertools
import mdtraj, mdtraj.geometry
import pandas as pd
traj = mdtraj.load("./traj.xtc", top="native.pdb")
top, bonds = traj.top.to_dataframe()
atoms = np.array(["H", "HA", "N", "CA", "C", "CB"])
@kyleabeauchamp
kyleabeauchamp / calc_dihedrals.py
Created August 22, 2013 21:00
Compute Dihedrals
import mdtraj, mdtraj.geometry
import pandas as pd
traj = mdtraj.load("./traj.xtc", top="native.pdb")
atom_names = ["H", "N", "CA", "HA"]
resid, atom_indices = mdtraj.geometry.dihedral.atom_sequence_finder(traj, atom_names)
dih = mdtraj.geometry.compute_dihedrals(traj, atom_indices)
@kyleabeauchamp
kyleabeauchamp / FAH_to_MSMB2.py
Last active December 26, 2015 14:09
Process OpenMM XML-based FAH Data
import shutil
import os
import tarfile
import tempfile
import mdtraj
import itertools
import pandas as pd
min_num_gen = 50