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 = sorted(res.atoms.keys())
94 self.assertEqual(atom_keys, ['1HA', '2HA', 'C', 'CA', 'H', 'N', 'O'])
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 atom_keys = sorted(res.atoms.keys())
119 self.assertEqual(atom_keys, ['1HA', '2HA', 'C', 'CA', 'H', 'N', 'O'])
120
121
123 """Test the Scientific_data.__residue_loop() method with a non-matching selection object."""
124
125
126 self.data.load_pdb(self.test_pdb_path)
127
128
129 sel_obj = Selection(':XXX')
130
131
132 res_count = 0
133 for res, res_num, res_name, res_index in self.data._Scientific_data__residue_loop(self.data.structural_data[0].mol[0], sel_obj):
134 res_count = res_count + 1
135
136
137 self.assertEqual(res_count, 0)
138
139
141 """Test the Scientific_data.atom_loop() method."""
142
143
144 self.data.load_pdb(self.test_pdb_path)
145
146
147 atom_count = 0
148 for atom in self.data.atom_loop():
149 atom_count = atom_count + 1
150
151
152 self.assertEqual(atom_count, 150)
153
154
156 """Test the Scientific_data.atom_loop() method with the '#XXX' mol selection."""
157
158
159 self.data.load_pdb(self.test_pdb_path)
160
161
162 atom_count = 0
163 for atom in self.data.atom_loop(atom_id='#XXX'):
164 atom_count = atom_count + 1
165
166
167 self.assertEqual(atom_count, 0)
168
169
171 """Test the Scientific_data.atom_loop() method with the ':8' res selection."""
172
173
174 self.data.load_pdb(self.test_pdb_path)
175
176
177 atom_count = 0
178 for res_num, res_name in self.data.atom_loop(atom_id=':8', res_num_flag=True, res_name_flag=True):
179
180 self.assertEqual(res_num, 8)
181 self.assertEqual(res_name, 'SER')
182
183
184 atom_count = atom_count + 1
185
186
187 self.assertEqual(atom_count, 11)
188
189
191 """Test the Scientific_data.atom_loop() method with the ':PRO' res selection."""
192
193
194 self.data.load_pdb(self.test_pdb_path)
195
196
197 atom_count = 0
198 for atom in self.data.atom_loop(atom_id=':PRO', res_name_flag=True):
199
200 self.assertEqual(atom, 'PRO')
201
202
203 atom_count = atom_count + 1
204
205
206 self.assertEqual(atom_count, 42)
207
208
210 """Test the Scientific_data.atom_loop() method with the '@CA' spin selection."""
211
212
213 self.data.load_pdb(self.test_pdb_path)
214
215
216 atom_count = 0
217 for spin_name in self.data.atom_loop(atom_id='@CA', atom_name_flag=True):
218
219 self.assertEqual(spin_name, 'CA')
220
221
222 atom_count = atom_count + 1
223
224
225 self.assertEqual(atom_count, 12)
226
227
229 """Test the Scientific_data.atom_loop() method with the '@163' spin selection."""
230
231
232 self.data.load_pdb(self.test_pdb_path)
233
234
235 atom_count = 0
236 for model_num, mol_name, res_num, res_name, spin_num, spin_name, element, pos in self.data.atom_loop(atom_id='@140', 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):
237
238 self.assertEqual(model_num, 1)
239 self.assertEqual(mol_name, 'Ap4Aase_res1-12_mol1')
240 self.assertEqual(res_num, 11)
241 self.assertEqual(res_name, 'GLU')
242 self.assertEqual(spin_num, 140)
243 self.assertEqual(spin_name, 'OE1')
244 self.assertEqual(element, 'O')
245 self.assertEqual(pos[0], float('10.055'))
246 self.assertEqual(pos[1], float('-2.74'))
247 self.assertEqual(pos[2], float('-13.193'))
248
249
250 atom_count = atom_count + 1
251
252
253 self.assertEqual(atom_count, 1)
254
255
257 """Load a PDB file using Scientific_data.load_pdb()."""
258
259
260 self.data.load_pdb(self.test_pdb_path)
261
262
263 model = self.data.structural_data[0]
264 mol = model.mol[0]
265
266
267 self.assertEqual(len(self.data.structural_data), 1)
268 self.assertEqual(len(model.mol), 1)
269 self.assertEqual(model.num, 1)
270 self.assertEqual(mol.mol_name, self.test_pdb_root+'_mol1')
271 self.assertEqual(mol.file_name, self.test_pdb_file_name)
272 self.assertEqual(mol.file_path, self.test_pdb_dir)
273 self.assertEqual(mol.file_model, 1)
274 self.assertEqual(mol.file_mol_num, 1)
275