Skip to content

Instantly share code, notes, and snippets.

@3ki5tj
3ki5tj / pdb.py
Created November 18, 2014 23:39
Search the protein data bank (PDB)
#!/usr/bin/env python
''' search or blast pdb '''
import SOAPpy, getopt, sys, os, shutil
@3ki5tj
3ki5tj / cindent.py
Created November 18, 2014 23:36
Format leading spaces and tabs in C-like code
#!/usr/bin/env python
''' format the leading spaces and tabs
Main functions:
* tab2sp(): change leading tabs to spaces
* reindent(): main function, reformat the leading indents
reindentf(): wrapper for reindent, accepts a file
* guessindent(): guess the indent size
@3ki5tj
3ki5tj / cspacer.py
Created November 18, 2014 23:34
Add spaces to C-like source code (a simple formatter)
#!/usr/bin/env python
'''
add spaces for C source code
the main function is addspacef()
Example 1:
if(a>b&&a>3)c=d;
--> if (a > b && a > 3) c = d;
@3ki5tj
3ki5tj / rstrip.py
Created November 18, 2014 23:32
Remove trailing spaces in a text file
#!/usr/bin/env python
''' remove trailing spaces in a text file '''
import os, sys, getopt
@3ki5tj
3ki5tj / scifmt.py
Created November 18, 2014 23:31
Format numbers in scientific notation
#!/usr/bin/env python
import math
class scifmt:
def __init__(me, x, err = 0):
@3ki5tj
3ki5tj / numthr.py
Created November 18, 2014 23:29
Number theory routines in python
from math import *
def getdigits(n, p):
''' write n as a base-p number
the least significant digit goes first
'''
arr = []
while n:
arr += [n % p, ]
@3ki5tj
3ki5tj / markovtext.py
Created November 18, 2014 23:26
Markov-chain text generator
#!/usr/bin/env python
''' Markov-chain text generator '''
import random, re, sys
from collections import deque
order = 2
fnin = "advshl.txt" # input text
@3ki5tj
3ki5tj / ljmdgl.c
Created November 18, 2014 23:18
Molecular dynamics of a Lennard-Jones fluid (OpenGL)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#if defined(Macintosh) || defined(__APPLE__)
/* to compile: gcc -framework OpenGL -framework GLUT lj3.c */
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
@3ki5tj
3ki5tj / inteq.c
Created November 18, 2014 23:08
Integral equation for a simple fluid using FFTW3
/* Numerically solve the 3D PY or HNC equation
* gcc -O3 inteq.c -lfftw3 -lm
* For the PY version
* ./a.out > a.dat
* For the HNC version
* ./a.out HNC > b.dat
* In Gnuplot:
* plot "a.dat" u 1:3 w l t "g(r), PY", \
* "b.dat" u 1:3 w l t "g(r), HNC"
* */
@3ki5tj
3ki5tj / renorm.ma
Created November 18, 2014 23:06
Renormalization of the quadratic map
(* renormalization of the quadratic map
cf. B-L Hao, Elementary Symbolic Dynamics, Sec. 2.7.2 Table 2.3 and Sec. 3.4.2-3.4.3 Table 3.4 *)
n = 3; (* number of terms *)
z = 2; (* map is f = 1 + A1 x^z + A2 x^(2z) + ... *)
niter = 3; (* 2 for period-doubling, 3 for -trippling *)
A = Table[ToExpression[ToString["A"] <> ToString[k]], {k, 1, n}]; (* coefficients *)
f[x_] := 1 + A.Table[x^(z k), {k, 1, n}]; (* the map *)
del = f[a x] - a Nest[f, x, niter]; (* renormalization equation, del should be 0 *)
eqs = Table[Coefficient[del, x, j z], {j, 0, n}]; (* the coefficients of the x^(j z) term *)
init = Append[ (* initial guess for A1, A2, ..., and a *)