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