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