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.                                     # 
  6  #                                                                             # 
  7  # relax 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 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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 relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  from os import path, sep 
 25  import sys 
 26   
 27  # relax module imports. 
 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   
38 -class Test_scientific(UnitTestCase):
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 # Execute the base class method. 49 super(Test_scientific, self).__init__(methodName)
50 51
52 - def setUp(self):
53 """Set up for all the Scientific Python PDB structural object unit tests.""" 54 55 # The path to a PDB file. 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 # Instantiate the structural data object. 63 self.data = Scientific_data()
64 65
66 - def tearDown(self):
67 """Reset the relax data storage object.""" 68 69 # Delete the structural data object. 70 del self.data 71 72 # Reset relax. 73 reset()
74 75
76 - def test___residue_loop(self):
77 """Test the private Scientific_data.__residue_loop() method.""" 78 79 # Load the PDB file. 80 self.data.load_pdb(self.test_pdb_path) 81 82 # Loop over the residues. 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 # Test the number of residues looped over. 88 self.assertEqual(res_count, 12) 89 90 # Test the data of the last residue. 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 # 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 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 # Load the PDB file. 125 self.data.load_pdb(self.test_pdb_path) 126 127 # Create the non-matching selection object. 128 sel_obj = Selection(':XXX') 129 130 # Loop over the residues. 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 # Test the number of residues looped over. 136 self.assertEqual(res_count, 0)
137 138
139 - def test_atom_loop(self):
140 """Test the Scientific_data.atom_loop() method.""" 141 142 # Load the PDB file. 143 self.data.load_pdb(self.test_pdb_path) 144 145 # Loop over the atoms. 146 atom_count = 0 147 for atom in self.data.atom_loop(): 148 atom_count = atom_count + 1 149 150 # Test the number of atoms looped over. 151 self.assertEqual(atom_count, 150)
152 153
155 """Test the Scientific_data.atom_loop() method with the '#XXX' mol selection.""" 156 157 # Load the PDB file. 158 self.data.load_pdb(self.test_pdb_path) 159 160 # Loop over the atoms. 161 atom_count = 0 162 for atom in self.data.atom_loop(atom_id='#XXX'): 163 atom_count = atom_count + 1 164 165 # Test the number of atoms looped over. 166 self.assertEqual(atom_count, 0)
167 168
170 """Test the Scientific_data.atom_loop() method with the ':8' res selection.""" 171 172 # Load the PDB file. 173 self.data.load_pdb(self.test_pdb_path) 174 175 # Loop over the atoms. 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 # Test the residue name and number. 179 self.assertEqual(res_num, 8) 180 self.assertEqual(res_name, 'SER') 181 182 # Increment the atom count. 183 atom_count = atom_count + 1 184 185 # Test the number of atoms looped over. 186 self.assertEqual(atom_count, 11)
187 188
190 """Test the Scientific_data.atom_loop() method with the ':PRO' res selection.""" 191 192 # Load the PDB file. 193 self.data.load_pdb(self.test_pdb_path) 194 195 # Loop over the atoms. 196 atom_count = 0 197 for atom in self.data.atom_loop(atom_id=':PRO', res_name_flag=True): 198 # Test the residue name. 199 self.assertEqual(atom[0], 'PRO') 200 201 # Increment the atom count. 202 atom_count = atom_count + 1 203 204 # Test the number of atoms looped over. 205 self.assertEqual(atom_count, 42)
206 207
209 """Test the Scientific_data.atom_loop() method with the '@CA' spin selection.""" 210 211 # Load the PDB file. 212 self.data.load_pdb(self.test_pdb_path) 213 214 # Loop over the atoms. 215 atom_count = 0 216 for spin_name in self.data.atom_loop(atom_id='@CA', atom_name_flag=True): 217 # Test the spin name. 218 self.assertEqual(spin_name[0], 'CA') 219 220 # Increment the atom count. 221 atom_count = atom_count + 1 222 223 # Test the number of atoms looped over. 224 self.assertEqual(atom_count, 12)
225 226
228 """Test the Scientific_data.atom_loop() method with the '@163' spin selection.""" 229 230 # Load the PDB file. 231 self.data.load_pdb(self.test_pdb_path) 232 233 # Loop over the atoms. 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 # Test the spin info. 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 # Increment the atom count. 249 atom_count = atom_count + 1 250 251 # Test the number of atoms looped over. 252 self.assertEqual(atom_count, 1)
253 254
255 - def test_load_pdb(self):
256 """Load a PDB file using Scientific_data.load_pdb().""" 257 258 # Load the PDB file. 259 self.data.load_pdb(self.test_pdb_path) 260 261 # The ModelContainer and MolContainer. 262 model = self.data.structural_data[0] 263 mol = model.mol[0] 264 265 # Test the structural data. 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