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, cos, float64, pi, sin, zeros 
 25  from unittest import TestCase 
 26   
 27   
 28  from lib.dispersion.dpl94 import r1rho_DPL94 
 29   
 30   
 32      """Unit tests for the lib.dispersion.dpl94 relax module.""" 
 33   
 35          """Set up for all unit tests.""" 
 36   
 37           
 38   
 39   
 40           
 41          self.r1rho_prime = 2.5 
 42           
 43          self.pA = 0.95 
 44           
 45          self.dw = 0.5 
 46          self.kex = 1000.0 
 47           
 48          self.r1 = 1.0 
 49           
 50          self.spin_lock_nu1 = array([ 1000., 1500., 2000., 2500., 3000., 3500., 4000., 4500., 5000., 5500., 6000.]) 
 51           
 52          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]) 
 53   
 54           
 55          self.sfrq = 599.8908617*1E6 
 56   
 57           
 58          self.num_points = 11 
 59          self.R1rho = zeros(self.num_points, float64) 
  60   
 61   
 63          """Calculate and check the R1rho values.""" 
 64   
 65           
 66          phi_ex_scaled, spin_lock_omega1_squared = self.param_conversion(pA=self.pA, dw=self.dw, sfrq=self.sfrq, spin_lock_nu1=self.spin_lock_nu1) 
 67   
 68           
 69          r1rho_DPL94(r1rho_prime=self.r1rho_prime, phi_ex=phi_ex_scaled, kex=self.kex, theta=self.theta, R1=self.r1, spin_lock_fields2=spin_lock_omega1_squared, back_calc=self.R1rho) 
 70   
 71           
 72          r1rho_no_rex = self.r1 * cos(self.theta)**2 + self.r1rho_prime * sin(self.theta)**2 
 73   
 74           
 75          if self.kex > 1.e5: 
 76              for i in range(self.num_points): 
 77                  self.assertAlmostEqual(self.R1rho[i], r1rho_no_rex[i], 2) 
 78          else: 
 79              for i in range(self.num_points): 
 80                  self.assertAlmostEqual(self.R1rho[i], r1rho_no_rex[i]) 
  81   
 82   
 84          """Convert the parameters. 
 85   
 86          @keyword pA:            The population of state A. 
 87          @type pA:               float 
 88          @keyword dw:            The chemical exchange difference between states A and B in ppm. 
 89          @type dw:               float 
 90          @keyword sfrq:          The spin Larmor frequencies in Hz. 
 91          @type sfrq:             float 
 92          @keyword spin_lock_nu1: The spin-lock field strengths in Hertz. 
 93          @type spin_lock_nu1:    float 
 94          @return:                The parameters {phi_ex_scaled, k_BA}. 
 95          @rtype:                 tuple of float 
 96          """ 
 97   
 98           
 99          pB = 1.0 - pA 
100   
101           
102          frqs = sfrq * 2 * pi 
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, spin_lock_omega1_squared 
 115   
116   
118          """Test the r1rho_dpl94() 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_dpl94() 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_dpl94() 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_dpl94() 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_dpl94() 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_dpl94() 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_dpl94() 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_dpl94() function for no exchange when kex = 1e20.""" 
193   
194           
195          self.kex = 1e20 
196   
197           
198          self.calc_r1rho() 
  199