mailr20965 - in /branches/relax_disp: lib/dispersion/tsmfk01.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 on September 10, 2013 - 14:39:
Author: bugman
Date: Tue Sep 10 14:39:49 2013
New Revision: 20965

URL: http://svn.gna.org/viewcvs/relax?rev=20965&view=rev
Log:
Optimized the target function for model TSMFK.

Progress sr #3071: https://gna.org/support/index.php?3071 - Implementation of 
Tollinger/Kay dispersion model (2001)
Following the guide at: 
http://wiki.nmr-relax.com/Tutorial_for_adding_relaxation_dispersion_models_to_relax

Troels E. Linnet provided this patch. Commit by: tlinnet _aaattt_ 
gmail_dot_com

Signed-off-by: Edward d'Auvergne <edward@xxxxxxxxxxxxx>

Modified:
    branches/relax_disp/lib/dispersion/tsmfk01.py
    branches/relax_disp/target_functions/relax_disp.py

Modified: branches/relax_disp/lib/dispersion/tsmfk01.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/lib/dispersion/tsmfk01.py?rev=20965&r1=20964&r2=20965&view=diff
==============================================================================
--- branches/relax_disp/lib/dispersion/tsmfk01.py (original)
+++ branches/relax_disp/lib/dispersion/tsmfk01.py Tue Sep 10 14:39:49 2013
@@ -47,7 +47,7 @@
 from math import sin
 
 
-def r2eff_TSMFK01(r20a=None, dw=None, k_AB=None, cpmg_frqs=None, 
back_calc=None, num_points=None):
+def r2eff_TSMFK01(r20a=None, dw=None, k_AB=None, tcp=None, back_calc=None, 
num_points=None):
     """Calculate the R2eff values for the TSMFK01 model.
 
     See the module docstring for details.
@@ -59,8 +59,8 @@
     @type dw:               float
     @keyword k_AB:          The k_AB parameter value (the forward exchange 
rate in rad/s).
     @type k_AB:             float
-    @keyword cpmg_frqs:     The CPMG nu1 frequencies.
-    @type cpmg_frqs:        numpy rank-1 float array
+    @keyword tcp:           The tau_CPMG times (1 / 4.nu1).
+    @type tcp:              numpy rank-1 float array
     @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.
@@ -69,24 +69,16 @@
 
     # Loop over the time points, back calculating the R2eff values.
     for i in range(num_points):
-        # Catch zeros (to avoid pointless mathematical operations).
-        if cpmg_frqs[i] == 0.0:
-            back_calc[i] = r20a
-            continue
-
-        # Repetitive calculations (to speed up calculations).
-        tau_CP = 1.0/(4*cpmg_frqs[i])
+        # Denominator.
+        denom = dw * tcp[i]
 
         # The numerator.
-        numer = sin(dw * tau_CP)
+        numer = sin(denom)
 
         # Catch zeros (to avoid pointless mathematical operations).
         if numer == 0.0:
             back_calc[i] = r20a + k_AB
             continue
-
-        # Denominator.
-        denom = dw * tau_CP
 
         # Avoid divide by zero.
         if denom == 0.0:

Modified: branches/relax_disp/target_functions/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/target_functions/relax_disp.py?rev=20965&r1=20964&r2=20965&view=diff
==============================================================================
--- branches/relax_disp/target_functions/relax_disp.py (original)
+++ branches/relax_disp/target_functions/relax_disp.py Tue Sep 10 14:39:49 
2013
@@ -1110,15 +1110,15 @@
                 dw_frq = dw[spin_index] * self.frqs[spin_index, frq_index]
 
                 # Back calculate the R2eff values.
-                r2eff_TSMFK01(r20a=R20A[r20a_index], dw=dw_frq, k_AB=k_AB, 
cpmg_frqs=self.cpmg_frqs, back_calc=self.back_calc[spin_index, frq_index], 
num_points=self.num_disp_points)
-
-                # 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 point_index in range(self.num_disp_points):
-                    if self.missing[spin_index, frq_index, point_index]:
-                        self.back_calc[spin_index, frq_index, point_index] = 
self.values[spin_index, frq_index, point_index]
-
-                # Calculate and return the chi-squared value.
-                chi2_sum += chi2(self.values[spin_index, frq_index], 
self.back_calc[spin_index, frq_index], self.errors[spin_index, frq_index])
-
-        # Return the total chi-squared value.
-        return chi2_sum
+                r2eff_TSMFK01(r20a=R20A[r20a_index], dw=dw_frq, k_AB=k_AB, 
tcp=self.tau_cpmg, back_calc=self.back_calc[spin_index, frq_index], 
num_points=self.num_disp_points)
+
+                # 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 point_index in range(self.num_disp_points):
+                    if self.missing[spin_index, frq_index, point_index]:
+                        self.back_calc[spin_index, frq_index, point_index] = 
self.values[spin_index, frq_index, point_index]
+
+                # Calculate and return the chi-squared value.
+                chi2_sum += chi2(self.values[spin_index, frq_index], 
self.back_calc[spin_index, frq_index], self.errors[spin_index, frq_index])
+
+        # Return the total chi-squared value.
+        return chi2_sum




Related Messages


Powered by MHonArc, Updated Tue Sep 10 14:40:02 2013