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

Source Code for Module test_suite.system_tests.rdc

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011-2015 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  # Module docstring. 
 23  """RDC-based system tests.""" 
 24   
 25   
 26  # Python module imports. 
 27  from os import sep 
 28  from tempfile import mktemp 
 29   
 30  # relax module imports. 
 31  from data_store import Relax_data_store; ds = Relax_data_store() 
 32  from pipe_control.interatomic import interatomic_loop 
 33  from pipe_control.mol_res_spin import count_spins 
 34  from status import Status; status = Status() 
 35  from test_suite.system_tests.base_classes import SystemTestCase 
 36   
 37   
38 -class Rdc(SystemTestCase):
39 """Class for testing RDC operations.""" 40
42 """Test the operation of the rdc.calc_q_factors user function when no alignment tensor is present.""" 43 44 # Create a data pipe. 45 self.interpreter.pipe.create('orig', 'N-state') 46 47 # Data directory. 48 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 49 50 # Load the spins. 51 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1) 52 self.interpreter.sequence.attach_protons() 53 self.interpreter.sequence.display() 54 55 # Load the RDCs. 56 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4) 57 self.interpreter.sequence.display() 58 59 # Create back-calculated RDC values from the real values. 60 for interatom in interatomic_loop(): 61 if hasattr(interatom, 'rdc'): 62 if not hasattr(interatom, 'rdc_bc'): 63 interatom.rdc_bc = {} 64 interatom.rdc_bc['tb'] = interatom.rdc['tb'] + 1.0 65 66 # Q factors. 67 self.interpreter.rdc.calc_q_factors()
68 69
70 - def test_corr_plot(self):
71 """Test the operation of the rdc.corr_plot user function.""" 72 73 # Create a data pipe. 74 self.interpreter.pipe.create('orig', 'N-state') 75 76 # Data directory. 77 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 78 79 # Load the spins. 80 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1) 81 self.interpreter.sequence.attach_protons() 82 self.interpreter.sequence.display() 83 84 # Load the RDCs. 85 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4) 86 self.interpreter.sequence.display() 87 88 # Create back-calculated RDC values from the real values. 89 for interatom in interatomic_loop(): 90 if hasattr(interatom, 'rdc'): 91 if not hasattr(interatom, 'rdc_bc'): 92 interatom.rdc_bc = {} 93 interatom.rdc_bc['tb'] = interatom.rdc['tb'] + 1.0 94 95 # Correlation plot. 96 ds.tmpfile = mktemp() 97 self.interpreter.rdc.corr_plot(format='grace', title='Test', subtitle='Test2', file=ds.tmpfile, dir=None, force=True) 98 99 # The expected file contents. 100 real_contents = [ 101 "@version 50121", 102 "@page size 842, 595", 103 "@with g0", 104 "@ world -27.0, -27.0, 16.0, 16.0", 105 "@ view 0.15, 0.15, 1.28, 0.85", 106 "@ title \"Test\"", 107 "@ subtitle \"Test2\"", 108 "@ xaxis label \"Back-calculated RDC (Hz)\"", 109 "@ xaxis label char size 1.00", 110 "@ xaxis tick major 10", 111 "@ xaxis tick major size 0.50", 112 "@ xaxis tick major linewidth 0.5", 113 "@ xaxis tick minor ticks 9", 114 "@ xaxis tick minor linewidth 0.5", 115 "@ xaxis tick minor size 0.25", 116 "@ xaxis ticklabel char size 0.70", 117 "@ yaxis label \"Measured RDC (Hz)\"", 118 "@ yaxis label char size 1.00", 119 "@ yaxis tick major 10", 120 "@ yaxis tick major size 0.50", 121 "@ yaxis tick major linewidth 0.5", 122 "@ yaxis tick minor ticks 9", 123 "@ yaxis tick minor linewidth 0.5", 124 "@ yaxis tick minor size 0.25", 125 "@ yaxis ticklabel char size 0.70", 126 "@ legend on", 127 "@ legend 1, 0.5", 128 "@ legend box fill pattern 1", 129 "@ legend char size 1.0", 130 "@ frame linewidth 0.5", 131 "@ s0 symbol 1", 132 "@ s0 symbol size 0.45", 133 "@ s0 symbol linewidth 0.5", 134 "@ s0 errorbar size 0.5", 135 "@ s0 errorbar linewidth 0.5", 136 "@ s0 errorbar riser linewidth 0.5", 137 "@ s0 line linestyle 2", 138 "@ s1 symbol 2", 139 "@ s1 symbol size 0.45", 140 "@ s1 symbol linewidth 0.5", 141 "@ s1 errorbar size 0.5", 142 "@ s1 errorbar linewidth 0.5", 143 "@ s1 errorbar riser linewidth 0.5", 144 "@ s1 line linestyle 0", 145 "@ s1 legend \"tb\"", 146 "@target G0.S0", 147 "@type xydy", 148 " -100.000000000000000 -100.000000000000000 0.000000000000000", 149 " 100.000000000000000 100.000000000000000 0.000000000000000", 150 "&", 151 "@target G0.S1", 152 "@type xydy", 153 " -25.250195862900000 -26.250195862900000 1.000000000000000 \"#CaM:5@N-#CaM:5@H\"", 154 " 10.930817669420000 9.930817669420000 1.000000000000000 \"#CaM:6@N-#CaM:6@H\"", 155 " 8.263176141559999 7.263176141560000 1.000000000000000 \"#CaM:7@N-#CaM:7@H\"", 156 " -0.248405269810000 -1.248405269810000 0.000000000000000 \"#CaM:8@N-#CaM:8@H\"", 157 " 6.318033143340000 5.318033143340000 1.000000000000000 \"#CaM:9@N-#CaM:9@H\"", 158 " 15.036290945599999 14.036290945599999 1.000000000000000 \"#CaM:10@N-#CaM:10@H\"", 159 " 2.336525303970000 1.336525303970000 0.000000000000000 \"#CaM:11@N-#CaM:11@H\"", 160 " -0.602167028100000 -1.602167028100000 0.000000000000000 \"#CaM:12@N-#CaM:12@H\"", 161 "&", 162 ] 163 164 # Check the data. 165 print("\nChecking the Grace file contents.") 166 file = open(ds.tmpfile) 167 lines = file.readlines() 168 file.close() 169 print(real_contents) 170 print(lines) 171 self.assertEqual(len(real_contents), len(lines)) 172 for i in range(len(lines)): 173 print(lines[i][:-1]) 174 self.assertEqual(real_contents[i], lines[i][:-1])
175 176
177 - def test_rdc_copy(self):
178 """Test the operation of the rdc.copy user function.""" 179 180 # Create a data pipe. 181 self.interpreter.pipe.create('orig', 'N-state') 182 183 # Data directory. 184 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 185 186 # Load the spins. 187 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1) 188 self.interpreter.sequence.attach_protons() 189 self.interpreter.sequence.display() 190 191 # Load the RDCs. 192 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4) 193 self.interpreter.sequence.display() 194 195 # The RDCs. 196 rdcs = [ -26.2501958629, 9.93081766942, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, 1.33652530397, -1.6021670281] 197 198 # Create a new data pipe by copying the old, then switch to it. 199 self.interpreter.pipe.copy(pipe_from='orig', pipe_to='new') 200 self.interpreter.pipe.switch(pipe_name='new') 201 202 # Delete the RDC data. 203 self.interpreter.rdc.delete() 204 205 # Copy the RDCs. 206 self.interpreter.rdc.copy(pipe_from='orig', align_id='tb') 207 208 # Checks. 209 self.assert_(hasattr(cdp, 'align_ids')) 210 self.assert_('tb' in cdp.align_ids) 211 self.assert_(hasattr(cdp, 'rdc_ids')) 212 self.assert_('tb' in cdp.rdc_ids) 213 self.assertEqual(count_spins(), 16) 214 self.assertEqual(len(cdp.interatomic), 8) 215 i = 0 216 for interatom in interatomic_loop(): 217 self.assertAlmostEqual(rdcs[i], interatom.rdc['tb']) 218 i += 1
219 220
222 """Test the operation of the rdc.copy user function for two data pipes with different spin system.""" 223 224 # Data directory. 225 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 226 227 # Set up two data identical pipes. 228 pipes = ['orig', 'new'] 229 delete = [':6', ':11'] 230 for i in range(2): 231 # Create a data pipe. 232 self.interpreter.pipe.create(pipes[i], 'N-state') 233 234 # Load the spins. 235 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1) 236 self.interpreter.spin.element('N') 237 238 # Delete the residue. 239 self.interpreter.residue.delete(delete[i]) 240 241 # Attach protons. 242 self.interpreter.sequence.attach_protons() 243 self.interpreter.sequence.display() 244 245 # Create the interatomic data containers. 246 self.interpreter.interatom.define(spin_id1='@N', spin_id2='@H') 247 248 # Printout. 249 print("\n\nInteratomic data containers for the 'orig' data pipe:") 250 for interatom in interatomic_loop(pipe='orig'): 251 print("'%s' '%s'" % (interatom.spin_id1, interatom.spin_id2)) 252 print("\nInteratomic data containers for the 'new' data pipe:") 253 for interatom in interatomic_loop(pipe='new'): 254 print("'%s' '%s'" % (interatom.spin_id1, interatom.spin_id2)) 255 256 # Load the RDCs into the first data pipe. 257 self.interpreter.pipe.switch('orig') 258 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4) 259 260 # Copy the RDCs into the second data pipe. 261 self.interpreter.rdc.copy(pipe_from='orig', pipe_to='new', align_id='tb') 262 263 # Checks. 264 rdcs = [ 265 [ -26.2501958629, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, 1.33652530397, -1.6021670281], 266 [ -26.2501958629, 9.93081766942, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, -1.6021670281] 267 ] 268 for i in range(2): 269 print("\nChecking data pipe '%s'." % pipes[i]) 270 271 # Metadata. 272 self.assert_(hasattr(ds[pipes[i]], 'align_ids')) 273 self.assert_('tb' in ds[pipes[i]].align_ids) 274 self.assert_(hasattr(ds[pipes[i]], 'rdc_ids')) 275 self.assert_('tb' in ds[pipes[i]].rdc_ids) 276 277 # Spin data. 278 self.assertEqual(count_spins(pipe=pipes[i]), 14) 279 self.assertEqual(len(ds[pipes[i]].interatomic), 7) 280 j = 0 281 for interatom in interatomic_loop(pipe=pipes[i]): 282 # Residue 6 in the 'new' data pipe has no RDCs. 283 if i == 1 and j == 1: 284 self.assert_(not hasattr(interatom, 'rdc')) 285 self.assert_(not hasattr(interatom, 'rdc_data_types')) 286 self.assert_(not hasattr(interatom, 'absolute_rdc')) 287 else: 288 self.assertAlmostEqual(rdcs[i][j], interatom.rdc['tb']) 289 self.assert_(hasattr(interatom, 'rdc_data_types')) 290 self.assert_('tb' in interatom.rdc_data_types) 291 self.assertEqual(interatom.rdc_data_types['tb'], 'D') 292 self.assert_(hasattr(interatom, 'absolute_rdc')) 293 self.assert_('tb' in interatom.absolute_rdc) 294 self.assertEqual(interatom.absolute_rdc['tb'], False) 295 j += 1
296 297
298 - def test_rdc_copy_back_calc(self):
299 """Test the operation of the rdc.copy user function for back-calculated values.""" 300 301 # Data directory. 302 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 303 304 # Set up two data identical pipes. 305 pipes = ['orig', 'new'] 306 delete = [':6', ':11'] 307 for i in range(2): 308 # Create a data pipe. 309 self.interpreter.pipe.create(pipes[i], 'N-state') 310 311 # Load the spins. 312 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1) 313 self.interpreter.spin.element('N') 314 315 # Delete the residue. 316 self.interpreter.residue.delete(delete[i]) 317 318 # Attach protons. 319 self.interpreter.sequence.attach_protons() 320 self.interpreter.sequence.display() 321 322 # Create the interatomic data containers. 323 self.interpreter.interatom.define(spin_id1='@N', spin_id2='@H') 324 325 # Printout. 326 print("\n\nInteratomic data containers for the 'orig' data pipe:") 327 for interatom in interatomic_loop(pipe='orig'): 328 print("'%s' '%s'" % (interatom.spin_id1, interatom.spin_id2)) 329 print("\nInteratomic data containers for the 'new' data pipe:") 330 for interatom in interatomic_loop(pipe='new'): 331 print("'%s' '%s'" % (interatom.spin_id1, interatom.spin_id2)) 332 333 # Load the RDCs into the first data pipe. 334 self.interpreter.pipe.switch('orig') 335 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4) 336 337 # Create back-calculated RDC values from the real values. 338 for interatom in interatomic_loop(): 339 if hasattr(interatom, 'rdc'): 340 if not hasattr(interatom, 'rdc_bc'): 341 interatom.rdc_bc = {} 342 interatom.rdc_bc['tb'] = interatom.rdc['tb'] + 1.0 343 344 # Copy the RDCs, including back-calculated values, into the second data pipe. 345 self.interpreter.rdc.copy(pipe_from='orig', pipe_to='new', align_id='tb', back_calc=True) 346 347 # Checks. 348 rdcs = [ 349 [ -26.2501958629, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, 1.33652530397, -1.6021670281], 350 [ -26.2501958629, 9.93081766942, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, -1.6021670281] 351 ] 352 for i in range(2): 353 print("\nChecking data pipe '%s'." % pipes[i]) 354 355 # Metadata. 356 self.assert_(hasattr(ds[pipes[i]], 'align_ids')) 357 self.assert_('tb' in ds[pipes[i]].align_ids) 358 self.assert_(hasattr(ds[pipes[i]], 'rdc_ids')) 359 self.assert_('tb' in ds[pipes[i]].rdc_ids) 360 361 # Spin data. 362 self.assertEqual(count_spins(pipe=pipes[i]), 14) 363 self.assertEqual(len(ds[pipes[i]].interatomic), 7) 364 j = 0 365 for interatom in interatomic_loop(pipe=pipes[i]): 366 # Residue 6 in the 'new' data pipe has no RDCs. 367 if i == 1 and j == 1: 368 self.assert_(not hasattr(interatom, 'rdc')) 369 self.assert_(not hasattr(interatom, 'rdc_data_types')) 370 self.assert_(not hasattr(interatom, 'absolute_rdc')) 371 else: 372 self.assertAlmostEqual(rdcs[i][j], interatom.rdc['tb']) 373 self.assertAlmostEqual(rdcs[i][j]+1.0, interatom.rdc_bc['tb']) 374 self.assert_(hasattr(interatom, 'rdc_data_types')) 375 self.assert_('tb' in interatom.rdc_data_types) 376 self.assertEqual(interatom.rdc_data_types['tb'], 'D') 377 self.assert_(hasattr(interatom, 'absolute_rdc')) 378 self.assert_('tb' in interatom.absolute_rdc) 379 self.assertEqual(interatom.absolute_rdc['tb'], False) 380 j += 1
381 382
383 - def test_rdc_load(self):
384 """Test for the loading of some RDC data with the spin ID format.""" 385 386 # Create a data pipe. 387 self.interpreter.pipe.create('test', 'N-state') 388 389 # Data directory. 390 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 391 392 # Load the spins. 393 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1) 394 self.interpreter.sequence.attach_protons() 395 self.interpreter.sequence.display() 396 397 # Load the RDCs. 398 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4) 399 self.interpreter.sequence.display() 400 401 # The RDCs. 402 rdcs = [ -26.2501958629, 9.93081766942, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, 1.33652530397, -1.6021670281] 403 404 # Checks. 405 self.assertEqual(count_spins(), 16) 406 self.assertEqual(len(cdp.interatomic), 8) 407 i = 0 408 for interatom in interatomic_loop(): 409 self.assertAlmostEqual(rdcs[i], interatom.rdc['tb']) 410 i += 1
411