Package test_suite :: Package unit_tests :: Package _lib :: Package _dispersion :: Module test_tap03
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._lib._dispersion.test_tap03

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2014 Troels E. Linnet                                         # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from numpy import arctan2, array, cos, float64, pi, sin, ones, zeros 
 24  from unittest import TestCase 
 25   
 26  # relax module imports. 
 27  from lib.dispersion.tap03 import r1rho_TAP03 
 28   
 29   
30 -class Test_tap03(TestCase):
31 """Unit tests for the lib.dispersion.tap03 relax module.""" 32
33 - def setUp(self):
34 """Set up for all unit tests.""" 35 36 # Default parameter values. 37 38 39 # The R1rho_prime parameter value (R1rho with no exchange). 40 self.r1rho_prime = 5.0 41 # The chemical shifts in rad/s. This is only used for off-resonance R1rho models. 42 self.omega = -35670.44192 43 # The structure of spin-lock or hard pulse offsets in rad/s. 44 self.offset = -35040.3526693 45 46 # Population of ground state. 47 self.pA = 0.95 48 # The chemical exchange difference between states A and B in ppm. 49 self.dw = 0.5 50 self.kex = 1000.0 51 # The R1 relaxation rates. 52 self.r1 = 1.0 53 # The spin-lock field strengths in Hertz. 54 self.spin_lock_nu1 = array([ 1000., 1500., 2000., 2500., 3000., 3500., 4000., 4500., 5000., 5500., 6000.]) 55 56 # The spin Larmor frequencies. 57 self.sfrq = 599.8908617*1E6 58 59 # Required data structures. 60 self.num_points = 11 61 self.R1rho = zeros(self.num_points, float64)
62 63
64 - def calc_r1rho(self):
65 """Calculate and check the R1rho values.""" 66 67 # Parameter conversions. 68 pB, dw_frq, spin_lock_omega1, spin_lock_omega1_squared = self.param_conversion(pA=self.pA, dw=self.dw, sfrq=self.sfrq, spin_lock_nu1=self.spin_lock_nu1) 69 70 # Convert to numpy array. 71 a = ones([self.num_points]) 72 73 # Calculate the R1rho values. 74 r1rho_TAP03(r1rho_prime=self.r1rho_prime, omega=self.omega, offset=self.offset, pA=self.pA, dw=dw_frq*a, kex=self.kex, R1=self.r1, spin_lock_fields=spin_lock_omega1, spin_lock_fields2=spin_lock_omega1_squared, back_calc=self.R1rho) 75 76 # Compare to function value. 77 # Larmor frequency [s^-1]. 78 Wa = self.omega 79 80 # Larmor frequency [s^-1]. 81 Wb = self.omega + dw_frq 82 83 # Pop-averaged Larmor frequency [s^-1]. 84 W = self.pA * Wa + pB * Wb 85 86 # Offset of spin-lock from pop-average. 87 d = W - self.offset 88 89 # The rotating frame flip angle. 90 theta = arctan2(spin_lock_omega1, d) 91 r1rho_no_rex = self.r1 * cos(theta)**2 + self.r1rho_prime * sin(theta)**2 92 93 # Check all R1rho values. 94 for i in range(self.num_points): 95 self.assertAlmostEqual(self.R1rho[i], r1rho_no_rex[i])
96 97
98 - def param_conversion(self, pA=None, dw=None, sfrq=None, spin_lock_nu1=None):
99 """Convert the parameters. 100 101 @keyword pA: The population of state A. 102 @type pA: float 103 @keyword dw: The chemical exchange difference between states A and B in ppm. 104 @type dw: float 105 @keyword sfrq: The spin Larmor frequencies in Hz. 106 @type sfrq: float 107 @keyword spin_lock_nu1: The spin-lock field strengths in Hertz. 108 @type spin_lock_nu1: float 109 @return: The parameters {pB, dw_frq, spin_lock_omega1, spin_lock_omega1_squared}. 110 @rtype: tuple of float 111 """ 112 113 # Calculate pB. 114 pB = 1.0 - pA 115 116 # Calculate spin Larmor frequencies in 2pi. 117 frqs = sfrq * 2 * pi 118 119 # Convert dw from ppm to rad/s. 120 dw_frq = dw * frqs / 1.e6 121 122 # The R1rho spin-lock field strengths (in rad.s-1). 123 spin_lock_omega1 = (2. * pi * spin_lock_nu1) 124 125 # The R1rho spin-lock field strengths squared (in rad^2.s^-2). 126 spin_lock_omega1_squared = spin_lock_omega1**2 127 128 # Return all values. 129 return pB, dw_frq, spin_lock_omega1, spin_lock_omega1_squared
130 131
132 - def test_tap03_no_rex1(self):
133 """Test the r1rho_tap03() function for no exchange when dw = 0.0.""" 134 135 # Parameter reset. 136 self.dw = 0.0 137 138 # Calculate and check the R1rho values. 139 self.calc_r1rho()
140 141
142 - def test_tap03_no_rex2(self):
143 """Test the r1rho_tap03() function for no exchange when pA = 1.0.""" 144 145 # Parameter reset. 146 self.pA = 1.0 147 148 # Calculate and check the R1rho values. 149 self.calc_r1rho()
150 151
152 - def test_tap03_no_rex3(self):
153 """Test the r1rho_tap03() function for no exchange when kex = 0.0.""" 154 155 # Parameter reset. 156 self.kex = 0.0 157 158 # Calculate and check the R1rho values. 159 self.calc_r1rho()
160 161
162 - def test_tap03_no_rex4(self):
163 """Test the r1rho_tap03() function for no exchange when dw = 0.0 and pA = 1.0.""" 164 165 # Parameter reset. 166 self.pA = 1.0 167 self.dw = 0.0 168 169 # Calculate and check the R1rho values. 170 self.calc_r1rho()
171 172
173 - def test_tap03_no_rex5(self):
174 """Test the r1rho_tap03() function for no exchange when dw = 0.0 and kex = 0.0.""" 175 176 # Parameter reset. 177 self.dw = 0.0 178 self.kex = 0.0 179 180 # Calculate and check the R1rho values. 181 self.calc_r1rho()
182 183
184 - def test_tap03_no_rex6(self):
185 """Test the r1rho_tap03() function for no exchange when pA = 1.0 and kex = 0.0.""" 186 187 # Parameter reset. 188 self.pA = 1.0 189 self.kex = 0.0 190 191 # Calculate and check the R1rho values. 192 self.calc_r1rho()
193 194
195 - def test_tap03_no_rex7(self):
196 """Test the r1rho_tap03() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0.""" 197 198 # Parameter reset. 199 self.dw = 0.0 200 self.kex = 0.0 201 202 # Calculate and check the R1rho values. 203 self.calc_r1rho()
204 205
206 - def test_tap03_no_rex8(self):
207 """Test the r1rho_tap03() function for no exchange when kex = 1e20.""" 208 209 # Parameter reset. 210 self.kex = 1e20 211 212 # Calculate and check the R2eff values. 213 self.calc_r1rho()
214