Author: tlinnet Date: Wed May 28 19:22:17 2014 New Revision: 23569 URL: http://svn.gna.org/viewcvs/relax?rev=23569&view=rev Log: Converting back to having back_calc as a function argument to model LM63: 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/lm63.py branches/disp_speed/target_functions/relax_disp.py branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_lm63.py Modified: branches/disp_speed/lib/dispersion/lm63.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/lm63.py?rev=23569&r1=23568&r2=23569&view=diff ============================================================================== --- branches/disp_speed/lib/dispersion/lm63.py (original) +++ branches/disp_speed/lib/dispersion/lm63.py Wed May 28 19:22:17 2014 @@ -67,7 +67,7 @@ from numpy import array, isfinite, sum, tanh -def r2eff_LM63(r20=None, phi_ex=None, kex=None, cpmg_frqs=None, num_points=None): +def r2eff_LM63(r20=None, phi_ex=None, kex=None, cpmg_frqs=None, back_calc=None, num_points=None): """Calculate the R2eff values for the LM63 model. See the module docstring for details. @@ -81,18 +81,22 @@ @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 divide with zeros (to avoid pointless mathematical operations). if kex == 0.0: - return array([r20]*num_points) + back_calc[:] = array([r20]*num_points) + return # Catch zeros (to avoid pointless mathematical operations). # This will result in no exchange, returning flat lines. if phi_ex == 0.0: - return array([r20]*num_points) + back_calc[:] = array([r20]*num_points) + return # Repetitive calculations (to speed up calculations). rex = phi_ex / kex @@ -106,4 +110,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=23569&r1=23568&r2=23569&view=diff ============================================================================== --- branches/disp_speed/target_functions/relax_disp.py (original) +++ branches/disp_speed/target_functions/relax_disp.py Wed May 28 19:22:17 2014 @@ -1117,7 +1117,7 @@ phi_ex_scaled = phi_ex[si] * self.frqs[0][si][mi]**2 # Back calculate the R2eff values. - self.back_calc[0][si][mi][0] = r2eff_LM63(r20=R20[r20_index], phi_ex=phi_ex_scaled, kex=kex, cpmg_frqs=self.cpmg_frqs[0][mi][0], num_points=self.num_disp_points[0][si][mi][0]) + r2eff_LM63(r20=R20[r20_index], phi_ex=phi_ex_scaled, 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_lm63.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_lm63.py?rev=23569&r1=23568&r2=23569&view=diff ============================================================================== --- branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_lm63.py (original) +++ branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_lm63.py Wed May 28 19:22:17 2014 @@ -46,6 +46,7 @@ # Required data structures. self.num_points = 3 self.cpmg_frqs = array([2.5, 1.25, 0.83], float64) + self.R2eff = zeros(self.num_points, float64) def calc_r2eff(self): @@ -55,15 +56,15 @@ phi_ex_scaled = self.param_conversion(pA=self.pA, dw=self.dw, sfrq=self.sfrq) # Calculate the R2eff values. - R2eff = r2eff_LM63(r20=self.r20, phi_ex=phi_ex_scaled, kex=self.kex, cpmg_frqs=self.cpmg_frqs, num_points=self.num_points) + R2eff = r2eff_LM63(r20=self.r20, phi_ex=phi_ex_scaled, kex=self.kex, cpmg_frqs=self.cpmg_frqs, back_calc=self.R2eff, num_points=self.num_points) # Check all R2eff values. if self.kex > 1.e5: for i in range(self.num_points): - self.assertAlmostEqual(R2eff[i], self.r20, 2) + self.assertAlmostEqual(self.R2eff[i], self.r20, 2) else: for i in range(self.num_points): - self.assertAlmostEqual(R2eff[i], self.r20) + self.assertAlmostEqual(self.R2eff[i], self.r20) def param_conversion(self, pA=None, dw=None, sfrq=None):