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

Source Code for Module test_suite.unit_tests._data.test_align_tensor

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007 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 numpy import array 
 25  from unittest import TestCase 
 26   
 27  # relax module imports. 
 28  from data.align_tensor import AlignTensorData, AlignTensorSimList 
 29  from generic_fns.align_tensor import kappa 
 30  from relax_errors import RelaxError 
 31   
 32   
33 -class Test_align_tensor(TestCase):
34 """Unit tests for the data.align_tensor relax module.""" 35
36 - def calc_objects(self, Axx, Ayy, Axy, Axz, Ayz):
37 """Function for calculating the alignment tensor objects.""" 38 39 # The parameter values. 40 Azz = - Axx - Ayy 41 Axxyy = Axx - Ayy 42 43 # Matrices. 44 tensor = array([[ Axx, Axy, Axz], 45 [ Axy, Ayy, Ayz], 46 [ Axz, Ayz, Azz]]) 47 48 # Return the objects. 49 return Azz, Axxyy, tensor
50 51
52 - def setUp(self):
53 """Set 'self.align_data' to an empty instance of the AlignTensorData class.""" 54 55 self.align_data = AlignTensorData('test')
56 57
58 - def test_append_sim(self):
59 """Test the appending of Monte Carlo simulation alignment tensor parameters. 60 61 The following parameters will be appended to empty lists: 62 - Axx: -16.6278 Hz 63 - Ayy: 6.13037 Hz 64 - Axy: 7.65639 Hz 65 - Axz: -1.89157 Hz 66 - Ayz: 19.2561 Hz 67 """ 68 69 # The MC sim parameter values. 70 Axx = -16.6278 / kappa() * 1.02e-10**3 71 Ayy = 6.13037 / kappa() * 1.02e-10**3 72 Axy = 7.65639 / kappa() * 1.02e-10**3 73 Axz = -1.89157 / kappa() * 1.02e-10**3 74 Ayz = 19.2561 / kappa() * 1.02e-10**3 75 76 # Set the MC sim alignment parameter lists. 77 self.align_data.Axx_sim = AlignTensorSimList('Axx', self.align_data) 78 self.align_data.Ayy_sim = AlignTensorSimList('Ayy', self.align_data) 79 self.align_data.Axy_sim = AlignTensorSimList('Axy', self.align_data) 80 self.align_data.Axz_sim = AlignTensorSimList('Axz', self.align_data) 81 self.align_data.Ayz_sim = AlignTensorSimList('Ayz', self.align_data) 82 83 # Append the values. 84 self.align_data.Axx_sim.append(Axx) 85 self.align_data.Ayy_sim.append(Ayy) 86 self.align_data.Axy_sim.append(Axy) 87 self.align_data.Axz_sim.append(Axz) 88 self.align_data.Ayz_sim.append(Ayz) 89 90 # Test the set values. 91 self.assertEqual(self.align_data.Axx_sim[0], Axx) 92 self.assertEqual(self.align_data.Ayy_sim[0], Ayy) 93 self.assertEqual(self.align_data.Axy_sim[0], Axy) 94 self.assertEqual(self.align_data.Axz_sim[0], Axz) 95 self.assertEqual(self.align_data.Ayz_sim[0], Ayz) 96 97 # Calculate the diffusion tensor objects. 98 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 99 100 # Test the automatically created values. 101 self.assertEqual(self.align_data.Azz_sim[0], Azz) 102 self.assertEqual(self.align_data.Axxyy_sim[0], Axxyy) 103 104 # Test the matrices. 105 self.assertEqual(self.align_data.A_sim[0].tostring(), tensor.tostring())
106 107
108 - def test_set_Szz(self):
109 """Test that the Szz parameter cannot be set.""" 110 111 # Assert that a RelaxError occurs when Szz is set. 112 self.assertRaises(RelaxError, setattr, self.align_data, 'Szz', -23.0) 113 114 # Make sure that the Szz parameter has not been set. 115 self.assert_(not hasattr(self.align_data, 'Szz'))
116 117
118 - def test_set_errors(self):
119 """Test the setting of spheroidal diffusion tensor parameter errors. 120 121 The following parameter errors will be set: 122 - Axx: 0.3 Hz 123 - Ayy: 0.5 Hz 124 - Axy: 0.4 Hz 125 - Axz: 0.1 Hz 126 - Ayz: 0.2 Hz 127 """ 128 129 # The parameter errors. 130 Axx = 0.3 / kappa() * 1.02e-10**3 131 Ayy = 0.5 / kappa() * 1.02e-10**3 132 Axy = 0.4 / kappa() * 1.02e-10**3 133 Axz = 0.1 / kappa() * 1.02e-10**3 134 Ayz = 0.2 / kappa() * 1.02e-10**3 135 136 # Set the diffusion parameters. 137 self.align_data.Axx_err = Axx 138 self.align_data.Ayy_err = Ayy 139 self.align_data.Axy_err = Axy 140 self.align_data.Axz_err = Axz 141 self.align_data.Ayz_err = Ayz 142 143 # Test the set values. 144 self.assertEqual(self.align_data.Axx_err, Axx) 145 self.assertEqual(self.align_data.Ayy_err, Ayy) 146 self.assertEqual(self.align_data.Axy_err, Axy) 147 self.assertEqual(self.align_data.Axz_err, Axz) 148 self.assertEqual(self.align_data.Ayz_err, Ayz) 149 150 # Calculate the diffusion tensor objects. 151 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 152 153 # Test the automatically created values. 154 self.assertEqual(self.align_data.Azz_err, Azz) 155 self.assertEqual(self.align_data.Axxyy_err, Axxyy) 156 157 # Test the matrices. 158 self.assertEqual(self.align_data.A_err.tostring(), tensor.tostring())
159 160
161 - def test_set_params(self):
162 """Test the setting of alignment tensor parameters. 163 164 The following parameters will be set: 165 - Axx: -16.6278 Hz 166 - Ayy: 6.13037 Hz 167 - Axy: 7.65639 Hz 168 - Axz: -1.89157 Hz 169 - Ayz: 19.2561 Hz 170 """ 171 172 # The parameter values. 173 Axx = -16.6278 / kappa() * 1.02e-10**3 174 Ayy = 6.13037 / kappa() * 1.02e-10**3 175 Axy = 7.65639 / kappa() * 1.02e-10**3 176 Axz = -1.89157 / kappa() * 1.02e-10**3 177 Ayz = 19.2561 / kappa() * 1.02e-10**3 178 179 # Set the diffusion parameters. 180 self.align_data.Axx = Axx 181 self.align_data.Ayy = Ayy 182 self.align_data.Axy = Axy 183 self.align_data.Axz = Axz 184 self.align_data.Ayz = Ayz 185 186 # Test the set values. 187 self.assertEqual(self.align_data.Axx, Axx) 188 self.assertEqual(self.align_data.Ayy, Ayy) 189 self.assertEqual(self.align_data.Axy, Axy) 190 self.assertEqual(self.align_data.Axz, Axz) 191 self.assertEqual(self.align_data.Ayz, Ayz) 192 193 # Calculate the diffusion tensor objects. 194 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 195 196 # Test the automatically created values. 197 self.assertEqual(self.align_data.Azz, Azz) 198 self.assertEqual(self.align_data.Axxyy, Axxyy) 199 200 # Test the matrices. 201 self.assertEqual(self.align_data.A.tostring(), tensor.tostring())
202 203
204 - def test_set_sim(self):
205 """Test the setting of Monte Carlo simulation alignment tensor parameters. 206 207 Firstly the following parameters will be appended to empty lists: 208 - Axx: -16.6278 Hz 209 - Ayy: 6.13037 Hz 210 - Axy: 7.65639 Hz 211 - Axz: -1.89157 Hz 212 - Ayz: 19.2561 Hz 213 214 These MC sim values will then be explicity overwritten by setting the first elements of the 215 lists to: 216 - Axx: 0.3 Hz 217 - Ayy: 0.5 Hz 218 - Axy: 0.4 Hz 219 - Axz: 0.1 Hz 220 - Ayz: 0.2 Hz 221 """ 222 223 # Set the MC sim alignment parameter lists. 224 self.align_data.Axx_sim = AlignTensorSimList('Axx', self.align_data) 225 self.align_data.Ayy_sim = AlignTensorSimList('Ayy', self.align_data) 226 self.align_data.Axy_sim = AlignTensorSimList('Axy', self.align_data) 227 self.align_data.Axz_sim = AlignTensorSimList('Axz', self.align_data) 228 self.align_data.Ayz_sim = AlignTensorSimList('Ayz', self.align_data) 229 230 # Append the initial values. 231 self.align_data.Axx_sim.append(-16.6278 / kappa() * 1.02e-10**3) 232 self.align_data.Ayy_sim.append(6.13037 / kappa() * 1.02e-10**3) 233 self.align_data.Axy_sim.append(7.65639 / kappa() * 1.02e-10**3) 234 self.align_data.Axz_sim.append(-1.89157 / kappa() * 1.02e-10**3) 235 self.align_data.Ayz_sim.append(19.2561 / kappa() * 1.02e-10**3) 236 237 # The new MC sim parameter values. 238 Axx = 0.3 / kappa() * 1.02e-10**3 239 Ayy = 0.5 / kappa() * 1.02e-10**3 240 Axy = 0.4 / kappa() * 1.02e-10**3 241 Axz = 0.1 / kappa() * 1.02e-10**3 242 Ayz = 0.2 / kappa() * 1.02e-10**3 243 244 # Set the MC sim parameter values (overwriting the initial values). 245 self.align_data.Axx_sim[0] = Axx 246 self.align_data.Ayy_sim[0] = Ayy 247 self.align_data.Axy_sim[0] = Axy 248 self.align_data.Axz_sim[0] = Axz 249 self.align_data.Ayz_sim[0] = Ayz 250 251 # Test the set values. 252 self.assertEqual(self.align_data.Axx_sim[0], Axx) 253 self.assertEqual(self.align_data.Ayy_sim[0], Ayy) 254 self.assertEqual(self.align_data.Axy_sim[0], Axy) 255 self.assertEqual(self.align_data.Axz_sim[0], Axz) 256 self.assertEqual(self.align_data.Ayz_sim[0], Ayz) 257 258 # Calculate the diffusion tensor objects. 259 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 260 261 # Test the automatically created values. 262 self.assertEqual(self.align_data.Azz_sim[0], Azz) 263 self.assertEqual(self.align_data.Axxyy_sim[0], Axxyy) 264 265 # Test the matrices. 266 self.assertEqual(self.align_data.A_sim[0].tostring(), tensor.tostring())
267 268
269 - def test_set_Axx(self):
270 """Test the setting of the Axx parameter.""" 271 272 # Set the Axx value to 0.0001. 273 self.align_data.Axx = 0.0001 274 275 # Test that the Axx parameter has been set correctly. 276 self.assert_(hasattr(self.align_data, 'Axx')) 277 self.assertEqual(self.align_data.Axx, 0.0001)
278