Package test_suite :: Package system_tests :: Module bmrb
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.bmrb

  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 copy import deepcopy 
 25  import inspect 
 26  from numpy import ndarray 
 27  from os import sep 
 28  from re import search 
 29  from tempfile import mktemp 
 30   
 31  # relax module imports. 
 32  from base_classes import SystemTestCase 
 33  from data import Relax_data_store; ds = Relax_data_store() 
 34  import dep_check 
 35  from status import Status; status = Status() 
 36   
 37   
38 -class Bmrb(SystemTestCase):
39 """TestCase class for functional tests of the reading and writing of BMRB STAR formatted files.""" 40
41 - def __init__(self, methodName='runTest'):
42 """Skip the tests if scipy is not installed. 43 44 @keyword methodName: The name of the test. 45 @type methodName: str 46 """ 47 48 # Missing module. 49 if not dep_check.bmrblib_module: 50 # Store in the status object. 51 status.skipped_tests.append([methodName, 'Bmrblib', 'system']) 52 53 # Execute the base class method. 54 super(Bmrb, self).__init__(methodName)
55 56
57 - def setUp(self):
58 """Common set up for these system tests.""" 59 60 # Create a temporary file name. 61 ds.tmpfile = mktemp()
62 63
64 - def data_check(self, old_pipe_name='results', new_pipe_name='new', version=None):
65 """Check that all data has been successfully restored from the BMRB files.""" 66 67 # Print out. 68 print("\n\nComparing data pipe contents:") 69 70 # Blacklists (data that is not restored, and relaxation data which has been reordered and will be checked in data_ri_comp()). 71 blacklist_spin = ['attached_proton', 'fixed', 'nucleus', 'proton_type', 'relax_sim_data', 'select', 'xh_vect'] + ['r_err', 'csa_err'] + ['chi2_sim', 'f_count', 'g_count', 'h_count', 'iter', 'warning'] + ['frq', 'frq_labels', 'noe_r1_table', 'remap_table', 'ri_labels', 'relax_data', 'relax_error'] 72 if version == '3.0': 73 blacklist_spin = blacklist_spin + ['r', 'local_tm', 'local_tm_err'] 74 blacklist_diff = [] 75 blacklist_global = ['diff_tensor', 'exp_info', 'hybrid_pipes', 'mol', 'sim_number', 'sim_state'] + ['ri_ids', 'frq', 'ri_type'] 76 77 # The data pipes. 78 old_pipe = ds[old_pipe_name] 79 new_pipe = ds[new_pipe_name] 80 81 # The molecule data structure. 82 self.assertEqual(len(old_pipe.mol), len(new_pipe.mol)) 83 for i in range(len(old_pipe.mol)): 84 # Check the attributes. 85 self.assertEqual(old_pipe.mol[i].name, old_pipe.mol[i].name) 86 self.assertEqual(old_pipe.mol[i].type, old_pipe.mol[i].type) 87 88 # The residue data structure. 89 self.assertEqual(len(old_pipe.mol[i].res), len(new_pipe.mol[i].res)) 90 for j in range(len(old_pipe.mol[i].res)): 91 # Check the attributes. 92 self.assertEqual(old_pipe.mol[i].res[j].name, old_pipe.mol[i].res[j].name) 93 self.assertEqual(old_pipe.mol[i].res[j].num, old_pipe.mol[i].res[j].num) 94 95 # The spin data structure. 96 self.assertEqual(len(old_pipe.mol[i].res[j].spin), len(new_pipe.mol[i].res[j].spin)) 97 for k in range(len(old_pipe.mol[i].res[j].spin)): 98 # Skip deselected spins. 99 if not old_pipe.mol[i].res[j].spin[k].select: 100 continue 101 102 # Check the containers. 103 self.data_cont_comp(label='Spin', cont_old=old_pipe.mol[i].res[j].spin[k], cont_new=new_pipe.mol[i].res[j].spin[k], blacklist=blacklist_spin) 104 if hasattr(old_pipe.mol[i].res[j].spin[k], 'ri_labels'): 105 self.data_ri_comp_spin(cont_old=old_pipe.mol[i].res[j].spin[k], cont_new=new_pipe.mol[i].res[j].spin[k]) 106 107 # The diffusion tensor. 108 if version != '3.0': 109 self.assert_(hasattr(new_pipe, 'diff_tensor')) 110 self.data_cont_comp(label='Diff tensor', cont_old=old_pipe.diff_tensor, cont_new=new_pipe.diff_tensor, prec=4, blacklist=blacklist_diff) 111 112 # The global data structures. 113 self.data_cont_comp(label='Global', cont_old=old_pipe, cont_new=new_pipe, blacklist=blacklist_global) 114 if hasattr(old_pipe, 'ri_ids'): 115 self.data_ri_comp_pipe(cont_old=old_pipe, cont_new=new_pipe)
116 117
118 - def data_cont_comp(self, label=None, cont_old=None, cont_new=None, prec=7, blacklist=[]):
119 """Compare the contents of the two data containers.""" 120 121 # Print a new line. 122 print('') 123 124 # Check the attributes. 125 names = dir(cont_old) 126 for name in names: 127 # Skip special names. 128 if search('^__', name): 129 continue 130 131 # Skip the data store methods. 132 if name in list(cont_old.__class__.__dict__.keys()): 133 continue 134 135 # Simulation data. 136 if search('_sim$', name): 137 continue 138 139 # Blacklisting. 140 if name in blacklist: 141 continue 142 143 # Print out. 144 print("%s object: '%s'" % (label, name)) 145 146 # Get the objects. 147 obj_old = getattr(cont_old, name) 148 obj_new = getattr(cont_new, name) 149 150 # Functions and methods. 151 if inspect.isfunction(obj_old) or inspect.ismethod(obj_old): 152 continue 153 154 # Does it exist? 155 self.assert_(hasattr(cont_new, name)) 156 157 # Compare lists. 158 if (isinstance(obj_old, list) or isinstance(obj_old, ndarray)): 159 self.assertEqual(len(obj_old), len(obj_new)) 160 161 # List of lists (or rank-2 array). 162 if (isinstance(obj_old[0], list) or isinstance(obj_old[0], ndarray)): 163 for i in range(len(obj_old)): 164 for j in range(len(obj_old[i])): 165 if isinstance(obj_old[i][j], float): 166 self.assertAlmostEqual(obj_old[i][j], obj_new[i][j], prec) 167 else: 168 self.assertEqual(obj_old[i][j], obj_new[i][j]) 169 170 # Standard list. 171 else: 172 for i in range(len(obj_old)): 173 if isinstance(obj_old[i], float): 174 self.assertAlmostEqual(obj_old[i], obj_new[i], prec) 175 else: 176 self.assertEqual(obj_old[i], obj_new[i]) 177 178 # Compare floats. 179 elif isinstance(obj_old, float): 180 self.assertAlmostEqual(obj_old, obj_new, prec) 181 182 # Compare ints and strings. 183 else: 184 self.assertEqual(obj_old, obj_new)
185 186
187 - def data_ri_comp_pipe(self, cont_old=None, cont_new=None):
188 """Compare the contents of the two pipe data containers.""" 189 190 # Check that the new container has relaxation data. 191 for name in ['frq', 'ri_ids', 'ri_type']: 192 self.assert_(hasattr(cont_new, name)) 193 194 # Check the IDs. 195 old_ids = deepcopy(cont_old.ri_ids) 196 new_ids = deepcopy(cont_new.ri_ids) 197 old_ids.sort() 198 new_ids.sort() 199 self.assertEqual(old_ids, new_ids) 200 201 # Check the frequencies and types. 202 for ri_id in old_ids: 203 self.assertEqual(cont_old.frq[ri_id], cont_new.frq[ri_id]) 204 self.assertEqual(cont_old.ri_type[ri_id], cont_new.ri_type[ri_id])
205 206
207 - def data_ri_comp_spin(self, cont_old=None, cont_new=None):
208 """Compare the contents of the two spin data containers.""" 209 210 # Check that the new container has relaxation data. 211 for name in ['ri_data', 'ri_data_err']: 212 self.assert_(hasattr(cont_new, name)) 213 214 # Check the IDs. 215 old_ids = cont_old.ri_data.keys() 216 new_ids = cont_new.ri_data.keys() 217 old_ids.sort() 218 new_ids.sort() 219 self.assertEqual(old_ids, new_ids) 220 221 # Check the data and errors. 222 for ri_id in old_ids: 223 self.assertEqual(cont_old.ri_data[ri_id], cont_new.ri_data[ri_id]) 224 self.assertEqual(cont_old.ri_data_err[ri_id], cont_new.ri_data_err[ri_id])
225 226
228 """Write and then read a BRMB STAR formatted file containing model-free results.""" 229 230 # Set the NMR-STAR version. 231 ds.version = '3.0' 232 233 # Execute the script. 234 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'bmrb_rw.py') 235 236 # Test the data. 237 self.data_check(version='3.0')
238 239
241 """Write and then read a BRMB STAR formatted file containing model-free results.""" 242 243 # Set the NMR-STAR version. 244 ds.version = '3.1' 245 246 # Execute the script. 247 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'bmrb_rw.py') 248 249 # Test the data. 250 self.data_check(version='3.1')
251