Hydrogen bond analysis error - AttributeError: 'int' object has no attribute 'positions'

48 views
Skip to first unread message

Srdjan Pusara

unread,
Sep 18, 2023, 5:56:44 AM9/18/23
to MDnalysis discussion
  Hello everyone,

I wrote program to analyse hydrogen bonds, and program worked well for 5 MD trajectories, but for other 2 MD trajectories I am getting this error:

Traceback (most recent call last):
  File "H_bonds2.py", line 24, in <module>
    hbonds.run(verbose=True)
  File "/home/srdjan/anaconda3/lib/python3.7/site-packages/MDAnalysis/analysis/base.py", line 197, in run
    self._single_frame()
  File "/home/srdjan/anaconda3/lib/python3.7/site-packages/MDAnalysis/analysis/hydrogenbonds/hbond_analysis.py", line 458, in _single_frame
    self._donors.positions,



This is my script:

from MDAnalysis.analysis import hbonds
from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import HydrogenBondAnalysis as HBA
hbonds = HBA(universe=u)
hbonds.hydrogens_sel = hbonds.guess_hydrogens("protein")
hbonds.acceptors_sel = hbonds.guess_acceptors("protein")
hbonds.run(verbose=True

I hope that someone can help me.

Thank you.

Srdjan Pusara

unread,
Sep 18, 2023, 10:05:17 AM9/18/23
to mdnalysis-...@googlegroups.com
I did some debugging and it seems the problem is that
hbonds.hydrogens_sel = hbonds.guess_hydrogens("protein")
returns empty array (it does not select any atoms but I dont understand why. I tried to change with command hbonds.hydrogens_sel = hbonds.guess_hydrogens("all")but still it cannot find any group.


--
You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mdnalysis-discussion/02cf39b5-1ecf-49bf-95e2-70996e3aba32n%40googlegroups.com.

Srdjan Pusara

unread,
Oct 2, 2023, 3:35:20 AM10/2/23
to mdnalysis-...@googlegroups.com
   Hello,

Could anyone help with this?

Oliver Beckstein

unread,
Oct 5, 2023, 10:51:24 AM10/5/23
to mdnalysis-discussion
Hello Srdjan,

Sorry that there haven’t been answers to your questions. Perhaps one reason was that we just held our first User Group Meeting and people were quite busy preparing and then travelling.

On Oct 2, 2023, at 09:34, Srdjan Pusara <srdjan...@gmail.com> wrote:

   Hello,

Could anyone help with this?

On Mon, 18 Sept 2023 at 15:58, Srdjan Pusara <srdjan...@gmail.com> wrote:
I did some debugging and it seems the problem is that
hbonds.hydrogens_sel = hbonds.guess_hydrogens("protein")
returns empty array (it does not select any atoms but I dont understand why. I tried to change with command hbonds.hydrogens_sel = hbonds.guess_hydrogens("all")but still it cannot find any group.

Did you check that your universe contains hydrogens? I.e., if you just look at

print(u.atoms.names)

then do you see anything that looks like names for hydrogens?

What input files are you using for your universe? If it’s from a simulation, what force field was used? 

Oliver


Srdjan Pusara

unread,
Oct 19, 2023, 9:58:04 AM10/19/23
to mdnalysis-...@googlegroups.com
   Hello,

Sorry for the late reply. I have tried that command and I get that there are hydrogen atoms when I type command  print(u.atoms.names)    ['N' 'HT1' 'HT2' ... 'OT1' 'OT2' 'HT2B']. I can also see hydrogens when I visually check PDB files of trajectory.
I find it strange because I have 7 MD trajectories, and code fails only on 2 trajectories.  Is it maybe a problem with my .tpr file to read topology?  (although I have already tried to create it again).

I will post again relevant parts of my code:

import MDAnalysis as mda

from MDAnalysis.analysis import hbonds
from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import HydrogenBondAnalysis as HBA
import numpy as np
import matplotlib.pyplot as plt

u = mda.Universe('../Check.tpr', '../Check.xtc')

num_residues = len(u.residues)
No_amino=int(num_residues/20)

num_atoms = len(u.atoms)
atoms_per_chain= int(num_atoms/20)    #there are 20 different chains

ContactMap = [[0 for x in range(No_amino)] for y in range(No_amino)]

ContactMap_intra = [[0 for x in range(No_amino)] for y in range(No_amino)]



hbonds = HBA(universe=u)
hbonds.hydrogens_sel = hbonds.guess_hydrogens("protein")
hbonds.acceptors_sel = hbonds.guess_acceptors("protein")

hbonds.run(verbose=True)

np.savetxt("hbonds.dat", hbonds.hbonds)

Srdjan Pusara

unread,
Oct 19, 2023, 9:58:09 AM10/19/23
to mdnalysis-...@googlegroups.com
  If it will be helpful, I can share my MD trajectory files and python code.
Reply all
Reply to author
Forward
0 new messages