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