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.m61b import r1rho_M61b 
 29   
 30   
 32      """Unit tests for the lib.dispersion.m61b relax module.""" 
 33   
 35          """Set up for all unit tests.""" 
 36   
 37           
 38          self.r1rho_prime = 2.5 
 39           
 40          self.pA = 0.95 
 41           
 42          self.dw = 0.5 
 43          self.kex = 1000.0 
 44           
 45          self.r1 = 1.0 
 46           
 47          self.spin_lock_nu1 = array([ 1000., 1500., 2000., 2500., 3000., 3500., 4000., 4500., 5000., 5500., 6000.]) 
 48           
 49          self.theta = array([1.5707963267948966, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966]) 
 50   
 51           
 52          self.sfrq = 599.8908617*1E6 
 53   
 54           
 55          self.num_points = 11 
 56          self.R1rho = zeros(self.num_points, float64) 
  57   
 58   
 60          """Calculate and check the R1rho values.""" 
 61   
 62           
 63          phi_ex_scaled, dw_frq, spin_lock_omega1_squared = self.param_conversion(pA=self.pA, dw=self.dw, sfrq=self.sfrq, spin_lock_nu1=self.spin_lock_nu1) 
 64   
 65          a = ones([self.num_points]) 
 66   
 67           
 68          R1rho = r1rho_M61b(r1rho_prime=self.r1rho_prime*a, pA=self.pA, dw=dw_frq*a, kex=self.kex, spin_lock_fields2=spin_lock_omega1_squared, back_calc=self.R1rho) 
 69   
 70   
 71           
 72          if self.kex > 1.e5: 
 73              for i in range(self.num_points): 
 74                  self.assertAlmostEqual(self.R1rho[i], self.r1rho_prime, 2) 
 75          else: 
 76              for i in range(self.num_points): 
 77                  self.assertAlmostEqual(self.R1rho[i], self.r1rho_prime) 
  78   
 79   
 81          """Convert the parameters. 
 82   
 83          @keyword pA:            The population of state A. 
 84          @type pA:               float 
 85          @keyword dw:            The chemical exchange difference between states A and B in ppm. 
 86          @type dw:               float 
 87          @keyword sfrq:          The spin Larmor frequencies in Hz. 
 88          @type sfrq:             float 
 89          @keyword spin_lock_nu1: The spin-lock field strengths in Hertz. 
 90          @type spin_lock_nu1:    float 
 91          @return:                The parameters {phi_ex_scaled, dw_frq, spin_lock_omega1_squared}. 
 92          @rtype:                 tuple of float 
 93          """ 
 94   
 95           
 96          pB = 1.0 - pA 
 97   
 98           
 99          frqs = sfrq * 2 * pi 
100   
101           
102          dw_frq = dw * frqs / 1.e6 
103   
104           
105          phi_ex = pA * pB * (dw / 1.e6)**2 
106   
107           
108          phi_ex_scaled = phi_ex * frqs**2 
109   
110           
111          spin_lock_omega1_squared = (2. * pi * spin_lock_nu1)**2 
112   
113           
114          return phi_ex_scaled, dw_frq, spin_lock_omega1_squared 
 115   
116   
118          """Test the r1rho_m61b() function for no exchange when dw = 0.0.""" 
119   
120           
121          self.dw = 0.0 
122   
123           
124          self.calc_r1rho() 
 125   
126   
128          """Test the r1rho_m61b() function for no exchange when pA = 1.0.""" 
129   
130           
131          self.pA = 1.0 
132   
133           
134          self.calc_r1rho() 
 135   
136   
138          """Test the r1rho_m61b() function for no exchange when kex = 0.0.""" 
139   
140           
141          self.kex = 0.0 
142   
143           
144          self.calc_r1rho() 
 145   
146   
148          """Test the r1rho_m61b() function for no exchange when dw = 0.0 and pA = 1.0.""" 
149   
150           
151          self.pA = 1.0 
152          self.dw = 0.0 
153   
154           
155          self.calc_r1rho() 
 156   
157   
159          """Test the r1rho_m61b() function for no exchange when dw = 0.0 and kex = 0.0.""" 
160   
161           
162          self.dw = 0.0 
163          self.kex = 0.0 
164   
165           
166          self.calc_r1rho() 
 167   
168   
170          """Test the r1rho_m61b() function for no exchange when pA = 1.0 and kex = 0.0.""" 
171   
172           
173          self.pA = 1.0 
174          self.kex = 0.0 
175   
176           
177          self.calc_r1rho() 
 178   
179   
181          """Test the r1rho_m61b() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0.""" 
182   
183           
184          self.dw = 0.0 
185          self.kex = 0.0 
186   
187           
188          self.calc_r1rho() 
 189   
190   
192          """Test the r1rho_m61b() function for no exchange when kex = 1e20.""" 
193   
194           
195          self.kex = 1e20 
196   
197           
198          self.calc_r1rho() 
  199