Package test_suite :: Package unit_tests :: Package _generic_fns :: Package _structure :: Module test_scientific
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._generic_fns._structure.test_scientific

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2011 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from os import path, sep 
 24  import sys 
 25   
 26  # relax module imports. 
 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   
37 -class Test_scientific(UnitTestCase):
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 # Execute the base class method. 48 super(Test_scientific, self).__init__(methodName)
49 50
51 - def setUp(self):
52 """Set up for all the Scientific Python PDB structural object unit tests.""" 53 54 # The path to a PDB file. 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 # Instantiate the structural data object. 62 self.data = Scientific_data()
63 64
65 - def tearDown(self):
66 """Reset the relax data storage object.""" 67 68 # Delete the structural data object. 69 del self.data 70 71 # Reset relax. 72 reset()
73 74
75 - def test___residue_loop(self):
76 """Test the private Scientific_data.__residue_loop() method.""" 77 78 # Load the PDB file. 79 self.data.load_pdb(self.test_pdb_path) 80 81 # Loop over the residues. 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 # Test the number of residues looped over. 87 self.assertEqual(res_count, 12) 88 89 # Test the data of the last residue. 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']) # Sorted key comparison needed as key order is not preserved in Python 3.
96 97
99 """Test the private Scientific_data.__residue_loop() method with a selection object.""" 100 101 # Load the PDB file. 102 self.data.load_pdb(self.test_pdb_path) 103 104 # Create the selection object (which should match the residue name of None). 105 sel_obj = Selection('#Ap4Aase_res1-12_mol1') 106 107 # Loop over the residues. 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 # Test the number of residues looped over. 113 self.assertEqual(res_count, 12) 114 115 # Test the data of the last residue. 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']) # Sorted key comparison needed as key order is not preserved in Python 3.
122 123
125 """Test the Scientific_data.__residue_loop() method with a non-matching selection object.""" 126 127 # Load the PDB file. 128 self.data.load_pdb(self.test_pdb_path) 129 130 # Create the non-matching selection object. 131 sel_obj = Selection(':XXX') 132 133 # Loop over the residues. 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 # Test the number of residues looped over. 139 self.assertEqual(res_count, 0)
140 141
142 - def test_atom_loop(self):
143 """Test the Scientific_data.atom_loop() method.""" 144 145 # Load the PDB file. 146 self.data.load_pdb(self.test_pdb_path) 147 148 # Loop over the atoms. 149 atom_count = 0 150 for atom in self.data.atom_loop(): 151 atom_count = atom_count + 1 152 153 # Test the number of atoms looped over. 154 self.assertEqual(atom_count, 150)
155 156
158 """Test the Scientific_data.atom_loop() method with the '#XXX' mol selection.""" 159 160 # Load the PDB file. 161 self.data.load_pdb(self.test_pdb_path) 162 163 # Loop over the atoms. 164 atom_count = 0 165 for atom in self.data.atom_loop(atom_id='#XXX'): 166 atom_count = atom_count + 1 167 168 # Test the number of atoms looped over. 169 self.assertEqual(atom_count, 0)
170 171
173 """Test the Scientific_data.atom_loop() method with the ':8' res selection.""" 174 175 # Load the PDB file. 176 self.data.load_pdb(self.test_pdb_path) 177 178 # Loop over the atoms. 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 # Test the residue name and number. 182 self.assertEqual(res_num, 8) 183 self.assertEqual(res_name, 'SER') 184 185 # Increment the atom count. 186 atom_count = atom_count + 1 187 188 # Test the number of atoms looped over. 189 self.assertEqual(atom_count, 11)
190 191
193 """Test the Scientific_data.atom_loop() method with the ':PRO' res selection.""" 194 195 # Load the PDB file. 196 self.data.load_pdb(self.test_pdb_path) 197 198 # Loop over the atoms. 199 atom_count = 0 200 for atom in self.data.atom_loop(atom_id=':PRO', res_name_flag=True): 201 # Test the residue name. 202 self.assertEqual(atom[0], 'PRO') 203 204 # Increment the atom count. 205 atom_count = atom_count + 1 206 207 # Test the number of atoms looped over. 208 self.assertEqual(atom_count, 42)
209 210
212 """Test the Scientific_data.atom_loop() method with the '@CA' spin selection.""" 213 214 # Load the PDB file. 215 self.data.load_pdb(self.test_pdb_path) 216 217 # Loop over the atoms. 218 atom_count = 0 219 for spin_name in self.data.atom_loop(atom_id='@CA', atom_name_flag=True): 220 # Test the spin name. 221 self.assertEqual(spin_name[0], 'CA') 222 223 # Increment the atom count. 224 atom_count = atom_count + 1 225 226 # Test the number of atoms looped over. 227 self.assertEqual(atom_count, 12)
228 229
231 """Test the Scientific_data.atom_loop() method with the '@163' spin selection.""" 232 233 # Load the PDB file. 234 self.data.load_pdb(self.test_pdb_path) 235 236 # Loop over the atoms. 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 # Test the spin info. 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 # Increment the atom count. 252 atom_count = atom_count + 1 253 254 # Test the number of atoms looped over. 255 self.assertEqual(atom_count, 1)
256 257
258 - def test_load_pdb(self):
259 """Load a PDB file using Scientific_data.load_pdb().""" 260 261 # Load the PDB file. 262 self.data.load_pdb(self.test_pdb_path) 263 264 # The ModelContainer and MolContainer. 265 model = self.data.structural_data[0] 266 mol = model.mol[0] 267 268 # Test the structural data. 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