Data analysis - MD analysis Python

136 Views Asked by At

I am seeing this error, need help on this!

warnings.warn("Failed to guess the mass for the following atom types: {}".format(atom_type)) Traceback (most recent call last): File "traj_residue-z.py", line 48, in protein_z=protein.centroid()[2] IndexError: index 2 is out of bounds for axis 0 with size 0

1

There are 1 best solutions below

0
orbeckst On

The problem was solved through a discussion in the mailing list thread https://groups.google.com/g/mdnalysis-discussion/c/J8oJ0M9Rjb4/m/kSD2jURODQAJ

In brief: The traj_residue-z.py script contained the line

protein=u.select_atoms('resid 1-%d' % (nprotein_res))

It turned out that the selection 'resid 1-%d' % (nprotein_res) would not select anything because the input GRO file started with resid 1327

 1327LEU      N    1   2.013   3.349   8.848  0.4933 -0.2510  0.2982
 1327LEU     H1    2   1.953   3.277   8.893  0.0174  0.1791  0.3637
 1327LEU     H2    3   1.960   3.377   8.762  0.6275 -0.5669  0.1094
 ...

and hence the selection of resids starting at 1 did not match anything. This produced an empty AtomGroup protein.

The subsequent centroid calculation

protein_z=protein.centroid()[2]

failed because for an empty AtomGroup, protein.centroid() returns an empty array and so trying to get the element at index 2 raises IndexError.

The solution (thanks to @IAlibay) was to

  • either change the selection string 'resid 1-%d' to accommodate start and stop resids, or
  • to just select the first nprotein_res residues protein = u.residues[:nprotein_res].atoms by slicing the ResiduesGroup.