Skip to content

Instantly share code, notes, and snippets.

@fabian-paul
fabian-paul / switch_network_renderer.py
Last active August 29, 2021 21:17
switch_network_renderer
class Renderer:
def __init__(self, root):
self.root = root
def svg(self):
leftmost = self.root.leftmost(0)
s = min(300 / self.root.w, 300 / self.root.h)
svg = f"""
<!DOCTYPE html>
<html>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fabian-paul
fabian-paul / short_widest_path.c
Created July 30, 2020 07:53
An implementation of Dijkstra's algorithm for the shortest path, the widest path, and an "interpolation" between shortest and widest path.
#include <math.h>
#include <stddef.h>
#include <signal.h>
#include <assert.h>
static volatile sig_atomic_t interrupted;
static void (*old_handler)(int);
static void signal_handler(int signo) {
interrupted = 1;
@fabian-paul
fabian-paul / induced_fit_parameter_inference.ipynb
Created March 27, 2020 18:04
parameter inference for kinetic model using HMC
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fabian-paul
fabian-paul / reorder-atoms.py
Created January 30, 2020 17:30
Reorder small molecule atoms in PDB file to match the order in template PDB file. Uses RDKit.
import numpy as np
import rdkit.Chem
def reorder_atoms(mol_pdb_fname, template_pdb_fname, output_pdb_fname):
from rdkit.Chem import rdmolfiles
mol_to_transform = rdkit.Chem.rdmolfiles.MolFromPDBFile(mol_pdb_fname, removeHs=False)
transform_order = list(rdmolfiles.CanonicalRankAtoms(mol_to_transform))
mol_template = rdkit.Chem.rdmolfiles.MolFromPDBFile(template_pdb_fname, removeHs=False)
@fabian-paul
fabian-paul / mutate.py
Last active April 5, 2020 08:18
Generate trajectories for computational alanine scan (mass generation of mutant structures)
import numpy as np
import mdtraj
import os
import os.path
import argparse
def prepare_maps(mut_pdb='mutant.pdb', wt_pdb=None):
if wt_pdb is None:
wt_pdb = os.path.expanduser('~/system/crystal.pdb')
@fabian-paul
fabian-paul / colvars_def_reader.py
Last active October 16, 2019 16:13
Reads some NAMD colvar defintions in Python
import pyparsing as pp
from pyparsing import pyparsing_common as ppc
__all__ = ['load_colvars', 'handle_colvars']
pp.ParserElement.setDefaultWhitespaceChars(' \t')
vector = pp.Group(pp.Literal('(').suppress() +
pp.delimitedList(ppc.number, delim=',') +
pp.Literal(')').suppress())
@fabian-paul
fabian-paul / TRAM-short-presentation.pdf
Last active August 19, 2019 20:40
slides: Estimating transition rates of ultimate rare events using the transition-based reweighting analysis method (TRAM)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fabian-paul
fabian-paul / vamp_for_two.py
Last active August 13, 2019 15:50
Find the main kinetic dividing plane using the Variational Approach to Markov Processes (VAMP)
import numpy as np
import scipy
import scipy.optimize
import warnings
__all__ = ['VAMP42']
__author__ = 'Fabian Paul <fapa@uchicago.edu>'
def sigma(x):
return scipy.special.expit(x)
@fabian-paul
fabian-paul / strip_most_water.py
Last active March 9, 2020 23:16
delete all water molecules from MD trajectory, except molecules close to ligand
#!/usr/bin/env python
import numpy as np
import mdtraj
def tl(filename, chunk=100):
with mdtraj.open(filename, mode='r') as fh:
try:
return (len(fh) - 1) // chunk + 1
except: