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

Source Code for Module test_suite.system_tests.n_state_model

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2008-2013 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2013 Troels E. Linnet                                         # 
   5  #                                                                             # 
   6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   7  #                                                                             # 
   8  # This program is free software: you can redistribute it and/or modify        # 
   9  # it under the terms of the GNU General Public License as published by        # 
  10  # the Free Software Foundation, either version 3 of the License, or           # 
  11  # (at your option) any later version.                                         # 
  12  #                                                                             # 
  13  # This program is distributed in the hope that it will be useful,             # 
  14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  16  # GNU General Public License for more details.                                # 
  17  #                                                                             # 
  18  # You should have received a copy of the GNU General Public License           # 
  19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  20  #                                                                             # 
  21  ############################################################################### 
  22   
  23  # Python module imports. 
  24  from math import pi 
  25  from numpy import array, float64 
  26  from numpy.linalg import norm 
  27  from os import listdir, sep 
  28  from tempfile import mkdtemp 
  29   
  30  # relax module imports. 
  31  from auto_analyses import stereochem_analysis 
  32  from data_store import Relax_data_store; ds = Relax_data_store() 
  33  import dep_check 
  34  from pipe_control.align_tensor import calc_chi_tensor 
  35  from pipe_control.interatomic import interatomic_loop, return_interatom 
  36  from pipe_control.mol_res_spin import return_spin, spin_index_loop, spin_loop 
  37  from pipe_control.pipes import get_pipe 
  38  from pipe_control.rdc import return_rdc_data 
  39  from status import Status; status = Status() 
  40  from test_suite.system_tests.base_classes import SystemTestCase 
  41   
  42   
43 -class N_state_model(SystemTestCase):
44 """Class for testing various aspects specific to the N-state model.""" 45
46 - def __init__(self, methodName='runTest'):
47 """Skip some tests if scipy is not installed. 48 49 @keyword methodName: The name of the test. 50 @type methodName: str 51 """ 52 53 # Execute the base class method. 54 super(N_state_model, self).__init__(methodName) 55 56 # Missing module. 57 if not dep_check.scipy_module and methodName == 'test_frame_order_align_fit': 58 # Store in the status object. 59 status.skipped_tests.append([methodName, 'Scipy', self._skip_type])
60 61
62 - def check_vectors(self):
63 """Auxiliary method for checking the correct loading of bond vectors.""" 64 65 # The new order. 66 ds.order_new = array([ds.order_struct[ds.order_model[ds.order_model[0]]], 67 ds.order_struct[ds.order_model[ds.order_model[1]]], 68 ds.order_struct[ds.order_model[ds.order_model[2]]]]) 69 70 # The atom positions. 71 C_pos = [] 72 C_pos.append(array([6.250, 0.948, 1.968])) 73 C_pos.append(array([6.438, -0.139, 1.226])) 74 C_pos.append(array([6.108, -0.169, 0.378])) 75 76 H_pos = [] 77 H_pos.append(array([7.243, 0.580, 1.676])) 78 H_pos.append(array([7.271, -0.291, 0.525])) 79 H_pos.append(array([5.735, 0.003, -0.639])) 80 81 # The real vectors. 82 vect = [] 83 for i in range(3): 84 vect.append(H_pos[i] - C_pos[i]) 85 86 # Normalise. 87 for i in range(3): 88 vect[i] = vect[i] / norm(vect[i]) 89 90 # Print out. 91 print("Structure order: %s" % ds.order_struct) 92 print("Model order: %s" % ds.order_model) 93 print("New order: %s" % ds.order_new) 94 for i in range(3): 95 print("\ni = %i" % i) 96 print("The real vector: %s" % vect[i]) 97 print("The reordered vector: %s" % vect[ds.order_new[i]]) 98 print("The loaded vector: %s" % cdp.interatomic[0].vector[i]) 99 100 # Check. 101 for i in range(3): 102 self.assertAlmostEqual(norm(C_pos[ds.order_new[i]] - cdp.mol[0].res[0].spin[0].pos[i]), 0.0) 103 self.assertAlmostEqual(norm(H_pos[ds.order_new[i]] - cdp.mol[0].res[0].spin[1].pos[i]), 0.0) 104 for i in range(3): 105 self.assertAlmostEqual(norm(vect[ds.order_new[i]] - cdp.interatomic[0].vector[i]), 0.0)
106 107
108 - def test_5_state_xz(self):
109 """A 5-state model in the xz-plane (no pivotting of alpha). 110 111 The 5 states correspond to the Euler angles (z-y-z notation): 112 - State 1: {0, pi/4, 0} 113 - State 2: {0, pi/8, 0} 114 - State 3: {0, 0, 0} 115 - State 4: {0, -pi/8, 0} 116 - State 5: {0, -pi/4, 0} 117 """ 118 119 # Execute the script. 120 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'5_state_xz.py') 121 122 # Test the optimised probabilities. 123 self.assertAlmostEqual(cdp.probs[0], 0.2) 124 self.assertAlmostEqual(cdp.probs[1], 0.2) 125 self.assertAlmostEqual(cdp.probs[2], 0.2) 126 self.assertAlmostEqual(cdp.probs[3], 0.2) 127 self.assertAlmostEqual(cdp.probs[4], 0.2) 128 129 # Test the optimised alpha Euler angles. 130 self.assertAlmostEqual(cdp.alpha[0], 0.0) 131 self.assertAlmostEqual(cdp.alpha[1], 0.0) 132 self.assertAlmostEqual(cdp.alpha[2], 0.0) 133 self.assertAlmostEqual(cdp.alpha[3], 0.0) 134 self.assertAlmostEqual(cdp.alpha[4], 0.0) 135 136 # Test the optimised beta Euler angles. 137 self.assertAlmostEqual(cdp.beta[0], pi/4) 138 self.assertAlmostEqual(cdp.beta[1], pi/8) 139 self.assertAlmostEqual(cdp.beta[2], 0.0) 140 self.assertAlmostEqual(cdp.beta[3], -pi/8) 141 self.assertAlmostEqual(cdp.beta[4], -pi/4) 142 143 # Test the optimised gamma Euler angles. 144 self.assertAlmostEqual(cdp.gamma[0], 0.0) 145 self.assertAlmostEqual(cdp.gamma[1], 0.0) 146 self.assertAlmostEqual(cdp.gamma[2], 0.0) 147 self.assertAlmostEqual(cdp.gamma[3], 0.0) 148 self.assertAlmostEqual(cdp.gamma[4], 0.0) 149 150 # Test the chi-squared. 151 self.assertAlmostEqual(cdp.chi2, 3.15009916529e-32)
152 153
154 - def test_A_to_chi(self):
155 """Test the conversion of the alignment tensor to the chi tensor.""" 156 157 # Execute the script. 158 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'A_to_chi.py') 159 160 # Test the optimised values. 161 for i in range(3): 162 self.assertAlmostEqual(cdp.chi[i, i] * 1e32, cdp.chi_ref[i] * 1e32, 2)
163 164
165 - def test_absolute_rdc(self):
166 """Test the fitting of signless RDCs.""" 167 168 # Execute the script. 169 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'absolute_rdcs.py') 170 171 # Test the optimised values. 172 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 173 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 174 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 175 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 176 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 177 self.assertAlmostEqual(cdp.chi2, 0.0) 178 self.assertAlmostEqual(cdp.q_rdc, 0.0) 179 180 # The signless RDC data. 181 rdcs = [5.59633342475, 13.31357940769, 7.03826972130, 3.39286328073, 2.09118060289, 11.44314950665, 9.06351706695, 2.33713806872, 5.81432510092, 13.10212128419, 2.52845064335, 4.70528375938, 4.07965480340, 6.28030444828, 4.69179757106, 2.34216201798, 3.89567105101, 5.51427513007, 0.72184322202, 3.81502890358, 10.88354253947, 1.66151988717, 4.29930397984, 4.46950447650, 6.99742077188, 2.27879506276, 3.64303288709, 6.83945430255, 3.19585334782] 182 183 # Back calc. 184 self.interpreter.rdc.back_calc('abs') 185 186 # Check the spin data. 187 i = 0 188 for spin in spin_loop(): 189 # No PCS. 190 if not hasattr(spin, 'rdc'): 191 continue 192 193 # Check the loaded and back-calculated absolute values. 194 self.assertAlmostEqual(spin.rdc['abs'], abs(rdcs[i])) 195 self.assertAlmostEqual(spin.rdc_bc['abs'], abs(rdcs[i])) 196 197 # Increment the spin index. 198 i += 1
199 200
201 - def test_absolute_rdc_menthol(self):
202 """Test the fitting of signless RDCs for menthol.""" 203 204 # Execute the script. 205 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'absolute_rdcs_menthol.py') 206 207 # Test the optimised values. 208 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -2.183595975281820e-04) 209 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, -7.014379141006286e-05) 210 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -1.744959310458587e-05) 211 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 3.646699595026552e-05) 212 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, 2.592895195459969e-04) 213 self.assertAlmostEqual(cdp.chi2, 728.32717233107246) 214 self.assertAlmostEqual(cdp.q_rdc, 0.0) 215 self.assertAlmostEqual(cdp.q_rdc_norm2, 0.7547452273747645)
216 217
218 - def test_absolute_T(self):
219 """Test the fitting of signless T values (J+D).""" 220 221 # Execute the script. 222 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'absolute_T.py') 223 224 # Test the optimised values. 225 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -1.436586299657e-04) 226 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, -5.004443735044e-04) 227 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -5.017832275009e-05) 228 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 1.366097786433e-04) 229 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -1.614772175671e-04) 230 self.assertAlmostEqual(cdp.chi2, 311.70348701353225) 231 self.assertAlmostEqual(cdp.q_rdc, 0.0) 232 self.assertAlmostEqual(cdp.q_rdc_norm2, 0.086891848854541404) 233 234 # The signless T data. 235 T = [195.2, 205.9, 109.4, 113.8, 127.4, 156.0, 92.1, 173.2, 183.0, 174.3, 152.2, 97.3, 136.0, 129.2, 145.5, 156.0, 121.6, 128.0, 154.5, 94.2] 236 T_bc = [ 237 195.009353539915281, 238 205.456622836526037, 239 112.285085032859712, 240 113.628896345578610, 241 127.440986667041187, 242 155.505017063790831, 243 94.332271833299316, 244 172.408496922639102, 245 181.972859458051403, 246 173.655640981746103, 247 153.402585241137388, 248 92.115389822570464, 249 139.743303992644570, 250 131.399101601878243, 251 146.219317894376132, 252 153.945261372587538, 253 119.541444938794172, 254 126.620471670822312, 255 155.940753902549545, 256 90.813638474619523 257 ] 258 259 # Back calc. 260 self.interpreter.rdc.back_calc('Gel') 261 262 # Check the spin data. 263 i = 0 264 for interatom in interatomic_loop(): 265 # No PCS. 266 if not hasattr(interatom, 'rdc'): 267 continue 268 269 # Check the loaded and back-calculated absolute values. 270 self.assertAlmostEqual(interatom.rdc['Gel'], T[i]) 271 self.assertAlmostEqual(interatom.rdc_bc['Gel'], T_bc[i], 5) 272 273 # Increment the spin index. 274 i += 1
275 276
277 - def test_align_fit(self):
278 """Test the use of RDCs and PCSs to find the alignment tensor.""" 279 280 # Set the mode to use both RDCs and PCSs. 281 ds.mode = 'all' 282 tag = 'synth' 283 284 # Execute the script. 285 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 286 287 # Test the optimised values. 288 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 289 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 290 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 291 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 292 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 293 self.assertAlmostEqual(cdp.chi2, 0.0) 294 self.assertAlmostEqual(cdp.q_rdc, 0.0) 295 self.assertAlmostEqual(cdp.q_pcs, 0.0) 296 297 # The spin data. 298 pcs = [1.0261275236, 0.75832284646, 0.65377417467, 0.88410306916, 0.83665620282, 1.887881182, 1.6564530832, 1.8489841033, -1.1143070855, -0.52863087918, -0.67600660991, -0.36996952054, -0.50720205688, -0.39889489474, -0.41237130008, -0.71313422816, -0.58642013802, -1.2160818959, -1.3990341569, -1.4084215541, -1.2007391713, -2.1392542193, -2.0165726596, -1.7623442985, -1.6437792517, -1.2415832517, -1.3008765368, -1.5872391105, -1.8060331465, -1.9063640494, -1.9817787999, -0.85264936663, -0.98332177588, -0.13370651687, -0.41762890604, -0.038212181921, -0.37986098085, 0.63582157322, 0.48346482178, 1.7566240094, 1.5694652222, 1.9914499872, 2.5316890107, 1.4559940851, 1.8661428328, 0.65003087965, 0.91690449156, 3.2096229388, 3.5547526651, 3.0579308183, 3.5933428117, 2.9062016872, 3.3750576279, 2.1848555929, 2.4769802024, 1.6466129291, 1.7719619979, 1.1373876736, 1.2182451528] 299 i = 0 300 for spin in spin_loop(): 301 # No PCS. 302 if not hasattr(spin, 'pcs'): 303 continue 304 305 # Check the value. 306 self.assertAlmostEqual(spin.pcs[tag], pcs[i]) 307 308 # Check the back-calculated value. 309 self.assertAlmostEqual(spin.pcs_bc[tag], pcs[i]) 310 311 # Check the simulation values. 312 for sim_index in range(cdp.sim_number): 313 self.assert_(abs(spin.pcs_sim[tag][sim_index] - spin.pcs[tag]) < 6.0*spin.pcs_err[tag]) 314 315 # Increment the spin index. 316 i += 1 317 318 # Back calc. 319 self.interpreter.pcs.back_calc(tag) 320 321 # Check the spin data. 322 i = 0 323 for spin in spin_loop(): 324 # No PCS. 325 if not hasattr(spin, 'pcs'): 326 continue 327 328 # Check the back-calculated value. 329 self.assertAlmostEqual(spin.pcs_bc[tag], pcs[i]) 330 331 # Increment the spin index. 332 i += 1
333 334
335 - def test_align_fit_rand(self):
336 """Test the use of randomised RDCs and PCSs to find the alignment tensor.""" 337 338 # Set the mode to use both RDCs and PCSs. 339 ds.mode = 'all' 340 341 # Select the randomised data. 342 ds.rand = True 343 344 # Execute the script. 345 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 346 347 # The tag. 348 tag = 'synth' 349 350 # Loop a few times. 351 for i in range(4): 352 # Test the optimised values (these values are from relax, so are not 100% reliable as a check). 353 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.000189412096996) 354 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.000271130087923) 355 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.000264898401302) 356 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.000284115871058) 357 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.000152207413184) 358 self.assertAlmostEqual(cdp.chi2, 783.530808266) 359 self.assertAlmostEqual(cdp.q_pcs, 0.063345784112045375) 360 self.assertAlmostEqual(cdp.q_rdc, 0.084926009099013003) 361 362 # Get a spin to check. 363 spin = return_spin(':114@N') 364 interatom = return_interatom(':114@N', ':114@H') 365 366 # Check the RDC and PCS values. 367 self.assertAlmostEqual(interatom.rdc[tag], -8.9193269604999994) 368 self.assertAlmostEqual(interatom.rdc_bc[tag], -9.1030018792821394) 369 self.assertAlmostEqual(spin.pcs[tag], -0.41430390310999998) 370 self.assertAlmostEqual(spin.pcs_bc[tag], -0.39723010845807194) 371 372 # MC sims so next round can check if values change. 373 if i == 0: 374 # Set some errors. 375 for interatom in interatomic_loop(): 376 interatom.rdc_err = {tag: 1.0} 377 for spin in spin_loop(): 378 spin.pcs_err = {tag: 0.1} 379 380 # MC sims. 381 self.interpreter.monte_carlo.setup(number=3) 382 self.interpreter.monte_carlo.create_data() 383 self.interpreter.monte_carlo.initial_values() 384 self.interpreter.minimise('simplex', constraints=False, max_iter=5) 385 self.interpreter.monte_carlo.error_analysis() 386 387 # Back-calc so next round can check if values change. 388 if i == 2: 389 self.interpreter.rdc.back_calc(tag) 390 self.interpreter.pcs.back_calc(tag) 391 392 # Calc Q factors so next round can check if values change. 393 if i == 1: 394 self.interpreter.rdc.calc_q_factors() 395 self.interpreter.pcs.calc_q_factors()
396 397
398 - def test_align_fit_pcs(self):
399 """Test the use of PCSs to find the alignment tensor.""" 400 401 # Set the mode to use PCSs. 402 ds.mode = 'pcs' 403 404 # Execute the script. 405 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 406 407 # Test the optimised values. 408 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 409 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 410 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 411 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 412 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 413 self.assertAlmostEqual(cdp.chi2, 0.0) 414 self.assertAlmostEqual(cdp.q_pcs, 0.0)
415 416
417 - def test_align_fit_pcs_rand(self):
418 """Test the use of randomised PCSs to find the alignment tensor.""" 419 420 # Set the mode to use PCSs. 421 ds.mode = 'pcs' 422 423 # Select the randomised data. 424 ds.rand = True 425 426 # Execute the script. 427 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 428 429 # Test the optimised values (these values are from relax, so are not 100% reliable as a check). 430 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.000189165581069) 431 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.000271897288335) 432 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.000264627388896) 433 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.000284180080857) 434 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.00015165641132) 435 self.assertAlmostEqual(cdp.chi2, 756.268087443) 436 self.assertAlmostEqual(cdp.q_pcs, 0.063341567973121266)
437 438
439 - def test_align_fit_rdc(self):
440 """Test the use of RDCs to find the alignment tensor.""" 441 442 # Set the mode to use RDCs. 443 ds.mode = 'rdc' 444 445 # Execute the script. 446 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 447 448 # Test the optimised values. 449 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 450 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 451 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 452 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 453 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 454 self.assertAlmostEqual(cdp.chi2, 0.0) 455 self.assertAlmostEqual(cdp.q_rdc, 0.0)
456 457
458 - def test_align_fit_rdc_rand(self):
459 """Test the use of randomised RDCs to find the alignment tensor.""" 460 461 # Set the mode to use RDCs. 462 ds.mode = 'rdc' 463 464 # Select the randomised data. 465 ds.rand = True 466 467 # Execute the script. 468 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 469 470 # Test the optimised values (these are about ~10% different from Pales). 471 # Pales: S(zz) S(xx-yy) S(xy) S(xz) S(yz) 472 # Pales: -9.8124e-05 -5.2533e-04 -3.4446e-04 3.7369e-04 -1.8949e-04 473 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.00017045) 474 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.00024905) 475 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.00027502) 476 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.00029833) 477 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.00015125) 478 self.assertAlmostEqual(cdp.chi2, 23.5877482365) # Pales: 23.709 479 self.assertAlmostEqual(cdp.q_rdc, 0.078460000413257444) # Pales (Q Saupe): 0.079 480 self.assertAlmostEqual(cdp.q_rdc_norm2, 0.14049691097282743) # Pales (Q RDC_RMS): 0.141
481 482
483 - def test_data_copying(self):
484 """The copying of RDC and PCS data from one pipe to another.""" 485 486 # Execute the script. 487 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'data_copying.py') 488 489 # Get the data pipes. 490 orig = get_pipe('orig') 491 new = get_pipe('new') 492 493 # Check the data. 494 self.assertEqual(orig.rdc_ids, new.rdc_ids) 495 self.assertEqual(orig.pcs_ids, new.pcs_ids) 496 self.assertEqual(orig.align_ids, new.align_ids) 497 498 # Check the spin data. 499 for mol_index, res_index, spin_index in spin_index_loop(): 500 # Alias the spin containers. 501 spin_orig = orig.mol[mol_index].res[res_index].spin[spin_index] 502 spin_new = new.mol[mol_index].res[res_index].spin[spin_index] 503 504 # Loop over the alignments. 505 for id in orig.align_ids: 506 # RDC checks. 507 if hasattr(spin_orig, 'rdc'): 508 # Check the keys. 509 self.assertEqual(spin_orig.rdc.keys(), spin_new.rdc.keys()) 510 511 # Check the values. 512 if id in spin_orig.rdc: 513 self.assertEqual(spin_orig.rdc[id], spin_new.rdc[id]) 514 515 # PCS checks. 516 if hasattr(spin_orig, 'pcs'): 517 # Check the keys. 518 self.assertEqual(spin_orig.pcs.keys(), spin_new.pcs.keys()) 519 520 # Check the values. 521 if id in spin_orig.pcs: 522 self.assertEqual(spin_orig.pcs[id], spin_new.pcs[id])
523 524
525 - def test_frame_order_align_fit(self):
526 """Test the use of alignment tensors, RDCs and PCSs from a frame order data pipe for the N-state model.""" 527 528 # Execute the script. 529 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'frame_order_align_fit.py') 530 531 # The actual tensors. 532 A_5D = [] 533 A_5D.append([1.42219822168827662867e-04, -1.44543001566521341940e-04, -7.07796211648713973798e-04, -6.01619494082773244303e-04, 2.02008007072950861996e-04]) 534 A_5D.append([3.56720663040924505435e-04, -2.68385787902088840916e-04, -1.69361406642305853832e-04, 1.71873715515064501074e-04, -3.05790155096090983822e-04]) 535 A_5D.append([2.32088908680377300801e-07, 2.08076808579168379617e-06, -2.21735465435989729223e-06, -3.74311563209448033818e-06, -2.40784858070560310370e-06]) 536 A_5D.append([-2.62495279588228071048e-04, 7.35617367964106275147e-04, 6.39754192258981332648e-05, 6.27880171180572523460e-05, 2.01197582457700226708e-04]) 537 538 # Check the tensors. 539 for i in range(1): 540 self.assertAlmostEqual(cdp.align_tensors[i].Axx, A_5D[i][0]) 541 self.assertAlmostEqual(cdp.align_tensors[i].Ayy, A_5D[i][1]) 542 self.assertAlmostEqual(cdp.align_tensors[i].Axy, A_5D[i][2]) 543 self.assertAlmostEqual(cdp.align_tensors[i].Axz, A_5D[i][3]) 544 self.assertAlmostEqual(cdp.align_tensors[i].Ayz, A_5D[i][4]) 545 546 # Test the optimised values. 547 self.assertAlmostEqual(cdp.chi2, 0.0) 548 self.assertAlmostEqual(cdp.q_rdc, 0.0) 549 self.assertAlmostEqual(cdp.q_pcs, 0.0)
550 551
552 - def test_lactose_n_state_fixed(self):
553 """The 4-state model analysis of lactose using RDCs and PCSs.""" 554 555 # The model. 556 ds.model = 'fixed' 557 558 # Execute the script. 559 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'lactose_n_state.py')
560 561
563 """The 4-state model analysis of lactose using RDCs and PCSs.""" 564 565 # The model. 566 ds.model = 'population' 567 568 # Execute the script. 569 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'lactose_n_state.py')
570 571
572 - def test_mc_sim_failure(self):
573 """Test the setup of the Monte Carlo simulations 574 575 This failed when this test was added, and is probably due to missing data. 576 """ 577 578 # Reset and load the state. 579 path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'n_state_model_mc_fail.bz2' 580 self.interpreter.reset() 581 self.interpreter.state.load(path) 582 583 # Monte Carlo simulations. 584 self.interpreter.monte_carlo.setup(number=3) 585 self.interpreter.monte_carlo.create_data() 586 self.interpreter.monte_carlo.initial_values() 587 self.interpreter.minimise('newton', constraints=False) 588 self.interpreter.monte_carlo.error_analysis() 589 590 # Activate the optimisation of the paramagnetic centre position and try again. 591 self.interpreter.paramag.centre(fix=False) 592 self.interpreter.monte_carlo.setup(number=3) 593 self.interpreter.monte_carlo.create_data() 594 self.interpreter.monte_carlo.initial_values() 595 self.interpreter.minimise('bfgs', constraints=False, max_iter=100) 596 self.interpreter.monte_carlo.error_analysis()
597 598
599 - def test_metal_pos_opt(self):
600 """Test a certain algorithm for the optimisation of the lanthanide position using RDCs and PCSs (with missing data).""" 601 602 # Execute the script. 603 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'metal_pos_opt.py') 604 605 # Check the metal position. 606 self.assertAlmostEqual(cdp.paramagnetic_centre[0], -14.845) 607 self.assertAlmostEqual(cdp.paramagnetic_centre[1], 0.969) 608 self.assertAlmostEqual(cdp.paramagnetic_centre[2], 0.265) 609 610 # The actual tensors. 611 A_5D = [] 612 A_5D.append([1.42219822168827662867e-04, -1.44543001566521341940e-04, -7.07796211648713973798e-04, -6.01619494082773244303e-04, 2.02008007072950861996e-04]) 613 A_5D.append([3.56720663040924505435e-04, -2.68385787902088840916e-04, -1.69361406642305853832e-04, 1.71873715515064501074e-04, -3.05790155096090983822e-04]) 614 A_5D.append([2.32088908680377300801e-07, 2.08076808579168379617e-06, -2.21735465435989729223e-06, -3.74311563209448033818e-06, -2.40784858070560310370e-06]) 615 A_5D.append([-2.62495279588228071048e-04, 7.35617367964106275147e-04, 6.39754192258981332648e-05, 6.27880171180572523460e-05, 2.01197582457700226708e-04]) 616 617 # Check the tensors. 618 for i in range(len(A_5D)): 619 self.assertAlmostEqual(cdp.align_tensors[i].Axx, A_5D[i][0]) 620 self.assertAlmostEqual(cdp.align_tensors[i].Ayy, A_5D[i][1]) 621 self.assertAlmostEqual(cdp.align_tensors[i].Axy, A_5D[i][2]) 622 self.assertAlmostEqual(cdp.align_tensors[i].Axz, A_5D[i][3]) 623 self.assertAlmostEqual(cdp.align_tensors[i].Ayz, A_5D[i][4]) 624 625 # Test the optimised values. 626 self.assertAlmostEqual(cdp.chi2, 0.0) 627 self.assertAlmostEqual(cdp.q_rdc, 0.0) 628 self.assertAlmostEqual(cdp.q_pcs, 0.0) 629 630 # The spin data. 631 pcs = { 632 'Dy': [ 0.257602207272000, 0.068336164014900, 0.110603133551000, 0.283488541078000, 0.339904760907000, 0.987042929223000, 0.442512226783000, 0.369383947069000, 0.576421001305000, 0.414840770458000, 0.332707187464000, -0.029503579631700, 0.134647155776000, 0.112481223655000, 0.355198596515000, -0.046913037723100, -0.118710220626000, 0.029273074820300, 0.302949891871000, 1.312854817740000, 0.040875625448800, 0.608281919748000, 0.023360076276000, 0.811293913028000, 0.258701382871000, 0.056025797668300, 0.609547727298000, 0.906885191563000], 633 'Tb': [0.644225239812000, 0.677797993460000, 0.492912191403000, 0.524119985177000, 0.600493382214000, 0.501470795483000, 0.516761193931000, 0.702967176951000, 0.914836321239000, 1.318114995620000, 1.350055099220000, 0.893477362442000, 0.999911636071000, 1.065232203160000, 0.996395971540000, 0.720982749003000, 1.374318729640000, 2.106902457600000], 634 'Tm': [ 0.000125066528687, -0.000564062193363, -0.000607973317902, 0.000090266635200, 0.000174865797403, 0.002488010156480, 0.000830246873289, 0.000762523870219, -0.000096933008248, 0.000742665143642, -0.000215152849719], 635 'Er': [-0.481445160767000, -0.361046693640000, -0.370098680342000, -0.413514467402000, -0.410802287329000, -1.081011578870000, -0.963176128222000, -0.745366702244000, -0.674570724880000, -0.751320872646000, -0.684906087274000, -0.461253969271000, -0.443680922437000, -0.344056233315000, -0.328118573270000, -0.395048353548000, -0.356220572284000, -0.324533952261000, -0.411777498713000, -0.511811581196000, -1.018565433020000, -0.959481602761000, -0.734022165690000, -0.660034918889000, -0.709085634512000, -0.878775632044000, -0.553464480425000, -0.765371835675000, -1.548006987460000] 636 } 637 spin_deselect_blacklist = ['pcs_bc', 'pcs_sim'] 638 639 # Loop over the align IDs. 640 for tag in ['Dy', 'Tb', 'Tm', 'Er']: 641 i = 0 642 for spin, spin_id in spin_loop(return_id=True): 643 # Deselected spin. 644 if not spin.select: 645 print("Checking the deselected spin '%s'" % spin_id) 646 647 # Check that the container is clean. 648 for name in spin_deselect_blacklist: 649 print(" Checking the blacklisted object %s." % name) 650 self.assert_(not hasattr(spin, name)) 651 652 # Skip the rest of the checks. 653 continue 654 655 # No PCS. 656 if not hasattr(spin, 'pcs'): 657 print("No PCS for spin '%s'." % spin_id) 658 continue 659 if not tag in spin.pcs: 660 print("No PCS for the '%s' alignment ID for spin '%s'." % (tag, spin_id)) 661 continue 662 print("Checking '%s' PCS data for spin '%s'" % (tag, spin_id)) 663 664 # Check the value. 665 self.assertAlmostEqual(spin.pcs[tag], pcs[tag][i]) 666 667 # Check the back-calculated value. 668 self.assertAlmostEqual(spin.pcs_bc[tag], pcs[tag][i]) 669 670 # Check the simulation values. 671 for sim_index in range(cdp.sim_number): 672 self.assert_(abs(spin.pcs_sim[tag][sim_index] - spin.pcs[tag]) < 6.0*spin.pcs_err[tag]) 673 674 # Increment the spin index. 675 i += 1 676 677 # The interatomic data. 678 rdc = { 679 'Dy': [-30.671893754700001, -31.307246147099999, -29.358121961700000, -7.235977742280000, -45.562589405399997, -42.816624411200003, -41.019354747700000, -25.361318450599999, -44.1129977796], 680 'Tm': [-0.057386340972700, -0.045650398398700, -0.074873514450400, 0.099056143214600, 0.021275817005300, 0.037132036464200, 0.047340390362400, 0.128745838536000, 0.010906407989400], 681 'Er': [ 22.944150028900001, 23.363231565100001, 25.948323446000000, 6.955380304960000, 1.784067087050000, 7.228324193240000, 8.271072502000001, -7.403618580470000] 682 } 683 interatom_deselect_blacklist = ['rdc_bc', 'rdc_sim'] 684 685 # Loop over the align IDs. 686 for tag in ['Dy', 'Tm', 'Er']: 687 i = 0 688 for interatom in interatomic_loop(): 689 # Deselected interatomic container. 690 if not interatom.select: 691 print("Checking the deselected interatom '%s-%s'" % (interatom.spin_id1, interatom.spin_id2)) 692 693 # Check that the container is clean. 694 for name in interatom_deselect_blacklist: 695 print(" Checking the blacklisted object %s." % name) 696 self.assert_(not hasattr(interatom, name)) 697 698 # Skip the rest of the checks. 699 continue 700 701 # No RDC. 702 if not hasattr(interatom, 'rdc'): 703 print("No RDC for interatom '%s-%s'." % (interatom.spin_id1, interatom.spin_id2)) 704 continue 705 if not tag in interatom.rdc: 706 print("No RDC for the '%s' alignment ID for interatom '%s-%s'." % (tag, interatom.spin_id1, interatom.spin_id2)) 707 continue 708 print("Checking '%s' RDC data for interatom '%s-%s'" % (tag, interatom.spin_id1, interatom.spin_id2)) 709 710 # Check the value. 711 self.assertAlmostEqual(interatom.rdc[tag], rdc[tag][i]) 712 713 # Check the back-calculated value. 714 self.assertAlmostEqual(interatom.rdc_bc[tag], rdc[tag][i]) 715 716 # Check the simulation values. 717 for sim_index in range(cdp.sim_number): 718 self.assert_(abs(interatom.rdc_sim[tag][sim_index] - interatom.rdc[tag]) < 6.0*interatom.rdc_err[tag]) 719 720 # Increment the interatom index. 721 i += 1
722 723
724 - def test_missing_data(self):
725 """Test the use of RDCs and PCSs to find the alignment tensor with missing data.""" 726 727 # Execute the script. 728 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'missing_data_test.py') 729 730 # The actual tensors. 731 A_5D = [] 732 A_5D.append([1.42219822168827662867e-04, -1.44543001566521341940e-04, -7.07796211648713973798e-04, -6.01619494082773244303e-04, 2.02008007072950861996e-04]) 733 A_5D.append([3.56720663040924505435e-04, -2.68385787902088840916e-04, -1.69361406642305853832e-04, 1.71873715515064501074e-04, -3.05790155096090983822e-04]) 734 A_5D.append([2.32088908680377300801e-07, 2.08076808579168379617e-06, -2.21735465435989729223e-06, -3.74311563209448033818e-06, -2.40784858070560310370e-06]) 735 A_5D.append([-2.62495279588228071048e-04, 7.35617367964106275147e-04, 6.39754192258981332648e-05, 6.27880171180572523460e-05, 2.01197582457700226708e-04]) 736 737 # Check the tensors. 738 for i in range(len(A_5D)): 739 self.assertAlmostEqual(cdp.align_tensors[i].Axx, A_5D[i][0]) 740 self.assertAlmostEqual(cdp.align_tensors[i].Ayy, A_5D[i][1]) 741 self.assertAlmostEqual(cdp.align_tensors[i].Axy, A_5D[i][2]) 742 self.assertAlmostEqual(cdp.align_tensors[i].Axz, A_5D[i][3]) 743 self.assertAlmostEqual(cdp.align_tensors[i].Ayz, A_5D[i][4]) 744 745 # Test the optimised values. 746 self.assertAlmostEqual(cdp.chi2, 0.0) 747 self.assertAlmostEqual(cdp.q_rdc, 0.0) 748 self.assertAlmostEqual(cdp.q_pcs, 0.0)
749 750
751 - def test_monte_carlo_sims(self):
752 """Test the Monte Carlo simulation data of fitting RDCs and PCSs.""" 753 754 # Execute the script. 755 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'monte_carlo_testing.py') 756 757 # Test the optimised values. 758 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 759 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 760 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 761 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 762 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 763 self.assertAlmostEqual(cdp.chi2 / 1e6, 1745860.0485368515 / 1e6, 6) 764 self.assertAlmostEqual(cdp.q_rdc, 0.0) 765 self.assertAlmostEqual(cdp.q_pcs, 0.0) 766 767 # The tensor key. 768 key = 'synth' 769 770 # The spin data. 771 for spin in spin_loop(): 772 # Print out. 773 print(spin) 774 775 # Check for simulation data. 776 self.assert_(hasattr(spin, 'pcs_sim')) 777 self.assert_(key in spin.pcs_sim) 778 779 # Check the values of the simulated data. 780 for i in range(cdp.sim_number): 781 self.assertAlmostEqual(spin.pcs[key], spin.pcs_sim[key][i]) 782 783 # The interatomic data. 784 for interatom in interatomic_loop(): 785 # Print out. 786 print(interatom) 787 788 # Check for simulation data. 789 self.assert_(hasattr(interatom, 'rdc_sim')) 790 self.assert_(key in interatom.rdc_sim) 791 792 # Check the values of the simulated data. 793 for i in range(cdp.sim_number): 794 self.assertAlmostEqual(interatom.rdc[key], interatom.rdc_sim[key][i], 5) 795 796 # Test the optimised simluation values. 797 for i in range(cdp.sim_number): 798 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 799 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 800 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 801 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 802 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 803 self.assertAlmostEqual(cdp.chi2 / 1e6, 1745860.0485368515 / 1e6, 5) 804 805 # Test the tensor error values. 806 self.assertAlmostEqual(cdp.align_tensors[0].Axx_err, 0.0) 807 self.assertAlmostEqual(cdp.align_tensors[0].Ayy_err, 0.0) 808 self.assertAlmostEqual(cdp.align_tensors[0].Axy_err, 0.0) 809 self.assertAlmostEqual(cdp.align_tensors[0].Axz_err, 0.0) 810 self.assertAlmostEqual(cdp.align_tensors[0].Ayz_err, 0.0)
811 812
813 - def test_paramag_align_fit(self):
814 """Test the use of RDCs and PCSs to find the alignment tensor.""" 815 816 # Execute the script. 817 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'paramag_align_fit.py') 818 819 # Test the optimised values. 820 self.assertAlmostEqual(cdp.align_tensors[1].Axx, 0.001414718232784) 821 self.assertAlmostEqual(cdp.align_tensors[1].Ayy, 0.001530457843766) 822 self.assertAlmostEqual(cdp.align_tensors[1].Axy, 0.001689957281873) 823 self.assertAlmostEqual(cdp.align_tensors[1].Axz, 0.000838692329704) 824 self.assertAlmostEqual(cdp.align_tensors[1].Ayz, -0.000984302159683) 825 self.assertAlmostEqual(cdp.q_factors_rdc['Er'], 0.0, 7) 826 self.assertAlmostEqual(cdp.q_factors_rdc_norm2['Er'], 0.0, 7) 827 self.assertAlmostEqual(cdp.q_factors_pcs['Er'], 0.0, 7) 828 self.assertAlmostEqual(cdp.q_rdc, 0.0, 7) 829 self.assertAlmostEqual(cdp.q_pcs, 0.0, 7)
830 831
832 - def test_paramag_centre_fit(self):
833 """Test the use of RDCs and PCSs to find the alignment tensor.""" 834 835 # Set the mode to use both RDCs and PCSs. 836 ds.mode = 'all' 837 838 # Execute the script. 839 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'paramag_centre_fit.py') 840 841 # Check the paramagnetic centre position. 842 self.assertAlmostEqual(cdp.paramagnetic_centre[0], 32.555, 1) 843 self.assertAlmostEqual(cdp.paramagnetic_centre[1], -19.130, 1) 844 self.assertAlmostEqual(cdp.paramagnetic_centre[2], 27.775, 1) 845 846 # Test the optimised values. 847 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000, 5) 848 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000, 5) 849 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000, 5) 850 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000, 5) 851 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000, 5) 852 self.assertAlmostEqual(cdp.chi2, 0.0, 2) 853 self.assertAlmostEqual(cdp.q_rdc, 0.0, 2) 854 self.assertAlmostEqual(cdp.q_pcs, 0.0, 2)
855 856
857 - def test_pcs_back_calc(self):
858 """Test the back-calculation of PCSs for ubiquitin.""" 859 860 # Execute the script. 861 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'pcs_back_calc.py') 862 863 # Test the optimised values. 864 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pcs_bc['A'], 0.061941887563792014) 865 self.assertAlmostEqual(cdp.mol[0].res[1].spin[0].pcs_bc['A'], -0.077886567972081502) 866 self.assertAlmostEqual(cdp.mol[0].res[2].spin[0].pcs_bc['A'], -0.13928519099517916)
867 868
869 - def test_pcs_fit_true_pos(self):
870 """Test the fit of DNA PCSs at the true Ln3+ position.""" 871 872 # Set the Ln3+ position. 873 ds.para_centre = 'true' 874 875 # Execute the script. 876 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'dna_pcs_fit.py') 877 878 # Test the optimised values. 879 self.assertAlmostEqual(cdp.align_tensors[0].Axx, 1.42219822168827662867e-04) 880 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, -1.44543001566521341940e-04) 881 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -7.07796211648713973798e-04) 882 self.assertAlmostEqual(cdp.align_tensors[0].Axz, -6.01619494082773244303e-04) 883 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, 2.02008007072950861996e-04) 884 self.assertAlmostEqual(cdp.chi2, 0.0) 885 self.assertAlmostEqual(cdp.q_pcs, 0.0)
886 887
888 - def test_pcs_fit_zero_pos(self):
889 """Test the fit of DNA PCSs at a Ln3+ position of [0, 0, 0].""" 890 891 # Set the Ln3+ position. 892 ds.para_centre = 'zero' 893 894 # Execute the script. 895 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'dna_pcs_fit.py') 896 897 # Test the optimised values. 898 self.assertAlmostEqual(cdp.align_tensors[0].Axx, 9.739588118243e-07) 899 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, -1.077401299806e-05) 900 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -2.321033328910e-06) 901 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 5.105903556692e-07) 902 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, 1.676638764825e-05) 903 self.assertAlmostEqual(cdp.chi2, 2125.9562247877066) 904 self.assertAlmostEqual(cdp.q_pcs, 0.76065986767333704) 905 906 # The chi tensor. 907 chi_diag = calc_chi_tensor(cdp.align_tensors[0].A_diag, 799.75376122 * 1e6, 298) 908 chi_diag = chi_diag * 1e33 909 self.assertAlmostEqual((chi_diag[2, 2] - (chi_diag[0, 0] + chi_diag[1, 1])/2.0), -6.726159808496, 5) 910 self.assertAlmostEqual((chi_diag[0, 0] - chi_diag[1, 1]), -3.960936794864, 6)
911 912
913 - def test_pcs_to_rdc(self):
914 """Test the back-calculation of RDCs from a PCS derived tensor.""" 915 916 # Execute the script. 917 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'pcs_to_rdc.py') 918 919 # Test the values. 920 self.assertAlmostEqual(cdp.interatomic[0].rdc_bc['A'], 4.1319413321530014) 921 self.assertAlmostEqual(cdp.interatomic[1].rdc_bc['A'], -9.5802642470087989) 922 self.assertAlmostEqual(cdp.interatomic[2].rdc_bc['A'], -16.244078605100817)
923 924
926 """Pyrotarctic anhydride alignment tensor optimisation using long range (1J, 2J & 3J) absolute T (J+D) data.""" 927 928 # The setup. 929 ds.abs_data = 'T' 930 931 # Execute the script. 932 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'pyrotartaric_anhydride.py') 933 934 # Test the optimised values. 935 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.0001756305, 5) 936 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.000278497, 5) 937 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.000253196, 5) 938 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.000280272, 5) 939 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.0001431835, 5) 940 self.assertAlmostEqual(cdp.chi2, 0.0, 2) 941 self.assertAlmostEqual(cdp.q_rdc, 0.0, 2)
942 943
945 """Pyrotarctic anhydride alignment tensor optimisation using short range RDC and long range (1J, 2J & 3J) absolute T (J+D) data.""" 946 947 # The setup. 948 ds.abs_data = 'mix' 949 950 # Execute the script. 951 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'pyrotartaric_anhydride.py') 952 953 # Test the optimised values. 954 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.0001756305, 5) 955 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.000278497, 5) 956 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.000253196, 5) 957 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.000280272, 5) 958 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.0001431835, 5) 959 self.assertAlmostEqual(cdp.chi2, 0.0, 2) 960 self.assertAlmostEqual(cdp.q_rdc, 0.0, 2)
961 962
964 """Pyrotarctic anhydride alignment tensor optimisation using long range (1J, 2J & 3J) RDC data.""" 965 966 # The setup. 967 ds.abs_data = 'D' 968 969 # Execute the script. 970 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'pyrotartaric_anhydride.py') 971 972 # Get the RDC data. 973 rdcs, rdc_err, rdc_weight, rdc_vector, rdc_dj, absolute_rdc, T_flags, j_couplings, rdc_pseudo_flags = return_rdc_data() 974 975 # The data as it should be. 976 ids = ['@9 - @Q9', '@4 - @6', '@5 - @7', '@5 - @8', '@1 - @6', '@3 - @6', '@5 - @6', '@9 - @6', '@1 - @7', '@3 - @7', '@4 - @7', '@9 - @7', '@1 - @8', '@3 - @8', '@4 - @8', '@9 - @8', '@3 - @Q9', '@4 - @Q9', '@5 - @Q9'] 977 real_rdcs = array([7.051710295953332, 14.64956993990, -9.80224941614, 4.49085022708, 1.16041049951, 0.57071216172, 3.68667449742, -2.26063357144, -4.77232431456, -0.17007443173, 2.37501105989, 1.64523216045, -0.94447557779, 0.06213688971, 1.48958862680, 0.21349779284, -1.2400897128766667, -1.8997427023766667, -0.0129325208733333], float64) 978 979 # Check the RDC data. 980 for i in range(len(ids)): 981 print("Spin pair '%s'." % ids[i]) 982 self.assertEqual(real_rdcs[i], rdcs[0, i]) 983 984 # Test the optimised values. 985 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.0001756305, 5) 986 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.000278497, 5) 987 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.000253196, 5) 988 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.000280272, 5) 989 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.0001431835, 5) 990 self.assertAlmostEqual(cdp.chi2, 0.0, 2) 991 self.assertAlmostEqual(cdp.q_rdc, 0.0, 2)
992 993
994 - def test_rdc_tensor(self):
995 """Test the calculation of an alignment tensor from RDC data.""" 996 997 # Execute the script. 998 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'rdc_tensor.py')
999 1000
1001 - def test_stereochem_analysis(self):
1002 """The full relative stereochemistry analysis.""" 1003 1004 # Create a temporary directory for all result files. 1005 ds.tmpdir = mkdtemp() 1006 1007 # Execute the script. 1008 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'stereochem_analysis.py') 1009 1010 # Check the base directory files. 1011 files = listdir(ds.tmpdir) 1012 for file in files: 1013 print("Checking file %s." % file) 1014 self.assert_(file in ['NOE_viol_S_sorted', 'ensembles_superimposed', 'RDC_PAN_dist.agr', 'Q_factors_S', 'NOE_viol_curve.agr', 'NOE_viol_dist.agr', 'RDC_PAN_curve.agr', 'NOE_viol_S', 'Q_factors_R_sorted', 'NOE_results', 'Q_factors_R', 'NOE_viol_R_sorted', 'logs', 'NOE_viol_R', 'Q_factors_S_sorted', 'RDC_PAN_results', 'correlation_plot.agr', 'correlation_plot_scaled.agr']) 1015 1016 # Check the sub-directory files. 1017 subdirs = ['ensembles_superimposed', 'logs', 'NOE_results', 'RDC_PAN_results'] 1018 files = [['S0.pdb', 'S2.pdb', 'R0.pdb', 'R1.pdb', 'S1.pdb', 'R2.pdb'], 1019 ['RDC_PAN_analysis.log', 'NOE_viol.log'], 1020 ['S_results_0.bz2', 'S_results_1.bz2', 'R_results_2.bz2', 'R_results_0.bz2', 'S_results_2.bz2', 'R_results_1.bz2'], 1021 ['S_results_0.bz2', 'S_results_1.bz2', 'R_results_2.bz2', 'R_results_0.bz2', 'S_results_2.bz2', 'R_results_1.bz2']] 1022 for i in range(len(subdirs)): 1023 for file in listdir(ds.tmpdir + sep + subdirs[i]): 1024 print("Checking file %s." % file) 1025 self.assert_(file in files[i])
1026 1027
1028 - def test_populations(self):
1029 """Test the 'population' N-state model optimisation using RDCs and PCSs (with missing data).""" 1030 1031 # Execute the script. 1032 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'populations.py') 1033 1034 # The actual tensors. 1035 A_5D = [] 1036 A_5D.append([1.42219822168827662867e-04, -1.44543001566521341940e-04, -7.07796211648713973798e-04, -6.01619494082773244303e-04, 2.02008007072950861996e-04]) 1037 A_5D.append([3.56720663040924505435e-04, -2.68385787902088840916e-04, -1.69361406642305853832e-04, 1.71873715515064501074e-04, -3.05790155096090983822e-04]) 1038 A_5D.append([2.32088908680377300801e-07, 2.08076808579168379617e-06, -2.21735465435989729223e-06, -3.74311563209448033818e-06, -2.40784858070560310370e-06]) 1039 A_5D.append([-2.62495279588228071048e-04, 7.35617367964106275147e-04, 6.39754192258981332648e-05, 6.27880171180572523460e-05, 2.01197582457700226708e-04]) 1040 1041 # Check the tensors. 1042 for i in range(len(A_5D)): 1043 self.assertAlmostEqual(cdp.align_tensors[i].Axx, A_5D[i][0], 5) 1044 self.assertAlmostEqual(cdp.align_tensors[i].Ayy, A_5D[i][1], 5) 1045 self.assertAlmostEqual(cdp.align_tensors[i].Axy, A_5D[i][2], 5) 1046 self.assertAlmostEqual(cdp.align_tensors[i].Axz, A_5D[i][3], 5) 1047 self.assertAlmostEqual(cdp.align_tensors[i].Ayz, A_5D[i][4], 5) 1048 1049 # Check the populations. 1050 self.assertEqual(len(cdp.probs), 3) 1051 self.assertAlmostEqual(cdp.probs[0], 0.3, 3) 1052 self.assertAlmostEqual(cdp.probs[1], 0.6, 3) 1053 self.assertAlmostEqual(cdp.probs[2], 0.1, 3) 1054 1055 # Test the optimised values. 1056 self.assertAlmostEqual(cdp.chi2, 0.0, 2) 1057 self.assertAlmostEqual(cdp.q_rdc, 0.0, 2) 1058 self.assertAlmostEqual(cdp.q_pcs, 0.0, 1)
1059 1060
1061 - def test_vector_loading1(self):
1062 """Test the loading of inter-atomic vectors in the 'population' N-state model.""" 1063 1064 # Order. 1065 ds.order_struct = [1, 2, 0] 1066 ds.order_model = [0, 1, 2] 1067 1068 # Execute the script. 1069 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'vector_loading.py') 1070 1071 # Check the vectors. 1072 self.check_vectors()
1073 1074
1075 - def test_vector_loading2(self):
1076 """Test the loading of inter-atomic vectors in the 'population' N-state model.""" 1077 1078 # Order. 1079 ds.order_struct = [0, 1, 2] 1080 ds.order_model = [2, 0, 1] 1081 1082 # Execute the script. 1083 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'vector_loading.py') 1084 1085 # Check the vectors. 1086 self.check_vectors()
1087 1088
1089 - def test_vector_loading3(self):
1090 """Test the loading of inter-atomic vectors in the 'population' N-state model.""" 1091 1092 # Order. 1093 ds.order_struct = [1, 0, 2] 1094 ds.order_model = [2, 0, 1] 1095 1096 # Execute the script. 1097 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'vector_loading.py') 1098 1099 # Check the vectors. 1100 self.check_vectors()
1101