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

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

  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, int16, ones, pi, zeros 
 25  from unittest import TestCase 
 26   
 27  # relax module imports. 
 28  from lib.dispersion.ns_cpmg_2site_expanded import r2eff_ns_cpmg_2site_expanded 
 29   
 30   
31 -class Test_ns_cpmg_2site_expanded(TestCase):
32 """Unit tests for the lib.dispersion.ns_cpmg_2site_expanded relax module.""" 33
34 - def setUp(self):
35 """Set up for all unit tests.""" 36 37 # Default parameter values. 38 self.r20 = 2.0 39 self.pA = 0.95 40 self.dw = 0.5 41 self.kex = 100.0 42 43 # Required data structures. 44 self.num_points = 3 45 self.tcp = array([0.1, 0.2, 0.3], float64) 46 self.num_cpmg = array([1, 2, 3], int16) 47 self.R2eff = zeros(self.num_points, float64) 48 49 # The spin Larmor frequencies. 50 self.sfrq = 200. * 1E6
51 52
53 - def calc_r2eff(self):
54 """Calculate and check the R2eff values.""" 55 56 # Parameter conversions. 57 k_AB, k_BA, dw_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq) 58 59 a = ones([self.num_points]) 60 61 # Calculate the R2eff values. 62 r2eff_ns_cpmg_2site_expanded(r20=self.r20*a, pA=self.pA, dw=dw_frq*a, dw_orig=dw_frq*a, kex=self.kex, relax_time=0.3, inv_relax_time=1/0.3, tcp=self.tcp, back_calc=self.R2eff, num_cpmg=self.num_cpmg) 63 64 # Check all R2eff values. 65 if self.kex >= 1.e5: 66 for i in range(self.num_points): 67 self.assertAlmostEqual(self.R2eff[i], self.r20, 5) 68 else: 69 for i in range(self.num_points): 70 self.assertAlmostEqual(self.R2eff[i], self.r20)
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, 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, dw_frq
103 104
106 """Test the r2eff_ns_cpmg_2site_expanded() 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
116 """Test the r2eff_ns_cpmg_2site_expanded() 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
126 """Test the r2eff_ns_cpmg_2site_expanded() 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
136 """Test the r2eff_ns_cpmg_2site_expanded() 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
147 """Test the r2eff_ns_cpmg_2site_expanded() 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
158 """Test the r2eff_ns_cpmg_2site_expanded() 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
169 """Test the r2eff_ns_cpmg_2site_expanded() 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