Skip to content

Instantly share code, notes, and snippets.

@orbeckst
Last active May 30, 2016 19:37
Show Gist options
  • Save orbeckst/94b2aa910eb9dbfddbe9ef6dacc4e384 to your computer and use it in GitHub Desktop.
Save orbeckst/94b2aa910eb9dbfddbe9ef6dacc4e384 to your computer and use it in GitHub Desktop.
How to calculate RMSF with MDAnalysis
import numpy as np
import MDAnalysis as mda
u = mda.Universe("topol.tpr", "trj.xtc")
ca = u.select_atoms("name CA")
means = np.zeros((len(ca), 3))
sumsq = np.zeros_like(means)
for k, ts in enumerate(u.trajectory):
sumsq += (k/(k+1.0)) * (ca.positions - means)**2
means[:] = (k*means + ca.positions)/(k+1.0)
rmsf = np.sqrt(sumsq.sum(axis=1)/(k+1.0))
matplotlib.pyplot.plot(ca.residues.resids, rmsf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment