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.mmq_cr72 import r2eff_mmq_cr72 
 28   
 29   
 31      """Unit tests for the lib.dispersion.mmq_cr72 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.dwH = 0.5 
 41          self.kex = 1000.0 
 42   
 43           
 44          self.num_points = 6 
 45          self.ncyc = array([2, 4, 8, 10, 20, 40]) 
 46          relax_times = 0.04 
 47          self.cpmg_frqs = self.ncyc / relax_times 
 48          self.inv_relax_times = 1.0 / relax_times 
 49          self.tau_cpmg = 0.25 / self.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, dwH_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, dwH=self.dwH, sfrq=self.sfrq) 
 61   
 62          a = ones(self.ncyc.shape) 
 63   
 64           
 65          r2eff_mmq_cr72(r20=self.r20*a, pA=self.pA, dw=dw_frq*a, dwH=dwH_frq*a, kex=self.kex, cpmg_frqs=self.cpmg_frqs, inv_tcpmg=self.inv_relax_times, tcp=self.tau_cpmg, back_calc=self.R2eff) 
 66   
 67           
 68          for i in range(self.num_points): 
 69              self.assertAlmostEqual(self.R2eff[i], self.r20) 
  70   
 71   
 73          """Convert the parameters. 
 74   
 75          @keyword pA:    The population of state A. 
 76          @type pA:       float 
 77          @keyword kex:   The rate of exchange. 
 78          @type kex:      float 
 79          @keyword dw:    The chemical exchange difference between states A and B in ppm. 
 80          @type dw:       float 
 81          @keyword dwH:   The proton chemical exchange difference between states A and B in ppm. 
 82          @type dwH:      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          dwH_frq = dwH * frqs / 1.e6 
104   
105           
106          return k_AB, k_BA, pB, dw_frq, dwH_frq 
 107   
108   
110          """Test the r2eff_mmq_cr72() function for no exchange when dw = 0.0 and dwH = 0.0.""" 
111   
112           
113          self.dw = 0.0 
114          self.dwH = 0.0 
115   
116           
117          self.calc_r2eff() 
 118   
119   
121          """Test the r2eff_mmq_cr72() function for no exchange when pA = 1.0.""" 
122   
123           
124          self.pA = 1.0 
125   
126           
127          self.calc_r2eff() 
 128   
129   
131          """Test the r2eff_mmq_cr72() function for no exchange when kex = 0.0.""" 
132   
133           
134          self.kex = 0.0 
135   
136           
137          self.calc_r2eff() 
 138   
139   
141          """Test the r2eff_mmq_cr72() function for no exchange when dw = 0.0, dwH = 0.0 and pA = 1.0.""" 
142   
143           
144          self.pA = 1.0 
145          self.dw = 0.0 
146          self.dwH = 0.0 
147   
148           
149          self.calc_r2eff() 
 150   
151   
153          """Test the r2eff_mmq_cr72() function for no exchange when dw = 0.0, dwH = 0.0 and kex = 0.0.""" 
154   
155           
156          self.dw = 0.0 
157          self.dwH = 0.0 
158          self.kex = 0.0 
159   
160           
161          self.calc_r2eff() 
 162   
163   
165          """Test the r2eff_mmq_cr72() function for no exchange when pA = 1.0 and kex = 0.0.""" 
166   
167           
168          self.pA = 1.0 
169          self.kex = 0.0 
170   
171           
172          self.calc_r2eff() 
 173   
174   
176          """Test the r2eff_mmq_cr72() function for no exchange when dw = 0.0, dwH = 0.0, pA = 1.0, and kex = 0.0.""" 
177   
178           
179          self.dw = 0.0 
180          self.dwH = 0.0 
181          self.pA = 1.0 
182          self.kex = 0.0 
183   
184           
185          self.calc_r2eff() 
 186   
187   
189          """Test the r2eff_mmq_cr72() function for no exchange when kex = 1e8.""" 
190   
191           
192          self.kex = 1e8 
193   
194           
195          self.calc_r2eff() 
  196