1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24  from data import Relax_data_store; ds = Relax_data_store() 
 25  from generic_fns import pipes 
 26  from generic_fns.reset import reset 
 27  from relax_errors import RelaxError, RelaxNoPipeError, RelaxNoTensorError 
 28  from test_suite.unit_tests.base_classes import UnitTestCase 
 29   
 30   
 32      """Base class for the tests of the diffusion tensor modules. 
 33       
 34      This includes both the 'prompt.diffusion_tensor' and 'generic_fns.diffusion_tensor' modules.  The base class also contains many shared unit tests. 
 35      """ 
 36   
 38          """Set up for all the diffusion tensor unit tests.""" 
 39   
 40           
 41          ds.add(pipe_name='orig', pipe_type='mf') 
 42   
 43           
 44          ds.add(pipe_name='test', pipe_type='mf') 
 45   
 46           
 47          pipes.switch('orig') 
  48   
 49   
 51          """Test the copying of an ellipsoid diffusion tensor (pulling the data from another pipe). 
 52   
 53          The functions tested are both generic_fns.diffusion_tensor.copy() and 
 54          prompt.diffusion_tensor.copy(). 
 55          """ 
 56   
 57           
 58          self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 
 59   
 60           
 61          pipes.switch('test') 
 62   
 63           
 64          dp = pipes.get_pipe('test') 
 65   
 66           
 67          self.diffusion_tensor_fns.copy(pipe_from='orig') 
 68   
 69           
 70          self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 
 71          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 
 72          self.assertEqual(dp.diff_tensor.Da, 1.8e7) 
 73          self.assertEqual(dp.diff_tensor.Dr, 0.7) 
 74          self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 
 75          self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 
 76          self.assertEqual(dp.diff_tensor.gamma, 0.34) 
 77          self.assertEqual(dp.diff_tensor.fixed, 1) 
  78   
 79   
103   
104   
106          """Test the copying of a spheroidal diffusion tensor (pulling the data from another pipe). 
107   
108          The functions tested are both generic_fns.diffusion_tensor.copy() and 
109          prompt.diffusion_tensor.copy(). 
110          """ 
111   
112           
113          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
114   
115           
116          pipes.switch('test') 
117   
118           
119          dp = pipes.get_pipe('test') 
120   
121           
122          self.diffusion_tensor_fns.copy(pipe_from='orig', pipe_to='test') 
123   
124           
125          self.assertEqual(dp.diff_tensor.type, 'spheroid') 
126          self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 
127          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 
128          self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 
129          self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 
130          self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 
131          self.assertEqual(dp.diff_tensor.fixed, 0) 
 132   
133   
135          """Test the copying of an ellipsoid diffusion tensor (pushing the data from another pipe). 
136   
137          The functions tested are both generic_fns.diffusion_tensor.copy() and 
138          prompt.diffusion_tensor.copy(). 
139          """ 
140   
141           
142          self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 
143   
144           
145          self.diffusion_tensor_fns.copy(pipe_to='test') 
146   
147           
148          dp = pipes.get_pipe('test') 
149   
150           
151          self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 
152          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 
153          self.assertEqual(dp.diff_tensor.Da, 1.8e7) 
154          self.assertEqual(dp.diff_tensor.Dr, 0.7) 
155          self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 
156          self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 
157          self.assertEqual(dp.diff_tensor.gamma, 0.34) 
158          self.assertEqual(dp.diff_tensor.fixed, 1) 
 159   
160   
162          """Test the copying of a spherical diffusion tensor (pushing the data from another pipe). 
163   
164          The functions tested are both generic_fns.diffusion_tensor.copy() and 
165          prompt.diffusion_tensor.copy(). 
166          """ 
167   
168           
169          self.diffusion_tensor_fns.init(params=1e-9) 
170   
171           
172          self.diffusion_tensor_fns.copy(pipe_to='test') 
173   
174           
175          dp = pipes.get_pipe('test') 
176   
177           
178          self.assertEqual(dp.diff_tensor.type, 'sphere') 
179          self.assertEqual(dp.diff_tensor.tm, 1e-9) 
180          self.assertEqual(dp.diff_tensor.fixed, 1) 
 181   
182   
184          """Test the copying of a spheroidal diffusion tensor (pushing the data from another pipe). 
185   
186          The functions tested are both generic_fns.diffusion_tensor.copy() and 
187          prompt.diffusion_tensor.copy(). 
188          """ 
189   
190           
191          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
192   
193           
194          self.diffusion_tensor_fns.copy(pipe_from='orig', pipe_to='test') 
195   
196           
197          dp = pipes.get_pipe('test') 
198   
199           
200          self.assertEqual(dp.diff_tensor.type, 'spheroid') 
201          self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 
202          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 
203          self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 
204          self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 
205          self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 
206          self.assertEqual(dp.diff_tensor.fixed, 0) 
 207   
208   
210          """Test the deletion of the diffusion tensor data structure. 
211   
212          The functions tested are both generic_fns.diffusion_tensor.delete() and 
213          prompt.diffusion_tensor.delete(). 
214          """ 
215   
216           
217          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
218   
219           
220          self.diffusion_tensor_fns.delete() 
221   
222           
223          dp = pipes.get_pipe('test') 
224   
225           
226          self.failIf(hasattr(dp, 'diff_tensor')) 
 227   
228   
230          """Failure of deletion of the diffusion tensor data structure when there is no data. 
231   
232          The functions tested are both generic_fns.diffusion_tensor.delete() and 
233          prompt.diffusion_tensor.delete(). 
234          """ 
235   
236           
237          self.assertRaises(RelaxNoTensorError, self.diffusion_tensor_fns.delete) 
 238   
239   
241          """Failure of deletion of the diffusion tensor data structure when there is no data pipe. 
242   
243          The functions tested are both generic_fns.diffusion_tensor.delete() and 
244          prompt.diffusion_tensor.delete(). 
245          """ 
246   
247           
248          reset() 
249   
250           
251          self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.delete) 
 252   
253   
255          """Display an ellipsoidal diffusion tensor. 
256   
257          The functions tested are both generic_fns.diffusion_tensor.display() and 
258          prompt.diffusion_tensor.display(). 
259          """ 
260   
261           
262          self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 
263   
264           
265          self.diffusion_tensor_fns.display() 
 266   
267   
269          """Failure of the display of the diffusion tensor data structure when there is no data. 
270   
271          The functions tested are both generic_fns.diffusion_tensor.display() and 
272          prompt.diffusion_tensor.display(). 
273          """ 
274   
275           
276          self.assertRaises(RelaxNoTensorError, self.diffusion_tensor_fns.display) 
 277   
278   
280          """Failure of the display of the diffusion tensor data structure when there is no data pipe. 
281   
282          The functions tested are both generic_fns.diffusion_tensor.display() and 
283          prompt.diffusion_tensor.display(). 
284          """ 
285   
286           
287          reset() 
288   
289           
290          self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.display) 
 291   
292   
305   
306   
308          """Display a spheroidal diffusion tensor. 
309   
310          The functions tested are both generic_fns.diffusion_tensor.display() and 
311          prompt.diffusion_tensor.display(). 
312          """ 
313   
314           
315          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
316   
317           
318          self.diffusion_tensor_fns.display() 
 319   
320   
321   
323          """Test the failure of setting up a diffusion tensor when angle_units is incorrect. 
324   
325          The functions tested are both generic_fns.diffusion_tensor.init() and 
326          prompt.diffusion_tensor.init(). 
327          """ 
328   
329           
330          self.assertRaises(RelaxError, self.diffusion_tensor_fns.init, params=1e-9, angle_units='aaa') 
 331   
332   
334          """Test the setting up of a ellipsoid diffusion tensor. 
335   
336          The functions tested are both generic_fns.diffusion_tensor.init() and 
337          prompt.diffusion_tensor.init(). 
338          """ 
339   
340           
341          dp = pipes.get_pipe('orig') 
342   
343           
344          self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 
345   
346           
347          self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 
348          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 
349          self.assertEqual(dp.diff_tensor.Da, 1.8e7) 
350          self.assertEqual(dp.diff_tensor.Dr, 0.7) 
351          self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 
352          self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 
353          self.assertEqual(dp.diff_tensor.gamma, 0.34) 
354          self.assertEqual(dp.diff_tensor.fixed, 1) 
 355   
356   
358          """Test the setting up of a spherical diffusion tensor. 
359   
360          The functions tested are both generic_fns.diffusion_tensor.init() and 
361          prompt.diffusion_tensor.init(). 
362          """ 
363   
364           
365          dp = pipes.get_pipe('orig') 
366   
367           
368          self.diffusion_tensor_fns.init(params=1e-9) 
369   
370           
371          self.assertEqual(dp.diff_tensor.type, 'sphere') 
372          self.assertEqual(dp.diff_tensor.tm, 1e-9) 
373          self.assertEqual(dp.diff_tensor.fixed, 1) 
 374   
375   
377          """Test the setting up of a spheroidal diffusion tensor. 
378   
379          The functions tested are both generic_fns.diffusion_tensor.init() and 
380          prompt.diffusion_tensor.init(). 
381          """ 
382   
383           
384          dp = pipes.get_pipe('orig') 
385   
386           
387          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
388   
389           
390          self.assertEqual(dp.diff_tensor.type, 'spheroid') 
391          self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 
392          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 
393          self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 
394          self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 
395          self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 
396          self.assertEqual(dp.diff_tensor.fixed, 0) 
  397