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