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