Author: tlinnet Date: Wed May 7 09:45:14 2014 New Revision: 23028 URL: http://svn.gna.org/viewcvs/relax?rev=23028&view=rev Log: Re-inserted the library function of b14.py the calculation of: deltaR2 = r20a - r20b alpha_m = deltaR2 + k_AB - k_BA zeta = 2 * dw * alpha_m Psi = alpha_m**2 + 4 * k_BA * k_AB - dw**2 And put the g_fact = 1/sqrt(2), inside the library function. It made no sense to put these calculations outside the library, since there would be no skipping of a loop. It actually makes much better sense to keep these calculation in the library function, to preserve the possibility to import this module in other software. sr #3154: (https://gna.org/support/?3154) Implementation of Baldwin (2014) B14 model - 2-site exact solution model for all time scales. This follows the tutorial for adding relaxation dispersion models at: http://wiki.nmr-relax.com/Tutorial_for_adding_relaxation_dispersion_models_to_relax#Debugging Modified: trunk/lib/dispersion/b14.py trunk/target_functions/relax_disp.py Modified: trunk/lib/dispersion/b14.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/dispersion/b14.py?rev=23028&r1=23027&r2=23028&view=diff ============================================================================== --- trunk/lib/dispersion/b14.py (original) +++ trunk/lib/dispersion/b14.py Wed May 7 09:45:14 2014 @@ -113,8 +113,10 @@ import numpy from numpy import arccosh, cos, cosh, log, sin, sinh, sqrt, power - -def r2eff_B14(r20a=None, r20b=None, deltaR2=None, alpha_m=None, pA=None, pB=None, dw=None, zeta=None, Psi=None, g_fact=None, kex=None, k_AB=None, k_BA=None, ncyc=None, inv_tcpmg=None, tcp=None, back_calc=None, num_points=None): +# 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, back_calc=None, num_points=None): """Calculate the R2eff values for the CR72 model. See the module docstring for details. @@ -124,22 +126,12 @@ @type r20a: float @keyword r20b: The R20 parameter value of state B (R2 with no exchange). @type r20b: float - @keyword deltaR2: The difference r20a - r20b. - @type deltaR2: float - @keyword alpha_m: The Carver and Richards (1972) alpha_minus short notation. alpha_m = deltaR2 + k_AB - k_BA = r20a - r20b + k_AB - k_BA. - @type alpha_m: float @keyword pA: The population of state A. @type pA: float @keyword pB: The population of state B. @type pB: float @keyword dw: The chemical exchange difference between states A and B in rad/s. @type dw: float - @keyword zeta: The Carver and Richards (1972) zeta notation. zeta = 2 * dw * alpha_m. - @type zeta: float - @keyword Psi: The Carver and Richards (1972) Psi notation. Psi = alpha_m**2 + 4 * k_BA * k_AB - dw**2. - @type Psi: float - @keyword g_fact: The factor g = 1/sqrt(2). This is calculated outside library function, to only be calculated once. - @type g_fact: float @keyword kex: The kex parameter value (the exchange rate in rad/s). @type kex: float @keyword k_AB: The rate of exchange from site A to B (rad/s). @@ -159,6 +151,14 @@ """ # Repetitive calculations (to speed up calculations). + deltaR2 = r20a - r20b + + # The Carver and Richards (1972) alpha_minus short notation. + alpha_m = deltaR2 + k_AB - k_BA + zeta = 2 * dw * alpha_m + Psi = alpha_m**2 + 4 * k_BA * k_AB - dw**2 + + # Repetitive calculations (to speed up calculations). dw2 = dw**2 zeta2 = zeta**2 Psi2 = Psi**2 Modified: trunk/target_functions/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_disp.py?rev=23028&r1=23027&r2=23028&view=diff ============================================================================== --- trunk/target_functions/relax_disp.py (original) +++ trunk/target_functions/relax_disp.py Wed May 7 09:45:14 2014 @@ -416,7 +416,6 @@ pB = 1.0 - pA k_BA = pA * kex k_AB = pB * kex - g_fact = 1/sqrt(2) # Initialise. chi2_sum = 0.0 @@ -427,6 +426,9 @@ for si in range(self.num_spins): # Loop over the spectrometer frequencies. for mi in range(self.num_frq): + # The R20 index. + r20_index = mi + si*self.num_frq + # Convert dw from ppm to rad/s. dw_frq = dw[si] * self.frqs[ei][si][mi] @@ -436,21 +438,8 @@ elif self.exp_types[ei] == EXP_TYPE_CPMG_PROTON_SQ: aliased_dw = dw_frq - # The R20 index. - r20_index = mi + si*self.num_frq - - # Repetitive calculations (to speed up calculations). - r20a = R20A[r20_index] - r20b = R20B[r20_index] - deltaR2 = r20a - r20b - - # The Carver and Richards (1972) alpha_minus short notation. - alpha_m = deltaR2 + k_AB - k_BA - zeta = 2 * aliased_dw * alpha_m - Psi = alpha_m**2 + 4 * k_BA * k_AB - aliased_dw**2 - # Back calculate the R2eff values. - r2eff_B14(r20a=r20a, r20b=r20b, deltaR2=deltaR2, alpha_m=alpha_m, pA=pA, pB=pB, dw=dw_frq, zeta=zeta, Psi=Psi, g_fact=g_fact, 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]) + 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]):