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