1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from numpy import array, float64, ones, pi, rollaxis, zeros
24 from unittest import TestCase
25
26
27 from lib.dispersion.ns_cpmg_2site_3d import r2eff_ns_cpmg_2site_3D
28 from lib.dispersion.ns_matrices import r180x_3d
29
30
32 """Unit tests for the lib.dispersion.ns_cpmg_2site_3D relax module."""
33
35 """Set up for all unit tests."""
36
37
38 self.r20a = 2.0
39 self.r20b = 3.0
40 self.pA = 0.95
41 self.dw = 2.0
42 self.kex = 1000.0
43
44
45
46 self.r180x = r180x_3d()
47
48 self.num_points = 7
49 self.ncyc = array([2, 4, 8, 10, 20, 40, 500])
50 relax_times = 0.04
51 cpmg_frqs = self.ncyc / relax_times
52 self.inv_relax_times = 1.0 / relax_times
53 self.tau_cpmg = 0.25 / cpmg_frqs
54
55 self.array_shape = [1, 1, 1, 1, self.num_points]
56 self.R2eff = zeros(self.num_points, float64) * ones(self.array_shape)
57
58
59 self.sfrq = 200. * 1E6
60
61
62 M0_0 = zeros( [1, 1, 1, 1, 1, 7, 1], float64)
63 M0_0[:, :, :, :, :, 0, 0] = 0.5
64 self.M0 = M0_0
65
66 self.M0_T = rollaxis(self.M0, 6, 5)
67
68
70 """Calculate and check the R2eff values."""
71
72
73 k_AB, k_BA, pB, dw_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq)
74
75 a = ones(self.array_shape)
76 b = ones([1, 1, 1, 1])
77
78
79 r2eff_ns_cpmg_2site_3D(r180x=self.r180x, M0=self.M0, M0_T=self.M0_T, r20a=self.r20a*a, r20b=self.r20b*a, pA=self.pA, dw=dw_frq*a, dw_orig=dw_frq*a, kex=self.kex, inv_tcpmg=self.inv_relax_times*a, tcp=self.tau_cpmg*a, back_calc=self.R2eff, num_points=self.num_points*b, power=self.ncyc*a)
80
81 if self.kex >= 1.e5:
82 for i in range(self.num_points):
83 self.assertAlmostEqual(self.R2eff[0][0][0][0][i], self.r20a, 5)
84 else:
85 for i in range(self.num_points):
86 self.assertAlmostEqual(self.R2eff[0][0][0][0][i], self.r20a)
87
88
90 """Convert the parameters.
91
92 @keyword pA: The population of state A.
93 @type pA: float
94 @keyword kex: The rate of exchange.
95 @type kex: float
96 @keyword dw: The chemical exchange difference between states A and B in ppm.
97 @type dw: float
98 @keyword sfrq: The spin Larmor frequencies in Hz.
99 @type sfrq: float
100 @keyword M0: Vector that contains the initial magnetizations corresponding to the A and B state transverse magnetizations.
101 @type M0: numpy float64, rank-1, 7D array
102 @return: The parameters {k_AB, k_BA, pB, dw_frq, M0}.
103 @rtype: tuple of float
104 """
105
106
107 pB = 1.0 - pA
108
109
110 k_BA = pA * kex
111 k_AB = pB * kex
112
113
114 frqs = sfrq * 2 * pi
115
116
117 dw_frq = dw * frqs / 1.e6
118
119
120 return k_AB, k_BA, pB, dw_frq
121
122
124 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0."""
125
126
127 self.dw = 0.0
128
129
130 self.calc_r2eff()
131
132
134 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when pA = 1.0."""
135
136
137 self.pA = 1.0
138
139
140 self.calc_r2eff()
141
142
144 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when kex = 0.0."""
145
146
147 self.kex = 0.0
148
149
150 self.calc_r2eff()
151
152
154 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0 and pA = 1.0."""
155
156
157 self.pA = 1.0
158 self.dw = 0.0
159
160
161 self.calc_r2eff()
162
163
165 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0 and kex = 0.0."""
166
167
168 self.dw = 0.0
169 self.kex = 0.0
170
171
172 self.calc_r2eff()
173
174
176 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when pA = 1.0 and kex = 0.0."""
177
178
179 self.pA = 1.0
180 self.kex = 0.0
181
182
183 self.calc_r2eff()
184
185
187 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0."""
188
189
190 self.dw = 0.0
191 self.kex = 0.0
192
193
194 self.calc_r2eff()
195