Author: tlinnet Date: Wed May 28 19:17:08 2014 New Revision: 23563 URL: http://svn.gna.org/viewcvs/relax?rev=23563&view=rev Log: Converting back to having back_calc as a function argument to model B14. This is to clean up the API. There can be bo no partial measures/implementations in the relax trunk. The problem is, that many numerical models can't be optimised further, since they evolve the spin-magnetisation in a matrix. That spin evolvement can't be put into a larger numpy array. This is related to: task #7793: (https://gna.org/task/?7793) Speed-up of dispersion models. Modified: branches/disp_speed/lib/dispersion/b14.py branches/disp_speed/target_functions/relax_disp.py branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_b14.py Modified: branches/disp_speed/lib/dispersion/b14.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/b14.py?rev=23563&r1=23562&r2=23563&view=diff ============================================================================== --- branches/disp_speed/lib/dispersion/b14.py (original) +++ branches/disp_speed/lib/dispersion/b14.py Wed May 28 19:17:08 2014 @@ -115,7 +115,7 @@ # Repetitive calculations (to speed up calculations). g_fact = 1/sqrt(2) -def r2eff_B14(r20a=None, r20b=None, pA=None, pB=None, dw=None, kex=None, k_AB=None, k_BA=None, ncyc=None, inv_tcpmg=None, tcp=None, num_points=None): +def r2eff_B14(r20a=None, r20b=None, pA=None, pB=None, dw=None, kex=None, k_AB=None, k_BA=None, ncyc=None, inv_tcpmg=None, tcp=None, back_calc=None, num_points=None): """Calculate the R2eff values for the CR72 model. See the module docstring for details. @@ -143,13 +143,16 @@ @type inv_tcpmg: float @keyword tcp: The tau_CPMG times (1 / 4.nu1). @type tcp: numpy rank-1 float array - @keyword num_points: The number of points on the dispersion curve, equal to the length of the cpmg_frqs. + @keyword back_calc: The array for holding the back calculated R2eff values. Each element corresponds to one of the CPMG nu1 frequencies. + @type back_calc: numpy rank-1 float array + @keyword num_points: The number of points on the dispersion curve, equal to the length of the cpmg_frqs and back_calc arguments. @type num_points: int """ # Catch parameter values that will result in no exchange, returning flat R2eff = R20 lines (when kex = 0.0, k_AB = 0.0). if dw == 0.0 or pA == 1.0 or k_AB == 0.0: - return array([r20a]*num_points) + back_calc[:] = array([r20a]*num_points) + return # Repetitive calculations (to speed up calculations). deltaR2 = r20a - r20b @@ -200,7 +203,8 @@ # Catch math domain error of sinh(val > 710). # This is when E0 > 710. if max(E0) > 700: - return array([r20a]*num_points) + back_calc[:] = array([r20a]*num_points) + return # Derived from chemical shifts #E2 = complex(0,-2.0 * tcp * (F00I - f11I)). E2 = two_tcp * g4 @@ -248,4 +252,4 @@ if not isfinite(sum(R2eff)): R2eff = array([1e100]*num_points) - return R2eff + back_calc[:] = R2eff Modified: branches/disp_speed/target_functions/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/target_functions/relax_disp.py?rev=23563&r1=23562&r2=23563&view=diff ============================================================================== --- branches/disp_speed/target_functions/relax_disp.py (original) +++ branches/disp_speed/target_functions/relax_disp.py Wed May 28 19:17:08 2014 @@ -439,7 +439,7 @@ aliased_dw = dw_frq # Back calculate the R2eff values. - self.back_calc[ei][si][mi][0] = r2eff_B14(r20a=R20A[r20_index], r20b=R20B[r20_index], pA=pA, pB=pB, dw=aliased_dw, kex=kex, k_AB=k_AB, k_BA=k_BA, ncyc=self.power[ei][mi], inv_tcpmg=self.inv_relax_times[ei][mi], tcp=self.tau_cpmg[ei][mi], num_points=self.num_disp_points[ei][si][mi][0]) + r2eff_B14(r20a=R20A[r20_index], r20b=R20B[r20_index], pA=pA, pB=pB, dw=aliased_dw, kex=kex, k_AB=k_AB, k_BA=k_BA, ncyc=self.power[ei][mi], inv_tcpmg=self.inv_relax_times[ei][mi], tcp=self.tau_cpmg[ei][mi], back_calc=self.back_calc[ei][si][mi][0], num_points=self.num_disp_points[ei][si][mi][0]) # For all missing data points, set the back-calculated value to the measured values so that it has no effect on the chi-squared value. for di in range(self.num_disp_points[ei][si][mi][0]): Modified: branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_b14.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_b14.py?rev=23563&r1=23562&r2=23563&view=diff ============================================================================== --- branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_b14.py (original) +++ branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_b14.py Wed May 28 19:17:08 2014 @@ -47,6 +47,7 @@ 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 @@ -59,11 +60,11 @@ k_AB, k_BA, pB, dw_frq = self.param_conversion(pA=self.pA, kex=self.kex, dw=self.dw, sfrq=self.sfrq) # 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_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, back_calc=self.R2eff, num_points=self.num_points) # 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):