Author: tlinnet Date: Tue May 27 00:08:06 2014 New Revision: 23450 URL: http://svn.gna.org/viewcvs/relax?rev=23450&view=rev Log: Added 8 unit tests demonstrating edge case 'no Rex' failures of the model 'NS CPMG 2site 3D'. This follows from the ideas in the post http://article.gmane.org/gmane.science.nmr.relax.devel/5858. This is related to: task #7793: (https://gna.org/task/?7793) Speed-up of dispersion models. This is to implement catching of math domain errors, before they occur. These tests cover all parameter value combinations which result in no exchange: - dw = 0.0, - pA = 1.0, - kex = 0.0, - dw = 0.0 and pA = 1.0, - dw = 0.0 and kex = 0.0, - pA = 1.0 and kex = 0.0, - dw = 0.0, pA = 1.0, and kex = 0.0. - kex = 1e7, Modified: branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_ns_cpmg_2site_3d.py Modified: branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_ns_cpmg_2site_3d.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_ns_cpmg_2site_3d.py?rev=23450&r1=23449&r2=23450&view=diff ============================================================================== --- branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_ns_cpmg_2site_3d.py (original) +++ branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_ns_cpmg_2site_3d.py Tue May 27 00:08:06 2014 @@ -24,29 +24,38 @@ from unittest import TestCase # relax module imports. -from lib.dispersion.b14 import r2eff_B14 +from lib.dispersion.ns_cpmg_2site_3d import r2eff_ns_cpmg_2site_3D +from lib.dispersion.ns_matrices import r180x_3d -class Test_b14(TestCase): - """Unit tests for the lib.dispersion.b14 relax module.""" +class Test_ns_cpmg_2site_3d(TestCase): + """Unit tests for the lib.dispersion.ns_cpmg_2site_3D relax module.""" def setUp(self): """Set up for all unit tests.""" # Default parameter values. self.r20a = 2.0 - self.r20b = 2.0 + self.r20b = 3.0 self.pA = 0.99 self.dw = 2.0 self.kex = 1000.0 # Required data structures. + # The 3D rotation matrix for an imperfect X-axis pi-pulse. + self.r180x = r180x_3d() + + # This is a vector that contains the initial magnetizations corresponding to the A and B state transverse magnetizations. + self.M0 = zeros(7, float64) + self.M0[0] = 0.5 + self.num_points = 7 self.ncyc = array([2, 4, 8, 10, 20, 40, 500]) relax_times = 0.04 cpmg_frqs = self.ncyc / relax_times self.inv_relax_times = 1.0 / relax_times self.tau_cpmg = 0.25 / cpmg_frqs + self.R2eff = zeros(self.num_points, float64) # The spin Larmor frequencies. self.sfrq = 200. * 1E6 @@ -55,17 +64,17 @@ """Calculate and check the R2eff values.""" # Parameter conversions. - k_AB, k_BA, pB, dw_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq) + k_AB, k_BA, pB, dw_frq, M0 = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq, M0=self.M0) # Calculate the R2eff values. - R2eff = r2eff_B14(r20a=self.r20a, r20b=self.r20b, pA=self.pA, pB=pB, dw=dw_frq, kex=self.kex, k_AB=k_AB, k_BA=k_BA, ncyc=self.ncyc, inv_tcpmg=self.inv_relax_times, tcp=self.tau_cpmg, num_points=self.num_points) - + r2eff_ns_cpmg_2site_3D(r180x=self.r180x, M0=M0, r20a=self.r20a, r20b=self.r20b, pA=self.pA, pB=pB, dw=dw_frq, k_AB=k_AB, k_BA=k_BA, inv_tcpmg=self.inv_relax_times, tcp=self.tau_cpmg, back_calc=self.R2eff, num_points=self.num_points, power=self.ncyc) + # Check all R2eff values. for i in range(self.num_points): - self.assertAlmostEqual(R2eff[i], self.r20a) + self.assertAlmostEqual(self.R2eff[i], self.r20a) - def param_conversion(self, pA=None, kex=None, dw=None, sfrq=None): + def param_conversion(self, pA=None, kex=None, dw=None, sfrq=None, M0=None): """Convert the parameters. @keyword pA: The population of state A. @@ -76,12 +85,18 @@ @type dw: float @keyword sfrq: The spin Larmor frequencies in Hz. @type sfrq: float - @return: The parameters {k_AB, k_BA, pB, dw_frq}. + @keyword M0: Vector that contains the initial magnetizations corresponding to the A and B state transverse magnetizations. + @type M0: numpy float64, rank-1, 7D array + @return: The parameters {k_AB, k_BA, pB, dw_frq, M0}. @rtype: tuple of float """ # Calculate pB. pB = 1.0 - pA + + # This is a vector that contains the initial magnetizations corresponding to the A and B state transverse magnetizations. + M0[1] = pA + M0[4] = pB # Exchange rates. k_BA = pA * kex @@ -94,11 +109,11 @@ dw_frq = dw * frqs # Return all values. - return k_AB, k_BA, pB, dw_frq + return k_AB, k_BA, pB, dw_frq, M0 - def test_b14_no_rex1(self): - """Test the r2eff_b14() function for no exchange when dw = 0.0.""" + def test_ns_cpmg_2site_3D_no_rex1(self): + """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0.""" # Parameter reset. self.dw = 0.0 @@ -107,8 +122,8 @@ self.calc_r2eff() - def test_b14_no_rex2(self): - """Test the r2eff_b14() function for no exchange when pA = 1.0.""" + def test_ns_cpmg_2site_3D_no_rex2(self): + """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when pA = 1.0.""" # Parameter reset. self.pA = 1.0 @@ -117,8 +132,8 @@ self.calc_r2eff() - def test_b14_no_rex3(self): - """Test the r2eff_b14() function for no exchange when kex = 0.0.""" + def test_ns_cpmg_2site_3D_no_rex3(self): + """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when kex = 0.0.""" # Parameter reset. self.kex = 0.0 @@ -127,8 +142,8 @@ self.calc_r2eff() - def test_b14_no_rex4(self): - """Test the r2eff_b14() function for no exchange when dw = 0.0 and pA = 1.0.""" + def test_ns_cpmg_2site_3D_no_rex4(self): + """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0 and pA = 1.0.""" # Parameter reset. self.pA = 1.0 @@ -138,8 +153,8 @@ self.calc_r2eff() - def test_b14_no_rex5(self): - """Test the r2eff_b14() function for no exchange when dw = 0.0 and kex = 0.0.""" + def test_ns_cpmg_2site_3D_no_rex5(self): + """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0 and kex = 0.0.""" # Parameter reset. self.dw = 0.0 @@ -149,8 +164,8 @@ self.calc_r2eff() - def test_b14_no_rex6(self): - """Test the r2eff_b14() function for no exchange when pA = 1.0 and kex = 0.0.""" + def test_ns_cpmg_2site_3D_no_rex6(self): + """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when pA = 1.0 and kex = 0.0.""" # Parameter reset. self.pA = 1.0 @@ -160,8 +175,8 @@ self.calc_r2eff() - def test_b14_no_rex7(self): - """Test the r2eff_b14() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0.""" + def test_ns_cpmg_2site_3D_no_rex7(self): + """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when dw = 0.0, pA = 1.0, and kex = 0.0.""" # Parameter reset. self.dw = 0.0 @@ -171,11 +186,11 @@ self.calc_r2eff() - def test_b14_no_rex8(self): - """Test the r2eff_b14() function for no exchange when kex = 1e5.""" + def test_ns_cpmg_2site_3D_no_rex8(self): + """Test the r2eff_ns_cpmg_2site_3D() function for no exchange when kex = 1e7.""" # Parameter reset. - self.kex = 1e5 + self.kex = 1e7 # Calculate and check the R2eff values. self.calc_r2eff()