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

Source Code for Module test_suite.system_tests.pcs

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011-2013 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  """PCS-based system tests.""" 
 24   
 25   
 26  # Python module imports. 
 27  from os import sep 
 28  from re import search 
 29  from tempfile import mkdtemp 
 30   
 31  # relax module imports. 
 32  from pipe_control.mol_res_spin import count_spins, spin_loop 
 33  from status import Status; status = Status() 
 34  from test_suite.system_tests.base_classes import SystemTestCase 
 35   
 36   
37 -class Pcs(SystemTestCase):
38 """Class for testing PCS operations.""" 39
40 - def test_grace_plot(self):
41 """Test the creation of Grace plots of PCS data.""" 42 43 # Create a data pipe for all the data. 44 self.interpreter.pipe.create('CaM N-dom', 'N-state') 45 46 # Create some spins. 47 self.interpreter.spin.create(spin_name='N', spin_num=1, res_name='Gly', res_num=3) 48 self.interpreter.spin.create(spin_name='H', spin_num=2, res_name='Gly', res_num=3) 49 self.interpreter.spin.create(spin_name='N', spin_num=3, res_name='Gly', res_num=4) 50 self.interpreter.spin.create(spin_name='H', spin_num=4, res_name='Gly', res_num=4) 51 self.interpreter.sequence.display() 52 53 # Set the element type. 54 self.interpreter.spin.element(element='N', spin_id='@N') 55 self.interpreter.spin.element(element='H', spin_id='@H') 56 57 # Data directory. 58 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 59 60 # PCSs. 61 self.interpreter.pcs.read(align_id='dy', file='pcs_dy_200911.txt', dir=dir, res_num_col=1, data_col=2, error_col=4, spin_id='@N') 62 self.interpreter.pcs.read(align_id='dy', file='pcs_dy_200911.txt', dir=dir, res_num_col=1, data_col=3, error_col=4, spin_id='@H') 63 64 # Fudge the back-calculated PCS data. 65 for spin in spin_loop(): 66 spin.pcs_bc = {} 67 spin.pcs_bc['dy'] = spin.pcs['dy'] + 0.1 68 69 # Create the grace plot. 70 self.tmpdir = mkdtemp() 71 self.interpreter.pcs.corr_plot(format='grace', file='pcs_corr.agr', dir=self.tmpdir, force=True) 72 73 # Read the file data. 74 file = open(self.tmpdir+sep+'pcs_corr.agr') 75 lines = file.readlines() 76 file.close() 77 78 # Check the diagonal data. 79 for i in range(len(lines)): 80 if search('G0.S0', lines[i]): 81 point1 = lines[i+2].split() 82 point2 = lines[i+3].split() 83 self.assertAlmostEqual(float(point1[0]), -100.0) 84 self.assertAlmostEqual(float(point1[1]), -100.0) 85 self.assertAlmostEqual(float(point2[0]), 100.0) 86 self.assertAlmostEqual(float(point2[1]), 100.0) 87 88 # Check the 15N data. 89 for i in range(len(lines)): 90 if search('G0.S1', lines[i]): 91 point1 = lines[i+2].split() 92 point2 = lines[i+3].split() 93 self.assertAlmostEqual(float(point1[0]), 0.917+0.1) 94 self.assertAlmostEqual(float(point1[1]), 0.917) 95 self.assertAlmostEqual(float(point1[2]), 0.1) 96 self.assertAlmostEqual(float(point2[0]), 1.131+0.1) 97 self.assertAlmostEqual(float(point2[1]), 1.131) 98 self.assertAlmostEqual(float(point2[2]), 0.1) 99 100 # Check the 1H data. 101 for i in range(len(lines)): 102 if search('G0.S2', lines[i]): 103 point1 = lines[i+2].split() 104 point2 = lines[i+3].split() 105 self.assertAlmostEqual(float(point1[0]), 0.843+0.1) 106 self.assertAlmostEqual(float(point1[1]), 0.843) 107 self.assertAlmostEqual(float(point1[2]), 0.1) 108 self.assertAlmostEqual(float(point2[0]), 1.279+0.1) 109 self.assertAlmostEqual(float(point2[1]), 1.279) 110 self.assertAlmostEqual(float(point2[2]), 0.1)
111 112
113 - def test_load_multi_col_data(self):
114 """Test the loading of PCS data from a file with different columns for each spin type.""" 115 116 # Create a data pipe for all the data. 117 self.interpreter.pipe.create('CaM N-dom', 'N-state') 118 119 # Create some spins. 120 self.interpreter.spin.create(spin_name='N', spin_num=1, res_name='Gly', res_num=3) 121 self.interpreter.spin.create(spin_name='H', spin_num=2, res_name='Gly', res_num=3) 122 self.interpreter.spin.create(spin_name='N', spin_num=3, res_name='Gly', res_num=4) 123 self.interpreter.spin.create(spin_name='H', spin_num=4, res_name='Gly', res_num=4) 124 self.interpreter.sequence.display() 125 126 # Data directory. 127 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 128 129 # PCSs. 130 self.interpreter.pcs.read(align_id='dy', file='pcs_dy_200911.txt', dir=dir, res_num_col=1, data_col=2, error_col=4, spin_id='@N') 131 self.interpreter.pcs.read(align_id='dy', file='pcs_dy_200911.txt', dir=dir, res_num_col=1, data_col=3, error_col=4, spin_id='@H') 132 133 # The data. 134 pcs_data = { 135 ':3@N': 0.917, 136 ':3@H': 0.843, 137 ':4@N': 1.131, 138 ':4@H': 1.279, 139 } 140 141 # Check the PCS data. 142 print("\n") 143 for spin, spin_id in spin_loop(return_id=True): 144 print("Checking the PCS data of spin '%s'." % spin_id) 145 self.assert_(hasattr(spin, 'pcs')) 146 self.assertEqual(spin.pcs['dy'], pcs_data[spin_id]) 147 self.assertEqual(spin.pcs_err['dy'], 0.1)
148 149
151 """Test the loading of PCS data from a file with different columns for each spin type.""" 152 153 # Create a data pipe for all the data. 154 self.interpreter.pipe.create('CaM N-dom', 'N-state') 155 156 # Create some spins. 157 self.interpreter.spin.create(spin_name='N', spin_num=1, res_name='Gly', res_num=3, mol_name='CaM') 158 self.interpreter.spin.create(spin_name='H', spin_num=2, res_name='Gly', res_num=3, mol_name='CaM') 159 self.interpreter.spin.create(spin_name='N', spin_num=3, res_name='Gly', res_num=4, mol_name='CaM') 160 self.interpreter.spin.create(spin_name='H', spin_num=4, res_name='Gly', res_num=4, mol_name='CaM') 161 self.interpreter.sequence.display() 162 163 # Data directory. 164 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 165 166 # PCSs. 167 self.interpreter.pcs.read(align_id='dy', file='pcs_dy_200911.txt', dir=dir, res_num_col=1, data_col=2, error_col=4, spin_id='@N') 168 self.interpreter.pcs.read(align_id='dy', file='pcs_dy_200911.txt', dir=dir, res_num_col=1, data_col=3, error_col=4, spin_id='@H') 169 170 # The data. 171 pcs_data = { 172 '#CaM:3@N': 0.917, 173 '#CaM:3@H': 0.843, 174 '#CaM:4@N': 1.131, 175 '#CaM:4@H': 1.279, 176 } 177 178 # Check the PCS data. 179 print("\n") 180 for spin, spin_id in spin_loop(return_id=True): 181 print("Checking the PCS data of spin '%s'." % spin_id) 182 self.assert_(hasattr(spin, 'pcs')) 183 self.assertEqual(spin.pcs['dy'], pcs_data[spin_id]) 184 self.assertEqual(spin.pcs_err['dy'], 0.1)
185 186
187 - def test_pcs_copy(self):
188 """Test the operation of the pcs.copy user function.""" 189 190 # Create a data pipe. 191 self.interpreter.pipe.create('orig', 'N-state') 192 193 # Data directory. 194 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 195 196 # Load the spins. 197 self.interpreter.sequence.read(file='pcs.txt', dir=dir, spin_name_col=1) 198 self.interpreter.sequence.display() 199 200 # Load the PCSs. 201 self.interpreter.pcs.read(align_id='tb', file='pcs.txt', dir=dir, spin_name_col=1, data_col=2) 202 self.interpreter.sequence.display() 203 204 # The PCSs. 205 pcs = [0.004, 0.008, 0.021, 0.029, 0.016, 0.010, 0.008, 0.003, 0.006, 0.003, 0.007, 0.005, 0.001, 0.070, None, 0.025, 0.098, 0.054, 0.075, 0.065, None, 0.070, 0.015, 0.098, 0.060, 0.120] 206 207 # Create a new data pipe by copying the old, then switch to it. 208 self.interpreter.pipe.copy(pipe_from='orig', pipe_to='new') 209 self.interpreter.pipe.switch(pipe_name='new') 210 211 # Delete the PCS data. 212 self.interpreter.pcs.delete() 213 214 # Copy the PCSs. 215 self.interpreter.pcs.copy(pipe_from='orig', align_id='tb') 216 217 # Checks. 218 self.assertEqual(count_spins(), 26) 219 self.assertEqual(len(cdp.interatomic), 0) 220 i = 0 221 for spin in spin_loop(): 222 self.assertEqual(pcs[i], spin.pcs['tb']) 223 i += 1
224 225
226 - def test_pcs_load(self):
227 """Test for the loading of some PCS data with the spin ID format.""" 228 229 # Create a data pipe. 230 self.interpreter.pipe.create('test', 'N-state') 231 232 # Data directory. 233 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep 234 235 # Load the spins. 236 self.interpreter.sequence.read(file='pcs.txt', dir=dir, spin_name_col=1) 237 self.interpreter.sequence.display() 238 239 # Load the PCSs. 240 self.interpreter.pcs.read(align_id='tb', file='pcs.txt', dir=dir, spin_name_col=1, data_col=2) 241 self.interpreter.sequence.display() 242 243 # The PCSs. 244 pcs = [0.004, 0.008, 0.021, 0.029, 0.016, 0.010, 0.008, 0.003, 0.006, 0.003, 0.007, 0.005, 0.001, 0.070, None, 0.025, 0.098, 0.054, 0.075, 0.065, None, 0.070, 0.015, 0.098, 0.060, 0.120] 245 246 # Checks. 247 self.assertEqual(count_spins(), 26) 248 self.assertEqual(len(cdp.interatomic), 0) 249 i = 0 250 for spin in spin_loop(): 251 self.assertEqual(pcs[i], spin.pcs['tb']) 252 i += 1
253 254
255 - def test_structural_noise(self):
256 """Test the operation of the pcs.structural_noise user function.""" 257 258 # The file. 259 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'pcs_structural_noise_test.bz2' 260 261 # Load the state. 262 self.interpreter.state.load(state) 263 264 # Structural noise (twice to make sure old errors are removed properly from the PCS error). 265 self.interpreter.pcs.structural_noise(rmsd=200.0, sim_num=100, file='devnull', dir=None, force=True) 266 self.interpreter.pcs.structural_noise(rmsd=0.2, sim_num=20000, file='devnull', dir=None, force=True) 267 268 # The simulated data (from 1,000,000 randomisations of 0.2 Angstrom RMSD). 269 pcs_struct_err = { 270 'Dy N-dom': 0.014643633242475744, 271 'Er N-dom': 0.0047594540182391868, 272 'Tm N-dom': 0.010454580925459261, 273 'Tb N-dom': 0.01613972832580988 274 } 275 pcs_err = { 276 'Dy N-dom': 0.1010664929367797, 277 'Er N-dom': 0.10011319794388618, 278 'Tm N-dom': 0.1005450061531003, 279 'Tb N-dom': 0.10129408092495312 280 } 281 282 # Alias the single spin. 283 spin = cdp.mol[0].res[0].spin[0] 284 285 # Test the PCS data. 286 for id in ['Dy N-dom', 'Tb N-dom', 'Tm N-dom', 'Er N-dom']: 287 self.assertAlmostEqual(spin.pcs_struct_err[id], pcs_struct_err[id], 2) 288 self.assertAlmostEqual(spin.pcs_err[id], pcs_err[id], 2)
289