1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from os import path, sep
24 import sys
25
26
27 from data import Relax_data_store; ds = Relax_data_store()
28 import dep_check
29 from generic_fns.mol_res_spin import Selection
30 from generic_fns.reset import reset
31 from generic_fns.structure.scientific import Scientific_data
32 from relax_io import file_root
33 from status import Status; status = Status()
34 from test_suite.unit_tests.base_classes import UnitTestCase
35
36
38 """Unit tests for the functions of the 'generic_fns.structure.scientific' module."""
39
40 - def __init__(self, methodName='runTest'):
41 """Skip scientific Python tests if not installed.
42
43 @keyword methodName: The name of the test.
44 @type methodName: str
45 """
46
47
48 super(Test_scientific, self).__init__(methodName)
49
50
52 """Set up for all the Scientific Python PDB structural object unit tests."""
53
54
55 self.test_pdb_path = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'structures'+sep+'Ap4Aase_res1-12.pdb'
56 expanded = path.split(self.test_pdb_path)
57 self.test_pdb_dir = expanded[0]
58 self.test_pdb_file_name = expanded[1]
59 self.test_pdb_root = file_root(self.test_pdb_path)
60
61
62 self.data = Scientific_data()
63
64
66 """Reset the relax data storage object."""
67
68
69 del self.data
70
71
72 reset()
73
74
76 """Test the private Scientific_data.__residue_loop() method."""
77
78
79 self.data.load_pdb(self.test_pdb_path)
80
81
82 res_count = 0
83 for res, res_num, res_name, res_index in self.data._Scientific_data__residue_loop(self.data.structural_data[0].mol[0]):
84 res_count = res_count + 1
85
86
87 self.assertEqual(res_count, 12)
88
89
90 self.assertEqual(res_num, 12)
91 self.assertEqual(res_name, 'GLY')
92 self.assertEqual(len(res.atoms), 7)
93 atom_keys = list(res.atoms.keys())
94 atom_keys.sort()
95 self.assertEqual(atom_keys, ['1HA', '2HA', 'C', 'CA', 'H', 'N', 'O'])
96
97
99 """Test the private Scientific_data.__residue_loop() method with a selection object."""
100
101
102 self.data.load_pdb(self.test_pdb_path)
103
104
105 sel_obj = Selection('#Ap4Aase_res1-12_mol1')
106
107
108 res_count = 0
109 for res, res_num, res_name, res_index in self.data._Scientific_data__residue_loop(self.data.structural_data[0].mol[0], sel_obj):
110 res_count = res_count + 1
111
112
113 self.assertEqual(res_count, 12)
114
115
116 self.assertEqual(res_num, 12)
117 self.assertEqual(res_name, 'GLY')
118 self.assertEqual(len(res.atoms), 7)
119 atom_keys = list(res.atoms.keys())
120 atom_keys.sort()
121 self.assertEqual(atom_keys, ['1HA', '2HA', 'C', 'CA', 'H', 'N', 'O'])
122
123
125 """Test the Scientific_data.__residue_loop() method with a non-matching selection object."""
126
127
128 self.data.load_pdb(self.test_pdb_path)
129
130
131 sel_obj = Selection(':XXX')
132
133
134 res_count = 0
135 for res, res_num, res_name, res_index in self.data._Scientific_data__residue_loop(self.data.structural_data[0].mol[0], sel_obj):
136 res_count = res_count + 1
137
138
139 self.assertEqual(res_count, 0)
140
141
143 """Test the Scientific_data.atom_loop() method."""
144
145
146 self.data.load_pdb(self.test_pdb_path)
147
148
149 atom_count = 0
150 for atom in self.data.atom_loop():
151 atom_count = atom_count + 1
152
153
154 self.assertEqual(atom_count, 150)
155
156
158 """Test the Scientific_data.atom_loop() method with the '#XXX' mol selection."""
159
160
161 self.data.load_pdb(self.test_pdb_path)
162
163
164 atom_count = 0
165 for atom in self.data.atom_loop(atom_id='#XXX'):
166 atom_count = atom_count + 1
167
168
169 self.assertEqual(atom_count, 0)
170
171
173 """Test the Scientific_data.atom_loop() method with the ':8' res selection."""
174
175
176 self.data.load_pdb(self.test_pdb_path)
177
178
179 atom_count = 0
180 for res_num, res_name in self.data.atom_loop(atom_id=':8', res_num_flag=True, res_name_flag=True):
181
182 self.assertEqual(res_num, 8)
183 self.assertEqual(res_name, 'SER')
184
185
186 atom_count = atom_count + 1
187
188
189 self.assertEqual(atom_count, 11)
190
191
193 """Test the Scientific_data.atom_loop() method with the ':PRO' res selection."""
194
195
196 self.data.load_pdb(self.test_pdb_path)
197
198
199 atom_count = 0
200 for atom in self.data.atom_loop(atom_id=':PRO', res_name_flag=True):
201
202 self.assertEqual(atom[0], 'PRO')
203
204
205 atom_count = atom_count + 1
206
207
208 self.assertEqual(atom_count, 42)
209
210
212 """Test the Scientific_data.atom_loop() method with the '@CA' spin selection."""
213
214
215 self.data.load_pdb(self.test_pdb_path)
216
217
218 atom_count = 0
219 for spin_name in self.data.atom_loop(atom_id='@CA', atom_name_flag=True):
220
221 self.assertEqual(spin_name[0], 'CA')
222
223
224 atom_count = atom_count + 1
225
226
227 self.assertEqual(atom_count, 12)
228
229
231 """Test the Scientific_data.atom_loop() method with the '@163' spin selection."""
232
233
234 self.data.load_pdb(self.test_pdb_path)
235
236
237 atom_count = 0
238 for model_num, mol_name, res_num, res_name, spin_num, spin_name, element, pos in self.data.atom_loop(atom_id='@163', model_num_flag=True, mol_name_flag=True, res_num_flag=True, res_name_flag=True, atom_num_flag=True, atom_name_flag=True, element_flag=True, pos_flag=True):
239
240 self.assertEqual(model_num, 1)
241 self.assertEqual(mol_name, 'Ap4Aase_res1-12_mol1')
242 self.assertEqual(res_num, 11)
243 self.assertEqual(res_name, 'GLU')
244 self.assertEqual(spin_num, 163)
245 self.assertEqual(spin_name, 'OE1')
246 self.assertEqual(element, 'O')
247 self.assertEqual(pos[0], float('10.055'))
248 self.assertEqual(pos[1], float('-2.74'))
249 self.assertEqual(pos[2], float('-13.193'))
250
251
252 atom_count = atom_count + 1
253
254
255 self.assertEqual(atom_count, 1)
256
257
259 """Load a PDB file using Scientific_data.load_pdb()."""
260
261
262 self.data.load_pdb(self.test_pdb_path)
263
264
265 model = self.data.structural_data[0]
266 mol = model.mol[0]
267
268
269 self.assertEqual(len(self.data.structural_data), 1)
270 self.assertEqual(len(model.mol), 1)
271 self.assertEqual(model.num, 1)
272 self.assertEqual(mol.mol_name, self.test_pdb_root+'_mol1')
273 self.assertEqual(mol.file_name, self.test_pdb_file_name)
274 self.assertEqual(mol.file_path, self.test_pdb_dir)
275 self.assertEqual(mol.file_model, 1)
276 self.assertEqual(mol.file_mol_num, 1)
277