Hydrogen bond calculation using lammps file format

767 views
Skip to first unread message

akgsj

unread,
Nov 8, 2018, 9:44:28 AM11/8/18
to MDnalysis discussion
Dear Friends,

I am trying to calculate hydrogen bonds between water molecules and facing some difficulties. The MDanalysis software
could not recognize atoms for the calculation. Here is the script that I used for the calculation
########### Script
#!/usr/bin/env python
import MDAnalysis
import MDAnalysis.analysis.hbonds

u = MDAnalysis.Universe("restart1.data", "trajectory2.dcd", format="LAMMPS")
h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis(u, 'type 2', 'type 3', distance=3.0, angle=120.0)

#################### Out_Put

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis(u, 'type 2', 'type 2 or 3', distance=3.0, angle=120.0)
  File "/home/amal/anaconda3/lib/python3.7/site-packages/MDAnalysis/analysis/hbonds/hbond_analysis.py", line 602, in __init__
    self._update_selection_1()
  File "/home/amal/anaconda3/lib/python3.7/site-packages/MDAnalysis/analysis/hbonds/hbond_analysis.py", line 808, in _update_selection_1
    'name {0}'.format(' '.join(self.donors)))
  File "/home/amal/anaconda3/lib/python3.7/site-packages/MDAnalysis/core/groups.py", line 2387, in select_atoms
    selections[0].apply(self))
  File "/home/amal/anaconda3/lib/python3.7/site-packages/MDAnalysis/core/selection.py", line 531, in apply
    mask |= getattr(group, self.field) == val
  File "/home/amal/anaconda3/lib/python3.7/site-packages/MDAnalysis/core/groups.py", line 1823, in __getattr__
    cls=self.__class__.__name__, attr=attr))
AttributeError: AtomGroup has no attribute names

############ What am I looking for
How would I select the atoms for hydrogen bond calculation?
By the way, Lammps topology file does not have atom names, and I tested the command "u.select_atoms('type 2')" which
works perfectly.

Best regards

Oliver Beckstein

unread,
Nov 13, 2018, 2:36:01 PM11/13/18
to MDnalysis discussion
Hi akgsj,

Welcome to the MDAnalysis mailing list!

The hbond code assumes somewhere that we can get names, so what you describe is a bug. Can you please raise an issue in the issue tracker?

A possible workaround is to assign fake names:

  u.add_TopologyAttr('names')
  u.atoms.names = 'X'

Now all particles have name 'X'. This might give confusing output so perhaps you rather want to distinguish your specific particles

  u.select_atoms("type 2").names = "H"
  u.select_atoms("type 3").names = "O"


Perhaps this works now?

Oliver

akgsj

unread,
Nov 14, 2018, 12:41:39 PM11/14/18
to MDnalysis discussion
Hi Oliver,

Thanks for your reply. The problem that I faced is partly solved. Now, I am facing another problem.

Here is the script###########

#!/usr/bin/env python
import MDAnalysis
import MDAnalysis.analysis.hbonds

u = MDAnalysis.Universe("restart1.data", "trajectory2.dcd", format="LAMMPS")
u.add_TopologyAttr('names')

u.select_atoms('type 2').names="O"
u.select_atoms('type 3').names="H"

h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis (u, 'name O', 'name O',
   donors=["O"], acceptors=['O'], distance=3.0, angle=120.0)
h.run()

Error#######################

Traceback (most recent call last):
  File "test.py", line 26, in <module>
    h.run()
  File "/home/amal/anaconda3/lib/python3.7/site-packages/MDAnalysis/analysis/hbonds/hbond_analysis.py", line 989, in run
    (h.resname, h.resid, h.name),
  File "/home/amal/anaconda3/lib/python3.7/site-packages/MDAnalysis/core/groups.py", line 3103, in __getattr__
    cls=self.__class__.__name__, attr=attr))
AttributeError: Atom has no attribute resname

Looking for############
How do I add resname in the topology?

Best regards
Akg

Oliver Beckstein

unread,
Nov 14, 2018, 5:30:22 PM11/14/18
to mdnalysis-...@googlegroups.com
Hi Akg,

Try the same trick

u.add_TopologyAttr(“resnames”)
u.atoms.residues.resnames = “UNK"

(and please file an issue in the issue tracker).

Oliver

--
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 post to this group, send email to mdnalysis-...@googlegroups.com.
Visit this group at https://groups.google.com/group/mdnalysis-discussion.
For more options, visit https://groups.google.com/d/optout.



Reply all
Reply to author
Forward
0 new messages