This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to solve this error IndexError: index 2 is out of bounds for axis 1 with size 0

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

moleculardynamics python

I'm guessing that md.compute_distances() is returning an empty matrix.

so how i can resolve this

Figure out what md.compute_distances() isn't working. I've never used the package, so I can't help with that.

0 answers

No answers yet.

Log in to answer this question.