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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
"""
Run Bio.PDB.Selection tests.
Currently only tests unfold_entities.
"""
import unittest
from Bio.PDB import PDBParser
from Bio.PDB.PDBExceptions import PDBException
from Bio.PDB.Residue import Residue
from Bio.PDB.Selection import unfold_entities
def res_full_id(res: Residue):
"""Return full residue identifier for thoroughly comparing residues."""
return (res.get_resname(), *res.get_id())
class UnfoldEntitiesTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.parser = PDBParser(PERMISSIVE=True)
cls.structure = cls.parser.get_structure("scr", "PDB/1A8O.pdb")
def test_from_structure_level(self):
"""Unfold from highest level to all levels."""
struct_unfold = unfold_entities(self.structure, "S")[0]
for res1, res2 in zip(
self.structure.get_residues(), struct_unfold.get_residues()
):
assert res_full_id(res1) == res_full_id(res2)
model_unfold = unfold_entities(self.structure, "M")[0]
for res1, res2 in zip(
self.structure.get_residues(), model_unfold.get_residues()
):
assert res_full_id(res1) == res_full_id(res2)
residue_unfold = unfold_entities(self.structure, "R")
for res1, res2 in zip(self.structure.get_residues(), residue_unfold):
assert res_full_id(res1) == res_full_id(res2)
atom_unfold = unfold_entities(self.structure, "A")
for at1, at2 in zip(self.structure.get_atoms(), atom_unfold):
assert at1 is at2
def test_from_model_level(self):
"""Unfold from model to all levels."""
structure_models = list(self.structure.get_models())
struct_unfold = unfold_entities(structure_models, "S")[0]
for res1, res2 in zip(
self.structure.get_residues(), struct_unfold.get_residues()
):
assert res_full_id(res1) == res_full_id(res2)
model_unfold = unfold_entities(structure_models, "M")[0]
for res1, res2 in zip(
self.structure.get_residues(), model_unfold.get_residues()
):
assert res_full_id(res1) == res_full_id(res2)
residue_unfold = unfold_entities(structure_models, "R")
for res1, res2 in zip(self.structure.get_residues(), residue_unfold):
assert res_full_id(res1) == res_full_id(res2)
atom_unfold = unfold_entities(structure_models, "A")
for at1, at2 in zip(self.structure.get_atoms(), atom_unfold):
assert at1 is at2
def test_from_chain_level(self):
"""Unfold from chain level to all levels."""
structure_chains = list(self.structure.get_chains())
struct_unfold = unfold_entities(structure_chains, "S")[0]
for res1, res2 in zip(
self.structure.get_residues(), struct_unfold.get_residues()
):
assert res_full_id(res1) == res_full_id(res2)
model_unfold = unfold_entities(structure_chains, "M")[0]
for res1, res2 in zip(
self.structure.get_residues(), model_unfold.get_residues()
):
assert res_full_id(res1) == res_full_id(res2)
residue_unfold = unfold_entities(structure_chains, "R")
for res1, res2 in zip(self.structure.get_residues(), residue_unfold):
assert res_full_id(res1) == res_full_id(res2)
atom_unfold = unfold_entities(structure_chains, "A")
for at1, at2 in zip(self.structure.get_atoms(), atom_unfold):
assert at1 is at2
def test_from_residue_level(self):
"""Unfold from chain level to all levels."""
structure_residues = list(self.structure.get_residues())
struct_unfold = unfold_entities(structure_residues, "S")[0]
for res1, res2 in zip(structure_residues, struct_unfold.get_residues()):
assert res_full_id(res1) == res_full_id(res2)
model_unfold = unfold_entities(structure_residues, "M")[0]
for res1, res2 in zip(structure_residues, model_unfold.get_residues()):
assert res_full_id(res1) == res_full_id(res2)
residue_unfold = unfold_entities(structure_residues, "R")
for res1, res2 in zip(structure_residues, residue_unfold):
assert res_full_id(res1) == res_full_id(res2)
atom_unfold = unfold_entities(structure_residues, "A")
for at1, at2 in zip(self.structure.get_atoms(), atom_unfold):
assert at1 is at2
def test_from_atom_level(self):
"""Unfold from lowest level to all levels."""
structure_atoms = list(self.structure.get_atoms())
struct_unfold = unfold_entities(structure_atoms, "S")[0]
for res1, res2 in zip(
self.structure.get_residues(), struct_unfold.get_residues()
):
assert res_full_id(res1) == res_full_id(res2)
model_unfold = unfold_entities(structure_atoms, "M")[0]
for res1, res2 in zip(
self.structure.get_residues(), model_unfold.get_residues()
):
assert res_full_id(res1) == res_full_id(res2)
residue_unfold = unfold_entities(structure_atoms, "R")
for res1, res2 in zip(self.structure.get_residues(), residue_unfold):
assert res_full_id(res1) == res_full_id(res2)
atom_unfold = unfold_entities(structure_atoms, "A")
for at1, at2 in zip(structure_atoms, atom_unfold):
assert at1 is at2
def test_invalid_level(self):
with self.assertRaises(PDBException):
unfold_entities(self.structure, "Z")
def test_entities_not_homogenous(self):
structure_atom = next(self.structure.get_atoms())
structure_chain = next(self.structure.get_chains())
with self.assertRaises(PDBException):
unfold_entities([structure_atom, structure_chain], "A")
if __name__ == "__main__":
runner = unittest.TextTestRunner(verbosity=2)
unittest.main(testRunner=runner)
|