Skip to content

Commit

Permalink
hbond_analysis complete codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclark5 committed Sep 29, 2022
1 parent 299b898 commit bd95900
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ examples/output.txt
# ignore Vagrant virtual machines
.vagrant
# ignore coverage files
.coverage
.coverage*
.noseids
htmlcov
# ignore trajectory offset caches
Expand Down
5 changes: 4 additions & 1 deletion package/MDAnalysis/analysis/hydrogenbonds/hbond_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@ def guess_donors(self, select='all', max_charge=-0.5):
hydrogens_sel = self.hydrogens_sel
hydrogens_ag = self.u.select_atoms(hydrogens_sel)

if hasattr(hydrogens_ag[0],"bonded_atoms") and hydrogens_ag[0].bonded_atoms:
# We're using u._topology.bonds rather than u.bonds as it is a million times faster to access.
# This is because u.bonds also calculates properties of each bond (e.g bond length).
# See https://github.com/MDAnalysis/mdanalysis/issues/2396#issuecomment-596251787
if (hasattr(self.u._topology, 'bonds') and len(self.u._topology.bonds.values) != 0):
donors_ag = find_hydrogen_donors(hydrogens_ag)
else:
ag = hydrogens_ag.residues.atoms.select_atoms(
Expand Down
31 changes: 29 additions & 2 deletions testsuite/MDAnalysisTests/analysis/test_hydrogenbonds_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,23 @@ def test_no_bond_info_exception(self, universe):
h = HydrogenBondAnalysis(universe, **kwargs)
h._get_dh_pairs()

def test_no_bond_donor_sel(self, universe):

kwargs = {
'donors_sel': "type O",
'hydrogens_sel': None,
'acceptors_sel': None,
'd_h_cutoff': 1.2,
'd_a_cutoff': 3.0,
'd_h_a_angle_cutoff': 120.0
}
u = universe.copy()
n_residues = 2
u.add_TopologyAttr('mass', [15.999, 1.008, 1.008] * n_residues)
u.add_TopologyAttr('charge', [-1.04, 0.52, 0.52] * n_residues)
h = HydrogenBondAnalysis(u, **kwargs)
donors = u.select_atoms(h.guess_donors())

def test_first_hbond(self, hydrogen_bonds):
assert len(hydrogen_bonds.results.hbonds) == 2
frame_no, donor_index, hydrogen_index, acceptor_index, da_dst, angle =\
Expand Down Expand Up @@ -319,6 +336,16 @@ def hydrogen_bonds(universe):
h.run()
return h

def test_count_by_type(self, universe):

h = HydrogenBondAnalysis(
universe,
**TestHydrogenBondAnalysisNoRes.kwargs
)
h.run()
counts = h.count_by_type()
ref_count = 2
assert int(counts[0, 2]) == ref_count

def test_no_bond_info_exception(self, universe):

Expand Down Expand Up @@ -365,9 +392,9 @@ def test_no_bond_donor_sel(self, universe):
u.add_TopologyAttr('mass', [15.999, 1.008, 1.008] * n_residues)
u.add_TopologyAttr('charge', [-1.04, 0.52, 0.52] * n_residues)
h = HydrogenBondAnalysis(u, **kwargs)
pairs = h._get_dh_pairs()
donors = u.select_atoms(h.guess_donors())

assert len(pairs) == 2
assert len(donors) == 2

def test_first_hbond(self, hydrogen_bonds):
assert len(hydrogen_bonds.results.hbonds) == 2
Expand Down

0 comments on commit bd95900

Please sign in to comment.