Replies: 1 comment
-
I strongly suggest you have a look at the User Guide: Hydrogenbond analysis and study the Hydrogen bond analysis docs — this is a powerful and flexible but complicated analysis tool with many settings.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hi,
I am new to MD Simulation, as a way of practice I am trying to run a hbond analysis but I keep getting errors. I have 2 attempts with different error messages. Can someone help me sort this out?
import numpy as np
import MDAnalysis as mda
from MDAnalysis.analysis.hydrogenbonds import HydrogenBondAnalysis
ATTEMPT 1
THE ERROR IS "NoDataError: This Universe does not contain charge information"
THE CODE IS
Load the protein structure file and trajectory
psf = 'sol5.gro'
trajectory = 'traj_comp.xtc'
Create the MDAnalysis Universe
u = mda.Universe(psf, trajectory)
Define donor and acceptor selections
donors = "protein and name N" # Example: Nitrogen atoms in protein backbone
acceptors = "protein and name O" # Example: Oxygen atoms in protein backbone
Create HydrogenBondAnalysis object
hba = HydrogenBondAnalysis(u, donors, acceptors)
Run the analysis over the trajectory
hba.run()
Get the results
hbonds = hba.count_by_time()
Print the results
print("Time (ps) No. of Hydrogen Bonds")
for time, count in hbonds:
print(f"{time:.2f} {count}")
ATTEMPT 2
THE ERROR IS "AttributeError: 'HydrogenBondAnalysis' object has no attribute 'timeseries'"
import numpy as np
import MDAnalysis
from MDAnalysis.analysis.hydrogenbonds import HydrogenBondAnalysis
Load the protein structure file and trajectory
psf = 'sol5.gro'
trajectory = 'traj_comp.xtc'
Create the MDAnalysis Universe
u = mda.Universe(psf, trajectory)
Define the donor and acceptor groups
donors="name O"
acceptors = "name OH2"
hydrogens_sel="name H1 H2"
Perform the hydrogen bond analysis
hb = HydrogenBondAnalysis(u, donors, hydrogens_sel, acceptors, d_a_cutoff=3.0, d_h_a_angle_cutoff=120.0)
hb.run()
Print the results
print("Hydrogen Bonds:")
for ts, bonds in hb.timeseries.items():
print(f"Time step {ts}:")
for bond in bonds:
donor, acceptor, distance, angle = bond
print(f" Donor: {donor.resname} {donor.resid} {donor.name}")
print(f" Acceptor: {acceptor.resname} {acceptor.resid} {acceptor.name}")
print(f" Distance: {distance:.2f} Å")
print(f" Angle: {angle:.2f} degrees")
print()
Beta Was this translation helpful? Give feedback.
All reactions