forked from MDAnalysis/mdanalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dssp.py
More file actions
111 lines (85 loc) · 3.61 KB
/
Copy pathtest_dssp.py
File metadata and controls
111 lines (85 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import glob
import MDAnalysis as mda
import pytest
from MDAnalysis.analysis.dssp import DSSP, translate
from MDAnalysisTests.datafiles import DSSP as DSSP_FOLDER
from MDAnalysisTests.datafiles import TPR, XTC
# Files that match glob pattern '????.pdb.gz' and matching '????.pdb.dssp' files,
# containing the secondary structure assignment string, will be tested automatically.
@pytest.mark.parametrize(
"pdb_filename", glob.glob(f"{DSSP_FOLDER}/?????.pdb.gz")
)
def test_file_guess_hydrogens(pdb_filename, client_DSSP):
u = mda.Universe(pdb_filename)
with open(f"{pdb_filename.rstrip('.gz')}.dssp", "r") as fin:
correct_answ = fin.read().strip().split()[0]
run = DSSP(u, guess_hydrogens=True).run(**client_DSSP)
answ = "".join(run.results.dssp[0])
assert answ == correct_answ
def test_trajectory(client_DSSP):
u = mda.Universe(TPR, XTC).select_atoms("protein").universe
run = DSSP(u).run(**client_DSSP, stop=10)
first_frame = "".join(run.results.dssp[0])
last_frame = "".join(run.results.dssp[-1])
avg_frame = "".join(translate(run.results.dssp_ndarray.mean(axis=0)))
assert (
first_frame[:10] != last_frame[:10] == avg_frame[:10] == "-EEEEEE---"
)
def test_atomgroup(client_DSSP):
protein = mda.Universe(TPR, XTC).select_atoms("protein")
run = DSSP(protein).run(**client_DSSP, stop=10)
first_frame = "".join(run.results.dssp[0])
last_frame = "".join(run.results.dssp[-1])
avg_frame = "".join(translate(run.results.dssp_ndarray.mean(axis=0)))
assert (
first_frame[:10] != last_frame[:10] == avg_frame[:10] == "-EEEEEE---"
)
def test_trajectory_with_hydrogens(client_DSSP):
u = mda.Universe(TPR, XTC).select_atoms("protein").universe
run = DSSP(u, guess_hydrogens=False).run(**client_DSSP, stop=10)
first_frame = "".join(run.results.dssp[0])
last_frame = "".join(run.results.dssp[-1])
avg_frame = "".join(translate(run.results.dssp_ndarray.mean(axis=0)))
assert (
first_frame[:10] == last_frame[:10] == avg_frame[:10] == "-EEEEEE---"
)
@pytest.mark.parametrize(
"pdb_filename", glob.glob(f"{DSSP_FOLDER}/2xdgA.pdb.gz")
)
def test_trajectory_without_hydrogen_fails(pdb_filename, client_DSSP):
u = mda.Universe(pdb_filename)
with pytest.raises(ValueError):
DSSP(u, guess_hydrogens=False).run(**client_DSSP)
@pytest.mark.parametrize(
"pdb_filename", glob.glob(f"{DSSP_FOLDER}/1mr1D_failing.pdb.gz")
)
def test_trajectory_with_uneven_number_of_atoms_fails(
pdb_filename, client_DSSP
):
u = mda.Universe(pdb_filename)
with pytest.raises(ValueError):
DSSP(u, guess_hydrogens=True).run(**client_DSSP)
@pytest.mark.parametrize(
"pdb_filename", glob.glob(f"{DSSP_FOLDER}/wrong_hydrogens.pdb.gz")
)
def test_exception_raises_with_atom_index(pdb_filename, client_DSSP):
u = mda.Universe(pdb_filename)
with pytest.raises(
ValueError,
match="Residue <Residue SER, 298> contains*",
):
DSSP(u, guess_hydrogens=False).run(**client_DSSP)
def test_insufficient_residues_raises_error(client_DSSP):
"""Test that DSSP raises clear error for insufficient residues."""
u = mda.Universe(TPR, XTC)
protein = u.select_atoms("protein")
with pytest.raises(ValueError, match="DSSP requires at least 6 residues"):
res2 = protein.residues[:2].atoms
DSSP(res2)
with pytest.raises(ValueError, match="DSSP requires at least 6 residues"):
res4 = protein.residues[:4].atoms
DSSP(res4)
res6 = protein.residues[:6].atoms
dssp = DSSP(res6)
result = dssp.run(**client_DSSP, stop=1)
assert result.results.dssp.shape[1] == 6