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

Source Code for Module test_suite.system_tests.palmer

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008 Sebastien Morin                                          # 
  4  # Copyright (C) 2010-2013 Edward d'Auvergne                                   # 
  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 os import sep 
 26  from tempfile import mkdtemp 
 27   
 28  # relax module imports. 
 29  from data_store import Relax_data_store; ds = Relax_data_store() 
 30  import dep_check 
 31  from pipe_control import pipes 
 32  from pipe_control.mol_res_spin import return_spin 
 33  from lib.errors import RelaxError 
 34  from lib.io import test_binary 
 35  from status import Status; status = Status() 
 36  from test_suite.system_tests.base_classes import SystemTestCase 
 37   
 38   
39 -class Palmer(SystemTestCase):
40 """Class for testing various aspects specific to model-free analysis using the program 'Modelfree4'.""" 41
42 - def __init__(self, methodName='runTest'):
43 """Skip the tests if the subprocess module is not available (Python 2.3 and earlier). 44 45 @keyword methodName: The name of the test. 46 @type methodName: str 47 """ 48 49 # Execute the base class method. 50 super(Palmer, self).__init__(methodName) 51 52 # Missing module. 53 if not dep_check.subprocess_module: 54 # Store in the status object. 55 status.skipped_tests.append([methodName, 'subprocess', self._skip_type])
56 57
58 - def setUp(self):
59 """Set up for all the functional tests.""" 60 61 # Create a temporary directory for ModelFree4 outputs. 62 ds.tmpdir = mkdtemp()
63 64
65 - def test_palmer(self):
66 """Test a complete model-free analysis using the program 'Modelfree4'.""" 67 68 # Test for the presence of the Modelfree4 binary (skip the test if not present). 69 try: 70 test_binary('modelfree4') 71 except: 72 return 73 74 # Execute the script. 75 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'palmer.py') 76 77 # Determine if the Gnu gcc or Portland C compiler version is being used. 78 spin = return_spin(':0@N', pipe='m2') 79 if spin.te == 1.951*1e-12: 80 binary = 'linux-i386-gcc' # Linux Gnu gcc modelfree4 version. 81 else: 82 binary = 'linux-i386-pgf' # Linux Portland C compiler modelfree4 version. 83 spin = return_spin(':-2@N', pipe='m1') 84 if spin.chi2 == 36.62: 85 binary = 'mac-i386' # Mac OS X intel binary. 86 if not binary: 87 raise RelaxError("The Modelfree4 binary cannot be identified, therefore the parameters cannot be meaningfully checked.") 88 print("\nDetected the '%s' Modelfree4 binary." % binary) 89 90 # Checks for model m1, m2, and m3 mfout file reading. 91 models = ['m1', 'm2', 'm3'] 92 params = [['s2'], ['s2', 'te'], ['s2', 'rex']] 93 spin_names = [':-2@N', ':-1@N', ':0@N'] 94 s2 = [[0.869, 0.732, None], [0.869, 0.730, None], [0.715, 0.643, None]] 95 if binary == 'linux-i386-gcc': 96 te = [[None, None, None], [0.0, 1.951, None], [None, None, None]] 97 else: 98 te = [[None, None, None], [0.0, 1.952, None], [None, None, None]] 99 rex = [[None, None, None], [None, None, None], [4.308, 4.278, None]] 100 chi2 = [[36.6223, 20.3954, None], [36.6223, 20.3299, None], [1.9763, 0.6307, None]] 101 if binary == 'mac-i386': 102 chi2 = [[36.62, 20.40, None], [36.62, 20.33, None], [1.976, 0.6307, None]] 103 for model_index in range(3): 104 print("Model " + repr(models[model_index])) 105 for spin_index in range(3): 106 print("Spin " + repr(spin_names[spin_index])) 107 108 # Get the spin. 109 spin = return_spin(spin_names[spin_index], pipe=models[model_index]) 110 111 # Conversions. 112 if te[model_index][spin_index]: 113 te[model_index][spin_index] = te[model_index][spin_index] * 1e-12 114 if rex[model_index][spin_index]: 115 rex[model_index][spin_index] = rex[model_index][spin_index] / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]])**2 116 117 # Checks. 118 self.assertEqual(spin.model, models[model_index]) 119 self.assertEqual(spin.params, params[model_index]) 120 self.assertEqual(spin.s2, s2[model_index][spin_index]) 121 self.assertEqual(spin.s2f, None) 122 self.assertEqual(spin.s2s, None) 123 if te[model_index][spin_index] == None: 124 self.assertEqual(spin.te, te[model_index][spin_index]) 125 else: 126 self.assertAlmostEqual(spin.te, te[model_index][spin_index]) 127 self.assertEqual(spin.tf, None) 128 self.assertEqual(spin.ts, None) 129 self.assertEqual(spin.rex, rex[model_index][spin_index]) 130 self.assertEqual(spin.chi2, chi2[model_index][spin_index]) 131 132 # Checks for the final mfout file reading. 133 models = ['m3', 'm3'] 134 params = [['s2', 'rex'], ['s2', 'rex']] 135 s2 = [0.844, 0.760] 136 te = [None, None] 137 rex = [0.005, 0.404] 138 chi2 = [1.7966, 0.7389] 139 if binary == 'mac-i386': 140 chi2 = [1.796, 0.7392] 141 for spin_index in range(3): 142 # Get the spin. 143 spin = return_spin(spin_names[spin_index], pipe='aic') 144 145 # Deselected spin. 146 if not spin.select: 147 continue 148 149 # Conversions. 150 if te[spin_index]: 151 te[spin_index] = te[spin_index] * 1e-12 152 if rex[spin_index]: 153 rex[spin_index] = rex[spin_index] / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]])**2 154 155 # Checks. 156 self.assertEqual(spin.model, models[spin_index]) 157 self.assertEqual(spin.params, params[spin_index]) 158 self.assertAlmostEqual(spin.s2, s2[spin_index]) 159 self.assertEqual(spin.s2f, None) 160 self.assertEqual(spin.s2s, None) 161 if te[spin_index]: 162 self.assertAlmostEqual(spin.te, te[spin_index]) 163 else: 164 self.assertEqual(spin.te, None) 165 self.assertEqual(spin.tf, None) 166 self.assertEqual(spin.ts, None) 167 self.assertAlmostEqual(spin.rex, rex[spin_index]) 168 self.assertEqual(spin.chi2, chi2[spin_index]) 169 170 # Final global values. 171 final_pipe = pipes.get_pipe('aic') 172 if binary == 'mac-i386': 173 self.assertAlmostEqual(final_pipe.chi2, 2.5355) 174 self.assertAlmostEqual(final_pipe.diff_tensor.tm, 12.051) 175 else: 176 self.assertAlmostEqual(final_pipe.chi2, 2.5356) 177 self.assertAlmostEqual(final_pipe.diff_tensor.tm, 12.045)
178 179
180 - def test_palmer_omp(self):
181 """Test a complete model-free analysis using 'Modelfree4' with the OMP relaxation data, a PDB file, and a spheroid tensor.""" 182 183 # Test for the presence of the Modelfree4 binary (skip the test if not present). 184 try: 185 test_binary('modelfree4') 186 except: 187 return 188 189 # Execute the script. 190 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'palmer_omp.py') 191 192 # Catch a the old, buggy modelfree4 versions and complain loudly! 193 spin = return_spin(':9@N', pipe='m2') 194 if spin.s2 == 0.855: 195 raise RelaxError("You are using an old, buggy Modelfree4 version! You must upgrade to version 4.20 or later.") 196 197 # Determine the Modelfree4 binary type used. 198 spin = return_spin(':9@N', pipe='aic') 199 binary = None 200 if spin.te * 1e12 == 52.195: 201 binary = 'linux-i386-gcc' # Linux Gnu gcc modelfree4 version. 202 elif spin.te * 1e12 == 52.197: 203 binary = 'linux-i386-pgf' # Linux Portland C compiler modelfree4 version. 204 spin = return_spin(':9@N', pipe='m1') 205 if spin.chi2 == 143.7: 206 binary = 'mac-i386' # Mac OS X intel binary. 207 if not binary: 208 raise RelaxError("The Modelfree4 binary cannot be identified, therefore the parameters cannot be meaningfully checked.") 209 print("\nDetected the '%s' Modelfree4 binary." % binary) 210 211 # Model m1, m2, and m3 mfout file data. 212 models = ['m1', 'm2', 'm3'] 213 params = [['s2'], ['s2', 'te'], ['s2', 'rex']] 214 spin_names = [':9@N', ':10@N', ':11@N'] 215 s2 = [[0.822, 0.799, 0.823], [0.788, 0.777, 0.812], [0.822, 0.799, 0.823]] 216 te = [[None, None, None], [61.506, 36.087, 20.039], [None, None, None]] 217 if binary == 'mac-i386': 218 te = [[None, None, None], [61.504, 36.087, 20.039], [None, None, None]] 219 rex = [[None, None, None], [None, None, None], [0.0, 0.0, 0.0]] 220 chi2 = [[143.6773, 105.1767, 61.6684], [40.9055, 57.1562, 48.4927], [143.6773, 105.1767, 61.6684]] 221 if binary == 'mac-i386': 222 chi2 = [[143.7, 105.2, 61.67], [40.91, 57.16, 48.49], [143.7, 105.2, 61.67]] 223 224 # Checks for model m1, m2, and m3 mfout file reading. 225 for model_index in range(3): 226 print("Model " + repr(models[model_index])) 227 for spin_index in range(3): 228 print("Spin " + repr(spin_names[spin_index])) 229 230 # Get the spin. 231 spin = return_spin(spin_names[spin_index], pipe=models[model_index]) 232 233 # Conversions. 234 if rex[model_index][spin_index]: 235 rex[model_index][spin_index] = rex[model_index][spin_index] / (2.0 * pi * cdp.spectrometer_frq[cdp.ri_ids[0]])**2 236 237 # Checks. 238 self.assertEqual(spin.model, models[model_index]) 239 self.assertEqual(spin.params, params[model_index]) 240 self.assertAlmostEqual(spin.s2, s2[model_index][spin_index]) 241 self.assertEqual(spin.s2f, None) 242 self.assertEqual(spin.s2s, None) 243 if te[model_index][spin_index]: 244 self.assertAlmostEqual(spin.te * 1e12, te[model_index][spin_index]) 245 self.assertEqual(spin.tf, None) 246 self.assertEqual(spin.ts, None) 247 self.assertEqual(spin.rex, rex[model_index][spin_index]) 248 self.assertEqual(spin.chi2, chi2[model_index][spin_index]) 249 250 # Final mfout file data. 251 models = ['m2', 'm2', 'm2'] 252 params = [['s2', 'te'], ['s2', 'te'], ['s2', 'te']] 253 s2 = [0.755, 0.761, 0.787] 254 if binary == 'linux-i386-gcc': 255 te = [52.195, 29.356, 12.678] 256 elif binary == 'linux-i386-pgf': 257 te = [52.197, 29.361, 12.677] 258 elif binary == 'mac-i386': 259 te = [52.197, 29.357, 12.676] 260 chi2 = [7.254, 8.0437, 0.5327] 261 if binary == 'mac-i386': 262 chi2 = [7.254, 8.044, 0.5327] 263 264 # Checks for the final mfout file reading. 265 for spin_index in range(3): 266 # Get the spin. 267 spin = return_spin(spin_names[spin_index], pipe='aic') 268 269 # Checks. 270 self.assertEqual(spin.model, models[spin_index]) 271 self.assertEqual(spin.params, params[spin_index]) 272 self.assertAlmostEqual(spin.s2, s2[spin_index]) 273 self.assertEqual(spin.s2f, None) 274 self.assertEqual(spin.s2s, None) 275 if te[spin_index]: 276 self.assertAlmostEqual(spin.te * 1e12, te[spin_index]) 277 self.assertEqual(spin.tf, None) 278 self.assertEqual(spin.ts, None) 279 self.assertEqual(spin.rex, None) 280 self.assertAlmostEqual(spin.chi2, chi2[spin_index]) 281 282 # Final global values. 283 final_pipe = pipes.get_pipe('aic') 284 self.assertEqual(final_pipe.chi2, 15.8304) 285 if binary == 'linux-i386-gcc': 286 self.assertAlmostEqual(final_pipe.diff_tensor.tm, 8.443) 287 self.assertAlmostEqual(final_pipe.diff_tensor.Dratio, 1.053) 288 self.assertAlmostEqual(final_pipe.diff_tensor.theta * 360 / 2.0 / pi, 68.592) 289 self.assertAlmostEqual(final_pipe.diff_tensor.phi * 360 / 2.0 / pi, 73.756) 290 elif binary == 'linux-i386-pgf': 291 self.assertAlmostEqual(final_pipe.diff_tensor.tm, 8.443) 292 self.assertAlmostEqual(final_pipe.diff_tensor.Dratio, 1.053) 293 self.assertAlmostEqual(final_pipe.diff_tensor.theta * 360 / 2.0 / pi, 68.864) 294 self.assertAlmostEqual(final_pipe.diff_tensor.phi * 360 / 2.0 / pi, 73.913) 295 elif binary == 'mac-i386': 296 self.assertAlmostEqual(final_pipe.diff_tensor.tm, 8.459) 297 self.assertAlmostEqual(final_pipe.diff_tensor.Dratio, 1.049) 298 self.assertAlmostEqual(final_pipe.diff_tensor.theta * 360 / 2.0 / pi, 64.611) 299 self.assertAlmostEqual(final_pipe.diff_tensor.phi * 360 / 2.0 / pi, 79.281)
300