-
Notifications
You must be signed in to change notification settings - Fork 764
Closed
Copy link
Labels
Description
Expected behavior
I'd like to use only certain frames from a trajectory for H bond analysis using a FrameIterator and then plot the number of H bonds for each selected frame.
Actual behavior
When I try to plot the count_by_time(), I get the following error:
plt.plot(hbonds.times, hbonds.count_by_time())
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/envs/mdanalysis-tools/lib/python3.11/site-packages/MDAnalysis/analysis/hydrogenbonds/hbond_analysis.py", line 901, in count_by_time
indices -= self.start
numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'subtract' output from dtype('O') to dtype('float64') with casting rule 'same_kind'Code to reproduce the behavior
import matplotlib.pyplot as plt
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import waterPSF, waterDCD
from MDAnalysis.analysis.hydrogenbonds import HydrogenBondAnalysis
u = mda.Universe(waterPSF, waterDCD)
frames_to_use = []
for ts in u.trajectory[0:3:1]:
frames_to_use.append(u.trajectory.frame)
for ts in u.trajectory[5:9:1]:
frames_to_use.append(u.trajectory.frame)
hbonds = HydrogenBondAnalysis(universe=u, donors_sel=None, hydrogens_sel="name H1 H2", acceptors_sel="name OH2", d_a_cutoff=3.0, d_h_a_angle_cutoff=150, update_selections=False)
hbonds.run(frames=frames_to_use)
plt.plot(hbonds.times, hbonds.count_by_time())Current version of MDAnalysis
MDAnalysis: 2.10.0
Python: 3.14
OS: macOS Monterey 12.7.6 but issue has also happened on a Linux computer
Originally posted by @capritchard in #5081