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.tsmfk01 import r2eff_TSMFK01 
 28   
 29   
 31      """Unit tests for the lib.dispersion.tsmfk01 relax module.""" 
 32   
 34          """Set up for all unit tests.""" 
 35   
 36           
 37          self.r20a = 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.tau_cpmg = 0.25 / self.cpmg_frqs 
 48          self.R2eff = zeros(self.num_points, float64) 
 49   
 50           
 51          self.sfrq = 200. * 1E6 
  52   
 53   
 55          """Calculate and check the R2eff values.""" 
 56   
 57           
 58          k_AB, k_BA, pB, dw_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq) 
 59   
 60          a = ones([self.num_points]) 
 61   
 62           
 63          r2eff_TSMFK01(r20a=self.r20a*a, dw=dw_frq*a, dw_orig=dw_frq, k_AB=k_AB, tcp=self.cpmg_frqs, back_calc=self.R2eff) 
 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_tsmfk01() 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_tsmfk01() 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_tsmfk01() 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_tsmfk01() 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_tsmfk01() 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_tsmfk01() 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_tsmfk01() 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