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