Package test_suite :: Package unit_tests :: Module align_tensor_testing_base
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests.align_tensor_testing_base

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-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  # Python module imports. 
 23  from math import pi 
 24   
 25  # relax module imports. 
 26  from data_store import Relax_data_store; ds = Relax_data_store() 
 27  from pipe_control import pipes 
 28  from pipe_control.reset import reset 
 29  from lib.errors import RelaxError, RelaxNoPipeError, RelaxNoTensorError 
 30  from test_suite.unit_tests.base_classes import UnitTestCase 
 31   
 32   
33 -class Align_tensor_base_class(UnitTestCase):
34 """Base class for the tests of the alignment tensor modules. 35 36 This includes both the 'prompt.align_tensor' and 'pipe_control.align_tensor' modules. This base class also contains many shared unit tests. 37 """ 38
39 - def setUp(self):
40 """Set up for all the alignment tensor unit tests.""" 41 42 # Add a data pipe to the data store. 43 ds.add(pipe_name='orig', pipe_type='mf') 44 45 # Add a second data pipe for copying tests. 46 ds.add(pipe_name='test', pipe_type='mf') 47 48 # Set the current data pipe to 'orig'. 49 pipes.switch('orig')
50 51
52 - def test_copy_pull(self):
53 """Test the copying of an alignment tensor (pulling the data from another pipe). 54 55 The functions tested are both pipe_control.align_tensor.copy() and 56 prompt.align_tensor.copy(). 57 """ 58 59 # Initialise the tensor. 60 self.align_tensor_fns.init(tensor='Pf1', align_id='Pf1', params=(-16.6278, 6.13037, 7.65639, -1.89157, 19.2561), scale=1.0, angle_units='rad', param_types=0) 61 62 # Change the current data pipe. 63 pipes.switch('test') 64 65 # Get the data pipe. 66 dp = pipes.get_pipe('test') 67 68 # Copy the tensor to the test pipe. 69 self.align_tensor_fns.copy(tensor_from='Pf1', pipe_from='orig', tensor_to='Pf1') 70 71 # Test the alignment tensor. 72 self.assertEqual(dp.align_tensors[0].Sxx, -16.6278) 73 self.assertEqual(dp.align_tensors[0].Syy, 6.13037) 74 self.assertEqual(dp.align_tensors[0].Sxy, 7.65639) 75 self.assertEqual(dp.align_tensors[0].Sxz, -1.89157) 76 self.assertAlmostEqual(dp.align_tensors[0].Syz, 19.2561)
77 78
79 - def test_copy_push(self):
80 """Test the copying of an alignment tensor (pushing the data from another pipe). 81 82 The functions tested are both pipe_control.align_tensor.copy() and 83 prompt.align_tensor.copy(). 84 """ 85 86 # Initialise the tensor. 87 self.align_tensor_fns.init(tensor='Pf1', align_id='Pf1', params=(-16.6278, 6.13037, 7.65639, -1.89157, 19.2561), scale=1.0, angle_units='rad', param_types=0) 88 89 # Copy the tensor to the test pipe. 90 self.align_tensor_fns.copy(tensor_from='Pf1', pipe_to='test', tensor_to='Pf1') 91 92 # Get the data pipe. 93 dp = pipes.get_pipe('test') 94 95 # Test the alignment tensor. 96 self.assertEqual(dp.align_tensors[0].Sxx, -16.6278) 97 self.assertEqual(dp.align_tensors[0].Syy, 6.13037) 98 self.assertEqual(dp.align_tensors[0].Sxy, 7.65639) 99 self.assertEqual(dp.align_tensors[0].Sxz, -1.89157) 100 self.assertAlmostEqual(dp.align_tensors[0].Syz, 19.2561)
101 102
103 - def test_copy_fail(self):
104 """Test the failure of copying of an alignment tensor (target and source are the same). 105 106 The functions tested are both pipe_control.align_tensor.copy() and 107 prompt.align_tensor.copy(). 108 """ 109 110 # Initialise the tensor. 111 self.align_tensor_fns.init(tensor='Pf1', align_id='Pf1', params=(-16.6278, 6.13037, 7.65639, -1.89157, 19.2561), scale=1.0, angle_units='rad', param_types=0) 112 113 # Copy the tensor to the test pipe. 114 self.assertRaises(RelaxError, self.align_tensor_fns.copy, tensor_from='Pf1', tensor_to='Pf1')
115 116
117 - def test_delete(self):
118 """Test the deletion of the alignment tensor data structure. 119 120 The functions tested are both pipe_control.align_tensor.delete() and 121 prompt.align_tensor.delete(). 122 """ 123 124 # Initialise the tensor. 125 self.align_tensor_fns.init(tensor='Pf1', align_id='Pf1', params=(-16.6278, 6.13037, 7.65639, -1.89157, 19.2561), scale=1.0, angle_units='rad', param_types=0) 126 127 # Delete the tensor data. 128 self.align_tensor_fns.delete(tensor='Pf1') 129 130 # Get the data pipe. 131 dp = pipes.get_pipe('test') 132 133 # Test that Axx does not exist. 134 self.failIf(hasattr(dp, 'align_tensors'))
135 136
137 - def test_delete_fail_no_data(self):
138 """Failure of deletion of the alignment tensor data structure when there is no data. 139 140 The functions tested are both pipe_control.align_tensor.delete() and 141 prompt.align_tensor.delete(). 142 """ 143 144 # Try to delete the tensor data. 145 self.assertRaises(RelaxNoTensorError, self.align_tensor_fns.delete, 'Pf1')
146 147
148 - def test_delete_fail_no_pipe(self):
149 """Failure of deletion of the alignment tensor data structure when there is no data pipe. 150 151 The functions tested are both pipe_control.align_tensor.delete() and 152 prompt.align_tensor.delete(). 153 """ 154 155 # Reset relax. 156 reset() 157 158 # Try to delete the tensor data. 159 self.assertRaises(RelaxNoPipeError, self.align_tensor_fns.delete, 'Pf1')
160 161
162 - def test_display(self):
163 """Display an alignment tensor. 164 165 The functions tested are both pipe_control.align_tensor.display() and 166 prompt.align_tensor.display(). 167 """ 168 169 # Initialise the tensor. 170 self.align_tensor_fns.init(tensor='Pf1', align_id='Pf1', params=(-16.6278, 6.13037, 7.65639, -1.89157, 19.2561), scale=1.0, angle_units='rad', param_types=0) 171 172 # Display the alignment tensor. 173 self.align_tensor_fns.display(tensor='Pf1')
174 175
177 """Failure of the display of the alignment tensor data structure when there is no data. 178 179 The functions tested are both pipe_control.align_tensor.display() and 180 prompt.align_tensor.display(). 181 """ 182 183 # Try to display the tensor data. 184 self.assertRaises(RelaxNoTensorError, self.align_tensor_fns.display, 'Pf1')
185 186
188 """Failure of the display of the alignment tensor data structure when there is no data pipe. 189 190 The functions tested are both pipe_control.align_tensor.display() and 191 prompt.align_tensor.display(). 192 """ 193 194 # Reset relax. 195 reset() 196 197 # Try to display the tensor data. 198 self.assertRaises(RelaxNoPipeError, self.align_tensor_fns.display, 'Pf1')
199 200
202 """Test the failure of setting up a alignment tensor when angle_units is incorrect. 203 204 The functions tested are both pipe_control.align_tensor.init() and 205 prompt.align_tensor.init(). 206 """ 207 208 # Initialise the tensor. 209 self.assertRaises(RelaxError, self.align_tensor_fns.init, align_id='Pf1', params=(-16.6278, 6.13037, 7.65639, -1.89157, 19.2561), angle_units='aaa')
210 211
212 - def test_init(self):
213 """Test the setting up of an alignment tensor. 214 215 The functions tested are both pipe_control.align_tensor.init() and 216 prompt.align_tensor.init(). 217 """ 218 219 # Get the data pipe. 220 dp = pipes.get_pipe('orig') 221 222 # Initialise the tensor. 223 self.align_tensor_fns.init(align_id='Pf1', params=(-16.6278, 6.13037, 7.65639, -1.89157, 19.2561), scale=1.0, angle_units='rad', param_types=0) 224 225 # Test the alignment tensor. 226 self.assertEqual(dp.align_tensors[0].Sxx, -16.6278) 227 self.assertEqual(dp.align_tensors[0].Syy, 6.13037) 228 self.assertEqual(dp.align_tensors[0].Sxy, 7.65639) 229 self.assertEqual(dp.align_tensors[0].Sxz, -1.89157) 230 self.assertAlmostEqual(dp.align_tensors[0].Syz, 19.2561)
231 232
234 """Test the matrix angles for a 5x5 identity matrix. 235 236 The functions tested are both pipe_control.align_tensor.matrix_angles() and 237 prompt.align_tensor.matrix_angles(). 238 """ 239 240 # Get the data pipe. 241 dp = pipes.get_pipe('orig') 242 243 # Initialise the 5 tensors. 244 self.align_tensor_fns.init(align_id='1', params=(1, 0, 0, 0, 0)) 245 self.align_tensor_fns.init(align_id='2', params=(0, 1, 0, 0, 0)) 246 self.align_tensor_fns.init(align_id='3', params=(0, 0, 1, 0, 0)) 247 self.align_tensor_fns.init(align_id='4', params=(0, 0, 0, 1, 0)) 248 self.align_tensor_fns.init(align_id='5', params=(0, 0, 0, 0, 1)) 249 250 # Matrix angles. 251 self.align_tensor_fns.matrix_angles() 252 253 # Test the angles. 254 self.assertEqual(dp.align_tensors.angles[0, 0], 0.0) 255 self.assertEqual(dp.align_tensors.angles[0, 1], pi/2) 256 self.assertEqual(dp.align_tensors.angles[0, 2], pi/2) 257 self.assertEqual(dp.align_tensors.angles[0, 3], pi/2) 258 self.assertEqual(dp.align_tensors.angles[0, 4], pi/2) 259 260 self.assertEqual(dp.align_tensors.angles[1, 0], pi/2) 261 self.assertEqual(dp.align_tensors.angles[1, 1], 0.0) 262 self.assertEqual(dp.align_tensors.angles[1, 2], pi/2) 263 self.assertEqual(dp.align_tensors.angles[1, 3], pi/2) 264 self.assertEqual(dp.align_tensors.angles[1, 4], pi/2) 265 266 self.assertEqual(dp.align_tensors.angles[2, 0], pi/2) 267 self.assertEqual(dp.align_tensors.angles[2, 1], pi/2) 268 self.assertEqual(dp.align_tensors.angles[2, 2], 0.0) 269 self.assertEqual(dp.align_tensors.angles[2, 3], pi/2) 270 self.assertEqual(dp.align_tensors.angles[2, 4], pi/2) 271 272 self.assertEqual(dp.align_tensors.angles[3, 0], pi/2) 273 self.assertEqual(dp.align_tensors.angles[3, 1], pi/2) 274 self.assertEqual(dp.align_tensors.angles[3, 2], pi/2) 275 self.assertEqual(dp.align_tensors.angles[3, 3], 0.0) 276 self.assertEqual(dp.align_tensors.angles[3, 4], pi/2) 277 278 self.assertEqual(dp.align_tensors.angles[4, 0], pi/2) 279 self.assertEqual(dp.align_tensors.angles[4, 1], pi/2) 280 self.assertEqual(dp.align_tensors.angles[4, 2], pi/2) 281 self.assertEqual(dp.align_tensors.angles[4, 3], pi/2) 282 self.assertEqual(dp.align_tensors.angles[4, 4], 0.0)
283 284
285 - def test_svd_identity(self):
286 """Test the SVD and condition number for a 5x5 identity matrix. 287 288 The functions tested are both pipe_control.align_tensor.svd() and 289 prompt.align_tensor.svd(). 290 """ 291 292 # Get the data pipe. 293 dp = pipes.get_pipe('orig') 294 295 # Initialise the 5 tensors. 296 self.align_tensor_fns.init(align_id='1', params=(1, 0, 0, 0, 0), param_types=0) 297 self.align_tensor_fns.init(align_id='2', params=(0, 1, 0, 0, 0), param_types=0) 298 self.align_tensor_fns.init(align_id='3', params=(0, 0, 1, 0, 0), param_types=0) 299 self.align_tensor_fns.init(align_id='4', params=(0, 0, 0, 1, 0), param_types=0) 300 self.align_tensor_fns.init(align_id='5', params=(0, 0, 0, 0, 1), param_types=0) 301 302 # SVD. 303 self.align_tensor_fns.svd() 304 305 # Test the values 306 self.assertEqual(dp.align_tensors.singular_vals[0], 1.0) 307 self.assertEqual(dp.align_tensors.singular_vals[1], 1.0) 308 self.assertEqual(dp.align_tensors.singular_vals[2], 1.0) 309 self.assertEqual(dp.align_tensors.singular_vals[3], 1.0) 310 self.assertEqual(dp.align_tensors.singular_vals[4], 1.0) 311 self.assertEqual(dp.align_tensors.cond_num, 1.0)
312