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, int16, pi, 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
49 self.M0 = zeros(7, float64)
50 self.M0[0] = 0.5
51
52 self.num_points = 7
53 self.ncyc = array([2, 4, 8, 10, 20, 40, 500])
54 relax_times = 0.04
55 cpmg_frqs = self.ncyc / relax_times
56 self.inv_relax_times = 1.0 / relax_times
57 self.tau_cpmg = 0.25 / cpmg_frqs
58 self.R2eff = zeros(self.num_points, float64)
59
60
61 self.sfrq = 200. * 1E6
62
63
65 """Calculate and check the R2eff values."""
66
67
68 k_AB, k_BA, pB, dw_frq, M0 = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq, M0=self.M0)
69
70
71 r2eff_ns_cpmg_2site_3D(r180x=self.r180x, M0=M0, r20a=self.r20a, r20b=self.r20b, pA=self.pA, pB=pB, dw=dw_frq, k_AB=k_AB, k_BA=k_BA, inv_tcpmg=self.inv_relax_times, tcp=self.tau_cpmg, back_calc=self.R2eff, num_points=self.num_points, power=self.ncyc)
72
73 if self.kex >= 1.e5:
74 for i in range(self.num_points):
75 self.assertAlmostEqual(self.R2eff[i], self.r20a, 5)
76 else:
77 for i in range(self.num_points):
78 self.assertAlmostEqual(self.R2eff[i], self.r20a)
79
80
82 """Convert the parameters.
83
84 @keyword pA: The population of state A.
85 @type pA: float
86 @keyword kex: The rate of exchange.
87 @type kex: float
88 @keyword dw: The chemical exchange difference between states A and B in ppm.
89 @type dw: float
90 @keyword sfrq: The spin Larmor frequencies in Hz.
91 @type sfrq: float
92 @keyword M0: Vector that contains the initial magnetizations corresponding to the A and B state transverse magnetizations.
93 @type M0: numpy float64, rank-1, 7D array
94 @return: The parameters {k_AB, k_BA, pB, dw_frq, M0}.
95 @rtype: tuple of float
96 """
97
98
99 pB = 1.0 - pA
100
101
102 M0[1] = pA
103 M0[4] = pB
104
105
106 k_BA = pA * kex
107 k_AB = pB * kex
108
109
110 frqs = sfrq * 2 * pi
111
112
113 dw_frq = dw * frqs / 1.e6
114
115
116 return k_AB, k_BA, pB, dw_frq, M0
117
118
120 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0."""
121
122
123 self.dw = 0.0
124
125
126 self.calc_r2eff()
127
128
130 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when pA = 1.0."""
131
132
133 self.pA = 1.0
134
135
136 self.calc_r2eff()
137
138
140 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when kex = 0.0."""
141
142
143 self.kex = 0.0
144
145
146 self.calc_r2eff()
147
148
150 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0 and pA = 1.0."""
151
152
153 self.pA = 1.0
154 self.dw = 0.0
155
156
157 self.calc_r2eff()
158
159
161 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0 and kex = 0.0."""
162
163
164 self.dw = 0.0
165 self.kex = 0.0
166
167
168 self.calc_r2eff()
169
170
172 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when pA = 1.0 and kex = 0.0."""
173
174
175 self.pA = 1.0
176 self.kex = 0.0
177
178
179 self.calc_r2eff()
180
181
183 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0."""
184
185
186 self.dw = 0.0
187 self.kex = 0.0
188
189
190 self.calc_r2eff()
191