Skip to content

Instantly share code, notes, and snippets.

View acadien's full-sized avatar

Adam Cadien acadien

View GitHub Profile
@acadien
acadien / emacs
Created June 2, 2016 17:51
Emacs config file
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes (quote ("8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "a8245b7cc985a0610d71f9852e9f2767ad1b852c2bdea6f4aadc12cce9c4d6d0" default)))
'(inhibit-startup-screen t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
@acadien
acadien / trajAnimate.py
Created May 19, 2015 19:48
Plots N trajectories in a 3D animation.
#!/usr/bin/python
import numpy as np
from scipy import integrate
import sys
import matplotlib as mpl
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import animation
@acadien
acadien / 0_reuse_code.js
Last active August 29, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#!/usr/bin/python
import sys,subprocess
#Simple code for starting jobs quick! Made for ATPESC 2014
def usage():
print "%s <directory/name> <# processors>"%(sys.argv[0])
try:
import matplotlib as mpl
import pylab as pl
def colorHist(pngFile):
a = pl.imread(pngFile)
b = mpl.colors.rgb_to_hsv(a[...,:3])[...,1].flatten()
vals,bins,dummy = pl.hist(b,256,visible=False)
#!/usr/bin/python
from numpy import *
x = random.random([10,3])
x[range(10), fabs(x-0.5).argsort()[:,0]]
#Break it down niao
x1 = fabs(x-0.5) # numbers closest to 0.5 will be closest to 0 now.
@acadien
acadien / msd.py
Last active August 29, 2015 13:56
The fastest way to compute the MSD of a huge set of atoms using Python: Scipy.weave + basic compiler optimization + openmp + clean memory access patterns.
#!/usr/bin/python
from scipy import weave
from scipy.weave import converters
from numpy import *
#Yeah that's right stick your code in a fucking comment cause its a weave hack.
msdCode = """
double c,d;
double *seta,*setb;
@acadien
acadien / testmayacolor.py
Last active December 11, 2015 04:18
Quick script to test mlab.pipeline.widgit with colormaps.
#!/usr/bin/python
import numpy as np
import mayavi.mlab as mlab
x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(s),
@acadien
acadien / K-nearest Python-Weave
Created December 10, 2011 17:15
Weave used to improve speed of K-nearest neighbors algorithm
#Python Euclidean distance
dist(a,b):
return sum([(i-j)**2 for i,j in zip(a,b)])**0.5
#Scipy-Weave Euclidean distance (x10 faster than standard Python implementation)
distcode = """
double c=0.0;
for(int i=0;i<64;i++)
c += (a[i]-b[i])*(a[i]-b[i]);
@acadien
acadien / scipyweave_atoms.py
Created November 9, 2011 19:45
Applying scipy and weave to simple calculations on large sets
#First the standard python list style code:
#Calculate the distance between 2 atoms:
def dist(p1,p2):
return sum([(a-b)*(a-b) for a,b in zip(p1,p2)])**0.5
#Calculate the angle between 3 atoms:
def ang(p1,p2,p3):
P12=dist(p1,p2)
P13=dist(p1,p3)