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
|
import pytest
import glob
import MDAnalysis as mda
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---"
)
protein = mda.Universe(TPR, XTC).select_atoms("protein")
run = DSSP(protein).run(**client_DSSP, stop=10)
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)
|