Skip to content

Instantly share code, notes, and snippets.

@mattwthompson
Created January 18, 2018 23:03
Show Gist options
  • Save mattwthompson/617113a37d49fc3d64969be757c401f6 to your computer and use it in GitHub Desktop.
Save mattwthompson/617113a37d49fc3d64969be757c401f6 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
histo = np.loadtxt('histo.xvg', comments=['#', '@'])
x_values = histo[:, 0]
plt.figure(figsize=(10, 4))
for hist in histo[:, 1:].T:
hist = [float('nan') if x==0 else x for x in hist] # Don't plot zero values
plt.plot(x_values, hist, '.-')
plt.xlabel('COM separation, nm')
plt.ylabel('Histogram counts, a.u.')
plt.savefig('histo.pdf')
@mattwthompson
Copy link
Author

Context: PMFs obtained via umbrella sampling in GROMACS rely on inverting histograms with WHAM. GROMACS is great for preparing, running, and analyzing these simulations. However, the raw histogram data are thrown to xvg files, which requires not only xmgrace to be installed and working properly, but some magic to actually plot all columns at once. This snippet avoids that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment