Repository navigation
Fix #5505: Incorrect masking of hydrogen bond donors in DSSP #5506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+180
−45
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7289187
improve constructing DSSP
BradyAJohnston e4a8c13
fix for chain starts issue
BradyAJohnston 59b50f0
comments
BradyAJohnston c4a4c9c
moved CHANGELOG entry to 2.12.0
orbeckst f3de35d
Update CHANGELOG: remove spurious entry from lower PR in stack
orbeckst 3ce6c82
Update package/MDAnalysis/analysis/dssp/dssp.py
orbeckst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,11 @@ | |
| import numpy as np | ||
| import pytest | ||
| from MDAnalysis.analysis.dssp import DSSP, assign, translate | ||
| from MDAnalysis.analysis.dssp.pydssp_numpy import ( | ||
| _get_hydrogen_atom_position, | ||
| get_hbond_map, | ||
| ) | ||
| from MDAnalysis.coordinates.memory import MemoryReader | ||
|
|
||
| from MDAnalysisTests.datafiles import DSSP as DSSP_FOLDER | ||
| from MDAnalysisTests.datafiles import TPR, XTC | ||
|
|
@@ -62,9 +67,11 @@ def test_donor_mask_proline_indices(): | |
| resnames = u.select_atoms("protein").residues.resnames | ||
| is_pro = resnames == "PRO" | ||
|
|
||
| # donor_mask should be False at proline positions and True at non-proline positions | ||
| # donor_mask should be False at proline positions and True at non-proline | ||
| # positions, except the first residue (a chain start) | ||
| assert np.all(~dssp._donor_mask[is_pro]) | ||
| assert np.all(dssp._donor_mask[~is_pro]) | ||
| assert np.all(dssp._donor_mask[1:][~is_pro[1:]]) | ||
| assert not dssp._donor_mask[0] | ||
|
|
||
|
|
||
| def test_donor_mask_none(): | ||
|
|
@@ -171,3 +178,90 @@ def test_insufficient_residues_raises_error(client_DSSP): | |
| dssp = DSSP(res6) | ||
| result = dssp.run(**client_DSSP, stop=1) | ||
| assert result.results.dssp.shape[1] == 6 | ||
|
|
||
|
|
||
| def _hydrogens_per_residue(ag, hydrogen_name): | ||
| """hydrogens selected one residue at a time (the selection DSSP made | ||
| before it was vectorised): the reference for the selection now""" | ||
| return [ | ||
| res.atoms.select_atoms(f"name {hydrogen_name}") | ||
| for res in ag.select_atoms("protein").residues | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "hydrogen_name", ["H HN HT1 HT2 HT3", "H HN H1", "H*"] | ||
| ) | ||
| @pytest.mark.parametrize("selection", ["all", "protein and not name H HN"]) | ||
| def test_hydrogens_match_per_residue_selection(hydrogen_name, selection): | ||
| # without H and HN in the selection, the hydrogens are still looked up | ||
| # among all atoms of each residue | ||
| ag = mda.Universe(TPR, XTC).select_atoms(selection) | ||
| dssp = DSSP(ag, hydrogen_name=hydrogen_name) | ||
| expected = _hydrogens_per_residue(ag, hydrogen_name) | ||
| np.testing.assert_equal(dssp._has_hydrogen, [bool(h) for h in expected]) | ||
| np.testing.assert_equal( | ||
| dssp._first_hydrogens.ix, [h.ix[0] for h in expected if h] | ||
| ) | ||
|
|
||
|
|
||
| def test_coords_with_hydrogens_match_per_residue_lookup(): | ||
| # residues without a hydrogen (here the N-terminal MET, whose hydrogens | ||
| # are H1-H3, and prolines) take the guessed hydrogen of the same index | ||
| u = mda.Universe(TPR, XTC) | ||
| coords = DSSP(u, guess_hydrogens=False)._get_coords() | ||
| guessed = _get_hydrogen_atom_position(coords[:, :4]) | ||
| hydrogens = _hydrogens_per_residue(u.atoms, "H HN HT1 HT2 HT3") | ||
| assert not all(hydrogens) | ||
| expected = [ | ||
| h.positions[0] if h else guessed[k] for k, h in enumerate(hydrogens) | ||
| ] | ||
| np.testing.assert_equal(coords[:, 4], expected) | ||
|
|
||
|
|
||
| def _protein_copies(copies, gap=100.0): | ||
| """``copies`` of the TPR/XTC protein as one system without a box, each | ||
| shifted by ``gap`` A along x, with all frames of the trajectory (made | ||
| whole: the protein is split across the box)""" | ||
| protein = mda.Universe(TPR, XTC).select_atoms("protein") | ||
| u = mda.Merge(*[protein] * copies) | ||
| frames = np.array([protein.unwrap() for _ in protein.universe.trajectory]) | ||
| coords = np.concatenate([frames] * copies, axis=1) | ||
| coords[:, :, 0] += np.repeat(np.arange(copies) * gap, protein.n_atoms) | ||
| u.load_new(coords.astype(np.float32), format=MemoryReader) | ||
| return u | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("guess_hydrogens", [True, False]) | ||
| def test_multiple_chains(guess_hydrogens, client_DSSP): | ||
| # the N-terminal residue of the second chain (MET, with hydrogens H1-H3) | ||
| # used to fail the check of one hydrogen per residue | ||
| single = DSSP(_protein_copies(1), guess_hydrogens=guess_hydrogens) | ||
| double = DSSP(_protein_copies(2), guess_hydrogens=guess_hydrogens) | ||
| n_residues = len(single._chain_start) | ||
| np.testing.assert_equal( | ||
| np.flatnonzero(double._chain_start), [0, n_residues] | ||
| ) | ||
| expected = single.run(**client_DSSP).results.dssp | ||
| result = double.run(**client_DSSP).results.dssp | ||
| np.testing.assert_equal(result[:, :n_residues], expected) | ||
| np.testing.assert_equal(result[:, n_residues:], expected) | ||
|
Comment on lines
+247
to
+248
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this test that both copies give the same results fail before this fix? |
||
|
|
||
|
|
||
| @pytest.mark.parametrize("guess_hydrogens", [True, False]) | ||
| def test_chain_breaks_do_not_donate(guess_hydrogens): | ||
| # residues after a gap have no peptide bond to the residue before them, | ||
| # so they start a chain and are no hydrogen-bond donors | ||
| protein = mda.Universe(TPR, XTC).select_atoms("protein") | ||
| after_gaps = [30, 80, 133] | ||
| keep = np.setdiff1d( | ||
| np.arange(protein.n_residues), | ||
| np.concatenate([np.arange(r - 3, r) for r in after_gaps]), | ||
| ) | ||
| dssp = DSSP(protein.residues[keep].atoms, guess_hydrogens=guess_hydrogens) | ||
| starts = [0] + [int(np.flatnonzero(keep == r)[0]) for r in after_gaps] | ||
| np.testing.assert_equal(np.flatnonzero(dssp._chain_start), starts) | ||
| assert not dssp._donor_mask[starts].any() | ||
| hbond_map = get_hbond_map(dssp._get_coords(), donor_mask=dssp._donor_mask) | ||
| # rows: donor residues (NH) | ||
| assert not hbond_map[starts].any() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With definition of self._chain_start it makes sense to now not exclude the initial residue anymore. ✅