File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
testsuite/MDAnalysisTests/analysis Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ The rules for this file:
2020 * 2.11.0
2121
2222Fixes
23+ * DSSP now explicitly checks for a minimum of 6 residues and raises a clear
24+ error message, unlike the previous behavior where it would fail with an
25+ incomprehensible broadcasting error at execution time (Issue #5046, PR #5163)
2326 * Fixes the verbose=False in EinsteinMSD, and only shows progress bar when
2427 verbose=True (Issue #5144, PR #5153)
2528 * Fix incorrect assignment of topology_format to format (and vice versa)
Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ class DSSP(AnalysisBase):
210210 Parameters
211211 ----------
212212 atoms : Union[Universe, AtomGroup]
213- input Universe or AtomGroup. In both cases, only protein residues will
213+ input Universe or AtomGroup with at least 6 protein residues . In both cases, only protein residues will
214214 be chosen prior to the analysis via `select_atoms('protein')`.
215215 Heavy atoms of the protein are then selected by name
216216 `heavyatom_names`, and hydrogens are selected by name
@@ -239,6 +239,8 @@ class DSSP(AnalysisBase):
239239
240240 Raises
241241 ------
242+ ValueError
243+ If fewer than 6 residues are provided in the selection.
242244 ValueError
243245 if ``guess_hydrogens`` is True but some non-PRO hydrogens are missing.
244246
@@ -357,6 +359,12 @@ def __init__(
357359 )
358360 )
359361
362+ if len (ag .residues ) < 6 :
363+ raise ValueError (
364+ "DSSP requires at least 6 residues for secondary structure analysis, "
365+ f"but only { len (ag .residues )} residue(s) were provided in the selection."
366+ )
367+
360368 def _prepare (self ):
361369 self .results .dssp_ndarray = []
362370
Original file line number Diff line number Diff line change @@ -89,3 +89,23 @@ def test_exception_raises_with_atom_index(pdb_filename, client_DSSP):
8989 match = "Residue <Residue SER, 298> contains*" ,
9090 ):
9191 DSSP (u , guess_hydrogens = False ).run (** client_DSSP )
92+
93+
94+ def test_insufficient_residues_raises_error (client_DSSP ):
95+ """Test that DSSP raises clear error for insufficient residues."""
96+ u = mda .Universe (TPR , XTC )
97+
98+ protein = u .select_atoms ("protein" )
99+
100+ with pytest .raises (ValueError , match = "DSSP requires at least 6 residues" ):
101+ res2 = protein .residues [:2 ].atoms
102+ DSSP (res2 )
103+
104+ with pytest .raises (ValueError , match = "DSSP requires at least 6 residues" ):
105+ res4 = protein .residues [:4 ].atoms
106+ DSSP (res4 )
107+
108+ res6 = protein .residues [:6 ].atoms
109+ dssp = DSSP (res6 )
110+ result = dssp .run (** client_DSSP , stop = 1 )
111+ assert result .results .dssp .shape [1 ] == 6
You can’t perform that action at this time.
0 commit comments