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

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

  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, ones, pi, sin, zeros 
 25  from unittest import TestCase 
 26   
 27  # relax module imports. 
 28  from lib.dispersion.mp05 import r1rho_MP05 
 29   
 30   
31 -class Test_mp05(TestCase):
32 """Unit tests for the lib.dispersion.mp05 relax module.""" 33
34 - def setUp(self):
35 """Set up for all unit tests.""" 36 37 # The R1rho_prime parameter value (R1rho with no exchange). 38 self.r1rho_prime = 5.0 39 # The chemical shifts in rad/s. This is only used for off-resonance R1rho models. 40 self.omega = -35670.44192 41 # The structure of spin-lock or hard pulse offsets in rad/s. 42 self.offset = -35040.3526693 43 44 # Population of ground state. 45 self.pA = 0.95 46 # The chemical exchange difference between states A and B in ppm. 47 self.dw = 0.5 48 self.kex = 1000.0 49 # The R1 relaxation rates. 50 self.r1 = 1.0 51 # The spin-lock field strengths in Hertz. 52 self.spin_lock_nu1 = array([ 1000., 1500., 2000., 2500., 3000., 3500., 4000., 4500., 5000., 5500., 6000.]) 53 54 # The spin Larmor frequencies. 55 self.sfrq = 599.8908617*1E6 56 57 # Required data structures. 58 self.num_points = 11 59 self.R1rho = zeros(self.num_points, float64)
60 61
62 - def calc_r1rho(self):
63 """Calculate and check the R1rho values.""" 64 65 # Parameter conversions. 66 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) 67 68 a = ones([self.num_points]) 69 70 # Calculate the R1rho values. 71 R1rho = r1rho_MP05(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) 72 73 # Compare to function value. 74 # Larmor frequency [s^-1]. 75 Wa = self.omega 76 77 # Larmor frequency [s^-1]. 78 Wb = self.omega + dw_frq 79 80 # Pop-averaged Larmor frequency [s^-1]. 81 W = self.pA * Wa + pB * Wb 82 83 # Offset of spin-lock from pop-average. 84 d = W - self.offset 85 86 # The rotating frame flip angle. 87 theta = arctan2(spin_lock_omega1, d) 88 r1rho_no_rex = self.r1 * cos(theta)**2 + self.r1rho_prime * sin(theta)**2 89 90 # Check all R1rho values. 91 for i in range(self.num_points): 92 self.assertAlmostEqual(self.R1rho[i], r1rho_no_rex[i])
93 94
95 - def param_conversion(self, pA=None, dw=None, sfrq=None, spin_lock_nu1=None):
96 """Convert the parameters. 97 98 @keyword pA: The population of state A. 99 @type pA: float 100 @keyword dw: The chemical exchange difference between states A and B in ppm. 101 @type dw: float 102 @keyword sfrq: The spin Larmor frequencies in Hz. 103 @type sfrq: float 104 @keyword spin_lock_nu1: The spin-lock field strengths in Hertz. 105 @type spin_lock_nu1: float 106 @return: The parameters {pB, dw_frq, spin_lock_omega1, spin_lock_omega1_squared}. 107 @rtype: tuple of float 108 """ 109 110 # Calculate pB. 111 pB = 1.0 - pA 112 113 # Calculate spin Larmor frequencies in 2pi. 114 frqs = sfrq * 2 * pi 115 116 # Convert dw from ppm to rad/s. 117 dw_frq = dw * frqs / 1.e6 118 119 # The R1rho spin-lock field strengths (in rad.s-1). 120 spin_lock_omega1 = (2. * pi * spin_lock_nu1) 121 122 # The R1rho spin-lock field strengths squared (in rad^2.s^-2). 123 spin_lock_omega1_squared = spin_lock_omega1**2 124 125 # Return all values. 126 return pB, dw_frq, spin_lock_omega1, spin_lock_omega1_squared
127 128
129 - def test_mp05_no_rex1(self):
130 """Test the r1rho_mp05() function for no exchange when dw = 0.0.""" 131 132 # Parameter reset. 133 self.dw = 0.0 134 135 # Calculate and check the R1rho values. 136 self.calc_r1rho()
137 138
139 - def test_mp05_no_rex2(self):
140 """Test the r1rho_mp05() function for no exchange when pA = 1.0.""" 141 142 # Parameter reset. 143 self.pA = 1.0 144 145 # Calculate and check the R1rho values. 146 self.calc_r1rho()
147 148
149 - def test_mp05_no_rex3(self):
150 """Test the r1rho_mp05() function for no exchange when kex = 0.0.""" 151 152 # Parameter reset. 153 self.kex = 0.0 154 155 # Calculate and check the R1rho values. 156 self.calc_r1rho()
157 158
159 - def test_mp05_no_rex4(self):
160 """Test the r1rho_mp05() function for no exchange when dw = 0.0 and pA = 1.0.""" 161 162 # Parameter reset. 163 self.pA = 1.0 164 self.dw = 0.0 165 166 # Calculate and check the R1rho values. 167 self.calc_r1rho()
168 169
170 - def test_mp05_no_rex5(self):
171 """Test the r1rho_mp05() function for no exchange when dw = 0.0 and kex = 0.0.""" 172 173 # Parameter reset. 174 self.dw = 0.0 175 self.kex = 0.0 176 177 # Calculate and check the R1rho values. 178 self.calc_r1rho()
179 180
181 - def test_mp05_no_rex6(self):
182 """Test the r1rho_mp05() function for no exchange when pA = 1.0 and kex = 0.0.""" 183 184 # Parameter reset. 185 self.pA = 1.0 186 self.kex = 0.0 187 188 # Calculate and check the R1rho values. 189 self.calc_r1rho()
190 191
192 - def test_mp05_no_rex7(self):
193 """Test the r1rho_mp05() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0.""" 194 195 # Parameter reset. 196 self.dw = 0.0 197 self.kex = 0.0 198 199 # Calculate and check the R1rho values. 200 self.calc_r1rho()
201 202
203 - def test_mp05_no_rex8(self):
204 """Test the r1rho_mp05() function for no exchange when kex = 1e20.""" 205 206 # Parameter reset. 207 self.kex = 1e20 208 209 # Calculate and check the R2eff values. 210 self.calc_r1rho()
211