mailr23269 - in /branches/disp_speed: 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 tlinnet on May 20, 2014 - 22:29:
Author: tlinnet
Date: Tue May 20 22:29:38 2014
New Revision: 23269

URL: http://svn.gna.org/viewcvs/relax?rev=23269&view=rev
Log:
Math-domain catching for model TSMFK01.

task #7793: (https://gna.org/task/?7793) Speed-up of dispersion models.

This is to implement catching of math domain errors, before they occur.
These can be found via the --numpy-raise function to the systemtests.

To make the code look clean, the class object "back_calc" is no longer
being updated per time point, but is updated in the relax_disp target 
function in
one go.

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

Modified: branches/disp_speed/lib/dispersion/tsmfk01.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/tsmfk01.py?rev=23269&r1=23268&r2=23269&view=diff
==============================================================================
--- branches/disp_speed/lib/dispersion/tsmfk01.py       (original)
+++ branches/disp_speed/lib/dispersion/tsmfk01.py       Tue May 20 22:29:38 
2014
@@ -67,10 +67,10 @@
 """
 
 # Python module imports.
-from numpy import array, sin, isfinite, sum
+from numpy import abs, array, min, sin, isfinite, sum
 
 
-def r2eff_TSMFK01(r20a=None, dw=None, k_AB=None, tcp=None, back_calc=None, 
num_points=None):
+def r2eff_TSMFK01(r20a=None, dw=None, k_AB=None, tcp=None, num_points=None):
     """Calculate the R2eff values for the TSMFK01 model.
 
     See the module docstring for details.
@@ -83,15 +83,20 @@
     @keyword k_AB:          The k_AB parameter value (the forward exchange 
rate in rad/s).
     @type k_AB:             float
     @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.
+    @type tcp:              numpy rank-1 float array.
+    @keyword num_points:    The number of points on the dispersion curve, 
equal to the length of the cpmg_frqs.
     @type num_points:       int
     """
 
     # Denominator.
     denom = dw * tcp
+
+    # Catch math domain error of dividing with 0.
+    # This is when sin(0).
+    if min(abs(denom)) == 0:
+        R2eff = array([1e100]*num_points)
+
+        return R2eff
 
     # The numerator.
     numer = sin(denom)
@@ -104,6 +109,4 @@
     if not isfinite(sum(R2eff)):
         R2eff = array([1e100]*num_points)
 
-    # Parse back the value to update the back_calc class object.
-    for i in range(num_points):
-        back_calc[i] = R2eff[i]
+    return 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=23269&r1=23268&r2=23269&view=diff
==============================================================================
--- branches/disp_speed/target_functions/relax_disp.py  (original)
+++ branches/disp_speed/target_functions/relax_disp.py  Tue May 20 22:29:38 
2014
@@ -1921,7 +1921,7 @@
                 dw_frq = dw[si] * self.frqs[0][si][mi]
 
                 # Back calculate the R2eff values.
-                r2eff_TSMFK01(r20a=R20A[r20a_index], dw=dw_frq, k_AB=k_AB, 
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])
+                self.back_calc[0][si][mi][0] = 
r2eff_TSMFK01(r20a=R20A[r20a_index], dw=dw_frq, k_AB=k_AB, 
tcp=self.tau_cpmg[0][mi], 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]):




Related Messages


Powered by MHonArc, Updated Tue May 20 22:40:02 2014