Author: tlinnet Date: Wed May 28 19:17:11 2014 New Revision: 23564 URL: http://svn.gna.org/viewcvs/relax?rev=23564&view=rev Log: Converting back to having back_calc as a function argument to model CR72: 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/cr72.py branches/disp_speed/target_functions/relax_disp.py branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_cr72.py Modified: branches/disp_speed/lib/dispersion/cr72.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/cr72.py?rev=23564&r1=23563&r2=23564&view=diff ============================================================================== --- branches/disp_speed/lib/dispersion/cr72.py (original) +++ branches/disp_speed/lib/dispersion/cr72.py Wed May 28 19:17:11 2014 @@ -97,7 +97,7 @@ # Repetitive calculations (to speed up calculations). eta_scale = 2.0**(-3.0/2.0) -def r2eff_CR72(r20a=None, r20b=None, pA=None, dw=None, kex=None, cpmg_frqs=None, num_points=None): +def r2eff_CR72(r20a=None, r20b=None, pA=None, dw=None, kex=None, cpmg_frqs=None, back_calc=None, num_points=None): """Calculate the R2eff values for the CR72 model. See the module docstring for details. @@ -115,9 +115,16 @@ @type kex: float @keyword cpmg_frqs: The CPMG nu1 frequencies. @type cpmg_frqs: 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 kex == 0.0: + back_calc[:] = array([r20a]*num_points) + return # The B population. pB = 1.0 - pA @@ -127,10 +134,6 @@ r20_kex = (r20a + r20b + kex) / 2.0 k_BA = pA * kex k_AB = pB * kex - - # 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) # The Psi and zeta values. if r20a != r20b: @@ -156,12 +159,14 @@ # Catch math domain error of cosh(val > 710). # This is when etapos > 710. if max(etapos) > 700: - return array([r20a]*num_points) + back_calc[:] = array([r20a]*num_points) + return # The arccosh argument - catch invalid values. fact = Dpos * cosh(etapos) - Dneg * cos(etaneg) if min(fact) < 1.0: - return array([r20_kex]*num_points) + back_calc[:] = array([r20_kex]*num_points) + return # Calculate R2eff. R2eff = r20_kex - cpmg_frqs * arccosh( fact ) @@ -171,4 +176,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=23564&r1=23563&r2=23564&view=diff ============================================================================== --- branches/disp_speed/target_functions/relax_disp.py (original) +++ branches/disp_speed/target_functions/relax_disp.py Wed May 28 19:17:11 2014 @@ -484,7 +484,7 @@ dw_frq = dw[si] * self.frqs[0][si][mi] # Back calculate the R2eff values. - self.back_calc[0][si][mi][0] = r2eff_CR72(r20a=R20A[r20_index], r20b=R20B[r20_index], pA=pA, dw=dw_frq, kex=kex, cpmg_frqs=self.cpmg_frqs[0][mi][0], num_points=self.num_disp_points[0][si][mi][0]) + r2eff_CR72(r20a=R20A[r20_index], r20b=R20B[r20_index], pA=pA, dw=dw_frq, kex=kex, cpmg_frqs=self.cpmg_frqs[0][mi][0], back_calc = self.back_calc[0][si][mi][0], num_points=self.num_disp_points[0][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[0][si][mi][0]): Modified: branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_cr72.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_cr72.py?rev=23564&r1=23563&r2=23564&view=diff ============================================================================== --- branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_cr72.py (original) +++ branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_cr72.py Wed May 28 19:17:11 2014 @@ -45,6 +45,7 @@ self.ncyc = array([2, 4, 8, 10, 20, 40, 500]) relax_times = 0.04 self.cpmg_frqs = self.ncyc / relax_times + self.R2eff = zeros(self.num_points, float64) # The spin Larmor frequencies. self.sfrq = 200. * 1E6 @@ -57,11 +58,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_CR72(r20a=self.r20a, r20b=self.r20b, pA=self.pA, dw=dw_frq, kex=self.kex, cpmg_frqs=self.cpmg_frqs, num_points=self.num_points) + r2eff_CR72(r20a=self.r20a, r20b=self.r20b, pA=self.pA, dw=dw_frq, kex=self.kex, cpmg_frqs=self.cpmg_frqs, 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):