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-2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from math import pi, sqrt 
 24  from numpy import array 
 25  from numpy.linalg import norm 
 26  from os import listdir, sep 
 27  from tempfile import mkdtemp 
 28   
 29  # relax module imports. 
 30  from data import Relax_data_store; ds = Relax_data_store() 
 31  from generic_fns.align_tensor import calc_chi_tensor 
 32  from generic_fns.interatomic import interatomic_loop, return_interatom 
 33  from generic_fns.mol_res_spin import return_spin, spin_loop 
 34  from status import Status; status = Status() 
 35  from test_suite.system_tests.base_classes import SystemTestCase 
 36   
 37   
38 -class N_state_model(SystemTestCase):
39 """Class for testing various aspects specific to the N-state model.""" 40
41 - def check_vectors(self):
42 """Auxiliary method for checking the correct loading of bond vectors.""" 43 44 # The new order. 45 ds.order_new = array([ds.order_struct[ds.order_model[ds.order_model[0]]], 46 ds.order_struct[ds.order_model[ds.order_model[1]]], 47 ds.order_struct[ds.order_model[ds.order_model[2]]]]) 48 49 # The atom positions. 50 C_pos = [] 51 C_pos.append(array([6.250, 0.948, 1.968])) 52 C_pos.append(array([6.438, -0.139, 1.226])) 53 C_pos.append(array([6.108, -0.169, 0.378])) 54 55 H_pos = [] 56 H_pos.append(array([7.243, 0.580, 1.676])) 57 H_pos.append(array([7.271, -0.291, 0.525])) 58 H_pos.append(array([5.735, 0.003, -0.639])) 59 60 # The real vectors. 61 vect = [] 62 for i in range(3): 63 vect.append(H_pos[i] - C_pos[i]) 64 65 # Normalise. 66 for i in range(3): 67 vect[i] = vect[i] / norm(vect[i]) 68 69 # Print out. 70 print("Structure order: %s" % ds.order_struct) 71 print("Model order: %s" % ds.order_model) 72 print("New order: %s" % ds.order_new) 73 for i in range(3): 74 print("\ni = %i" % i) 75 print("The real vector: %s" % vect[i]) 76 print("The reordered vector: %s" % vect[ds.order_new[i]]) 77 print("The loaded vector: %s" % cdp.interatomic[0].vector[i]) 78 79 # Check. 80 for i in range(3): 81 self.assertAlmostEqual(norm(C_pos[ds.order_new[i]] - cdp.mol[0].res[0].spin[0].pos[i]), 0.0) 82 self.assertAlmostEqual(norm(H_pos[ds.order_new[i]] - cdp.mol[0].res[0].spin[1].pos[i]), 0.0) 83 for i in range(3): 84 self.assertAlmostEqual(norm(vect[ds.order_new[i]] - cdp.interatomic[0].vector[i]), 0.0)
85 86
87 - def test_5_state_xz(self):
88 """A 5-state model in the xz-plane (no pivotting of alpha). 89 90 The 5 states correspond to the Euler angles (z-y-z notation): 91 - State 1: {0, pi/4, 0} 92 - State 2: {0, pi/8, 0} 93 - State 3: {0, 0, 0} 94 - State 4: {0, -pi/8, 0} 95 - State 5: {0, -pi/4, 0} 96 """ 97 98 # Execute the script. 99 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'5_state_xz.py') 100 101 # Test the optimised probabilities. 102 self.assertAlmostEqual(cdp.probs[0], 0.2) 103 self.assertAlmostEqual(cdp.probs[1], 0.2) 104 self.assertAlmostEqual(cdp.probs[2], 0.2) 105 self.assertAlmostEqual(cdp.probs[3], 0.2) 106 self.assertAlmostEqual(cdp.probs[4], 0.2) 107 108 # Test the optimised alpha Euler angles. 109 self.assertAlmostEqual(cdp.alpha[0], 0.0) 110 self.assertAlmostEqual(cdp.alpha[1], 0.0) 111 self.assertAlmostEqual(cdp.alpha[2], 0.0) 112 self.assertAlmostEqual(cdp.alpha[3], 0.0) 113 self.assertAlmostEqual(cdp.alpha[4], 0.0) 114 115 # Test the optimised beta Euler angles. 116 self.assertAlmostEqual(cdp.beta[0], pi/4) 117 self.assertAlmostEqual(cdp.beta[1], pi/8) 118 self.assertAlmostEqual(cdp.beta[2], 0.0) 119 self.assertAlmostEqual(cdp.beta[3], -pi/8) 120 self.assertAlmostEqual(cdp.beta[4], -pi/4) 121 122 # Test the optimised gamma Euler angles. 123 self.assertAlmostEqual(cdp.gamma[0], 0.0) 124 self.assertAlmostEqual(cdp.gamma[1], 0.0) 125 self.assertAlmostEqual(cdp.gamma[2], 0.0) 126 self.assertAlmostEqual(cdp.gamma[3], 0.0) 127 self.assertAlmostEqual(cdp.gamma[4], 0.0) 128 129 # Test the chi-squared. 130 self.assertAlmostEqual(cdp.chi2, 3.15009916529e-32)
131 132
133 - def test_A_to_chi(self):
134 """Test the conversion of the alignment tensor to the chi tensor.""" 135 136 # Execute the script. 137 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'A_to_chi.py') 138 139 # Test the optimised values. 140 for i in range(3): 141 self.assertAlmostEqual(cdp.chi[i, i] * 1e32, cdp.chi_ref[i] * 1e32, 2)
142 143
144 - def test_absolute_rdc(self):
145 """Test the fitting of signless RDCs.""" 146 147 # Execute the script. 148 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'absolute_rdcs.py') 149 150 # Test the optimised values. 151 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 152 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 153 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 154 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 155 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 156 self.assertAlmostEqual(cdp.chi2, 0.0) 157 self.assertAlmostEqual(cdp.q_rdc, 0.0) 158 159 # The signless RDC data. 160 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] 161 162 # Back calc. 163 self.interpreter.rdc.back_calc('abs') 164 165 # Check the spin data. 166 i = 0 167 for spin in spin_loop(): 168 # No PCS. 169 if not hasattr(spin, 'rdc'): 170 continue 171 172 # Check the loaded and back-calculated absolute values. 173 self.assertAlmostEqual(spin.rdc['abs'], abs(rdcs[i])) 174 self.assertAlmostEqual(spin.rdc_bc['abs'], abs(rdcs[i])) 175 176 # Increment the spin index. 177 i += 1
178 179
180 - def test_align_fit(self):
181 """Test the use of RDCs and PCSs to find the alignment tensor.""" 182 183 # Set the mode to use both RDCs and PCSs. 184 ds.mode = 'all' 185 tag = 'synth' 186 187 # Execute the script. 188 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 189 190 # Test the optimised values. 191 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 192 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 193 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 194 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 195 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 196 self.assertAlmostEqual(cdp.chi2, 0.0) 197 self.assertAlmostEqual(cdp.q_rdc, 0.0) 198 self.assertAlmostEqual(cdp.q_pcs, 0.0) 199 200 # The spin data. 201 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] 202 i = 0 203 for spin in spin_loop(): 204 # No PCS. 205 if not hasattr(spin, 'pcs'): 206 continue 207 208 # Check the value. 209 self.assertAlmostEqual(spin.pcs[tag], pcs[i]) 210 211 # Check the back-calculated value. 212 self.assertAlmostEqual(spin.pcs_bc[tag], pcs[i]) 213 214 # Increment the spin index. 215 i += 1 216 217 # Back calc. 218 self.interpreter.pcs.back_calc(tag) 219 220 # Check the spin data. 221 i = 0 222 for spin in spin_loop(): 223 # No PCS. 224 if not hasattr(spin, 'pcs'): 225 continue 226 227 # Check the back-calculated value. 228 self.assertAlmostEqual(spin.pcs_bc[tag], pcs[i]) 229 230 # Increment the spin index. 231 i += 1
232 233
234 - def test_align_fit_rand(self):
235 """Test the use of randomised RDCs and PCSs to find the alignment tensor.""" 236 237 # Set the mode to use both RDCs and PCSs. 238 ds.mode = 'all' 239 240 # Select the randomised data. 241 ds.rand = True 242 243 # Execute the script. 244 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 245 246 # The tag. 247 tag = 'synth' 248 249 # Loop a few times. 250 for i in range(4): 251 # Test the optimised values (these values are from relax, so are not 100% reliable as a check). 252 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.000189412096996) 253 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.000271130087923) 254 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.000264898401302) 255 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.000284115871058) 256 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.000152207413184) 257 self.assertAlmostEqual(cdp.chi2, 783.530808266) 258 self.assertAlmostEqual(cdp.q_pcs, 0.063345784112045375) 259 self.assertAlmostEqual(cdp.q_rdc, 0.084926009099013003) 260 261 # Get a spin to check. 262 spin = return_spin(':114@N') 263 interatom = return_interatom(':114@N', ':114@H') 264 265 # Check the RDC and PCS values. 266 self.assertAlmostEqual(interatom.rdc[tag], -8.9193269604999994) 267 self.assertAlmostEqual(interatom.rdc_bc[tag], -9.1030018792821394) 268 self.assertAlmostEqual(spin.pcs[tag], -0.41430390310999998) 269 self.assertAlmostEqual(spin.pcs_bc[tag], -0.39723010845807194) 270 271 # MC sims so next round can check if values change. 272 if i == 0: 273 # Set some errors. 274 for interatom in interatomic_loop(): 275 interatom.rdc_err = {tag: 1.0} 276 for spin in spin_loop(): 277 spin.pcs_err = {tag: 0.1} 278 279 # MC sims. 280 self.interpreter.monte_carlo.setup(number=3) 281 self.interpreter.monte_carlo.create_data() 282 self.interpreter.monte_carlo.initial_values() 283 self.interpreter.minimise('simplex', constraints=False, max_iter=5) 284 self.interpreter.monte_carlo.error_analysis() 285 286 # Back-calc so next round can check if values change. 287 if i == 2: 288 self.interpreter.rdc.back_calc(tag) 289 self.interpreter.pcs.back_calc(tag) 290 291 # Calc Q factors so next round can check if values change. 292 if i == 1: 293 self.interpreter.rdc.calc_q_factors() 294 self.interpreter.pcs.calc_q_factors()
295 296
297 - def test_align_fit_pcs(self):
298 """Test the use of PCSs to find the alignment tensor.""" 299 300 # Set the mode to use PCSs. 301 ds.mode = 'pcs' 302 303 # Execute the script. 304 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 305 306 # Test the optimised values. 307 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 308 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 309 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 310 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 311 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 312 self.assertAlmostEqual(cdp.chi2, 0.0) 313 self.assertAlmostEqual(cdp.q_pcs, 0.0)
314 315
316 - def test_align_fit_pcs_rand(self):
317 """Test the use of randomised PCSs to find the alignment tensor.""" 318 319 # Set the mode to use PCSs. 320 ds.mode = 'pcs' 321 322 # Select the randomised data. 323 ds.rand = True 324 325 # Execute the script. 326 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 327 328 # Test the optimised values (these values are from relax, so are not 100% reliable as a check). 329 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.000189165581069) 330 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.000271897288335) 331 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.000264627388896) 332 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.000284180080857) 333 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.00015165641132) 334 self.assertAlmostEqual(cdp.chi2, 756.268087443) 335 self.assertAlmostEqual(cdp.q_pcs, 0.063341567973121266)
336 337
338 - def test_align_fit_rdc(self):
339 """Test the use of RDCs to find the alignment tensor.""" 340 341 # Set the mode to use RDCs. 342 ds.mode = 'rdc' 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 # Test the optimised values. 348 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 349 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 350 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 351 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 352 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 353 self.assertAlmostEqual(cdp.chi2, 0.0) 354 self.assertAlmostEqual(cdp.q_rdc, 0.0)
355 356
357 - def test_align_fit_rdc_rand(self):
358 """Test the use of randomised RDCs to find the alignment tensor.""" 359 360 # Set the mode to use RDCs. 361 ds.mode = 'rdc' 362 363 # Select the randomised data. 364 ds.rand = True 365 366 # Execute the script. 367 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'align_fit.py') 368 369 # Test the optimised values (these are about ~10% different from Pales). 370 # Pales: S(zz) S(xx-yy) S(xy) S(xz) S(yz) 371 # Pales: -9.8124e-05 -5.2533e-04 -3.4446e-04 3.7369e-04 -1.8949e-04 372 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.00017045) 373 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.00024905) 374 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.00027502) 375 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.00029833) 376 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.00015125) 377 self.assertAlmostEqual(cdp.chi2, 23.5877482365) # Pales: 23.709 378 self.assertAlmostEqual(cdp.q_rdc, 0.078460000413257444) # Pales (Q Saupe): 0.079 379 self.assertAlmostEqual(cdp.q_rdc_norm2, 0.14049691097282743) # Pales (Q RDC_RMS): 0.141
380 381
383 """The 4-state model analysis of lactose using RDCs and PCSs.""" 384 385 # The model. 386 ds.model = 'fixed' 387 388 # Execute the script. 389 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'lactose_n_state.py')
390 391
393 """The 4-state model analysis of lactose using RDCs and PCSs.""" 394 395 # The model. 396 ds.model = 'population' 397 398 # Execute the script. 399 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'lactose_n_state.py')
400 401
402 - def test_metal_pos_opt(self):
403 """Test a certain algorithm for the optimisation of the lanthanide position using RDCs and PCSs (with missing data).""" 404 405 # Execute the script. 406 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'metal_pos_opt.py') 407 408 # Check the metal position. 409 self.assertAlmostEqual(cdp.paramagnetic_centre[0], -14.845) 410 self.assertAlmostEqual(cdp.paramagnetic_centre[1], 0.969) 411 self.assertAlmostEqual(cdp.paramagnetic_centre[2], 0.265) 412 413 # The actual tensors. 414 A_5D = [] 415 A_5D.append([1.42219822168827662867e-04, -1.44543001566521341940e-04, -7.07796211648713973798e-04, -6.01619494082773244303e-04, 2.02008007072950861996e-04]) 416 A_5D.append([3.56720663040924505435e-04, -2.68385787902088840916e-04, -1.69361406642305853832e-04, 1.71873715515064501074e-04, -3.05790155096090983822e-04]) 417 A_5D.append([2.32088908680377300801e-07, 2.08076808579168379617e-06, -2.21735465435989729223e-06, -3.74311563209448033818e-06, -2.40784858070560310370e-06]) 418 A_5D.append([-2.62495279588228071048e-04, 7.35617367964106275147e-04, 6.39754192258981332648e-05, 6.27880171180572523460e-05, 2.01197582457700226708e-04]) 419 420 # Check the tensors. 421 for i in range(len(A_5D)): 422 self.assertAlmostEqual(cdp.align_tensors[i].Axx, A_5D[i][0]) 423 self.assertAlmostEqual(cdp.align_tensors[i].Ayy, A_5D[i][1]) 424 self.assertAlmostEqual(cdp.align_tensors[i].Axy, A_5D[i][2]) 425 self.assertAlmostEqual(cdp.align_tensors[i].Axz, A_5D[i][3]) 426 self.assertAlmostEqual(cdp.align_tensors[i].Ayz, A_5D[i][4]) 427 428 # Test the optimised values. 429 self.assertAlmostEqual(cdp.chi2, 0.0) 430 self.assertAlmostEqual(cdp.q_rdc, 0.0) 431 self.assertAlmostEqual(cdp.q_pcs, 0.0)
432 433
434 - def test_missing_data(self):
435 """Test the use of RDCs and PCSs to find the alignment tensor with missing data.""" 436 437 # Execute the script. 438 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'missing_data_test.py') 439 440 # The actual tensors. 441 A_5D = [] 442 A_5D.append([1.42219822168827662867e-04, -1.44543001566521341940e-04, -7.07796211648713973798e-04, -6.01619494082773244303e-04, 2.02008007072950861996e-04]) 443 A_5D.append([3.56720663040924505435e-04, -2.68385787902088840916e-04, -1.69361406642305853832e-04, 1.71873715515064501074e-04, -3.05790155096090983822e-04]) 444 A_5D.append([2.32088908680377300801e-07, 2.08076808579168379617e-06, -2.21735465435989729223e-06, -3.74311563209448033818e-06, -2.40784858070560310370e-06]) 445 A_5D.append([-2.62495279588228071048e-04, 7.35617367964106275147e-04, 6.39754192258981332648e-05, 6.27880171180572523460e-05, 2.01197582457700226708e-04]) 446 447 # Check the tensors. 448 for i in range(len(A_5D)): 449 self.assertAlmostEqual(cdp.align_tensors[i].Axx, A_5D[i][0]) 450 self.assertAlmostEqual(cdp.align_tensors[i].Ayy, A_5D[i][1]) 451 self.assertAlmostEqual(cdp.align_tensors[i].Axy, A_5D[i][2]) 452 self.assertAlmostEqual(cdp.align_tensors[i].Axz, A_5D[i][3]) 453 self.assertAlmostEqual(cdp.align_tensors[i].Ayz, A_5D[i][4]) 454 455 # Test the optimised values. 456 self.assertAlmostEqual(cdp.chi2, 0.0) 457 self.assertAlmostEqual(cdp.q_rdc, 0.0) 458 self.assertAlmostEqual(cdp.q_pcs, 0.0)
459 460
461 - def test_monte_carlo_sims(self):
462 """Test the Monte Carlo simulation data of fitting RDCs and PCSs.""" 463 464 # Execute the script. 465 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'monte_carlo_testing.py') 466 467 # Test the optimised values. 468 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 469 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 470 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 471 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 472 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 473 self.assertAlmostEqual(cdp.chi2 / 1e6, 1745860.0485368515 / 1e6, 6) 474 self.assertAlmostEqual(cdp.q_rdc, 0.0) 475 self.assertAlmostEqual(cdp.q_pcs, 0.0) 476 477 # The tensor key. 478 key = 'synth' 479 480 # The spin data. 481 for spin in spin_loop(): 482 # Print out. 483 print(spin) 484 485 # Check for simulation data. 486 self.assert_(hasattr(spin, 'pcs_sim')) 487 self.assert_(key in spin.pcs_sim) 488 489 # Check the values of the simulated data. 490 for i in range(cdp.sim_number): 491 self.assertAlmostEqual(spin.pcs[key], spin.pcs_sim[key][i]) 492 493 # The interatomic data. 494 for interatom in interatomic_loop(): 495 # Print out. 496 print(interatom) 497 498 # Check for simulation data. 499 self.assert_(hasattr(interatom, 'rdc_sim')) 500 self.assert_(key in interatom.rdc_sim) 501 502 # Check the values of the simulated data. 503 for i in range(cdp.sim_number): 504 self.assertAlmostEqual(interatom.rdc[key], interatom.rdc_sim[key][i], 5) 505 506 # Test the optimised simluation values. 507 for i in range(cdp.sim_number): 508 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000) 509 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000) 510 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000) 511 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000) 512 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000) 513 self.assertAlmostEqual(cdp.chi2 / 1e6, 1745860.0485368515 / 1e6) 514 515 # Test the tensor error values. 516 self.assertAlmostEqual(cdp.align_tensors[0].Axx_err, 0.0) 517 self.assertAlmostEqual(cdp.align_tensors[0].Ayy_err, 0.0) 518 self.assertAlmostEqual(cdp.align_tensors[0].Axy_err, 0.0) 519 self.assertAlmostEqual(cdp.align_tensors[0].Axz_err, 0.0) 520 self.assertAlmostEqual(cdp.align_tensors[0].Ayz_err, 0.0)
521 522
523 - def test_paramag_centre_fit(self):
524 """Test the use of RDCs and PCSs to find the alignment tensor.""" 525 526 # Set the mode to use both RDCs and PCSs. 527 ds.mode = 'all' 528 529 # Execute the script. 530 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'paramag_centre_fit.py') 531 532 # Check the paramagnetic centre position. 533 self.assertAlmostEqual(cdp.paramagnetic_centre[0], 32.555, 1) 534 self.assertAlmostEqual(cdp.paramagnetic_centre[1], -19.130, 1) 535 self.assertAlmostEqual(cdp.paramagnetic_centre[2], 27.775, 1) 536 537 # Test the optimised values. 538 self.assertAlmostEqual(cdp.align_tensors[0].Axx, -0.351261/2000, 5) 539 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, 0.556994/2000, 5) 540 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -0.506392/2000, 5) 541 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 0.560544/2000, 5) 542 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, -0.286367/2000, 5) 543 self.assertAlmostEqual(cdp.chi2, 0.0, 2) 544 self.assertAlmostEqual(cdp.q_rdc, 0.0, 2) 545 self.assertAlmostEqual(cdp.q_pcs, 0.0, 2)
546 547
548 - def test_pcs_back_calc(self):
549 """Test the back-calculation of PCSs for ubiquitin.""" 550 551 # Execute the script. 552 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'pcs_back_calc.py') 553 554 # Test the optimised values. 555 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pcs_bc['A'], 0.061941887563792014) 556 self.assertAlmostEqual(cdp.mol[0].res[1].spin[0].pcs_bc['A'], -0.077886567972081502) 557 self.assertAlmostEqual(cdp.mol[0].res[2].spin[0].pcs_bc['A'], -0.13928519099517916)
558 559
560 - def test_pcs_fit_true_pos(self):
561 """Test the fit of DNA PCSs at the true Ln3+ position.""" 562 563 # Set the Ln3+ position. 564 ds.para_centre = 'true' 565 566 # Execute the script. 567 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'dna_pcs_fit.py') 568 569 # Test the optimised values. 570 self.assertAlmostEqual(cdp.align_tensors[0].Axx, 1.42219822168827662867e-04) 571 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, -1.44543001566521341940e-04) 572 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -7.07796211648713973798e-04) 573 self.assertAlmostEqual(cdp.align_tensors[0].Axz, -6.01619494082773244303e-04) 574 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, 2.02008007072950861996e-04) 575 self.assertAlmostEqual(cdp.chi2, 0.0) 576 self.assertAlmostEqual(cdp.q_pcs, 0.0)
577 578
579 - def test_pcs_fit_zero_pos(self):
580 """Test the fit of DNA PCSs at a Ln3+ position of [0, 0, 0].""" 581 582 # Set the Ln3+ position. 583 ds.para_centre = 'zero' 584 585 # Execute the script. 586 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'dna_pcs_fit.py') 587 588 # Test the optimised values. 589 self.assertAlmostEqual(cdp.align_tensors[0].Axx, 9.739588118243e-07) 590 self.assertAlmostEqual(cdp.align_tensors[0].Ayy, -1.077401299806e-05) 591 self.assertAlmostEqual(cdp.align_tensors[0].Axy, -2.321033328910e-06) 592 self.assertAlmostEqual(cdp.align_tensors[0].Axz, 5.105903556692e-07) 593 self.assertAlmostEqual(cdp.align_tensors[0].Ayz, 1.676638764825e-05) 594 self.assertAlmostEqual(cdp.chi2, 2125.9562247877066) 595 self.assertAlmostEqual(cdp.q_pcs, 0.76065986767333704) 596 597 # The chi tensor. 598 chi_diag = calc_chi_tensor(cdp.align_tensors[0].A_diag, 799.75376122 * 1e6, 298) 599 chi_diag = chi_diag * 1e33 600 self.assertAlmostEqual((chi_diag[2, 2] - (chi_diag[0, 0] + chi_diag[1, 1])/2.0), -6.726159808496, 5) 601 self.assertAlmostEqual((chi_diag[0, 0] - chi_diag[1, 1]), -3.960936794864, 6)
602 603
604 - def test_pcs_to_rdc(self):
605 """Test the back-calculation of RDCs from a PCS derived tensor.""" 606 607 # Execute the script. 608 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'pcs_to_rdc.py') 609 610 # Test the values. 611 self.assertAlmostEqual(cdp.interatomic[0].rdc_bc['A'], 4.1319413321530014) 612 self.assertAlmostEqual(cdp.interatomic[1].rdc_bc['A'], -9.5802642470087989) 613 self.assertAlmostEqual(cdp.interatomic[2].rdc_bc['A'], -16.244078605100817)
614 615
616 - def test_rdc_tensor(self):
617 """Test the calculation of an alignment tensor from RDC data.""" 618 619 # Execute the script. 620 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'rdc_tensor.py')
621 622
623 - def test_stereochem_analysis(self):
624 """The full relative stereochemistry analysis.""" 625 626 # Create a temporary directory for all result files. 627 ds.tmpdir = mkdtemp() 628 629 # Execute the script. 630 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'stereochem_analysis.py') 631 632 # Check the base directory files. 633 files = listdir(ds.tmpdir) 634 for file in files: 635 print("Checking file %s." % file) 636 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']) 637 638 # Check the sub-directory files. 639 subdirs = ['ensembles_superimposed', 'logs', 'NOE_results', 'RDC_PAN_results'] 640 files = [['S0.pdb', 'S2.pdb', 'R0.pdb', 'R1.pdb', 'S1.pdb', 'R2.pdb'], 641 ['RDC_PAN_analysis.log', 'NOE_viol.log'], 642 ['S_results_0.bz2', 'S_results_1.bz2', 'R_results_2.bz2', 'R_results_0.bz2', 'S_results_2.bz2', 'R_results_1.bz2'], 643 ['S_results_0.bz2', 'S_results_1.bz2', 'R_results_2.bz2', 'R_results_0.bz2', 'S_results_2.bz2', 'R_results_1.bz2']] 644 for i in range(len(subdirs)): 645 for file in listdir(ds.tmpdir + sep + subdirs[i]): 646 print("Checking file %s." % file) 647 self.assert_(file in files[i])
648 649
650 - def test_populations(self):
651 """Test the 'population' N-state model optimisation using RDCs and PCSs (with missing data).""" 652 653 # Execute the script. 654 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'populations.py') 655 656 # The actual tensors. 657 A_5D = [] 658 A_5D.append([1.42219822168827662867e-04, -1.44543001566521341940e-04, -7.07796211648713973798e-04, -6.01619494082773244303e-04, 2.02008007072950861996e-04]) 659 A_5D.append([3.56720663040924505435e-04, -2.68385787902088840916e-04, -1.69361406642305853832e-04, 1.71873715515064501074e-04, -3.05790155096090983822e-04]) 660 A_5D.append([2.32088908680377300801e-07, 2.08076808579168379617e-06, -2.21735465435989729223e-06, -3.74311563209448033818e-06, -2.40784858070560310370e-06]) 661 A_5D.append([-2.62495279588228071048e-04, 7.35617367964106275147e-04, 6.39754192258981332648e-05, 6.27880171180572523460e-05, 2.01197582457700226708e-04]) 662 663 # Check the tensors. 664 for i in range(len(A_5D)): 665 self.assertAlmostEqual(cdp.align_tensors[i].Axx, A_5D[i][0]) 666 self.assertAlmostEqual(cdp.align_tensors[i].Ayy, A_5D[i][1]) 667 self.assertAlmostEqual(cdp.align_tensors[i].Axy, A_5D[i][2]) 668 self.assertAlmostEqual(cdp.align_tensors[i].Axz, A_5D[i][3]) 669 self.assertAlmostEqual(cdp.align_tensors[i].Ayz, A_5D[i][4]) 670 671 # Check the populations. 672 self.assertEqual(len(cdp.probs), 3) 673 self.assertAlmostEqual(cdp.probs[0], 0.3) 674 self.assertAlmostEqual(cdp.probs[1], 0.6) 675 self.assertAlmostEqual(cdp.probs[2], 0.1) 676 677 # Test the optimised values. 678 self.assertAlmostEqual(cdp.chi2, 0.0) 679 self.assertAlmostEqual(cdp.q_rdc, 0.0) 680 self.assertAlmostEqual(cdp.q_pcs, 0.0)
681 682
683 - def test_vector_loading1(self):
684 """Test the loading of inter-atomic vectors in the 'population' N-state model.""" 685 686 # Order. 687 ds.order_struct = [1, 2, 0] 688 ds.order_model = [0, 1, 2] 689 690 # Execute the script. 691 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'vector_loading.py') 692 693 # Check the vectors. 694 self.check_vectors()
695 696
697 - def test_vector_loading2(self):
698 """Test the loading of inter-atomic vectors in the 'population' N-state model.""" 699 700 # Order. 701 ds.order_struct = [0, 1, 2] 702 ds.order_model = [2, 0, 1] 703 704 # Execute the script. 705 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'vector_loading.py') 706 707 # Check the vectors. 708 self.check_vectors()
709 710
711 - def test_vector_loading3(self):
712 """Test the loading of inter-atomic vectors in the 'population' N-state model.""" 713 714 # Order. 715 ds.order_struct = [1, 0, 2] 716 ds.order_model = [2, 0, 1] 717 718 # Execute the script. 719 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'n_state_model'+sep+'vector_loading.py') 720 721 # Check the vectors. 722 self.check_vectors()
723