Entering edit mode
8.3 years ago
python
▴
20
please help me with this error:index 2 is out of bounds for axis 1 with size ,
from __future__ import print_function
import matplotlib.pyplot as plt
import itertools
import mdtraj as md
import t = md.load_xtc('traj.xtc',top='traj.gro')
print(t)mdtraj.testing
hbonds = md.baker_hubbard(t, periodic=False)
label = lambda hbond : '%s -- %s' % (t.topology.atom(hbond[0]), t.topology.atom(hbond[2]))
for hbond in hbonds:
print(label(hbond))
da_distances = md.compute_distances(t, hbonds[:, [1,2]], periodic=False)
color = itertools.cycle(['r', 'b', 'gold'])
for i in [2, 3, 4]:
plt.hist(da_distances[:, i], color=next(color), label=label(hbonds[i]), alpha=0.5)
plt.legend()
plt.ylabel('Freq');
plt.xlabel('Donor-acceptor distance [nm]')
out put
IndexError Traceback (most recent call last)
<ipython-input-30-00847caa816f> in <module>()
1 color = itertools.cycle(['r', 'b', 'gold'])
2 for i in [2, 3]:
----> 3 plt.hist(da_distances[:, i], color=next(color), label=label(hbonds[i]), alpha=0.5)
4 plt.legend()
5 plt.ylabel('Freq');
IndexError: index 2 is out of bounds for axis 1 with size 0