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