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