Skip to content

Commit

Permalink
Fix code formatting and add coverage exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
marinegor committed Feb 23, 2024
1 parent c0fdd99 commit 118be27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
35 changes: 13 additions & 22 deletions package/MDAnalysis/analysis/dssp/dssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,35 +233,26 @@ class DSSP(AnalysisBase):
For example, you can assign secondary structure for a single PDB file:
.. code-block:: python
from MDAnalysis.analysis.dssp import DSSP
from MDAnalysisTests.datafiles import PDB
import MDAnalysis as mda
u = mda.Universe(PDB)
run = DSSP(u).run()
print("".join(run.results.dssp[0][:20]))
Running this code produces ::
>>> from MDAnalysis.analysis.dssp import DSSP
>>> from MDAnalysisTests.datafiles import PDB
>>> import MDAnalysis as mda
>>> u = mda.Universe(PDB)
>>> run = DSSP(u).run()
>>> print("".join(run.results.dssp[0][:20]))
'--EEEEE-----HHHHHHHH'
Also, per-frame dssp assignment allows you to build average
secondary structure -- ``DSSP.results.dssp_ndarray`` holds
(n_frames, n_residues, 3) shape ndarray with one-hot encoding of
loop, helix and sheet, respectively:
.. code-block:: python
from MDAnalysis.analysis.dssp import translate
u = mda.Universe(...)
long_run = DSSP(u).run()
mean_secondary_structure = translate(
long_run.results.dssp_ndarray.mean(axis=0)
)
print(''.join(mean_secondary_structure)[:20])
Running this code produces ::
>>> from MDAnalysis.analysis.dssp import translate
>>> u = mda.Universe(...)
>>> long_run = DSSP(u).run()
>>> mean_secondary_structure = translate(
>>> long_run.results.dssp_ndarray.mean(axis=0)
>>> )
>>> print(''.join(mean_secondary_structure)[:20])
'---HHHHHHHH---------'
.. versionadded:: 2.8.0
Expand Down
10 changes: 5 additions & 5 deletions package/MDAnalysis/analysis/dssp/pydssp_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
DEFAULT_MARGIN = 1.0


def _upsample(a: np.ndarray, window: int) -> np.ndarray:
def _upsample(a: np.ndarray, window: int) -> np.ndarray: # pragma: no cover
"""Performs array upsampling with given window along given axis.
Example
Expand Down Expand Up @@ -63,14 +63,14 @@ def _upsample(a: np.ndarray, window: int) -> np.ndarray:
return _unfold(_unfold(a, window, -2), window, -2)


def _unfold(a: np.ndarray, window: int, axis: int):
def _unfold(a: np.ndarray, window: int, axis: int): # pragma: no cover
"Helper function for 2D array upsampling"
idx = np.arange(window)[:, None] + np.arange(a.shape[axis] - window + 1)[None, :]
unfolded = np.take(a, idx, axis=axis)
return np.moveaxis(unfolded, axis - 1, -1)


def _get_hydrogen_atom_position(coord: np.ndarray) -> np.ndarray:
def _get_hydrogen_atom_position(coord: np.ndarray) -> np.ndarray: # pragma: no cover
"""Fills in hydrogen atoms positions if they are abscent, under the
assumption that C-N-H and H-N-CA angles are perfect 120 degrees,
and N-H bond length is 1.01 A.
Expand Down Expand Up @@ -118,7 +118,7 @@ def get_hbond_map(
cutoff: float = DEFAULT_CUTOFF,
margin: float = DEFAULT_MARGIN,
return_e: bool = False,
) -> np.ndarray:
) -> np.ndarray: # pragma: no cover
"""Returns hydrogen bond map
Parameters
Expand Down Expand Up @@ -200,7 +200,7 @@ def get_hbond_map(
return hbond_map


def assign(coord: np.ndarray) -> np.ndarray:
def assign(coord: np.ndarray) -> np.ndarray: # pragma: no cover
"""Assigns secondary structure for a given coordinate array,
either with or without assigned hydrogens
Expand Down

0 comments on commit 118be27

Please sign in to comment.