Skip to content

Instantly share code, notes, and snippets.

View evanfeinberg's full-sized avatar

Evan N. Feinberg evanfeinberg

View GitHub Profile
def fix_topology(topology):
new_top = topology.copy()
residues = {}
for chain in new_top.chains:
#print chain
for residue in chain.residues:
resname = str(residue)
if resname in list(residues.keys()):
@evanfeinberg
evanfeinberg / tic_rfr.py
Created February 24, 2016 22:58
Random Forests for interpreting tICs
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
import numpy as np
def compute_random_forests(features, projected_tica_coords, rf_dir, n_trees=500,
n_tica_components=25, start_tIC=0):
features = np.concatenate(features)
tics = np.concatenate(projected_tica_coords)
for j in range(start_tIC, np.shape(tics)[1]):
@evanfeinberg
evanfeinberg / LandmarkNystroem.py
Created July 17, 2015 23:29
Modification of Nystroem Approximation to Incorporate User-Specified Landmark Points
"""
The :mod:`sklearn.kernel_approximation` module implements several
approximate kernel feature maps base on Fourier transforms.
"""
# Author: Andreas Mueller <amueller@ais.uni-bonn.de>
#
# License: BSD 3 clause
import warnings
@evanfeinberg
evanfeinberg / fix_traj.py
Last active August 29, 2015 14:20
Fixes naughty trajectories where residues are fragmented in pdb/mae files (for Anton simulations ,for example)
def fix_topology(topology):
new_top = topology.copy()
residues = {}
for chain in new_top.chains:
#print chain
for residue in chain.residues:
resname = str(residue)
if resname in residues.keys():
residues[resname].append(residue)
@evanfeinberg
evanfeinberg / reimage.py
Last active August 29, 2015 14:20
interfaces between mdtraj and pytraj to reimage a directory of trajectories
import mdtraj as md
import os
import h5py
import multiprocessing as mp
from functools import partial
import pytraj.io as mdio
def get_trajectory_files(traj_dir, ext = ".h5"):
traj_files = []
for traj in os.listdir(traj_dir):
@evanfeinberg
evanfeinberg / fix_topology.py
Created April 30, 2015 21:42
"Merges" Residues in MDTraj Topology Object
def fix_topology(topology):
new_top = topology.copy()
residues = {}
for chain in new_top.chains:
#print chain
for residue in chain.residues:
resname = str(residue)
if resname in residues.keys():
@evanfeinberg
evanfeinberg / PDB_Order_Fixer.py
Created April 30, 2015 21:22
Fixes naughty PDB's where individual residues are split up into fragments. This confuses many PDB readers.
'''
Many PDB Files have an issue where a single chemical residue (e.g., a single histidine) will have each of its atoms, while
chemically bonded, spread out across the PDB file. This confuses many PDB readers, as it will assume each non-contiguous
line for that residue corresponds to separate residues. This class has a function that takes as inputs the name of the original
pdb file and the name of a new file to which the user would like to write. It then finds all residues corresponding to proteins,
and stores them in a dict, with keys as a tuple of (residue_name, residue_chain, and residue_number) and with values as a
list of physical lines in the PDB file that correspond to that unique residue identifier. The function then prints the initial header,
prints the exact same PDB file lines just in a different order that maintains contiguousness within each residue, and then prints
all membrane, solvent, and other lines.
@evanfeinberg
evanfeinberg / Custom_Featurizer.py
Last active August 29, 2015 14:20
custom dihedral featurizer for naughty pdb files
'''I should formalize this with a class, etc., but here's how one can use this:
with a file corresponding to a trajectory you want to featurize, call:
featurize_custom(traj_file)
'''
def fix_topology(topology):