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