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_set_Szz(self):
104 """Test that the Szz parameter cannot be set.""" 105 106 # Assert that a RelaxError occurs when Szz is set. 107 self.assertRaises(RelaxError, setattr, self.align_data, 'Szz', -23.0) 108 109 # Make sure that the Szz parameter has not been set. 110 self.assert_(not hasattr(self.align_data, 'Szz'))
111 112
113 - def test_set_errors(self):
114 """Test the setting of spheroidal diffusion tensor parameter errors. 115 116 The following parameter errors will be set: 117 - Axx: 0.3 Hz 118 - Ayy: 0.5 Hz 119 - Axy: 0.4 Hz 120 - Axz: 0.1 Hz 121 - Ayz: 0.2 Hz 122 """ 123 124 # The parameter errors. 125 Axx = 0.3 / kappa() * 1.02e-10**3 126 Ayy = 0.5 / kappa() * 1.02e-10**3 127 Axy = 0.4 / kappa() * 1.02e-10**3 128 Axz = 0.1 / kappa() * 1.02e-10**3 129 Ayz = 0.2 / kappa() * 1.02e-10**3 130 131 # Set the diffusion parameters. 132 self.align_data.set(param='Axx', value=Axx, category='err') 133 self.align_data.set(param='Ayy', value=Ayy, category='err') 134 self.align_data.set(param='Axy', value=Axy, category='err') 135 self.align_data.set(param='Axz', value=Axz, category='err') 136 self.align_data.set(param='Ayz', value=Ayz, category='err') 137 138 # Test the set values. 139 self.assertEqual(self.align_data.Axx_err, Axx) 140 self.assertEqual(self.align_data.Ayy_err, Ayy) 141 self.assertEqual(self.align_data.Axy_err, Axy) 142 self.assertEqual(self.align_data.Axz_err, Axz) 143 self.assertEqual(self.align_data.Ayz_err, Ayz) 144 145 # Calculate the diffusion tensor objects. 146 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 147 148 # Test the automatically created values. 149 self.assertEqual(self.align_data.Azz_err, Azz) 150 self.assertEqual(self.align_data.Axxyy_err, Axxyy) 151 152 # Test the matrices. 153 self.assertEqual(self.align_data.A_err.tostring(), tensor.tostring())
154 155
156 - def test_set_params(self):
157 """Test the setting of alignment tensor parameters. 158 159 The following parameters will be set: 160 - Axx: -16.6278 Hz 161 - Ayy: 6.13037 Hz 162 - Axy: 7.65639 Hz 163 - Axz: -1.89157 Hz 164 - Ayz: 19.2561 Hz 165 """ 166 167 # The parameter values. 168 Axx = -16.6278 / kappa() * 1.02e-10**3 169 Ayy = 6.13037 / kappa() * 1.02e-10**3 170 Axy = 7.65639 / kappa() * 1.02e-10**3 171 Axz = -1.89157 / kappa() * 1.02e-10**3 172 Ayz = 19.2561 / kappa() * 1.02e-10**3 173 174 # Set the diffusion parameters. 175 self.align_data.set(param='Axx', value=Axx) 176 self.align_data.set(param='Ayy', value=Ayy) 177 self.align_data.set(param='Axy', value=Axy) 178 self.align_data.set(param='Axz', value=Axz) 179 self.align_data.set(param='Ayz', value=Ayz) 180 181 # Test the set values. 182 self.assertEqual(self.align_data.Axx, Axx) 183 self.assertEqual(self.align_data.Ayy, Ayy) 184 self.assertEqual(self.align_data.Axy, Axy) 185 self.assertEqual(self.align_data.Axz, Axz) 186 self.assertEqual(self.align_data.Ayz, Ayz) 187 188 # Calculate the diffusion tensor objects. 189 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 190 191 # Test the automatically created values. 192 self.assertEqual(self.align_data.Azz, Azz) 193 self.assertEqual(self.align_data.Axxyy, Axxyy) 194 195 # Test the matrices. 196 self.assertEqual(self.align_data.A.tostring(), tensor.tostring())
197 198
199 - def test_set_sim(self):
200 """Test the setting of Monte Carlo simulation alignment tensor parameters. 201 202 Firstly the following parameters will be appended to empty lists: 203 - Axx: -16.6278 Hz 204 - Ayy: 6.13037 Hz 205 - Axy: 7.65639 Hz 206 - Axz: -1.89157 Hz 207 - Ayz: 19.2561 Hz 208 209 These MC sim values will then be explicity overwritten by setting the first elements of the 210 lists to: 211 - Axx: 0.3 Hz 212 - Ayy: 0.5 Hz 213 - Axy: 0.4 Hz 214 - Axz: 0.1 Hz 215 - Ayz: 0.2 Hz 216 """ 217 218 # Set the number of MC sims. 219 self.align_data.set_sim_num(1) 220 221 # Append the initial values. 222 self.align_data.set(param='Axx', value=-16.6278 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 223 self.align_data.set(param='Ayy', value=6.13037 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 224 self.align_data.set(param='Axy', value=7.65639 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 225 self.align_data.set(param='Axz', value=-1.89157 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 226 self.align_data.set(param='Ayz', value=19.2561 / kappa() * 1.02e-10**3, category='sim', sim_index=0) 227 228 # The new MC sim parameter values. 229 Axx = 0.3 / kappa() * 1.02e-10**3 230 Ayy = 0.5 / kappa() * 1.02e-10**3 231 Axy = 0.4 / kappa() * 1.02e-10**3 232 Axz = 0.1 / kappa() * 1.02e-10**3 233 Ayz = 0.2 / kappa() * 1.02e-10**3 234 235 # Set the MC sim parameter values (overwriting the initial values). 236 self.align_data.set(param='Axx', value=Axx, category='sim', sim_index=0) 237 self.align_data.set(param='Ayy', value=Ayy, category='sim', sim_index=0) 238 self.align_data.set(param='Axy', value=Axy, category='sim', sim_index=0) 239 self.align_data.set(param='Axz', value=Axz, category='sim', sim_index=0) 240 self.align_data.set(param='Ayz', value=Ayz, category='sim', sim_index=0) 241 242 # Test the set values. 243 self.assertEqual(self.align_data.Axx_sim[0], Axx) 244 self.assertEqual(self.align_data.Ayy_sim[0], Ayy) 245 self.assertEqual(self.align_data.Axy_sim[0], Axy) 246 self.assertEqual(self.align_data.Axz_sim[0], Axz) 247 self.assertEqual(self.align_data.Ayz_sim[0], Ayz) 248 249 # Calculate the diffusion tensor objects. 250 Azz, Axxyy, tensor = self.calc_objects(Axx, Ayy, Axy, Axz, Ayz) 251 252 # Test the automatically created values. 253 self.assertEqual(self.align_data.Azz_sim[0], Azz) 254 self.assertEqual(self.align_data.Axxyy_sim[0], Axxyy) 255 256 # Test the matrices. 257 self.assertEqual(self.align_data.A_sim[0].tostring(), tensor.tostring())
258 259
260 - def test_set_Axx(self):
261 """Test the setting of the Axx parameter.""" 262 263 # Set the Axx value to 0.0001. 264 self.align_data.set(param='Axx', value=0.0001) 265 266 # Test that the Axx parameter has been set correctly. 267 self.assert_(hasattr(self.align_data, 'Axx')) 268 self.assertEqual(self.align_data.Axx, 0.0001)
269