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 math import pi
25 from numpy import array, dot, float64, transpose, zeros
26 from os import close, sep
27 from tempfile import mkstemp
28
29
30 from data_store import Relax_data_store; ds = Relax_data_store()
31 from pipe_control.pipes import get_pipe
32 from pipe_control.reset import reset
33 from lib.geometry.coord_transform import spherical_to_cartesian
34 from lib.geometry.rotations import axis_angle_to_R, euler_to_R_zyz, two_vect_to_R
35 from lib.io import delete
36 from status import Status; status = Status()
37 from test_suite.system_tests.base_classes import SystemTestCase
38
39
41 """Class for testing various aspects specific to the diffusion tensor."""
42
44 """Function for initialising a spherical, spheroidal, and ellipsoidal diffusion tensor."""
45
46
47 status = Status()
48
49
50 self.interpreter.pipe.create('sphere', 'mf')
51 self.interpreter.pipe.create('spheroid', 'mf')
52 self.interpreter.pipe.create('ellipsoid', 'mf')
53
54
55 self.interpreter.pipe.switch('sphere')
56 self.interpreter.structure.read_pdb(file='Ap4Aase_res1-12.pdb', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures', read_model=1)
57 self.interpreter.sequence.read(file='Ap4Aase.seq', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep, res_num_col=1, res_name_col=2)
58 self.interpreter.diffusion_tensor.init(10e-9, fixed=True)
59 self.tmpfile_sphere_handle, self.tmpfile_sphere = mkstemp(suffix='.pdb')
60
61
62 self.interpreter.pipe.switch('spheroid')
63 self.interpreter.structure.read_pdb(file='Ap4Aase_res1-12.pdb', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures', read_model=1)
64 self.interpreter.sequence.read(file='Ap4Aase.seq', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep, res_num_col=1, res_name_col=2)
65 self.interpreter.diffusion_tensor.init((5e-09, -10000000., 1.6, 2.7), angle_units='rad', spheroid_type='oblate', fixed=True)
66 self.tmpfile_spheroid_handle, self.tmpfile_spheroid = mkstemp(suffix='.pdb')
67
68
69 self.interpreter.pipe.switch('ellipsoid')
70 self.interpreter.structure.read_pdb(file='Ap4Aase_res1-12.pdb', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures', read_model=1)
71 self.interpreter.sequence.read(file='Ap4Aase.seq', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep, res_num_col=1, res_name_col=2)
72 self.interpreter.diffusion_tensor.init((9e-8, 5e6, 0.3, 60+360, 290, 100), fixed=False)
73 self.tmpfile_ellipsoid_handle, self.tmpfile_ellipsoid = mkstemp(suffix='.pdb')
74
75
76
77 self.interpreter.pipe.switch('sphere')
78 cdp.diff_tensor.set(param='tm', value=10e-11, category='err')
79 cdp.diff_tensor.set_sim_num(5)
80 tm_sim = [8.98e-8, 8.99e-8, 9.00e-7, 9.01e-8, 9.02e-8]
81 for i in range(5):
82 cdp.diff_tensor.set(param='tm', value=tm_sim[i], category='sim', sim_index=i)
83
84
85 cdp.diff_tensor.set(param='tm', value=9.00e-8, category='sim', sim_index=0)
86
87
88
89 self.interpreter.pipe.switch('spheroid')
90
91
92 cdp.diff_tensor.set(param='Da', value=1000000, category='err')
93 cdp.diff_tensor.set(param='theta', value=0.01, category='err')
94 cdp.diff_tensor.set(param='tm', value=1e-11, category='err')
95 cdp.diff_tensor.set(param='phi', value=0.01, category='err')
96
97
98 cdp.diff_tensor.set_sim_num(5)
99 Da_sim = [-12000000., -11000000., -10000000., -9000000., -8000000.]
100 theta_sim = [1.70, 1.65, 1.6, 1.55, 1.50]
101 tm_sim = [5.4e-09, 4.8e-09, 5e-09, 5.4e-09, 5.8e-09]
102 phi_sim = [2.5, 2.6, 2.7, 2.8, 100]
103 for i in range(5):
104 cdp.diff_tensor.set(param='Da', value=Da_sim[i], category='sim', sim_index=i)
105 cdp.diff_tensor.set(param='theta', value=theta_sim[i], category='sim', sim_index=i)
106 cdp.diff_tensor.set(param='tm', value=tm_sim[i], category='sim', sim_index=i)
107 cdp.diff_tensor.set(param='phi', value=phi_sim[i], category='sim', sim_index=i)
108
109
110 cdp.diff_tensor.set(param='tm', value=4.4e-9, category='sim', sim_index=0)
111 cdp.diff_tensor.set(param='phi', value=2.9, category='sim', sim_index=4)
112
113
114
115 self.interpreter.pipe.switch('ellipsoid')
116
117
118 cdp.diff_tensor.set_sim_num(5)
119 Dr_sim = [0.28, 0.29, 0.3, 0.31, 0.32]
120 tm_sim = [8.97e-8, 8.99e-8, 9.00e-8, 9.01e-8, 9.02e-8]
121 Da_sim = [5.02e6, 5.01e6, 5.00e6, 4.99e6, 4.98e6]
122 alpha_sim = [80.0/360*2*pi, 70.0/360*2*pi, 60.0/360*2*pi, 50.0/360*2*pi, 40.0/360*2*pi]
123 beta_sim = [295.0/360*2*pi, 292.5/360*2*pi, 290.0/360*2*pi, 289.5/360*2*pi, 288.0/360*2*pi]
124 gamma_sim = [102.0/360*2*pi, 101.0/360*2*pi, 0, 99.0/360*2*pi, 98.0/360*2*pi]
125 for i in range(5):
126 cdp.diff_tensor.set(param='Dr', value=Dr_sim[i], category='sim', sim_index=i)
127 cdp.diff_tensor.set(param='tm', value=tm_sim[i], category='sim', sim_index=i)
128 cdp.diff_tensor.set(param='Da', value=Da_sim[i], category='sim', sim_index=i)
129 cdp.diff_tensor.set(param='alpha', value=alpha_sim[i], category='sim', sim_index=i)
130 cdp.diff_tensor.set(param='beta', value=beta_sim[i], category='sim', sim_index=i)
131 cdp.diff_tensor.set(param='gamma', value=gamma_sim[i], category='sim', sim_index=i)
132
133
134 cdp.diff_tensor.set(param='tm', value=8.98e-8, category='sim', sim_index=0)
135 cdp.diff_tensor.set(param='gamma', value=100.0/360*2*pi, category='sim', sim_index=2)
136
137
139 """Reset the relax data storage object."""
140
141
142 reset()
143
144
145 close(self.tmpfile_sphere_handle)
146 close(self.tmpfile_spheroid_handle)
147 close(self.tmpfile_ellipsoid_handle)
148
149
150 delete(self.tmpfile_sphere, fail=False)
151 delete(self.tmpfile_spheroid, fail=False)
152 delete(self.tmpfile_ellipsoid, fail=False)
153
154
155 - def check_ellipsoid(self, Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R):
156 """Check if the ellipsoid in the cdp has the same values as given."""
157
158
159 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor)
160 print("\nThe real tensor:\n%s" % D)
161 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor)
162 print("\nThe real tensor (in eig frame):\n%s" % D_prime)
163 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag)
164
165
166 self.assertAlmostEqual(Dx * 1e-7, cdp.diff_tensor.Dx * 1e-7)
167 self.assertAlmostEqual(Dy * 1e-7, cdp.diff_tensor.Dy * 1e-7)
168 self.assertAlmostEqual(Dz * 1e-7, cdp.diff_tensor.Dz * 1e-7)
169 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7)
170 self.assertAlmostEqual(Da * 1e-7, cdp.diff_tensor.Da * 1e-7)
171 self.assertAlmostEqual(Dr * 1e-7, cdp.diff_tensor.Dr * 1e-7)
172 self.assertAlmostEqual(alpha, cdp.diff_tensor.alpha)
173 self.assertAlmostEqual(beta, cdp.diff_tensor.beta)
174 self.assertAlmostEqual(gamma, cdp.diff_tensor.gamma)
175
176
177 for i in range(3):
178 for j in range(3):
179 self.assertAlmostEqual(cdp.diff_tensor.tensor[i, j] * 1e-7, D[i, j] * 1e-7)
180 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7)
181 self.assertAlmostEqual(cdp.diff_tensor.rotation[i, j], R[i, j])
182
183
184 - def check_spheroid(self, tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type=None):
185 """Check if the spheroid in the cdp has the same values as given."""
186
187
188 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor)
189 print("\nThe real tensor:\n%s" % D)
190 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor)
191 print("\nThe real tensor (in eig frame):\n%s" % D_prime)
192 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag)
193 print("\nThe real rotation matrix:\n%s" % R)
194 print("\nThe rotation matrix in relax:\n%s" % cdp.diff_tensor.rotation)
195
196
197 self.assertAlmostEqual(tm * 1e8, cdp.diff_tensor.tm * 1e8)
198 self.assertAlmostEqual(Dpar * 1e-7, cdp.diff_tensor.Dpar * 1e-7)
199 self.assertAlmostEqual(Dper * 1e-7, cdp.diff_tensor.Dper * 1e-7)
200 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7)
201 self.assertAlmostEqual(Da * 1e-7, cdp.diff_tensor.Da * 1e-7)
202 self.assertAlmostEqual(Dratio, cdp.diff_tensor.Dratio)
203 self.assertAlmostEqual(theta, cdp.diff_tensor.theta)
204 self.assertAlmostEqual(phi, cdp.diff_tensor.phi)
205
206
207 for i in range(3):
208 for j in range(3):
209 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7)
210
211
212 vects = []
213 vects.append([1, 0, 0])
214 vects.append([0, 1, 0])
215 vects.append([0, 0, 1])
216 vects = array(vects)
217 for vect in vects:
218
219 proj1 = dot(vect, dot(cdp.diff_tensor.tensor, vect))
220 proj2 = dot(vect, dot(D, vect))
221
222
223 self.assertAlmostEqual(proj1, proj2)
224
225
226 if spheroid_type:
227 self.assertEqual(spheroid_type, cdp.diff_tensor.spheroid_type)
228
229
231 """Check if the ellipsoid in the cdp has the same values as given spheroid."""
232
233
234 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor)
235 print("\nThe real tensor:\n%s" % D)
236 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor)
237 print("\nThe real tensor (in eig frame):\n%s" % D_prime)
238 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag)
239 print("\nThe real rotation matrix:\n%s" % R)
240 print("\nThe rotation matrix in relax:\n%s" % cdp.diff_tensor.rotation)
241
242
243 self.assertAlmostEqual(tm * 1e8, cdp.diff_tensor.tm * 1e8)
244 self.assertAlmostEqual(Dx * 1e-7, cdp.diff_tensor.Dx * 1e-7)
245 self.assertAlmostEqual(Dy * 1e-7, cdp.diff_tensor.Dy * 1e-7)
246 self.assertAlmostEqual(Dz * 1e-7, cdp.diff_tensor.Dz * 1e-7)
247 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7)
248
249
250 for i in range(3):
251 for j in range(3):
252 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7)
253
254
255 vects = []
256 vects.append([1, 0, 0])
257 vects.append([0, 1, 0])
258 vects.append([0, 0, 1])
259 vects = array(vects)
260 for vect in vects:
261
262 proj1 = dot(vect, dot(cdp.diff_tensor.tensor, vect))
263 proj2 = dot(vect, dot(D, vect))
264
265
266 print("\nVector: %s" % vect)
267 print("Real proj: %s" % proj1)
268 print("Proj in relax: %s" % proj2)
269
270
271 self.assertAlmostEqual(proj1, proj2)
272
273
275 """Return all the diffusion tensor info about the {Dx, Dy, Dz, alpha, beta, gamma} = {1e7, 2e7, 3e7, 1, 2, 0.5} ellipsoid tensor."""
276
277
278 Dx = 1e7
279 Dy = 2e7
280 Dz = 3e7
281 Diso = 2e7
282 Da = 1.5e7
283 Dr = 1.0/3.0
284 alpha = 1.0
285 beta = 2.0
286 gamma = 0.5
287
288
289 D = array([[ 22758858.4088357, -7267400.1700938, 6272205.75829415],
290 [ -7267400.1700938, 17923072.3436445, 1284270.53726401],
291 [ 6272205.75829415, 1284270.53726401, 19318069.2475198 ]], float64)
292
293
294 D_prime = zeros((3, 3), float64)
295 D_prime[0, 0] = Dx
296 D_prime[1, 1] = Dy
297 D_prime[2, 2] = Dz
298
299
300 R = zeros((3, 3), float64)
301 euler_to_R_zyz(gamma, beta, alpha, R)
302 R = transpose(R)
303
304
305 return Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R
306
307
308 - def get_spheroid(self, Dpar=None, Dper=None, theta=None, phi=None):
309 """Return all the diffusion tensor info about the given spheroid tensor."""
310
311
312 Diso = (Dpar + 2*Dper) / 3.0
313 tm = 1.0/(6.0 * Diso)
314 Da = Dpar - Dper
315 Dratio = Dpar / Dper
316
317
318 if Dpar > Dper:
319 Dx, Dy, Dz = Dper, Dper, Dpar
320 axis = array([0, 0, 1], float64)
321 else:
322 Dx, Dy, Dz = Dpar, Dper, Dper
323 axis = array([1, 0, 0], float64)
324
325
326 R = zeros((3, 3), float64)
327 spher_vect = array([1, theta, phi], float64)
328 diff_axis = zeros(3, float64)
329 spherical_to_cartesian(spher_vect, diff_axis)
330 two_vect_to_R(diff_axis, axis, R)
331
332
333 D_prime = zeros((3, 3), float64)
334 D_prime[0, 0] = Dx
335 D_prime[1, 1] = Dy
336 D_prime[2, 2] = Dz
337
338
339 twist = zeros((3, 3), float64)
340 axis_angle_to_R(axis, 0.3, twist)
341 D = dot(twist, dot(D_prime, transpose(twist)))
342
343
344 D = dot(R, dot(D, transpose(R)))
345
346
347 return tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R
348
349
351 """Check the back-calculation of relaxation data for the spherical diffusion tensor."""
352
353
354 reset()
355
356
357 ds.diff_dir = 'ellipsoid'
358 ds.diff_type = 'ellipsoid'
359
360
361 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'ri_back_calc.py')
362
363
364 for i in range(len(cdp.mol[0].res)):
365
366 spin = cdp.mol[0].res[i].spin[0]
367
368
369 for ri_id in cdp.ri_ids:
370 self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
371
372
374 """Check the back-calculation of relaxation data for the spherical diffusion tensor."""
375
376
377 reset()
378
379
380 ds.diff_dir = 'sphere'
381 ds.diff_type = 'sphere'
382
383
384 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'ri_back_calc.py')
385
386
387 for i in range(len(cdp.mol[0].res)):
388
389 spin = cdp.mol[0].res[i].spin[0]
390
391
392 for ri_id in cdp.ri_ids:
393 self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
394
395
397 """Check the back-calculation of relaxation data for the spherical diffusion tensor."""
398
399
400 reset()
401
402
403 ds.diff_dir = 'spheroid_prolate'
404 ds.diff_type = 'spheroid'
405
406
407 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'ri_back_calc.py')
408
409
410 for i in range(len(cdp.mol[0].res)):
411
412 spin = cdp.mol[0].res[i].spin[0]
413
414
415 for ri_id in cdp.ri_ids:
416 self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
417
418
420 """Catch U{bug #21561<https://web.archive.org/web/https://gna.org/bugs/?21561>} reported by Martin Ballaschk, the failure of the diffusion tensor PDB creation when Monte Carlo simulations are not present."""
421
422
423 self.interpreter.pipe.create('diff PDB', 'mf')
424
425
426 self.interpreter.diffusion_tensor.init((2e-8, 1.3, 60, 290), spheroid_type='prolate', param_types=2, fixed=True)
427
428
429 path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures'
430 self.interpreter.structure.read_pdb('Ap4Aase_res1-12.pdb', dir=path)
431
432
433 self.interpreter.structure.create_diff_tensor_pdb(file=self.tmpfile_spheroid, force=True)
434
435
437 """The user function diffusion_tensor.copy()."""
438
439
440 self.interpreter.pipe.create('sphere2', 'mf')
441 self.interpreter.pipe.create('spheroid2', 'mf')
442 self.interpreter.pipe.create('ellipsoid2', 'mf')
443
444
445 self.interpreter.diffusion_tensor.copy('sphere', 'sphere2')
446 self.interpreter.diffusion_tensor.copy('spheroid', 'spheroid2')
447 self.interpreter.diffusion_tensor.copy('ellipsoid', 'ellipsoid2')
448
449
450 sphere_pipe = get_pipe('sphere')
451 sphere2_pipe = get_pipe('sphere2')
452
453
454 self.assertEqual(sphere2_pipe.diff_tensor.tm_sim[4], 9.02e-8)
455 self.assertEqual(sphere2_pipe.diff_tensor.Diso_sim[4], 1/(6*9.02e-8))
456 sphere_pipe.diff_tensor.set(param='tm', value=8.88e-8, category='sim', sim_index=4)
457 self.assertEqual(sphere_pipe.diff_tensor.tm_sim[4], 8.88e-8)
458 self.assertEqual(sphere_pipe.diff_tensor.Diso_sim[4], 1/(6*8.88e-8))
459 self.assertEqual(sphere2_pipe.diff_tensor.tm_sim[4], 9.02e-8)
460 self.assertEqual(sphere2_pipe.diff_tensor.Diso_sim[4], 1/(6*9.02e-8))
461
462
473
474
485
486
527
528
569
570
611
612
614 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0."""
615
616
617 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid()
618
619
620 self.interpreter.pipe.create('ellipsoid2', 'mf')
621
622
623 self.interpreter.diffusion_tensor.init((1/(6.0*Diso), Da, Dr, alpha, beta, gamma), param_types=0, angle_units='rad')
624
625
626 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
627
628
630 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0."""
631
632
633 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid()
634
635
636 self.interpreter.pipe.create('ellipsoid2', 'mf')
637
638
639 self.interpreter.diffusion_tensor.init((Diso, Da, Dr, alpha, beta, gamma), param_types=1, angle_units='rad')
640
641
642 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
643
644
646 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0."""
647
648
649 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid()
650
651
652 self.interpreter.pipe.create('ellipsoid2', 'mf')
653
654
655 self.interpreter.diffusion_tensor.init((Dx, Dy, Dz, alpha, beta, gamma), param_types=2, angle_units='rad')
656
657
658 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
659
660
662 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0."""
663
664
665 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid()
666
667
668 self.interpreter.pipe.create('ellipsoid2', 'mf')
669
670
671 self.interpreter.diffusion_tensor.init((D[0, 0], D[1, 1], D[2, 2], D[0, 1], D[0, 2], D[1, 2]), param_types=3)
672
673
674 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
675
676
678 """Test the initialisation of the spheroid diffusion tensor using parameter set 4."""
679
680
681 Dpar, Dper, theta, phi = 1e7, 4e7, pi/4.0, 0.0
682 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
683
684
685 self.interpreter.pipe.create('spheroid2', 'mf')
686
687
688 self.interpreter.diffusion_tensor.init((D[0, 0], D[1, 1], D[2, 2], D[0, 1], D[0, 2], D[1, 2]), param_types=3)
689
690
691 self.check_spheroid_as_ellipsoid(tm, Dx, Dy, Dz, Diso, Da, D, D_prime, R)
692
693
695 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 0."""
696
697
698 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0
699 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
700
701
702 self.interpreter.pipe.create('spheroid2', 'mf')
703
704
705 self.interpreter.diffusion_tensor.init((tm, Da, theta, phi), param_types=0, angle_units='rad')
706
707
708 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
709
710
712 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 1."""
713
714
715 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0
716 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
717
718
719 self.interpreter.pipe.create('spheroid2', 'mf')
720
721
722 self.interpreter.diffusion_tensor.init((Diso, Da, theta, phi), param_types=1, angle_units='rad')
723
724
725 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
726
727
729 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 1, and angles in deg."""
730
731
732 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0
733 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
734
735
736 self.interpreter.pipe.create('spheroid2', 'mf')
737
738
739 self.interpreter.diffusion_tensor.init((Diso, Da, theta/2.0/pi*360.0, phi/2.0/pi*360.0), param_types=1, angle_units='deg')
740
741
742 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
743
744
746 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 2."""
747
748
749 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0
750 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
751
752
753 self.interpreter.pipe.create('spheroid2', 'mf')
754
755
756 self.interpreter.diffusion_tensor.init((tm, Dratio, theta, phi), param_types=2, angle_units='rad')
757
758
759 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
760
761
763 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 3."""
764
765
766 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0
767 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
768
769
770 self.interpreter.pipe.create('spheroid2', 'mf')
771
772
773 self.interpreter.diffusion_tensor.init((Dpar, Dper, theta, phi), param_types=3, angle_units='rad')
774
775
776 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
777
778
780 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 4."""
781
782
783 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0
784 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
785
786
787 self.interpreter.pipe.create('spheroid2', 'mf')
788
789
790 self.interpreter.diffusion_tensor.init((Diso, Dratio, theta, phi), param_types=4, angle_units='rad')
791
792
793 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
794
795
797 """Test the initialisation of the spheroid diffusion tensor using parameter set 4."""
798
799
800 Dpar, Dper, theta, phi = 4e7, 2e7, 0.5, 1.0
801 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
802
803
804 self.interpreter.pipe.create('spheroid2', 'mf')
805
806
807 self.interpreter.diffusion_tensor.init((D[0, 0], D[1, 1], D[2, 2], D[0, 1], D[0, 2], D[1, 2]), param_types=3)
808
809
810 self.check_spheroid_as_ellipsoid(tm, Dx, Dy, Dz, Diso, Da, D, D_prime, R)
811
812
814 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 0."""
815
816
817 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0
818 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
819
820
821 self.interpreter.pipe.create('spheroid2', 'mf')
822
823
824 self.interpreter.diffusion_tensor.init((tm, Da, theta, phi), spheroid_type='prolate', param_types=0, angle_units='rad')
825
826
827 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
828
829
831 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 0."""
832
833
834 Dpar, Dper, theta, phi = 8e7, 8e7, 0.5, 1.0
835 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
836
837
838 self.interpreter.pipe.create('spheroid2', 'mf')
839
840
841 self.interpreter.diffusion_tensor.init((tm, Da, theta, phi), spheroid_type='prolate', param_types=0, angle_units='rad')
842
843
844 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
845
846
848 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 1."""
849
850
851 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0
852 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
853
854
855 self.interpreter.pipe.create('spheroid2', 'mf')
856
857
858 self.interpreter.diffusion_tensor.init((Diso, Da, theta, phi), param_types=1, angle_units='rad')
859
860
861 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
862
863
865 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 1, and angles in deg."""
866
867
868 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0
869 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
870
871
872 self.interpreter.pipe.create('spheroid2', 'mf')
873
874
875 self.interpreter.diffusion_tensor.init((Diso, Da, theta/2.0/pi*360.0, phi/2.0/pi*360.0), param_types=1, angle_units='deg')
876
877
878 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
879
880
882 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 2."""
883
884
885 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0
886 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
887
888
889 self.interpreter.pipe.create('spheroid2', 'mf')
890
891
892 self.interpreter.diffusion_tensor.init((tm, Dratio, theta, phi), param_types=2, angle_units='rad')
893
894
895 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
896
897
899 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 3."""
900
901
902 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0
903 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
904
905
906 self.interpreter.pipe.create('spheroid2', 'mf')
907
908
909 self.interpreter.diffusion_tensor.init((Dpar, Dper, theta, phi), param_types=3, angle_units='rad')
910
911
912 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
913
914
916 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 4."""
917
918
919 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0
920 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi)
921
922
923 self.interpreter.pipe.create('spheroid2', 'mf')
924
925
926 self.interpreter.diffusion_tensor.init((Diso, Dratio, theta, phi), param_types=4, angle_units='rad')
927
928
929 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
930
931
933 """Check that the ellipsoid diffusion tensor optimisation functions correctly."""
934
935
936 reset()
937
938
939 ds.diff_dir = 'ellipsoid'
940 ds.diff_type = 'ellipsoid'
941
942
943 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py')
944
945
946 print(cdp.diff_tensor)
947
948
949 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid()
950
951
952 self.assertAlmostEqual(cdp.chi2, 0.0)
953 self.assertEqual(cdp.diff_tensor.fixed, False)
954 self.assertEqual(cdp.diff_tensor.type, 'ellipsoid')
955
956
957 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
958
959
961 """Check that the sphere diffusion tensor optimisation functions correctly."""
962
963
964 reset()
965
966
967 ds.diff_dir = 'sphere'
968 ds.diff_type = 'sphere'
969
970
971 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py')
972
973
974 self.assertAlmostEqual(cdp.chi2, 0.0)
975 self.assertEqual(cdp.diff_tensor.fixed, False)
976 self.assertEqual(cdp.diff_tensor.type, 'sphere')
977 self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*2e7) * 1e9)
978 self.assertEqual(cdp.diff_tensor.rotation[0, 0], 1.0)
979 self.assertEqual(cdp.diff_tensor.rotation[1, 1], 1.0)
980 self.assertEqual(cdp.diff_tensor.rotation[2, 2], 1.0)
981 self.assertEqual(cdp.diff_tensor.rotation[0, 1], 0.0)
982 self.assertEqual(cdp.diff_tensor.rotation[0, 2], 0.0)
983 self.assertEqual(cdp.diff_tensor.rotation[1, 2], 0.0)
984 self.assertEqual(cdp.diff_tensor.rotation[1, 0], 0.0)
985 self.assertEqual(cdp.diff_tensor.rotation[2, 0], 0.0)
986 self.assertEqual(cdp.diff_tensor.rotation[2, 1], 0.0)
987
988
990 """Check that the spheroid diffusion tensor optimisation functions correctly."""
991
992
993 reset()
994
995
996 ds.diff_dir = 'spheroid_prolate'
997 ds.diff_type = 'spheroid'
998
999
1000 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py')
1001
1002
1003 self.assertAlmostEqual(cdp.chi2, 0.0)
1004 self.assertEqual(cdp.diff_tensor.fixed, False)
1005 self.assertEqual(cdp.diff_tensor.type, 'spheroid')
1006 self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*7e7/3.0) * 1e9)
1007 self.assertAlmostEqual(cdp.diff_tensor.Da * 1e-7, 1.0)
1008 self.assertAlmostEqual(cdp.diff_tensor.theta, 2.0)
1009 self.assertAlmostEqual(cdp.diff_tensor.phi, pi-0.5)
1010