Package test_suite :: Module model_free
[hide private]
[frames] | no frames]

Source Code for Module test_suite.model_free

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006 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  from math import pi 
  24  import sys 
  25   
  26   
27 -class Mf:
28 - def __init__(self, relax, test_name):
29 """Class for testing various aspects specific to model-free analysis.""" 30 31 self.relax = relax 32 33 # Relaxation data reading test. 34 if test_name == 'read relaxation data': 35 # The name of the test. 36 self.name = "The user function relax_data.read()" 37 38 # The test. 39 self.test = self.read_relax_data 40 41 # Test of setting the CSA. 42 if test_name == 'set csa': 43 # The name of the test. 44 self.name = "Setting the CSA value through the user function value.set()" 45 46 # The test. 47 self.test = self.set_csa 48 49 # Test of setting the bond length. 50 if test_name == 'set bond length': 51 # The name of the test. 52 self.name = "Setting the bond length through the user function value.set()" 53 54 # The test. 55 self.test = self.set_csa 56 57 # Test of setting the CSA and the bond length. 58 if test_name == 'set csa and bond length': 59 # The name of the test. 60 self.name = "Setting both the CSA value and bond length through the user function value.set()" 61 62 # The test. 63 self.test = self.set_csa_bond_length 64 65 # Test of selecting model-free model m4. 66 if test_name == 'select m4': 67 # The name of the test. 68 self.name = "Selecting model m4 with parameters {S2, te, Rex} using model_free.select_model()" 69 70 # The test. 71 self.test = self.select_m4 72 73 # Test of creating model-free model m4. 74 if test_name == 'create m4': 75 # The name of the test. 76 self.name = "Creating model m4 with parameters {S2, te, Rex} using model_free.create_model()" 77 78 # The test. 79 self.test = self.select_m4 80 81 # Results reading test. 82 if test_name == 'read results': 83 # The name of the test. 84 self.name = "The user function results.read()" 85 86 # The test. 87 self.test = self.read_results 88 89 # OpenDX {S2, te, Rex} mapping test. 90 if test_name == 'opendx {S2, te, Rex} map': 91 # The name of the test. 92 self.name = "Mapping the {S2, te, Rex} chi2 space through the OpenDX user function dx.map()" 93 94 # The test. 95 self.test = self.opendx_s2_te_rex 96 97 # OpenDX {theta, phi, Da} mapping test. 98 if test_name == 'opendx {theta, phi, Da} map': 99 # The name of the test. 100 self.name = "Mapping the {theta, phi, Da} chi2 space through the OpenDX user function dx.map()" 101 102 # The test. 103 self.test = self.opendx_theta_phi_da 104 105 # OpenDX {local_tm, S2, te} mapping test. 106 if test_name == 'opendx {local_tm, S2, te} map': 107 # The name of the test. 108 self.name = "Mapping the {local_tm, S2, te} chi2 space through the OpenDX user function dx.map()" 109 110 # The test. 111 self.test = self.opendx_tm_s2_te 112 113 114 # Optimisation: Constrained grid search {S2=0.970, te=2048, Rex=0.149}. 115 if test_name == 'Constrained grid search {S2=0.970, te=2048, Rex=0.149}': 116 # The name of the test. 117 self.name = "Constrained grid search {S2=0.970, te=2048, Rex=0.149}" 118 119 # The test. 120 self.test = self.opt_grid_search_S2_0_970_te_2048_Rex_0_149 121 122 123 # Optimisation: Constrained SD, backtracking {S2=0.970, te=2048, Rex=0.149}. 124 if test_name == 'Constrained SD, backtracking opt {S2=0.970, te=2048, Rex=0.149}': 125 # The name of the test. 126 self.name = "Constrained steepest descent opt, backtracking line search {S2=0.970, te=2048, Rex=0.149}" 127 128 # The test. 129 self.test = self.opt_constr_sd_back_S2_0_970_te_2048_Rex_0_149 130 131 132 # Optimisation: Constrained SD, MT {S2=0.970, te=2048, Rex=0.149}. 133 if test_name == 'Constrained SD, MT opt {S2=0.970, te=2048, Rex=0.149}': 134 # The name of the test. 135 self.name = "Constrained steepest descent opt, More and Thuente line search {S2=0.970, te=2048, Rex=0.149}" 136 137 # The test. 138 self.test = self.opt_constr_sd_mt_S2_0_970_te_2048_Rex_0_149 139 140 141 # Optimisation: Constrained CD, backtracking {S2=0.970, te=2048, Rex=0.149}. 142 if test_name == 'Constrained CD, backtracking opt {S2=0.970, te=2048, Rex=0.149}': 143 # The name of the test. 144 self.name = "Constrained coordinate descent opt, backtracking line search {S2=0.970, te=2048, Rex=0.149}" 145 146 # The test. 147 self.test = self.opt_constr_cd_back_S2_0_970_te_2048_Rex_0_149 148 149 150 # Optimisation: Constrained CD, MT {S2=0.970, te=2048, Rex=0.149}. 151 if test_name == 'Constrained CD, MT opt {S2=0.970, te=2048, Rex=0.149}': 152 # The name of the test. 153 self.name = "Constrained coordinate descent opt, More and Thuente line search {S2=0.970, te=2048, Rex=0.149}" 154 155 # The test. 156 self.test = self.opt_constr_cd_mt_S2_0_970_te_2048_Rex_0_149 157 158 159 # Optimisation: Constrained BFGS, backtracking {S2=0.970, te=2048, Rex=0.149}. 160 if test_name == 'Constrained BFGS, backtracking opt {S2=0.970, te=2048, Rex=0.149}': 161 # The name of the test. 162 self.name = "Constrained BFGS opt, backtracking line search {S2=0.970, te=2048, Rex=0.149}" 163 164 # The test. 165 self.test = self.opt_constr_bfgs_back_S2_0_970_te_2048_Rex_0_149 166 167 168 # Optimisation: Constrained BFGS, MT {S2=0.970, te=2048, Rex=0.149}. 169 if test_name == 'Constrained BFGS, MT opt {S2=0.970, te=2048, Rex=0.149}': 170 # The name of the test. 171 self.name = "Constrained BFGS opt, More and Thuente line search {S2=0.970, te=2048, Rex=0.149}" 172 173 # The test. 174 self.test = self.opt_constr_bfgs_mt_S2_0_970_te_2048_Rex_0_149 175 176 177 # Optimisation: Constrained Newton, GMW, backtracking {S2=0.970, te=2048, Rex=0.149}. 178 if test_name == 'Constrained Newton, GMW, backtracking opt {S2=0.970, te=2048, Rex=0.149}': 179 # The name of the test. 180 self.name = "Constrained Newton opt, GMW Hessian mod, backtracking line search {S2=0.970, te=2048, Rex=0.149}" 181 182 # The test. 183 self.test = self.opt_constr_newton_gmw_back_S2_0_970_te_2048_Rex_0_149 184 185 186 # Optimisation: Constrained Newton, GMW, MT {S2=0.970, te=2048, Rex=0.149}. 187 if test_name == 'Constrained Newton, GMW, MT opt {S2=0.970, te=2048, Rex=0.149}': 188 # The name of the test. 189 self.name = "Constrained Newton opt, GMW Hessian mod, More and Thuente line search {S2=0.970, te=2048, Rex=0.149}" 190 191 # The test. 192 self.test = self.opt_constr_newton_gmw_mt_S2_0_970_te_2048_Rex_0_149
193 194
195 - def create_m4(self, run):
196 """Testing the creation of model-free model m4.""" 197 198 # Arguments. 199 self.run = run 200 201 # Create the run. 202 self.relax.generic.runs.create(self.run, 'mf') 203 204 # Path of the files. 205 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 206 207 # Read the sequence. 208 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 209 210 # Select the model. 211 self.relax.interpreter._Model_free.create_model(self.run, model='m4', equation='mf_orig', params=['S2', 'te', 'Rex']) 212 213 # Test the model. 214 if self.relax.data.res[self.run][1].model != 'm4': 215 print "The model has not been selected." 216 return 217 218 # Test the parameters. 219 if self.relax.data.res[self.run][1].params != ['S2', 'te', 'Rex']: 220 print "The parameters are incorrect." 221 return 222 223 return 1
224 225
226 - def opendx_s2_te_rex(self, run):
227 """The OpenDX {S2, te, Rex} mapping test.""" 228 229 # Arguments. 230 self.run = run 231 232 # Create the run. 233 self.relax.generic.runs.create(self.run, 'mf') 234 235 # Path of the files. 236 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 237 238 # Nuclei type 239 self.relax.interpreter._Nuclei.nuclei('N') 240 241 # Read the sequence. 242 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 243 244 # Read the relaxation data. 245 self.relax.interpreter._Relax_data.read(self.run, 'R1', '600', 600.0 * 1e6, 'r1.600.out', dir=path) 246 self.relax.interpreter._Relax_data.read(self.run, 'R2', '600', 600.0 * 1e6, 'r2.600.out', dir=path) 247 self.relax.interpreter._Relax_data.read(self.run, 'NOE', '600', 600.0 * 1e6, 'noe.600.out', dir=path) 248 self.relax.interpreter._Relax_data.read(self.run, 'R1', '500', 500.0 * 1e6, 'r1.500.out', dir=path) 249 self.relax.interpreter._Relax_data.read(self.run, 'R2', '500', 500.0 * 1e6, 'r2.500.out', dir=path) 250 self.relax.interpreter._Relax_data.read(self.run, 'NOE', '500', 500.0 * 1e6, 'noe.500.out', dir=path) 251 252 # Setup other values. 253 self.relax.interpreter._Diffusion_tensor.init(self.run, 1e-8, fixed=1) 254 self.relax.interpreter._Value.set(self.run, [-172 * 1e-6, 1.02 * 1e-10], ['csa', 'bond_length']) 255 256 # Select the model. 257 self.relax.interpreter._Model_free.select_model(self.run, model='m4') 258 259 # Map the space. 260 self.relax.interpreter._OpenDX.map(self.run, params=['S2', 'te', 'Rex'], res_num=2, inc=2, lower=[0.0, 0, 0], upper=[1.0, 10000e-12, 3.0 / (2.0 * pi * 600000000.0)**2], point=[0.970, 2048.0e-12, 0.149 / (2.0 * pi * 600000000.0)**2], file='devnull', point_file='devnull') 261 262 return 1
263 264
265 - def opendx_theta_phi_da(self, run):
266 """The OpenDX {theta, phi, Da} mapping test.""" 267 268 # Arguments. 269 self.run = run 270 271 # Create the run. 272 self.relax.generic.runs.create(self.run, 'mf') 273 274 # Path of the files. 275 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 276 277 # Nuclei type 278 self.relax.interpreter._Nuclei.nuclei('N') 279 280 # Read the sequence. 281 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 282 283 # Read the PDF file. 284 self.relax.interpreter._PDB.pdb(run, file='pdb', dir=path, model=1, heteronuc='N', proton='H', load_seq=0) 285 286 # Read the relaxation data. 287 self.relax.interpreter._Relax_data.read(self.run, 'R1', '600', 600.0 * 1e6, 'r1.600.out', dir=path) 288 self.relax.interpreter._Relax_data.read(self.run, 'R2', '600', 600.0 * 1e6, 'r2.600.out', dir=path) 289 self.relax.interpreter._Relax_data.read(self.run, 'NOE', '600', 600.0 * 1e6, 'noe.600.out', dir=path) 290 self.relax.interpreter._Relax_data.read(self.run, 'R1', '500', 500.0 * 1e6, 'r1.500.out', dir=path) 291 self.relax.interpreter._Relax_data.read(self.run, 'R2', '500', 500.0 * 1e6, 'r2.500.out', dir=path) 292 self.relax.interpreter._Relax_data.read(self.run, 'NOE', '500', 500.0 * 1e6, 'noe.500.out', dir=path) 293 294 # Setup other values. 295 self.relax.interpreter._Diffusion_tensor.init(self.run, (1.601 * 1e7, 1.34, 72.4, 90-77.9), param_types=4) 296 self.relax.interpreter._Value.set(self.run, [-172 * 1e-6, 1.02 * 1e-10], ['csa', 'bond_length']) 297 self.relax.interpreter._Value.set(self.run, [0.8, 50 * 1e-12, 0.0], ['S2', 'te', 'Rex']) 298 299 # Select the model. 300 self.relax.interpreter._Model_free.select_model(self.run, model='m4') 301 302 # Map the space. 303 self.relax.interpreter._OpenDX.map(self.run, params=['theta', 'phi', 'Da'], res_num=2, inc=2, lower=[0, 0, -0.5*1e7], upper=[pi, 2.0*pi, 1.0*1e7], file='devnull') 304 305 return 1
306 307
308 - def opendx_tm_s2_te(self, run):
309 """The OpenDX {local_tm, S2, te} mapping test.""" 310 311 # Arguments. 312 self.run = run 313 314 # Create the run. 315 self.relax.generic.runs.create(self.run, 'mf') 316 317 # Path of the files. 318 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 319 320 # Nuclei type 321 self.relax.interpreter._Nuclei.nuclei('N') 322 323 # Read the sequence. 324 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 325 326 # Read the relaxation data. 327 self.relax.interpreter._Relax_data.read(self.run, 'R1', '600', 600.0 * 1e6, 'r1.600.out', dir=path) 328 self.relax.interpreter._Relax_data.read(self.run, 'R2', '600', 600.0 * 1e6, 'r2.600.out', dir=path) 329 self.relax.interpreter._Relax_data.read(self.run, 'NOE', '600', 600.0 * 1e6, 'noe.600.out', dir=path) 330 self.relax.interpreter._Relax_data.read(self.run, 'R1', '500', 500.0 * 1e6, 'r1.500.out', dir=path) 331 self.relax.interpreter._Relax_data.read(self.run, 'R2', '500', 500.0 * 1e6, 'r2.500.out', dir=path) 332 self.relax.interpreter._Relax_data.read(self.run, 'NOE', '500', 500.0 * 1e6, 'noe.500.out', dir=path) 333 334 # Setup other values. 335 self.relax.interpreter._Value.set(self.run, [-172 * 1e-6, 1.02 * 1e-10], ['csa', 'bond_length']) 336 337 # Select the model. 338 self.relax.interpreter._Model_free.select_model(self.run, model='tm2') 339 340 # Map the space. 341 self.relax.interpreter._OpenDX.map(self.run, params=['local_tm', 'S2', 'te'], res_num=2, inc=2, file='devnull') 342 343 return 1
344 345
347 """Optimisation test. 348 349 The optimisation options are: 350 BFGS optimisation. 351 Backtracking line search. 352 Constrained. 353 354 The true data set is: 355 S2 = 0.970 356 te = 2048 ps 357 Rex = 0.149 s^-1 358 """ 359 360 # Setup the run for optimisation. 361 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 362 363 # Set up the initial model-free parameter values (bypass the grid search for speed). 364 self.relax.interpreter._Value.set(self.run, [1.0, 0.0, 0.0], ['S2', 'te', 'Rex']) 365 366 # Minimise. 367 self.relax.interpreter._Minimisation.minimise('bfgs', 'back', run=self.run) 368 369 370 # Test the optimisation statistics and parameter values. 371 ######################################################## 372 373 # Alias the data structure. 374 data = self.relax.data.res[self.run][1] 375 376 # Error tolerance. 377 error = 1e-8 378 379 # Test the values. 380 success = 1 381 if not self.test_values(val1=0.970, val2=data.s2, error=error, name='S2 value'): 382 success = 0 383 if not self.test_values(val1=2048 * 1e-12, val2=data.te, error=error, name='te value (ns)', scale=1e9): 384 success = 0 385 if not self.test_values(val1=0.149 / (2.0 * pi * data.frq[0])**2, val2=data.rex, error=error, name='Rex value', scale=(2.0 * pi * data.frq[0])**2): 386 success = 0 387 if not self.test_values(val1=3.1024517431117421e-27, val2=data.chi2, error=1e-20, name='chi-squared value'): 388 success = 0 389 if not self.test_values(val1=203, val2=data.iter, name='iteration count', max=1): 390 success = 0 391 if not self.test_values(val1=955, val2=data.f_count, name='function count', max=1): 392 success = 0 393 if not self.test_values(val1=209, val2=data.g_count, name='gradient count', max=1): 394 success = 0 395 if not self.test_values(val1=0, val2=data.h_count, name='Hessian count', max=1): 396 success = 0 397 398 # Warning. 399 if data.warning: 400 print data.warning 401 success = 0 402 403 # Success. 404 return success
405 406
408 """Optimisation test. 409 410 The optimisation options are: 411 BFGS optimisation. 412 More and Thuente line search. 413 Constrained. 414 415 The true data set is: 416 S2 = 0.970 417 te = 2048 ps 418 Rex = 0.149 s^-1 419 """ 420 421 # Setup the run for optimisation. 422 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 423 424 # Set up the initial model-free parameter values (bypass the grid search for speed). 425 self.relax.interpreter._Value.set(self.run, [1.0, 0.0, 0.0], ['S2', 'te', 'Rex']) 426 427 # Minimise. 428 self.relax.interpreter._Minimisation.minimise('bfgs', 'mt', run=self.run) 429 430 431 # Test the optimisation statistics and parameter values. 432 ######################################################## 433 434 # Alias the data structure. 435 data = self.relax.data.res[self.run][1] 436 437 # Error tolerance. 438 error = 1e-8 439 440 # Test the values. 441 success = 1 442 if not self.test_values(val1=0.970, val2=data.s2, error=error, name='S2 value'): 443 success = 0 444 if not self.test_values(val1=2048 * 1e-12, val2=data.te, error=error, name='te value (ns)', scale=1e9): 445 success = 0 446 if not self.test_values(val1=0.149 / (2.0 * pi * data.frq[0])**2, val2=data.rex, error=error, name='Rex value', scale=(2.0 * pi * data.frq[0])**2): 447 success = 0 448 if not self.test_values(val1=3.1024517431117421e-27, val2=data.chi2, error=1e-20, name='chi-squared value'): 449 success = 0 450 if not self.test_values(val1=203, val2=data.iter, name='iteration count', max=1): 451 success = 0 452 if not self.test_values(val1=955, val2=data.f_count, name='function count', max=1): 453 success = 0 454 if not self.test_values(val1=209, val2=data.g_count, name='gradient count', max=1): 455 success = 0 456 if not self.test_values(val1=0, val2=data.h_count, name='Hessian count', max=1): 457 success = 0 458 459 # Warning. 460 if data.warning: 461 print data.warning 462 success = 0 463 464 # Success. 465 return success
466 467
469 """Optimisation test. 470 471 The optimisation options are: 472 Coordinate descent optimisation. 473 Backtracking line search. 474 Constrained. 475 476 The true data set is: 477 S2 = 0.970 478 te = 2048 ps 479 Rex = 0.149 s^-1 480 """ 481 482 # Setup the run for optimisation. 483 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 484 485 # Set up the initial model-free parameter values (bypass the grid search for speed). 486 self.relax.interpreter._Value.set(self.run, [1.0, 0.0, 0.0], ['S2', 'te', 'Rex']) 487 488 # Minimise. 489 self.relax.interpreter._Minimisation.minimise('cd', 'back', max_iter=50, run=self.run) 490 491 492 # Test the optimisation statistics and parameter values. 493 ######################################################## 494 495 # Alias the data structure. 496 data = self.relax.data.res[self.run][1] 497 498 # Error tolerance. 499 error = 1e-8 500 501 # Test the values. 502 success = 1 503 if not self.test_values(val1=0.9097900390625, val2=data.s2, error=error, name='S2 value'): 504 success = 0 505 if not self.test_values(val1=2.5000000000000001e-11, val2=data.te, error=error, name='te value (ns)', scale=1e9): 506 success = 0 507 if not self.test_values(val1=1.24017333984375 / (2.0 * pi * data.frq[0])**2, val2=data.rex, error=error, name='Rex value', scale=(2.0 * pi * data.frq[0])**2): 508 success = 0 509 if not self.test_values(val1=53.476155463267176, val2=data.chi2, error=error, name='chi-squared value'): 510 success = 0 511 if not self.test_values(val1=50, val2=data.iter, name='iteration count', max=1): 512 success = 0 513 if not self.test_values(val1=131, val2=data.f_count, name='function count', max=1): 514 success = 0 515 if not self.test_values(val1=51, val2=data.g_count, name='gradient count', max=1): 516 success = 0 517 if not self.test_values(val1=0, val2=data.h_count, name='Hessian count', max=1): 518 success = 0 519 520 # Warning. 521 if data.warning and not data.warning == 'Maximum number of iterations reached': 522 print data.warning 523 success = 0 524 525 # Success. 526 return success
527 528
530 """Optimisation test. 531 532 The optimisation options are: 533 Coordinate descent optimisation. 534 More and Thuente line search. 535 Constrained. 536 537 The true data set is: 538 S2 = 0.970 539 te = 2048 ps 540 Rex = 0.149 s^-1 541 """ 542 543 # Setup the run for optimisation. 544 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 545 546 # Set up the initial model-free parameter values (bypass the grid search for speed). 547 self.relax.interpreter._Value.set(self.run, [1.0, 0.0, 0.0], ['S2', 'te', 'Rex']) 548 549 # Minimise. 550 self.relax.interpreter._Minimisation.minimise('cd', 'mt', run=self.run) 551 552 553 # Test the optimisation statistics and parameter values. 554 ######################################################## 555 556 # Alias the data structure. 557 data = self.relax.data.res[self.run][1] 558 559 # Error tolerance. 560 error = 1e-8 561 562 # Test the values. 563 success = 1 564 if not self.test_values(val1=0.970, val2=data.s2, error=error, name='S2 value'): 565 success = 0 566 if not self.test_values(val1=2048 * 1e-12, val2=data.te, error=error, name='te value (ns)', scale=1e9): 567 success = 0 568 if not self.test_values(val1=0.149 / (2.0 * pi * data.frq[0])**2, val2=data.rex, error=error, name='Rex value'): 569 success = 0 570 if not self.test_values(val1=2.34772342485e-18, val2=data.chi2, error=error, name='chi-squared value'): 571 success = 0 572 if not self.test_values(val1=198, val2=data.iter, name='iteration count', max=1): 573 success = 0 574 if not self.test_values(val1=757, val2=data.f_count, name='function count', max=1): 575 success = 0 576 if not self.test_values(val1=757, val2=data.g_count, name='gradient count', max=1): 577 success = 0 578 if not self.test_values(val1=0, val2=data.h_count, name='Hessian count', max=1): 579 success = 0 580 581 # Warning. 582 if data.warning: 583 print data.warning 584 success = 0 585 586 # Success. 587 return success
588 589
591 """Optimisation test. 592 593 The optimisation options are: 594 Newton optimisation. 595 GMW Hessian modification. 596 Backtracking line search. 597 Constrained. 598 599 The true data set is: 600 S2 = 0.970 601 te = 2048 ps 602 Rex = 0.149 s^-1 603 """ 604 605 # Setup the run for optimisation. 606 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 607 608 # Set up the initial model-free parameter values (bypass the grid search for speed). 609 self.relax.interpreter._Value.set(self.run, [1.0, 0.0, 0.0], ['S2', 'te', 'Rex']) 610 611 # Minimise. 612 self.relax.interpreter._Minimisation.minimise('newton', 'gmw', 'back', run=self.run) 613 614 615 # Test the optimisation statistics and parameter values. 616 ######################################################## 617 618 # Alias the data structure. 619 data = self.relax.data.res[self.run][1] 620 621 # Error tolerance. 622 error = 1e-8 623 624 # Test the values. 625 success = 1 626 if not self.test_values(val1=0.970, val2=data.s2, error=error, name='S2 value'): 627 success = 0 628 if not self.test_values(val1=2048 * 1e-12, val2=data.te, error=error, name='te value (ns)', scale=1e9): 629 success = 0 630 if not self.test_values(val1=0.149 / (2.0 * pi * data.frq[0])**2, val2=data.rex, error=error, name='Rex value', scale=(2.0 * pi * data.frq[0])**2): 631 success = 0 632 if not self.test_values(val1=7.3040158179665562e-28, val2=data.chi2, error=1e-20, name='chi-squared value'): 633 success = 0 634 if not self.test_values(val1=18, val2=data.iter, name='iteration count', max=1): 635 success = 0 636 if not self.test_values(val1=96, val2=data.f_count, name='function count', max=1): 637 success = 0 638 if not self.test_values(val1=23, val2=data.g_count, name='gradient count', max=1): 639 success = 0 640 if not self.test_values(val1=18, val2=data.h_count, name='Hessian count', max=1): 641 success = 0 642 643 # Warning. 644 if data.warning: 645 print data.warning 646 success = 0 647 648 # Success. 649 return success
650 651
653 """Optimisation test. 654 655 The optimisation options are: 656 Newton optimisation. 657 GMW Hessian modification. 658 More and Thuente line search. 659 Constrained. 660 661 The true data set is: 662 S2 = 0.970 663 te = 2048 ps 664 Rex = 0.149 s^-1 665 """ 666 667 # Setup the run for optimisation. 668 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 669 670 # Set up the initial model-free parameter values (bypass the grid search for speed). 671 self.relax.interpreter._Value.set(self.run, [1.0, 0.0, 0.0], ['S2', 'te', 'Rex']) 672 673 # Minimise. 674 self.relax.interpreter._Minimisation.minimise('newton', 'gmw', 'mt', run=self.run) 675 676 677 # Test the optimisation statistics and parameter values. 678 ######################################################## 679 680 # Alias the data structure. 681 data = self.relax.data.res[self.run][1] 682 683 # Error tolerance. 684 error = 1e-8 685 686 # Test the values. 687 success = 1 688 if not self.test_values(val1=0.970, val2=data.s2, error=error, name='S2 value'): 689 success = 0 690 if not self.test_values(val1=2048 * 1e-12, val2=data.te, error=error, name='te value (ns)', scale=1e9): 691 success = 0 692 if not self.test_values(val1=0.149 / (2.0 * pi * data.frq[0])**2, val2=data.rex, error=error, name='Rex value', scale=(2.0 * pi * data.frq[0])**2): 693 success = 0 694 if not self.test_values(val1=6.8756889983348349e-28, val2=data.chi2, error=1e-20, name='chi-squared value'): 695 success = 0 696 if not self.test_values(val1=22, val2=data.iter, name='iteration count', max=1): 697 success = 0 698 if not self.test_values(val1=159, val2=data.f_count, name='function count', max=1): 699 success = 0 700 if not self.test_values(val1=159, val2=data.g_count, name='gradient count', max=1): 701 success = 0 702 if not self.test_values(val1=22, val2=data.h_count, name='Hessian count', max=1): 703 success = 0 704 705 # Warning. 706 if data.warning: 707 print data.warning 708 success = 0 709 710 # Success. 711 return success
712 713
715 """Optimisation test. 716 717 The optimisation options are: 718 Steepest descent optimisation. 719 Backtracking line search. 720 Constrained. 721 722 The true data set is: 723 S2 = 0.970 724 te = 2048 ps 725 Rex = 0.149 s^-1 726 """ 727 728 # Setup the run for optimisation. 729 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 730 731 # Set up the initial model-free parameter values (bypass the grid search for speed). 732 self.relax.interpreter._Value.set(self.run, [1.0, 0.0, 0.0], ['S2', 'te', 'Rex']) 733 734 # Minimise. 735 self.relax.interpreter._Minimisation.minimise('sd', 'back', max_iter=50, run=self.run) 736 737 738 # Test the optimisation statistics and parameter values. 739 ######################################################## 740 741 # Alias the data structure. 742 data = self.relax.data.res[self.run][1] 743 744 # Error tolerance. 745 error = 1e-8 746 747 # Test the values. 748 success = 1 749 if not self.test_values(val1=0.91579220834688024, val2=data.s2, error=error, name='S2 value'): 750 success = 0 751 if not self.test_values(val1=3.056865872253173e-13, val2=data.te, error=error, name='te value (ns)', scale=1e9): 752 success = 0 753 if not self.test_values(val1=0.34008409798366124 / (2.0 * pi * data.frq[0])**2, val2=data.rex, error=error, name='Rex value', scale=(2.0 * pi * data.frq[0])**2): 754 success = 0 755 if not self.test_values(val1=68.321956795264342, val2=data.chi2, error=error, name='chi-squared value'): 756 success = 0 757 if not self.test_values(val1=50, val2=data.iter, name='iteration count', max=1): 758 success = 0 759 if not self.test_values(val1=134, val2=data.f_count, name='function count', max=1): 760 success = 0 761 if not self.test_values(val1=51, val2=data.g_count, name='gradient count', max=1): 762 success = 0 763 if not self.test_values(val1=0, val2=data.h_count, name='Hessian count', max=1): 764 success = 0 765 766 # Warning. 767 if data.warning and not data.warning == 'Maximum number of iterations reached': 768 print data.warning 769 success = 0 770 771 # Success. 772 return success
773 774
776 """Optimisation test. 777 778 The optimisation options are: 779 Steepest descent optimisation. 780 More and Thuente line search. 781 Constrained. 782 783 The true data set is: 784 S2 = 0.970 785 te = 2048 ps 786 Rex = 0.149 s^-1 787 """ 788 789 # Setup the run for optimisation. 790 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 791 792 # Set up the initial model-free parameter values (bypass the grid search for speed). 793 self.relax.interpreter._Value.set(self.run, [1.0, 0.0, 0.0], ['S2', 'te', 'Rex']) 794 795 # Minimise. 796 self.relax.interpreter._Minimisation.minimise('sd', 'mt', max_iter=50, run=self.run) 797 798 799 # Test the optimisation statistics and parameter values. 800 ######################################################## 801 802 # Alias the data structure. 803 data = self.relax.data.res[self.run][1] 804 805 # Error tolerance. 806 error = 1e-8 807 808 # Test the values. 809 success = 1 810 if not self.test_values(val1=0.91619994957822126, val2=data.s2, error=error, name='S2 value'): 811 success = 0 812 if not self.test_values(val1=1.2319687570987945e-13, val2=data.te, error=error, name='te value (ns)', scale=1e9): 813 success = 0 814 if not self.test_values(val1=0.16249110942961512 / (2.0 * pi * data.frq[0])**2, val2=data.rex, error=error, name='Rex value', scale=(2.0 * pi * data.frq[0])**2): 815 success = 0 816 if not self.test_values(val1=73.843613546506191, val2=data.chi2, error=error, name='chi-squared value'): 817 success = 0 818 if not self.test_values(val1=50, val2=data.iter, name='iteration count', max=1): 819 success = 0 820 if not self.test_values(val1=108, val2=data.f_count, name='function count', max=1): 821 success = 0 822 if not self.test_values(val1=108, val2=data.g_count, name='gradient count', max=1): 823 success = 0 824 if not self.test_values(val1=0, val2=data.h_count, name='Hessian count', max=1): 825 success = 0 826 827 # Warning. 828 if data.warning and not data.warning == 'Maximum number of iterations reached': 829 print data.warning 830 success = 0 831 832 # Success. 833 return success
834 835
837 """Optimisation test. 838 839 The optimisation options are: 840 Constrained grid search. 841 842 The true data set is: 843 S2 = 0.970 844 te = 2048 ps 845 Rex = 0.149 s^-1 846 """ 847 848 # Setup the run for optimisation. 849 self.opt_setup_S2_0_970_te_2048_Rex_0_149(run) 850 851 # Grid search. 852 self.relax.interpreter._Minimisation.grid_search(self.run, inc=11) 853 854 # Test the optimisation statistics and parameter values. 855 ######################################################## 856 857 # Alias the data structure. 858 data = self.relax.data.res[self.run][1] 859 860 # Error tolerance. 861 error = 1e-8 862 863 # Test the values. 864 success = 1 865 if not self.test_values(val1=1.0, val2=data.s2, error=error, name='S2 value'): 866 success = 0 867 if not self.test_values(val1=0.0, val2=data.te, error=error, name='te value (ns)', scale=1e9): 868 success = 0 869 if not self.test_values(val1=0.0, val2=data.rex, error=error, name='Rex value'): 870 success = 0 871 if not self.test_values(val1=3.9844117908982288, val2=data.chi2, error=error, name='chi-squared value'): 872 success = 0 873 if not self.test_values(val1=1331, val2=data.iter, name='iteration count', max=1): 874 success = 0 875 if not self.test_values(val1=1331, val2=data.f_count, name='function count', max=1): 876 success = 0 877 if not self.test_values(val1=0, val2=data.g_count, name='gradient count', max=1): 878 success = 0 879 if not self.test_values(val1=0, val2=data.h_count, name='Hessian count', max=1): 880 success = 0 881 882 # Warning. 883 if data.warning: 884 print data.warning 885 success = 0 886 887 # Success. 888 return success
889 890
892 """Setup the run for testing optimisation. 893 894 The data set is: 895 S2 = 0.970. 896 te = 2048 ps. 897 Rex = 0.149 s^-1. 898 """ 899 900 # Create the run. 901 self.run = run 902 self.relax.generic.runs.create(self.run, 'mf') 903 904 # Path of the files. 905 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 906 907 # Nuclei type 908 self.relax.interpreter._Nuclei.nuclei('N') 909 910 # Load the sequence. 911 self.relax.interpreter._Sequence.read(self.run, 'noe.500.out', dir=path) 912 913 # Load the relaxation data. 914 self.relax.interpreter._Relax_data.read(self.run, 'R1', '600', 600.0 * 1e6, 'r1.600.out', dir=path) 915 self.relax.interpreter._Relax_data.read(self.run, 'R2', '600', 600.0 * 1e6, 'r2.600.out', dir=path) 916 self.relax.interpreter._Relax_data.read(self.run, 'NOE', '600', 600.0 * 1e6, 'noe.600.out', dir=path) 917 self.relax.interpreter._Relax_data.read(self.run, 'R1', '500', 500.0 * 1e6, 'r1.500.out', dir=path) 918 self.relax.interpreter._Relax_data.read(self.run, 'R2', '500', 500.0 * 1e6, 'r2.500.out', dir=path) 919 self.relax.interpreter._Relax_data.read(self.run, 'NOE', '500', 500.0 * 1e6, 'noe.500.out', dir=path) 920 921 # Setup other values. 922 self.relax.interpreter._Diffusion_tensor.init(self.run, 10e-9, fixed=1) 923 self.relax.interpreter._Value.set(self.run, 1.02 * 1e-10, 'bond_length') 924 self.relax.interpreter._Value.set(self.run, -160 * 1e-6, 'csa') 925 926 # Select the model-free model. 927 self.relax.interpreter._Model_free.select_model(run=self.run, model='m4')
928 929
930 - def read_relax_data(self, run):
931 """The relaxation data reading test.""" 932 933 # Arguments. 934 self.run = run 935 936 # Create the run. 937 self.relax.generic.runs.create(self.run, 'mf') 938 939 # Path of the files. 940 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 941 942 # Read the sequence. 943 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 944 945 # Read the relaxation data. 946 self.relax.interpreter._Relax_data.read(self.run, 'R1', '600', 600.0 * 1e6, 'r1.600.out', dir=path) 947 948 # Test the data. 949 if self.relax.data.res[self.run][1].relax_data[0] != 1.3874977659397683: 950 print "The relaxation data does not match." 951 return 952 953 # Test the error. 954 if self.relax.data.res[self.run][1].relax_error[0] != 0.027749955318795365: 955 print "The relaxation error does not match." 956 return 957 958 return 1
959 960
961 - def read_results(self, run):
962 """The results reading test.""" 963 964 # Arguments. 965 self.run = run 966 967 # Load the original state. 968 self.relax.interpreter._State.load(file='orig_state', dir=sys.path[-1] + '/test_suite/data/model_free') 969 970 # Create the run. 971 self.relax.generic.runs.create(self.run, 'mf') 972 973 # Read the results. 974 self.relax.interpreter._Results.read(self.run, dir=sys.path[-1] + '/test_suite/data/model_free') 975 976 # Print out. 977 print "\nTesting the integrity of the loaded data.\n" 978 979 # Diffusion tensor type. 980 if self.relax.data.diff['orig'].type != self.relax.data.diff[self.run].type: 981 print "The diffusion tensor types do not match." 982 return 983 984 # tm. 985 if self.relax.data.diff['orig'].tm != self.relax.data.diff[self.run].tm: 986 print "The tm values do not match." 987 return 988 989 # Loop over the residues of the original data. 990 for i in xrange(len(self.relax.data.res['orig'])): 991 # Aliases 992 orig_data = self.relax.data.res['orig'][i] 993 new_data = self.relax.data.res[self.run][i] 994 995 # Residue alias. 996 self.orig_res = `orig_data.num` + orig_data.name 997 self.new_res = `new_data.num` + new_data.name 998 999 # Residue numbers. 1000 if orig_data.num != new_data.num: 1001 self.print_error('residue numbers') 1002 return 1003 1004 # Residue names. 1005 if orig_data.name != new_data.name: 1006 self.print_error('residue names') 1007 return 1008 1009 # Selection. 1010 if orig_data.select != new_data.select: 1011 self.print_error('selection flags') 1012 return 1013 1014 # Skip unselected residues. 1015 if not orig_data.select: 1016 continue 1017 1018 # Model-free model test. 1019 if orig_data.model != new_data.model: 1020 self.print_error('model-free models') 1021 return 1022 1023 # Model-free parameter set test. 1024 if orig_data.params != new_data.params: 1025 self.print_error('model-free parameter sets') 1026 return 1027 1028 # S2 test. 1029 if orig_data.s2 != new_data.s2: 1030 self.print_error('S2 values') 1031 return 1032 1033 # S2f test. 1034 if orig_data.s2f != new_data.s2f: 1035 self.print_error('S2f values') 1036 return 1037 1038 # S2s test. 1039 if orig_data.s2s != new_data.s2s: 1040 self.print_error('S2s values') 1041 return 1042 1043 # local tm test. 1044 if orig_data.local_tm != new_data.local_tm: 1045 self.print_error('local tm values') 1046 return 1047 1048 # te test. 1049 if orig_data.te != new_data.te: 1050 self.print_error('te values') 1051 return 1052 1053 # tf test. 1054 if orig_data.tf != new_data.tf: 1055 self.print_error('tf values') 1056 return 1057 1058 # ts test. 1059 if orig_data.ts != new_data.ts: 1060 self.print_error('ts values') 1061 return 1062 1063 # Rex test. 1064 if orig_data.rex != new_data.rex: 1065 self.print_error('Rex values') 1066 return 1067 1068 # bond length test. 1069 if orig_data.r != new_data.r: 1070 self.print_error('bond length values') 1071 return 1072 1073 # CSA test. 1074 if orig_data.csa != new_data.csa: 1075 self.print_error('CSA values') 1076 return 1077 1078 # Chi-squared test. 1079 if orig_data.chi2 != new_data.chi2: 1080 self.print_error('Chi-squared values') 1081 return 1082 1083 # Iteration number test. 1084 if orig_data.iter != new_data.iter: 1085 self.print_error('iteration numbers') 1086 return 1087 1088 # Function count test. 1089 if orig_data.f_count != new_data.f_count: 1090 self.print_error('function counts') 1091 return 1092 1093 # Gradient count test. 1094 if orig_data.g_count != new_data.g_count: 1095 self.print_error('gradient counts') 1096 return 1097 1098 # Hessian count test. 1099 if orig_data.h_count != new_data.h_count: 1100 self.print_error('Hessian counts') 1101 return 1102 1103 # Warning test. 1104 if orig_data.warning != new_data.warning: 1105 self.print_error('warnings') 1106 return 1107 1108 # Relaxation data lables test. 1109 if orig_data.ri_labels != new_data.ri_labels: 1110 self.print_error('relaxation data labels') 1111 return 1112 1113 # Relaxation data remap table test. 1114 if orig_data.remap_table != new_data.remap_table: 1115 self.print_error('relaxation data remap tables') 1116 return 1117 1118 # Frequency lables test. 1119 if orig_data.frq_labels != new_data.frq_labels: 1120 self.print_error('frequency labels') 1121 return 1122 1123 # Relaxation data test. 1124 if orig_data.relax_data != new_data.relax_data: 1125 self.print_error('relaxation data') 1126 return 1127 1128 # Relaxation data error test. 1129 if orig_data.relax_error != new_data.relax_error: 1130 self.print_error('relaxation data errors') 1131 return 1132 1133 # Success. 1134 print "The data structures have been created successfully." 1135 return 1
1136 1137
1138 - def print_error(self, name):
1139 """Function for printing a residue mismatch.""" 1140 1141 print "The " + name + " of " + self.orig_res + " and " + self.new_res + " do not match."
1142 1143
1144 - def select_m4(self, run):
1145 """Testing the selection of model-free model m4.""" 1146 1147 # Arguments. 1148 self.run = run 1149 1150 # Create the run. 1151 self.relax.generic.runs.create(self.run, 'mf') 1152 1153 # Path of the files. 1154 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 1155 1156 # Read the sequence. 1157 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 1158 1159 # Select the model. 1160 self.relax.interpreter._Model_free.select_model(self.run, model='m4') 1161 1162 # Test the model. 1163 if self.relax.data.res[self.run][1].model != 'm4': 1164 print "The model has not been selected." 1165 return 1166 1167 # Test the parameters. 1168 if self.relax.data.res[self.run][1].params != ['S2', 'te', 'Rex']: 1169 print "The parameters are incorrect." 1170 return 1171 1172 return 1
1173 1174
1175 - def set_bond_length(self, run):
1176 """Testing the setting of the bond length.""" 1177 1178 # Arguments. 1179 self.run = run 1180 1181 # Create the run. 1182 self.relax.generic.runs.create(self.run, 'mf') 1183 1184 # Path of the files. 1185 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 1186 1187 # Read the sequence. 1188 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 1189 1190 # Set the CSA value. 1191 self.relax.interpreter._Value.set(self.run, 1.02 * 1e-10, 'bond_length') 1192 1193 # Test the value. 1194 if self.relax.data.res[self.run][1].r != 1.02 * 1e-10: 1195 print "The bond length has not been set correctly." 1196 return 1197 1198 return 1
1199 1200
1201 - def set_csa(self, run):
1202 """Testing the setting of the CSA value.""" 1203 1204 # Arguments. 1205 self.run = run 1206 1207 # Create the run. 1208 self.relax.generic.runs.create(self.run, 'mf') 1209 1210 # Path of the files. 1211 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 1212 1213 # Read the sequence. 1214 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 1215 1216 # Set the CSA value. 1217 self.relax.interpreter._Value.set(self.run, -172 * 1e-6, 'csa') 1218 1219 # Test the value. 1220 if self.relax.data.res[self.run][1].csa != -172*1e-6: 1221 print "The CSA value has not been set correctly." 1222 return 1223 1224 return 1
1225 1226
1227 - def set_csa_bond_length(self, run):
1228 """Testing the setting of the CSA value and bond length simultaneously.""" 1229 1230 # Arguments. 1231 self.run = run 1232 1233 # Create the run. 1234 self.relax.generic.runs.create(self.run, 'mf') 1235 1236 # Path of the files. 1237 path = sys.path[-1] + '/test_suite/data/model_free/S2_0.970_te_2048_Rex_0.149' 1238 1239 # Read the sequence. 1240 self.relax.interpreter._Sequence.read(self.run, file='noe.500.out', dir=path) 1241 1242 # Set the CSA value and bond length simultaneously. 1243 self.relax.interpreter._Value.set(self.run, [-172 * 1e-6, 1.02 * 1e-10], ['csa', 'bond_length']) 1244 1245 # Test the CSA value. 1246 if self.relax.data.res[self.run][1].csa != -172*1e-6: 1247 print "The CSA value has not been set correctly." 1248 return 1249 1250 # Test the bond length. 1251 if self.relax.data.res[self.run][1].r != 1.02 * 1e-10: 1252 print "The bond length has not been set correctly." 1253 return 1254 1255 return 1
1256 1257
1258 - def test_values(self, val1, val2, error=None, name=None, scale=1.0, max=0):
1259 """Test that value 1 is equal to value 2, within the error.""" 1260 1261 # Failure (with an error tolerance). 1262 if error: 1263 if val2*scale < val1*scale - error or val2*scale > val1*scale + error: 1264 print "The " + name + " of " + `val2*scale` + " should be within +/- " + `error` + " of " + `val1*scale` + "." 1265 return 1266 1267 # Failure (val2 is greater than val1). 1268 elif max: 1269 if val2 > val1: 1270 print "The " + name + " of " + `val2*scale` + " should be less than " + `val1*scale` + "." 1271 return 1272 1273 # Failure (with no error tolerance). 1274 else: 1275 if val2 != val1: 1276 print "The " + name + " of " + `val2*scale` + " should be " + `val1*scale` + "." 1277 return 1278 1279 # Success. 1280 return 1
1281