try pytraj
online:
# load pytraj and trajectory
import pytraj as pt
# to save time for this tutorial, we only load first 8000 frames (8 ns)
traj = pt.iterload('traj.nc', 'lysozyme.top', frame_slice=(0, 8000))
traj
# load experimental data (residue number and S2)
resnums, s2_expl = np.loadtxt('Lys.order.expl.dat').T[:2]
resnums = resnums.astype('i4')
print('residue numbers: ', resnums)
print('s2 from expl ', s2_expl)
# creat N-H vector pairs
# select H (backbone) indices with given residue number (from previous step)
H_mask = ':' + ','.join(str(i) for i in resnums) + '@H'
print('H_mask: ', H_mask)
h_indices = pt.select_atoms(traj.top, H_mask)
# select N (backbone) indices
n_indices = h_indices - 1
# create pairs
nh_pairs = list(zip(n_indices, h_indices))
nh_pairs[:3]
# do calculation
s2 = pt.NH_order_paramters(traj, nh_pairs, tcorr=8000., tstep=1.0)
s2
# load experimental S2 data
import numpy as np
# only take data in 2nd column
print(s2_expl)
# plot
%matplotlib inline
%config InlineBackend.figure_format = 'retina' # high resolution
import matplotlib
matplotlib.rcParams['savefig.dpi'] = 1.5 * matplotlib.rcParams['savefig.dpi'] # larger image
from matplotlib import pyplot as plt
plt.plot(s2, 'red', label='MD')
plt.plot(s2_expl, 'black', label='NMR')
plt.ylim([0., 1.])
plt.ylabel('S2')
plt.xlabel('Residue')
plt.legend(loc=4)
# get help
help(pt.NH_order_paramters)