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

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

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2014 Edward d'Auvergne                                        # 
  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 array, float64, ones, pi, rollaxis, zeros 
 24  from unittest import TestCase 
 25   
 26  # relax module imports. 
 27  from lib.dispersion.ns_cpmg_2site_3d import r2eff_ns_cpmg_2site_3D 
 28  from lib.dispersion.ns_matrices import r180x_3d 
 29   
 30   
31 -class Test_ns_cpmg_2site_3d(TestCase):
32 """Unit tests for the lib.dispersion.ns_cpmg_2site_3D relax module.""" 33
34 - def setUp(self):
35 """Set up for all unit tests.""" 36 37 # Default parameter values. 38 self.r20a = 2.0 39 self.r20b = 3.0 40 self.pA = 0.95 41 self.dw = 2.0 42 self.kex = 1000.0 43 44 # Required data structures. 45 # The 3D rotation matrix for an imperfect X-axis pi-pulse. 46 self.r180x = r180x_3d() 47 48 self.num_points = 7 49 self.ncyc = array([2, 4, 8, 10, 20, 40, 500]) 50 relax_times = 0.04 51 cpmg_frqs = self.ncyc / relax_times 52 self.inv_relax_times = 1.0 / relax_times 53 self.tau_cpmg = 0.25 / cpmg_frqs 54 55 self.array_shape = [1, 1, 1, 1, self.num_points] 56 self.R2eff = zeros(self.num_points, float64) * ones(self.array_shape) 57 58 # The spin Larmor frequencies. 59 self.sfrq = 200. * 1E6 60 61 # This is a vector that contains the initial magnetizations corresponding to the A and B state transverse magnetizations. 62 M0_0 = zeros( [1, 1, 1, 1, 1, 7, 1], float64) 63 M0_0[:, :, :, :, :, 0, 0] = 0.5 64 self.M0 = M0_0 65 # Transpose M0, to prepare for dot operation. Roll the last axis one back, corresponds to a transpose for the outer two axis. 66 self.M0_T = rollaxis(self.M0, 6, 5)
67 68
69 - def calc_r2eff(self):
70 """Calculate and check the R2eff values.""" 71 72 # Parameter conversions. 73 k_AB, k_BA, pB, dw_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq) 74 75 a = ones(self.array_shape) 76 b = ones([1, 1, 1, 1]) 77 78 # Calculate the R2eff values. 79 r2eff_ns_cpmg_2site_3D(r180x=self.r180x, M0=self.M0, M0_T=self.M0_T, r20a=self.r20a*a, r20b=self.r20b*a, pA=self.pA, dw=dw_frq*a, dw_orig=dw_frq*a, kex=self.kex, inv_tcpmg=self.inv_relax_times*a, tcp=self.tau_cpmg*a, back_calc=self.R2eff, num_points=self.num_points*b, power=self.ncyc*a) 80 81 if self.kex >= 1.e5: 82 for i in range(self.num_points): 83 self.assertAlmostEqual(self.R2eff[0][0][0][0][i], self.r20a, 5) 84 else: 85 for i in range(self.num_points): 86 self.assertAlmostEqual(self.R2eff[0][0][0][0][i], self.r20a)
87 88
89 - def param_conversion(self, pA=None, kex=None, dw=None, sfrq=None):
90 """Convert the parameters. 91 92 @keyword pA: The population of state A. 93 @type pA: float 94 @keyword kex: The rate of exchange. 95 @type kex: float 96 @keyword dw: The chemical exchange difference between states A and B in ppm. 97 @type dw: float 98 @keyword sfrq: The spin Larmor frequencies in Hz. 99 @type sfrq: float 100 @keyword M0: Vector that contains the initial magnetizations corresponding to the A and B state transverse magnetizations. 101 @type M0: numpy float64, rank-1, 7D array 102 @return: The parameters {k_AB, k_BA, pB, dw_frq, M0}. 103 @rtype: tuple of float 104 """ 105 106 # Calculate pB. 107 pB = 1.0 - pA 108 109 # Exchange rates. 110 k_BA = pA * kex 111 k_AB = pB * kex 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 # Return all values. 120 return k_AB, k_BA, pB, dw_frq
121 122
124 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0.""" 125 126 # Parameter reset. 127 self.dw = 0.0 128 129 # Calculate and check the R2eff values. 130 self.calc_r2eff()
131 132
134 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when pA = 1.0.""" 135 136 # Parameter reset. 137 self.pA = 1.0 138 139 # Calculate and check the R2eff values. 140 self.calc_r2eff()
141 142
144 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when kex = 0.0.""" 145 146 # Parameter reset. 147 self.kex = 0.0 148 149 # Calculate and check the R2eff values. 150 self.calc_r2eff()
151 152
154 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0 and pA = 1.0.""" 155 156 # Parameter reset. 157 self.pA = 1.0 158 self.dw = 0.0 159 160 # Calculate and check the R2eff values. 161 self.calc_r2eff()
162 163
165 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0 and kex = 0.0.""" 166 167 # Parameter reset. 168 self.dw = 0.0 169 self.kex = 0.0 170 171 # Calculate and check the R2eff values. 172 self.calc_r2eff()
173 174
176 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when pA = 1.0 and kex = 0.0.""" 177 178 # Parameter reset. 179 self.pA = 1.0 180 self.kex = 0.0 181 182 # Calculate and check the R2eff values. 183 self.calc_r2eff()
184 185
187 """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0.""" 188 189 # Parameter reset. 190 self.dw = 0.0 191 self.kex = 0.0 192 193 # Calculate and check the R2eff values. 194 self.calc_r2eff()
195