Skip to content

Instantly share code, notes, and snippets.

@rmatsum836
Created May 11, 2020 21:34
Show Gist options
  • Save rmatsum836/08f31a7554d13ae7f1ddb9d552b6be5f to your computer and use it in GitHub Desktop.
Save rmatsum836/08f31a7554d13ae7f1ddb9d552b6be5f to your computer and use it in GitHub Desktop.
import mdtraj as md
import numpy as np
import matplotlib.pyplot as plt
from scattering.scattering import structure_factor
# Load trajectory with MDTraj
trj = md.load('sample.trr', top='sample.gro')
il = trj.topology.select('resid 0')
trj_il = trj.atom_slice(il)
L = trj.unitcell_lengths[0][0]
low_lim = (2 * np.pi) / (L / 2)
fig, ax = plt.subplots()
# Calculate structure factor
Q, S = structure_factor(trj, Q_range=(low_lim, 200))
ax.plot(Q, S, label=f'{i} chunk size')
plt.legend()
plt.ylim((0, 4))
plt.xlim((low_lim, 200))
plt.savefig('structure_factor.pdf')
np.savetxt('emim_sq.txt',
np.transpose(np.vstack([Q, S])),
header='# Q \tS (1/nm)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment