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, zeros
25 from unittest import TestCase
26
27
28 from lib.dispersion.b14 import r2eff_B14
29
30
32 """Unit tests for the lib.dispersion.b14 relax module."""
33
35 """Set up for all unit tests."""
36
37
38 self.r20a = 2.0
39 self.r20b = 4.0
40 self.pA = 0.95
41 self.dw = 2.0
42 self.kex = 1000.0
43
44
45 self.num_points = 7
46 self.ncyc = array([2, 4, 8, 10, 20, 40, 500])
47 relax_times = 0.04
48 cpmg_frqs = self.ncyc / relax_times
49 self.inv_relax_times = 1.0 / relax_times
50 self.tau_cpmg = 0.25 / cpmg_frqs
51 self.R2eff = zeros(self.num_points, float64)
52
53
54 self.sfrq = 200. * 1E6
55
56
58 """Calculate and check the R2eff values."""
59
60
61 k_AB, k_BA, pB, dw_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq)
62
63
64 a = ones([self.num_points])
65
66
67 r2eff_B14(r20a=self.r20a*a, r20b=self.r20b*a, pA=self.pA, dw=dw_frq*a, dw_orig=dw_frq*a, kex=self.kex, ncyc=self.ncyc, inv_tcpmg=self.inv_relax_times, tcp=self.tau_cpmg, back_calc=self.R2eff)
68
69
70 for i in range(self.num_points):
71 self.assertAlmostEqual(self.R2eff[i], self.r20a)
72
73
75 """Convert the parameters.
76
77 @keyword pA: The population of state A.
78 @type pA: float
79 @keyword kex: The rate of exchange.
80 @type kex: float
81 @keyword dw: The chemical exchange difference between states A and B in ppm.
82 @type dw: float
83 @keyword sfrq: The spin Larmor frequencies in Hz.
84 @type sfrq: float
85 @return: The parameters {k_AB, k_BA, pB, dw_frq}.
86 @rtype: tuple of float
87 """
88
89
90 pB = 1.0 - pA
91
92
93 k_BA = pA * kex
94 k_AB = pB * kex
95
96
97 frqs = sfrq * 2 * pi
98
99
100 dw_frq = dw * frqs / 1.e6
101
102
103 return k_AB, k_BA, pB, dw_frq
104
105
107 """Test the r2eff_b14() function for no exchange when dw = 0.0."""
108
109
110 self.dw = 0.0
111
112
113 self.calc_r2eff()
114
115
117 """Test the r2eff_b14() function for no exchange when pA = 1.0."""
118
119
120 self.pA = 1.0
121
122
123 self.calc_r2eff()
124
125
127 """Test the r2eff_b14() function for no exchange when kex = 0.0."""
128
129
130 self.kex = 0.0
131
132
133 self.calc_r2eff()
134
135
137 """Test the r2eff_b14() function for no exchange when dw = 0.0 and pA = 1.0."""
138
139
140 self.pA = 1.0
141 self.dw = 0.0
142
143
144 self.calc_r2eff()
145
146
148 """Test the r2eff_b14() function for no exchange when dw = 0.0 and kex = 0.0."""
149
150
151 self.dw = 0.0
152 self.kex = 0.0
153
154
155 self.calc_r2eff()
156
157
159 """Test the r2eff_b14() function for no exchange when pA = 1.0 and kex = 0.0."""
160
161
162 self.pA = 1.0
163 self.kex = 0.0
164
165
166 self.calc_r2eff()
167
168
170 """Test the r2eff_b14() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0."""
171
172
173 self.dw = 0.0
174 self.kex = 0.0
175
176
177 self.calc_r2eff()
178
179
181 """Test the r2eff_b14() function for no exchange when kex = 1e8."""
182
183
184 self.kex = 1e8
185
186
187 self.calc_r2eff()
188