Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ Chronological list of authors
- Pranay Pelapkar
- Shreejan Dolai
- Tanisha Dubey
- Brady Johnston

External code
-------------
Expand Down
4 changes: 3 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ The rules for this file:

-------------------------------------------------------------------------------
??/??/?? IAlibay, orbeckst, marinegor, tylerjereddy, ljwoods2, marinegor,
spyke7, talagayev, tanii1125
spyke7, talagayev, tanii1125, BradyAJohnston

* 2.11.0

Fixes
* HydrogenBondAnalysis: Fixed `count_by_time()` when using `run(FrameIterator)` that
results in `self.start` and `self.end` being None (Issue #5200, PR #5202)
* NoJump shows a more informative message and fails when applied
outside of the first frame (Issue #4915, PR #5201)
* DSSP now explicitly checks for a minimum of 6 residues and raises a clear
Expand Down
16 changes: 6 additions & 10 deletions package/MDAnalysis/analysis/hydrogenbonds/hbond_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,17 +911,13 @@ def count_by_time(self):
Can be used along with :attr:`HydrogenBondAnalysis.times` to plot
the number of hydrogen bonds over time.
"""
hbond_frames = self.results.hbonds[:, 0].astype(int)
frame_unique, frame_counts = np.unique(hbond_frames, return_counts=True)
frame_min, frame_max = self.frames.min(), self.frames.max()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good, you used np min/max — they are much faster than applying python min/max to arrays


indices, tmp_counts = np.unique(self.results.hbonds[:, 0], axis=0,
return_counts=True)

indices -= self.start
indices /= self.step

counts = np.zeros_like(self.frames)
counts[indices.astype(np.intp)] = tmp_counts

return counts
counts = np.zeros(frame_max - frame_min + 1, dtype=int)
counts[frame_unique - frame_min] = frame_counts
return counts[self.frames - frame_min]

def count_by_type(self):
"""Counts the total number of each unique type of hydrogen bond.
Expand Down
20 changes: 20 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_hydrogenbonds_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,23 @@ def test_hbond_analysis(self, universe, client_HydrogenBondAnalysis):
assert h.hydrogens_sel == ""
assert h.acceptors_sel == ""
assert h.results.hbonds.size == 0


class TestHydrogenBondAnalysisFrameIterator:
@staticmethod
@pytest.fixture(scope="class")
def universe():
return MDAnalysis.Universe(waterPSF, waterDCD)

def test_frame_iterator(self, universe):
frames = np.array([0, 1, 2, 5, 6, 7, 8])
hbonds = HydrogenBondAnalysis(
universe=universe,
hydrogens_sel="name H1 H2",
acceptors_sel="name OH2",
update_selections=False,
)
hbonds.run(frames=frames)
assert np.array_equal(
hbonds.count_by_time(), np.array([2, 1, 4, 3, 3, 2, 2])
)
Loading