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