mailRe: r23003 - in /trunk: lib/dispersion/b14.py target_functions/relax_disp.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on May 06, 2014 - 17:26:
The change looks good.  Though this has an additional change - the
addition of the looping over experiment types.  This should have been
a separate commit, or minimally mentioned in the commit message.

Cheers,

Edward

On 6 May 2014 17:20,  <tlinnet@xxxxxxxxxxxxx> wrote:
Author: tlinnet
Date: Tue May  6 17:20:53 2014
New Revision: 23003

URL: http://svn.gna.org/viewcvs/relax?rev=23003&view=rev
Log:
Speed-up. Moved the Repetitive calculations of pB, k_BA and k_AB out of the 
library function.

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=23003&r1=23002&r2=23003&view=diff
==============================================================================
--- trunk/lib/dispersion/b14.py (original)
+++ trunk/lib/dispersion/b14.py Tue May  6 17:20:53 2014
@@ -102,7 +102,7 @@
 from numpy import arccosh, cos, cosh, log, sin, sinh, sqrt, power


-def r2eff_B14(r20a=None, r20b=None, pA=None, dw=None, kex=None, ncyc=None, 
inv_tcpmg=None, tcp=None, back_calc=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.
@@ -114,10 +114,16 @@
     @type r20b:             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 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).
+    @type k_AB:             float
+    @keyword k_BA:          The rate of exchange from site B to A (rad/s).
+    @type k_BA:             float
     @keyword ncyc:          The matrix exponential power array. The number 
of CPMG blocks.
     @type ncyc:             numpy int16, rank-1 array
     @keyword inv_tcpmg:     The inverse of the total duration of the CPMG 
element (in inverse seconds).
@@ -130,12 +136,7 @@
     @type num_points:       int
     """

-    # The B population.
-    pB = 1.0 - pA
-
     # Repetitive calculations (to speed up calculations).
-    k_BA = pA * kex
-    k_AB = pB * kex
     dw2 = dw**2

     
#########################################################################

Modified: trunk/target_functions/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_disp.py?rev=23003&r1=23002&r2=23003&view=diff
==============================================================================
--- trunk/target_functions/relax_disp.py        (original)
+++ trunk/target_functions/relax_disp.py        Tue May  6 17:20:53 2014
@@ -786,29 +786,42 @@
         pA = params[self.end_index[2]]
         kex = params[self.end_index[2]+1]

+        # Once off parameter conversions.
+        pB = 1.0 - pA
+        k_BA = pA * kex
+        k_AB = pB * kex
+
         # Initialise.
         chi2_sum = 0.0

-        # Loop over the spins.
-        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[0][si][mi]
-
-                # Back calculate the R2eff values.
-                r2eff_B14(r20a=R20A[r20_index], r20b=R20B[r20_index], 
pA=pA, dw=dw_frq, kex=kex, ncyc=self.power[0][mi], 
inv_tcpmg=self.inv_relax_times[0][mi], tcp=self.tau_cpmg[0][mi], 
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]):
-                    if self.missing[0][si][mi][0][di]:
-                        self.back_calc[0][si][mi][0][di] = 
self.values[0][si][mi][0][di]
-
-                # Calculate and return the chi-squared value.
-                chi2_sum += chi2(self.values[0][si][mi][0], 
self.back_calc[0][si][mi][0], self.errors[0][si][mi][0])
+        # Loop over the experiment types.
+        for ei in range(self.num_exp):
+            # Loop over the spins.
+            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]
+
+                    # Alias the dw frequency combinations.
+                    if self.exp_types[ei] == EXP_TYPE_CPMG_SQ:
+                        aliased_dw = dw_frq
+                    elif self.exp_types[ei] == EXP_TYPE_CPMG_PROTON_SQ:
+                        aliased_dw = dw_frq
+
+                    # Back calculate the R2eff values.
+                    r2eff_B14(r20a=R20A[r20_index], r20b=R20B[r20_index], 
pA=pA, pB=pB, dw=dw_frq, 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]):
+                        if self.missing[ei][si][mi][0][di]:
+                            self.back_calc[ei][si][mi][0][di] = 
self.values[ei][si][mi][0][di]
+
+                    # Calculate and return the chi-squared value.
+                    chi2_sum += chi2(self.values[ei][si][mi][0], 
self.back_calc[ei][si][mi][0], self.errors[ei][si][mi][0])

         # Return the total chi-squared value.
         return chi2_sum


_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-commits mailing list
relax-commits@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits



Related Messages


Powered by MHonArc, Updated Tue May 06 17:40:10 2014