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-2013 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 = sorted(res.atoms.keys()) 94 self.assertEqual(atom_keys, ['1HA', '2HA', 'C', 'CA', 'H', 'N', 'O']) # Sorted key comparison needed as key order is not preserved in Python 3.
95 96
98 """Test the private Scientific_data.__residue_loop() method with a selection object.""" 99 100 # Load the PDB file. 101 self.data.load_pdb(self.test_pdb_path) 102 103 # Create the selection object (which should match the residue name of None). 104 sel_obj = Selection('#Ap4Aase_res1-12_mol1') 105 106 # Loop over the residues. 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 # Test the number of residues looped over. 112 self.assertEqual(res_count, 12) 113 114 # Test the data of the last residue. 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']) # Sorted key comparison needed as key order is not preserved in Python 3.
120 121
123 """Test the Scientific_data.__residue_loop() method with a non-matching selection object.""" 124 125 # Load the PDB file. 126 self.data.load_pdb(self.test_pdb_path) 127 128 # Create the non-matching selection object. 129 sel_obj = Selection(':XXX') 130 131 # Loop over the residues. 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 # Test the number of residues looped over. 137 self.assertEqual(res_count, 0)
138 139
140 - def test_atom_loop(self):
141 """Test the Scientific_data.atom_loop() method.""" 142 143 # Load the PDB file. 144 self.data.load_pdb(self.test_pdb_path) 145 146 # Loop over the atoms. 147 atom_count = 0 148 for atom in self.data.atom_loop(): 149 atom_count = atom_count + 1 150 151 # Test the number of atoms looped over. 152 self.assertEqual(atom_count, 150)
153 154
156 """Test the Scientific_data.atom_loop() method with the '#XXX' mol selection.""" 157 158 # Load the PDB file. 159 self.data.load_pdb(self.test_pdb_path) 160 161 # Loop over the atoms. 162 atom_count = 0 163 for atom in self.data.atom_loop(atom_id='#XXX'): 164 atom_count = atom_count + 1 165 166 # Test the number of atoms looped over. 167 self.assertEqual(atom_count, 0)
168 169
171 """Test the Scientific_data.atom_loop() method with the ':8' res selection.""" 172 173 # Load the PDB file. 174 self.data.load_pdb(self.test_pdb_path) 175 176 # Loop over the atoms. 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 # Test the residue name and number. 180 self.assertEqual(res_num, 8) 181 self.assertEqual(res_name, 'SER') 182 183 # Increment the atom count. 184 atom_count = atom_count + 1 185 186 # Test the number of atoms looped over. 187 self.assertEqual(atom_count, 11)
188 189
191 """Test the Scientific_data.atom_loop() method with the ':PRO' res selection.""" 192 193 # Load the PDB file. 194 self.data.load_pdb(self.test_pdb_path) 195 196 # Loop over the atoms. 197 atom_count = 0 198 for atom in self.data.atom_loop(atom_id=':PRO', res_name_flag=True): 199 # Test the residue name. 200 self.assertEqual(atom, 'PRO') 201 202 # Increment the atom count. 203 atom_count = atom_count + 1 204 205 # Test the number of atoms looped over. 206 self.assertEqual(atom_count, 42)
207 208
210 """Test the Scientific_data.atom_loop() method with the '@CA' spin selection.""" 211 212 # Load the PDB file. 213 self.data.load_pdb(self.test_pdb_path) 214 215 # Loop over the atoms. 216 atom_count = 0 217 for spin_name in self.data.atom_loop(atom_id='@CA', atom_name_flag=True): 218 # Test the spin name. 219 self.assertEqual(spin_name, 'CA') 220 221 # Increment the atom count. 222 atom_count = atom_count + 1 223 224 # Test the number of atoms looped over. 225 self.assertEqual(atom_count, 12)
226 227
229 """Test the Scientific_data.atom_loop() method with the '@163' spin selection.""" 230 231 # Load the PDB file. 232 self.data.load_pdb(self.test_pdb_path) 233 234 # Loop over the atoms. 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 # Test the spin info. 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 # Increment the atom count. 250 atom_count = atom_count + 1 251 252 # Test the number of atoms looped over. 253 self.assertEqual(atom_count, 1)
254 255
256 - def test_load_pdb(self):
257 """Load a PDB file using Scientific_data.load_pdb().""" 258 259 # Load the PDB file. 260 self.data.load_pdb(self.test_pdb_path) 261 262 # The ModelContainer and MolContainer. 263 model = self.data.structural_data[0] 264 mol = model.mol[0] 265 266 # Test the structural data. 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