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

Source Code for Module test_suite.unit_tests._data_store.test_align_tensor

  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 numpy import array 
 24  from unittest import TestCase 
 25   
 26  # relax module imports. 
 27  from data_store.align_tensor import AlignTensorData 
 28  from pipe_control.align_tensor import kappa 
 29  from lib.errors import RelaxError 
 30   
 31   
32 -class Test_align_tensor(TestCase):
33 """Unit tests for the data.align_tensor relax module.""" 34
35 - def calc_objects(self, Axx, Ayy, Axy, Axz, Ayz):
36 """Function for calculating the alignment tensor objects.""" 37 38 # The parameter values. 39 Azz = - Axx - Ayy 40 Axxyy = Axx - Ayy 41 42 # Matrices. 43 tensor = array([[ Axx, Axy, Axz], 44 [ Axy, Ayy, Ayz], 45 [ Axz, Ayz, Azz]]) 46 47 # Return the objects. 48 return Azz, Axxyy, tensor
49 50
51 - def setUp(self):
52 """Set 'self.align_data' to an empty instance of the AlignTensorData class.""" 53 54 self.align_data = AlignTensorData('test')
55 56
57 - def test_append_sim(self):
58 """Test the appending of Monte Carlo simulation alignment tensor parameters. 59 60 The following parameters will be appended to empty lists: 61 - Axx: -16.6278 Hz 62 - Ayy: 6.13037 Hz 63 - Axy: 7.65639 Hz 64 - Axz: -1.89157 Hz 65 - Ayz: 19.2561 Hz 66 """ 67 68 # The MC sim parameter values. 69 Axx = -16.6278 / kappa() * 1.02e-10**3 70 Ayy = 6.13037 / kappa() * 1.02e-10**3 71 Axy = 7.65639 / kappa() * 1.02e-10**3 72 Axz = -1.89157 / kappa() * 1.02e-10**3 73 Ayz = 19.2561 / kappa() * 1.02e-10**3 74 75 # Set the number of MC sims. 76 self.align_data.set_sim_num(1) 77 78 # Set the values. 79 self.align_data.set(param='Axx', value=Axx, category='sim', sim_index=0) 80 self.align_data.set(param='Ayy', value=Ayy, category='sim', sim_index=0) 81 self.align_data.set(param='Axy', value=Axy, category='sim', sim_index=0) 82 self.align_data.set(param='Axz', value=Axz, category='sim', sim_index=0) 83 self.align_data.set(param='Ayz', value=Ayz, category='sim', sim_index=0) 84 85 # Test the set values. 86 self.assertEqual(self.align_data.Axx_sim[0], Axx) 87 self.assertEqual(self.align_data.Ayy_sim[0], Ayy) 88 self.assertEqual(self.align_data.Axy_sim[0], Axy) 89 self.assertEqual(self.align_data.Axz_sim[0], Axz) 90 self.assertEqual(self.align_data.Ayz_sim[0], Ayz) 91 92 # Calculate the diffusion tensor objects. 93 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 94 95 # Test the automatically created values. 96 self.assertEqual(self.align_data.Azz_sim[0], Azz) 97 self.assertEqual(self.align_data.Axxyy_sim[0], Axxyy) 98 99 # Test the matrices. 100 self.assertEqual(self.align_data.A_sim[0].tostring(), tensor.tostring())
101 102
103 - def test_irreducible_params(self):
104 """Test the irreducible parameters {A-2, A-1, A0, A1, A2}. 105 106 This is to test if the Pales results can be matched. The example is:: 107 108 DATA SAUPE_MATRIX S(zz) S(xx-yy) S(xy) S(xz) S(yz) 109 DATA SAUPE -1.2856e-04 -5.6870e-04 -3.1704e-04 3.5099e-04 -1.7937e-04 110 DATA IRREDUCIBLE_REP A0 A1R A1I A2R A2I 111 DATA IRREDUCIBLE -2.0380e-04 -4.5433e-04 -2.3218e-04 -3.6807e-04 4.1038e-04 112 DATA IRREDUCIBLE GENERAL_MAGNITUDE 1.0816e-03 113 """ 114 115 # From Pales (S(zz) S(xx-yy) S(xy) S(xz) S(yz)) 116 Azz = 2.0 / 3.0 * -1.2856e-04 117 Axxyy = 2.0 / 3.0 * -5.6870e-04 118 Axy = 2.0 / 3.0 * -3.1704e-04 119 Axz = 2.0 / 3.0 * 3.5099e-04 120 Ayz = 2.0 / 3.0 * -1.7937e-04 121 122 # Parameter conversion. 123 Axx = (Axxyy - Azz) / 2.0 124 Ayy = (-Axxyy - Azz) / 2.0 125 126 # Set the values. 127 self.align_data.set(param='Axx', value=Axx) 128 self.align_data.set(param='Ayy', value=Ayy) 129 self.align_data.set(param='Axy', value=Axy) 130 self.align_data.set(param='Axz', value=Axz) 131 self.align_data.set(param='Ayz', value=Ayz) 132 133 # Pales equivalent printout. 134 print("Pales output:\n") 135 print("DATA SAUPE_MATRIX S(zz) S(xx-yy) S(xy) S(xz) S(yz)") 136 print("DATA SAUPE -1.2856e-04 -5.6870e-04 -3.1704e-04 3.5099e-04 -1.7937e-04") 137 print("") 138 print("DATA IRREDUCIBLE_REP A0 A1R A1I A2R A2I ") 139 print("DATA IRREDUCIBLE -2.0380e-04 -4.5433e-04 -2.3218e-04 -3.6807e-04 4.1038e-04") 140 print("DATA IRREDUCIBLE GENERAL_MAGNITUDE 1.0816e-03") 141 print("") 142 print("Calculated values:\n") 143 print("A0: %15.4e" % self.align_data.A0) 144 print("A1: %15.4e %11.4ei" % (self.align_data.A1.real, self.align_data.A1.imag)) 145 print("Am1: %15.4e %11.4ei" % (self.align_data.Am1.real, self.align_data.Am1.imag)) 146 print("A2: %15.4e %11.4ei" % (self.align_data.A2.real, self.align_data.A2.imag)) 147 print("Am2: %15.4e %11.4ei" % (self.align_data.Am2.real, self.align_data.Am2.imag)) 148 149 # Check that the values match Pales (guessing that Pales is using the negative indices). 150 self.assertAlmostEqual(self.align_data.A0, -2.0380e-04) 151 self.assertAlmostEqual(self.align_data.A1.real, 4.5433e-04) 152 self.assertAlmostEqual(self.align_data.A1.imag, -2.3218e-04) 153 self.assertAlmostEqual(self.align_data.Am1.real, -4.5433e-04) 154 self.assertAlmostEqual(self.align_data.Am1.imag, -2.3218e-04) 155 self.assertAlmostEqual(self.align_data.A2.real, -3.6807e-04) 156 self.assertAlmostEqual(self.align_data.A2.imag, -4.1038e-04) 157 self.assertAlmostEqual(self.align_data.Am2.real, -3.6807e-04) 158 self.assertAlmostEqual(self.align_data.Am2.imag, 4.1038e-04)
159 160
161 - def test_set_Szz(self):
162 """Test that the Szz parameter cannot be set.""" 163 164 # Assert that a RelaxError occurs when Szz is set. 165 self.assertRaises(RelaxError, setattr, self.align_data, 'Szz', -23.0) 166 167 # Make sure that the Szz parameter has not been set. 168 self.assert_(not hasattr(self.align_data, 'Szz'))
169 170
171 - def test_set_errors(self):
172 """Test the setting of spheroidal diffusion tensor parameter errors. 173 174 The following parameter errors will be set: 175 - Axx: 0.3 Hz 176 - Ayy: 0.5 Hz 177 - Axy: 0.4 Hz 178 - Axz: 0.1 Hz 179 - Ayz: 0.2 Hz 180 """ 181 182 # The parameter errors. 183 Axx = 0.3 / kappa() * 1.02e-10**3 184 Ayy = 0.5 / kappa() * 1.02e-10**3 185 Axy = 0.4 / kappa() * 1.02e-10**3 186 Axz = 0.1 / kappa() * 1.02e-10**3 187 Ayz = 0.2 / kappa() * 1.02e-10**3 188 189 # Set the diffusion parameters. 190 self.align_data.set(param='Axx', value=Axx, category='err') 191 self.align_data.set(param='Ayy', value=Ayy, category='err') 192 self.align_data.set(param='Axy', value=Axy, category='err') 193 self.align_data.set(param='Axz', value=Axz, category='err') 194 self.align_data.set(param='Ayz', value=Ayz, category='err') 195 196 # Test the set values. 197 self.assertEqual(self.align_data.Axx_err, Axx) 198 self.assertEqual(self.align_data.Ayy_err, Ayy) 199 self.assertEqual(self.align_data.Axy_err, Axy) 200 self.assertEqual(self.align_data.Axz_err, Axz) 201 self.assertEqual(self.align_data.Ayz_err, Ayz) 202 203 # Calculate the diffusion tensor objects. 204 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 205 206 # Test the automatically created values. 207 self.assertEqual(self.align_data.Azz_err, Azz) 208 self.assertEqual(self.align_data.Axxyy_err, Axxyy) 209 210 # Test the matrices. 211 self.assertEqual(self.align_data.A_err.tostring(), tensor.tostring())
212 213
214 - def test_set_params(self):
215 """Test the setting of alignment tensor parameters. 216 217 The following parameters will be set: 218 - Axx: -16.6278 Hz 219 - Ayy: 6.13037 Hz 220 - Axy: 7.65639 Hz 221 - Axz: -1.89157 Hz 222 - Ayz: 19.2561 Hz 223 """ 224 225 # The parameter values. 226 Axx = -16.6278 / kappa() * 1.02e-10**3 227 Ayy = 6.13037 / kappa() * 1.02e-10**3 228 Axy = 7.65639 / kappa() * 1.02e-10**3 229 Axz = -1.89157 / kappa() * 1.02e-10**3 230 Ayz = 19.2561 / kappa() * 1.02e-10**3 231 232 # Set the diffusion parameters. 233 self.align_data.set(param='Axx', value=Axx) 234 self.align_data.set(param='Ayy', value=Ayy) 235 self.align_data.set(param='Axy', value=Axy) 236 self.align_data.set(param='Axz', value=Axz) 237 self.align_data.set(param='Ayz', value=Ayz) 238 239 # Test the set values. 240 self.assertEqual(self.align_data.Axx, Axx) 241 self.assertEqual(self.align_data.Ayy, Ayy) 242 self.assertEqual(self.align_data.Axy, Axy) 243 self.assertEqual(self.align_data.Axz, Axz) 244 self.assertEqual(self.align_data.Ayz, Ayz) 245 246 # Calculate the diffusion tensor objects. 247 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 248 249 # Test the automatically created values. 250 self.assertEqual(self.align_data.Azz, Azz) 251 self.assertEqual(self.align_data.Axxyy, Axxyy) 252 253 # Test the matrices. 254 self.assertEqual(self.align_data.A.tostring(), tensor.tostring())
255 256
257 - def test_set_sim(self):
258 """Test the setting of Monte Carlo simulation alignment tensor parameters. 259 260 Firstly the following parameters will be appended to empty lists: 261 - Axx: -16.6278 Hz 262 - Ayy: 6.13037 Hz 263 - Axy: 7.65639 Hz 264 - Axz: -1.89157 Hz 265 - Ayz: 19.2561 Hz 266 267 These MC sim values will then be explicity overwritten by setting the first elements of the 268 lists to: 269 - Axx: 0.3 Hz 270 - Ayy: 0.5 Hz 271 - Axy: 0.4 Hz 272 - Axz: 0.1 Hz 273 - Ayz: 0.2 Hz 274 """ 275 276 # Set the number of MC sims. 277 self.align_data.set_sim_num(1) 278 279 # Append the initial values. 280 self.align_data.set(param='Axx', value=-16.6278 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 281 self.align_data.set(param='Ayy', value=6.13037 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 282 self.align_data.set(param='Axy', value=7.65639 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 283 self.align_data.set(param='Axz', value=-1.89157 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 284 self.align_data.set(param='Ayz', value=19.2561 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 285 286 # The new MC sim parameter values. 287 Axx = 0.3 / kappa() * 1.02e-10**3 288 Ayy = 0.5 / kappa() * 1.02e-10**3 289 Axy = 0.4 / kappa() * 1.02e-10**3 290 Axz = 0.1 / kappa() * 1.02e-10**3 291 Ayz = 0.2 / kappa() * 1.02e-10**3 292 293 # Set the MC sim parameter values (overwriting the initial values). 294 self.align_data.set(param='Axx', value=Axx, category='sim', sim_index=0) 295 self.align_data.set(param='Ayy', value=Ayy, category='sim', sim_index=0) 296 self.align_data.set(param='Axy', value=Axy, category='sim', sim_index=0) 297 self.align_data.set(param='Axz', value=Axz, category='sim', sim_index=0) 298 self.align_data.set(param='Ayz', value=Ayz, category='sim', sim_index=0) 299 300 # Test the set values. 301 self.assertEqual(self.align_data.Axx_sim[0], Axx) 302 self.assertEqual(self.align_data.Ayy_sim[0], Ayy) 303 self.assertEqual(self.align_data.Axy_sim[0], Axy) 304 self.assertEqual(self.align_data.Axz_sim[0], Axz) 305 self.assertEqual(self.align_data.Ayz_sim[0], Ayz) 306 307 # Calculate the diffusion tensor objects. 308 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 309 310 # Test the automatically created values. 311 self.assertEqual(self.align_data.Azz_sim[0], Azz) 312 self.assertEqual(self.align_data.Axxyy_sim[0], Axxyy) 313 314 # Test the matrices. 315 self.assertEqual(self.align_data.A_sim[0].tostring(), tensor.tostring())
316 317
318 - def test_set_Axx(self):
319 """Test the setting of the Axx parameter.""" 320 321 # Set the Axx value to 0.0001. 322 self.align_data.set(param='Axx', value=0.0001) 323 324 # Test that the Axx parameter has been set correctly. 325 self.assert_(hasattr(self.align_data, 'Axx')) 326 self.assertEqual(self.align_data.Axx, 0.0001)
327