Skip to content

Instantly share code, notes, and snippets.

@sunhwan
sunhwan / gist:197446cdb29ff2cf0b7562fabf5d31b0
Created June 21, 2021 01:52
ipython cell magic - kroki
from IPython.core.magic import register_cell_magic
from IPython.display import SVG, display
import requests
diagrams_supported = set(['blockdiag', 'seqdiag', 'mermaid', 'actdiag',
'nwdiag', 'packetdiag', 'rackdiag', 'erd',
'nomnoml', 'plantuml', 'umlet', 'wavedrom',
'bpmn', 'bytefield', 'pikchr', 'graphviz',
'vega', 'vega-lite', 'ditaa', 'svgbob'])
@sunhwan
sunhwan / config
Last active April 11, 2023 19:48
AWS parallel-cluster config file
[aws]
aws_region_name = us-east-1
[aliases]
ssh = ssh {CFN_USER}@{MASTER_IP} {ARGS}
[global]
cluster_template = default
update_check = true
sanity_check = true
from numpy.random import choice
class KMedoid:
def __init__(self, k, verbose=False):
self.k = k
self.maxiter = 100
self.verbose = verbose
def assign_labels(self, S):
return np.argmin(S, axis=1)
import argparse
import re
import base64
from io import BytesIO
import cairosvg
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem.Draw.MolDrawing import MolDrawing, DrawingOptions #Only needed if modifying defaults
@sunhwan
sunhwan / density.py
Last active May 15, 2020 20:18
compute number density of probe along Z axis from Gromacs trajectories
import argparse
from pathlib import Path
import re
import sys
from multiprocessing import Pool
from functools import partial
from tqdm import tqdm
import mdtraj as md
import numpy as np
@sunhwan
sunhwan / doi2bib
Created June 24, 2016 15:30 — forked from achabotl/doi2bib
doi2bib
#!/bin/sh
if [[ "${1}" == "http"* ]] ; then
doi="${1}"
else
doi="http://dx.doi.org/${1}"
fi
# Stopped working around 2015-10-04.
# curl -sLH "Accept: text/bibliography; style=bibtex" "${doi}" | sed 's/^ *//'
@sunhwan
sunhwan / mywham.py
Last active January 2, 2016 21:19
WHAM
import sys
import numpy as np
debug = False
if len(sys.argv) > 1: debug = True
input = sys.stdin
pmf_filename = input.readline().strip() # stores pmf
rho_filename = input.readline().strip() # stores average density
bia_filename = input.readline().strip() # stores biased distribution
@sunhwan
sunhwan / dist.conf
Last active December 28, 2015 17:09
2D Replica-Exchange (T & colvar) for NAMD with NPT ensemble
# configuration for replica exchange scripts
# run simulation:
# mkdir output
# (cd output; mkdir 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
# mpirun -np 16 -hostfile hostfile $bindir/namd2 +replicas 16 job0.conf +stdout output/%d/job0.%d.log
# the number of MPI ranks (-np) must be a multiple of the number of replicas (+replicas)
# to continue:
# mpirun -np 16 -hostfile hostfile $bindir/namd2 +replicas 16 job1.conf +stdout output/%d/job1.%d.log
@sunhwan
sunhwan / pdb2crd.py
Created October 27, 2013 01:34
convert PDB to CHARMM CRD format (requires PSF file)
import argparse
import re
import sys
_s = re.compile('\s+')
def parse_psf(psffile):
psf = open(psffile)
psf.readline(); psf.readline()
ntitle = int(psf.readline().strip().split()[0])
@sunhwan
sunhwan / gist:3170565
Created July 24, 2012 15:09
remote tail
import subprocess as sp
pid = sp.Popen(['ssh', 'purdue', 'tail -f work/glycan/benchmarks/rexmd/aarex/server.log'], stdin=sp.PIPE, stdout=sp.PIPE, close_fds=True)
stdin, stdout = pid.stdin, pid.stdout
while 1:
print stdout.readline()