forked from biopython/biopython
/
test_PDBexposure.py
170 lines (140 loc) · 7 KB
/
test_PDBexposure.py
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Copyright 2009 by Peter Cock. All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license. Please see the LICENSE file that should have been included
# as part of this package.
try :
import numpy
except ImportError :
from Bio import MissingExternalDependencyError
raise MissingExternalDependencyError(\
"Install NumPy if you want to use Bio.PDB.")
import os
import unittest
from Bio import PDB
import logging
import pdb
class PDB_AStructureCase(unittest.TestCase):
"""
test the a_structure.pdb file
To create other use cases on PDB.Exposure, you can subclass this test case,
and change the known values below accordingly.
For example:
class PDB_OtherPDBExposureCase(PDB_AStructureCase):
residue_number = 100
known_residues = {0: 'ARG', ....
...
# TODO: derive all test cases from a metaclass instead of this one.
"""
residue_number = 86
known_residues = {0: 'CYS', 1: 'ARG', 2: 'CYS', 3: 'GLY',
-3: 'TYR', -2: 'ARG', -1: 'CYS'}
pdb_filename = os.path.join("PDB", "a_structure.pdb")
structure_type = 'X' # parameter for PDBParser.get_structure
restrict_to_chain = 'A'
radius = 13.0
expected_values = {'HSExposureCA': {
0: {},
1: {},
2: {'EXP_CB_PCB_ANGLE': 0.81250973133184456, 'EXP_HSE_A_D': 14, 'EXP_HSE_A_U': 14},
3: {'EXP_CB_PCB_ANGLE': 1.3383737, 'EXP_HSE_A_D': 13, 'EXP_HSE_A_U': 16},
-1: {},
-2: {'EXP_CB_PCB_ANGLE': 0.77124014456278489, 'EXP_HSE_A_D': 24, 'EXP_HSE_A_U': 24},
-3: {'EXP_CB_PCB_ANGLE': 0.35424831250657834, 'EXP_HSE_A_D': 27, 'EXP_HSE_A_U': 15},
},
'HSExposureCB': {
0: {},
1: {'EXP_HSE_B_D': 20, 'EXP_HSE_B_U': 5},
2: {'EXP_HSE_B_D': 10, 'EXP_HSE_B_U': 18},
3: {'EXP_HSE_B_D': 7, 'EXP_HSE_B_U': 22},
-1: {'EXP_HSE_B_D': 23, 'EXP_HSE_B_U': 15},
-2: { 'EXP_HSE_B_D': 14, 'EXP_HSE_B_U': 34},
-3: {'EXP_HSE_B_D': 24, 'EXP_HSE_B_U': 18},
},
'HSExposureCN': {
0: {},
1: {'EXP_CN': 25},
2: {'EXP_CN': 28},
3: {'EXP_CN': 29},
-1: {'EXP_CN': 38},
-2: {'EXP_CN': 48},
-3: {'EXP_CN': 42},
}}
_setup = False
# @classmethod # uncomment this class and substitute it to setUp if you want global fixtures.
# def setUpAll(cls):
#
# assert os.path.isfile(cls.pdb_filename)
# structure = PDB.PDBParser(PERMISSIVE=True).get_structure(cls.structure_type,
# cls.pdb_filename)
# cls.model = structure[1]
#
# #Look at first chain only
# cls.residues = list(cls.model[cls.restrict_to_chain].child_list)
# cls._setup = True
# @classmethod
def setUp(self):
"these instructions will be executed before every test in this TestCase"
assert os.path.isfile(self.pdb_filename)
structure = PDB.PDBParser(PERMISSIVE=True).get_structure(self.structure_type,
self.pdb_filename)
self.model = structure[1]
#Look at first chain only
self.residues = list(self.model[self.restrict_to_chain].child_list)
self._setup = True
# if self._setup is False:
# self.setUpAll()
def tearDown(self):
"""cleanup of every residue.xtra"""
pdb.set_trace()
for residue in self.residues:
residue.xtra = {}
def test_TotalResidueNumber(self):
self.assertEqual(self.residue_number, len(self.residues))
def test_knowResidueNames(self):
for residue_id in self.known_residues:
self.assertEqual(self.residues[residue_id].get_resname(),
self.known_residues[residue_id])
def test_HSExposureCAKnownValues(self) :
hse = PDB.HSExposureCA(self.model, self.radius)
residues = self.residues
for residue_id in self.expected_values['HSExposureCA']:
expected_values = self.expected_values['HSExposureCA'][residue_id]
current_residue = self.residues[residue_id]
self.assertEqual(len(expected_values), len(current_residue.xtra))
if len(current_residue.xtra) != 0:
# logging.debug("current residue.xtra is not empty")
self.assertAlmostEqual(expected_values["EXP_CB_PCB_ANGLE"],
current_residue.xtra["EXP_CB_PCB_ANGLE"]),
self.assertEqual(expected_values["EXP_HSE_A_D"],
current_residue.xtra["EXP_HSE_A_D"])
self.assertEqual(expected_values["EXP_HSE_A_U"],
current_residue.xtra["EXP_HSE_A_U"])
def test_HSExposureCBKnownValues(self) :
hse = PDB.HSExposureCB(self.model, self.radius)
residues = self.residues
for residue_id in self.expected_values['HSExposureCB']:
expected_values = self.expected_values['HSExposureCB'][residue_id]
current_residue = self.residues[residue_id]
self.assertEqual(len(expected_values), len(current_residue.xtra))
if len(current_residue.xtra) != 0:
# logging.debug("current residue.xtra is not empty")
self.assertAlmostEqual(expected_values["EXP_HSE_B_D"],
current_residue.xtra["EXP_HSE_B_D"])
self.assertEqual(expected_values["EXP_HSE_B_U"],
current_residue.xtra["EXP_HSE_B_U"])
def test_ExposureCNKnownValues(self) :
logging.debug('CN test')
hse = PDB.ExposureCN(self.model, self.radius)
residues = self.residues
for residue_id in self.expected_values['HSExposureCN']:
expected_values = self.expected_values['HSExposureCN'][residue_id]
current_residue = self.residues[residue_id]
logging.debug(current_residue.xtra)
self.assertEqual(len(expected_values), len(current_residue.xtra))
if len(current_residue.xtra) != 0:
# logging.debug("current residue.xtra is not empty")
self.assertAlmostEqual(expected_values["EXP_CN"],
current_residue.xtra["EXP_CN"])
if __name__ == "__main__" :
runner = unittest.TextTestRunner(verbosity = 2)
unittest.main(testRunner=runner)