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

Source Code for Module test_suite.system_tests.relax_fit

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-2014 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 os import sep 
 24  from re import search 
 25  from tempfile import mkdtemp 
 26   
 27  # relax module imports. 
 28  from data_store import Relax_data_store; ds = Relax_data_store() 
 29  import dep_check 
 30  from pipe_control.mol_res_spin import spin_index_loop, spin_loop 
 31  from pipe_control import pipes 
 32  from lib.errors import RelaxError 
 33  from status import Status; status = Status() 
 34  from test_suite.system_tests.base_classes import SystemTestCase 
 35   
 36   
37 -class Relax_fit(SystemTestCase):
38 """Class for testing various aspects specific to relaxation curve-fitting.""" 39
40 - def __init__(self, methodName='runTest'):
41 """Skip the tests if the C modules are non-functional. 42 43 @keyword methodName: The name of the test. 44 @type methodName: str 45 """ 46 47 # Execute the base class method. 48 super(Relax_fit, self).__init__(methodName) 49 50 # Missing module. 51 if not dep_check.C_module_exp_fn: 52 # Store in the status object. 53 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type])
54 55
56 - def setUp(self):
57 """Set up for all the functional tests.""" 58 59 # Create the data pipe. 60 self.interpreter.pipe.create('mf', 'mf') 61 62 # Create a temporary directory for dumping files. 63 ds.tmpdir = mkdtemp()
64 65
66 - def check_curve_fitting(self):
67 """Check the results of the curve-fitting.""" 68 69 # Data. 70 relax_times = [0.0176, 0.0176, 0.0352, 0.0704, 0.0704, 0.1056, 0.1584, 0.1584, 0.1936, 0.1936] 71 chi2 = [None, None, None, 2.916952651567855, 5.4916923952919632, 16.21182245065274, 4.3591263759462926, 9.8925377583244316, None, None, None, 6.0238341559877782] 72 rx = [None, None, None, 8.0814894819820662, 8.6478971039559642, 9.5710638183013845, 10.716551838066295, 11.143793935455122, None, None, None, 12.82875370075309] 73 i0 = [None, None, None, 1996050.9679875025, 2068490.9458927638, 1611556.5194095275, 1362887.2331948928, 1877670.5623875158, None, None, None, 897044.17382064369] 74 75 # Some checks. 76 self.assertEqual(cdp.curve_type, 'exp') 77 self.assertEqual(cdp.int_method, ds.int_type) 78 self.assertEqual(len(cdp.relax_times), 10) 79 cdp_relax_times = sorted(cdp.relax_times.values()) 80 for i in range(10): 81 self.assertEqual(cdp_relax_times[i], relax_times[i]) 82 83 # Check the errors. 84 for key in cdp.sigma_I: 85 self.assertAlmostEqual(cdp.sigma_I[key], 10578.039482421433, 6) 86 self.assertAlmostEqual(cdp.var_I[key], 111894919.29166669) 87 88 # Spin data check. 89 i = 0 90 for spin in spin_loop(): 91 # No data present. 92 if chi2[i] == None: 93 self.assert_(not hasattr(spin, 'chi2')) 94 95 # Data present. 96 else: 97 self.assertAlmostEqual(spin.chi2, chi2[i]) 98 self.assertAlmostEqual(spin.rx, rx[i]) 99 self.assertAlmostEqual(spin.i0/1e6, i0[i]/1e6) 100 101 # Increment the spin index. 102 i = i + 1 103 if i >= 12: 104 break
105 106
107 - def test_bug_12670_12679(self):
108 """Test the relaxation curve fitting, replicating U{bug #12670<https://web.archive.org/web/https://gna.org/bugs/?12670>} and U{bug #12679<https://web.archive.org/web/https://gna.org/bugs/?12679>}.""" 109 110 # Execute the script. 111 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'1UBQ_relax_fit.py') 112 113 # Open the intensities.agr file. 114 file = open(ds.tmpdir + sep + 'intensities.agr') 115 lines = file.readlines() 116 file.close() 117 118 # Loop over all lines. 119 for i in range(len(lines)): 120 # Find the "@target G0.S0" line. 121 if search('@target', lines[i]): 122 index = i + 2 123 124 # Split up the lines. 125 lines[i] = lines[i].split() 126 127 # Check some of the Grace data. 128 self.assertEqual(len(lines[index]), 3) 129 self.assertEqual(lines[index][0], '0.004') 130 self.assertEqual(lines[index][1], '487178.000000000000000') 131 self.assertEqual(lines[index][2], '20570.000000000000000')
132 133
134 - def test_bug_18789(self):
135 """Test for zero errors in Grace plots, replicating U{bug #18789<https://web.archive.org/web/https://gna.org/bugs/?18789>}.""" 136 137 # Execute the script. 138 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'curve_fitting'+sep+'bug_18789_no_grace_errors.py') 139 140 # Open the Grace file. 141 file = open(ds.tmpdir + sep + 'rx.agr') 142 lines = file.readlines() 143 file.close() 144 145 # Loop over all lines. 146 for i in range(len(lines)): 147 # Find the "@target G0.S0" line. 148 if search('@target', lines[i]): 149 index = i + 2 150 151 # Split up the lines. 152 lines[i] = lines[i].split() 153 154 # Check for zero errors. 155 self.assertEqual(len(lines[index]), 3) 156 self.assertNotEqual(float(lines[index][2]), 0.0) 157 self.assertNotEqual(float(lines[index+1][2]), 0.0)
158 159
161 """Test for the failure of relaxation curve-fitting, replicating U{bug #19887<https://web.archive.org/web/https://gna.org/bugs/?19887>}.""" 162 163 # Execute the script. 164 try: 165 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'curve_fitting'+sep+'bug_19887_curvefit_fail.py') 166 167 # A RelaxError is expected (but assertRaises() does not work with the script_exec method). 168 except RelaxError: 169 pass
170 171
173 """Test the relaxation curve fitting C modules.""" 174 175 # The intensity type. 176 ds.int_type = 'height' 177 178 # Execute the script. 179 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit.py') 180 181 # Check the curve-fitting results. 182 self.check_curve_fitting()
183 184
186 """Test the relaxation curve fitting C modules.""" 187 188 # The intensity type. 189 ds.int_type = 'point sum' 190 191 # Execute the script. 192 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit.py') 193 194 # Check the curve-fitting results. 195 self.check_curve_fitting()
196 197
198 - def test_read_sparky(self):
199 """The Sparky peak height loading test.""" 200 201 # Load the original state. 202 self.interpreter.state.load(state='basic_heights_T2_ncyc1', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states', force=True) 203 204 # Create a new data pipe for the new data. 205 self.interpreter.pipe.create('new', 'relax_fit') 206 207 # Load the Lupin Ap4Aase sequence. 208 self.interpreter.sequence.read(file="Ap4Aase.seq", dir=status.install_path + sep+'test_suite'+sep+'shared_data', res_num_col=1, res_name_col=2) 209 210 # Name the spins so they can be matched to the assignments. 211 self.interpreter.spin.name(name='N') 212 213 # Read the peak heights. 214 self.interpreter.spectrum.read_intensities(file="T2_ncyc1_ave.list", dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting', spectrum_id='0.0176') 215 216 217 # Test the integrity of the data. 218 ################################# 219 220 # Get the data pipes. 221 dp_new = pipes.get_pipe('new') 222 dp_rx = pipes.get_pipe('rx') 223 224 # Loop over the spins of the original data. 225 for mol_index, res_index, spin_index in spin_index_loop(): 226 # Alias the spin containers. 227 new_spin = dp_new.mol[mol_index].res[res_index].spin[spin_index] 228 orig_spin = dp_rx.mol[mol_index].res[res_index].spin[spin_index] 229 230 # Check the sequence info. 231 self.assertEqual(dp_new.mol[mol_index].name, dp_rx.mol[mol_index].name) 232 self.assertEqual(dp_new.mol[mol_index].res[res_index].num, dp_rx.mol[mol_index].res[res_index].num) 233 self.assertEqual(dp_new.mol[mol_index].res[res_index].name, dp_rx.mol[mol_index].res[res_index].name) 234 self.assertEqual(new_spin.num, orig_spin.num) 235 self.assertEqual(new_spin.name, orig_spin.name) 236 237 # Skip deselected spins. 238 if not orig_spin.select: 239 continue 240 241 # Check intensities (if they exist). 242 if hasattr(orig_spin, 'peak_intensity'): 243 for id in dp_new.spectrum_ids: 244 self.assertEqual(orig_spin.peak_intensity[id], new_spin.peak_intensity[id])
245