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

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

  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, zeros 
 25  from unittest import TestCase 
 26   
 27  # relax module imports. 
 28  from lib.dispersion.b14 import r2eff_B14 
 29   
 30   
31 -class Test_b14(TestCase):
32 """Unit tests for the lib.dispersion.b14 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 = 4.0 40 self.pA = 0.95 41 self.dw = 2.0 42 self.kex = 1000.0 43 44 # Required data structures. 45 self.num_points = 7 46 self.ncyc = array([2, 4, 8, 10, 20, 40, 500]) 47 relax_times = 0.04 48 cpmg_frqs = self.ncyc / relax_times 49 self.inv_relax_times = 1.0 / relax_times 50 self.tau_cpmg = 0.25 / cpmg_frqs 51 self.R2eff = zeros(self.num_points, float64) 52 53 # The spin Larmor frequencies. 54 self.sfrq = 200. * 1E6
55 56
57 - def calc_r2eff(self):
58 """Calculate and check the R2eff values.""" 59 60 # Parameter conversions. 61 k_AB, k_BA, pB, dw_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq) 62 63 # Convert to array. 64 a = ones([self.num_points]) 65 66 # Calculate the R2eff values. 67 r2eff_B14(r20a=self.r20a*a, r20b=self.r20b*a, pA=self.pA, dw=dw_frq*a, dw_orig=dw_frq*a, kex=self.kex, ncyc=self.ncyc, inv_tcpmg=self.inv_relax_times, tcp=self.tau_cpmg, back_calc=self.R2eff) 68 69 # Check all R2eff values. 70 for i in range(self.num_points): 71 self.assertAlmostEqual(self.R2eff[i], self.r20a)
72 73
74 - def param_conversion(self, pA=None, kex=None, dw=None, sfrq=None):
75 """Convert the parameters. 76 77 @keyword pA: The population of state A. 78 @type pA: float 79 @keyword kex: The rate of exchange. 80 @type kex: float 81 @keyword dw: The chemical exchange difference between states A and B in ppm. 82 @type dw: float 83 @keyword sfrq: The spin Larmor frequencies in Hz. 84 @type sfrq: float 85 @return: The parameters {k_AB, k_BA, pB, dw_frq}. 86 @rtype: tuple of float 87 """ 88 89 # Calculate pB. 90 pB = 1.0 - pA 91 92 # Exchange rates. 93 k_BA = pA * kex 94 k_AB = pB * kex 95 96 # Calculate spin Larmor frequencies in 2pi. 97 frqs = sfrq * 2 * pi 98 99 # Convert dw from ppm to rad/s. 100 dw_frq = dw * frqs / 1.e6 101 102 # Return all values. 103 return k_AB, k_BA, pB, dw_frq
104 105
106 - def test_b14_no_rex1(self):
107 """Test the r2eff_b14() function for no exchange when dw = 0.0.""" 108 109 # Parameter reset. 110 self.dw = 0.0 111 112 # Calculate and check the R2eff values. 113 self.calc_r2eff()
114 115
116 - def test_b14_no_rex2(self):
117 """Test the r2eff_b14() function for no exchange when pA = 1.0.""" 118 119 # Parameter reset. 120 self.pA = 1.0 121 122 # Calculate and check the R2eff values. 123 self.calc_r2eff()
124 125
126 - def test_b14_no_rex3(self):
127 """Test the r2eff_b14() function for no exchange when kex = 0.0.""" 128 129 # Parameter reset. 130 self.kex = 0.0 131 132 # Calculate and check the R2eff values. 133 self.calc_r2eff()
134 135
136 - def test_b14_no_rex4(self):
137 """Test the r2eff_b14() function for no exchange when dw = 0.0 and pA = 1.0.""" 138 139 # Parameter reset. 140 self.pA = 1.0 141 self.dw = 0.0 142 143 # Calculate and check the R2eff values. 144 self.calc_r2eff()
145 146
147 - def test_b14_no_rex5(self):
148 """Test the r2eff_b14() function for no exchange when dw = 0.0 and kex = 0.0.""" 149 150 # Parameter reset. 151 self.dw = 0.0 152 self.kex = 0.0 153 154 # Calculate and check the R2eff values. 155 self.calc_r2eff()
156 157
158 - def test_b14_no_rex6(self):
159 """Test the r2eff_b14() function for no exchange when pA = 1.0 and kex = 0.0.""" 160 161 # Parameter reset. 162 self.pA = 1.0 163 self.kex = 0.0 164 165 # Calculate and check the R2eff values. 166 self.calc_r2eff()
167 168
169 - def test_b14_no_rex7(self):
170 """Test the r2eff_b14() function for no exchange when dw = 0.0, pA = 1.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 R2eff values. 177 self.calc_r2eff()
178 179
180 - def test_b14_no_rex8(self):
181 """Test the r2eff_b14() function for no exchange when kex = 1e8.""" 182 183 # Parameter reset. 184 self.kex = 1e8 185 186 # Calculate and check the R2eff values. 187 self.calc_r2eff()
188