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