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