mailr23271 - in /branches/disp_speed: lib/dispersion/tap03.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:41 2014
New Revision: 23271

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

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/tap03.py
    branches/disp_speed/target_functions/relax_disp.py

Modified: branches/disp_speed/lib/dispersion/tap03.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/tap03.py?rev=23271&r1=23270&r2=23271&view=diff
==============================================================================
--- branches/disp_speed/lib/dispersion/tap03.py (original)
+++ branches/disp_speed/lib/dispersion/tap03.py Tue May 20 22:29:41 2014
@@ -60,10 +60,10 @@
 """
 
 # Python module imports.
-from numpy import arctan2, array, isfinite, sin, sqrt, sum
+from numpy import abs, arctan2, array, isfinite, min, sin, sqrt, sum
 
 
-def r1rho_TAP03(r1rho_prime=None, omega=None, offset=None, pA=None, pB=None, 
dw=None, kex=None, R1=0.0, spin_lock_fields=None, spin_lock_fields2=None, 
back_calc=None, num_points=None):
+def r1rho_TAP03(r1rho_prime=None, omega=None, offset=None, pA=None, pB=None, 
dw=None, kex=None, R1=0.0, spin_lock_fields=None, spin_lock_fields2=None, 
num_points=None):
     """Calculate the R1rho' values for the TP02 model.
 
     See the module docstring for details.  This is the Trott, Abergel and 
Palmer (2003) equation.
@@ -89,9 +89,7 @@
     @type spin_lock_fields:     numpy rank-1 float array
     @keyword spin_lock_fields2: The R1rho spin-lock field strengths squared 
(in rad^2.s^-2).  This is for speed.
     @type spin_lock_fields2:    numpy rank-1 float array
-    @keyword back_calc:         The array for holding the back calculated 
R1rho values.  Each element corresponds to one of the spin-lock fields.
-    @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 spin_lock_fields and back_calc arguments.
+    @keyword num_points:        The number of points on the dispersion 
curve, equal to the length of the spin_lock_fields.
     @type num_points:           int
     """
 
@@ -113,7 +111,16 @@
     # The gamma factor.
     sigma = pB*da + pA*db
     sigma2 = sigma**2
-    gamma = 1.0 + phi_ex*(sigma2 - kex2 + spin_lock_fields2) / (sigma2 + 
kex2 + spin_lock_fields2)**2
+    gamma_denom = (sigma2 + kex2 + spin_lock_fields2)**2
+
+    # Catch math domain error of dividing with 0.
+    # This is when gamma_denom =0.
+    if min(abs(gamma_denom)) == 0:
+        R1rho = array([1e100]*num_points)
+
+        return R1rho
+
+    gamma = 1.0 + phi_ex*(sigma2 - kex2 + spin_lock_fields2) / gamma_denom
 
     # Special omega values.
     waeff2 = gamma*spin_lock_fields2 + da**2     # Effective field at A.
@@ -133,6 +140,20 @@
     # Denominator.
     denom = waeff2*wbeff2/weff2 + kex2 - 2.0*hat_sin_theta2*phi_ex + (1.0 - 
gamma)*spin_lock_fields2
  
+    # Catch math domain error of dividing with 0.
+    # This is when denom =0.
+    if min(abs(denom)) == 0:
+        R1rho = array([1e100]*num_points)
+
+        return R1rho
+
+    # Catch math domain error of dividing with 0.
+    # This is when gamma =0.
+    if min(abs(gamma)) == 0:
+        R1rho = array([1e100]*num_points)
+
+        return R1rho
+
     # R1rho calculation.
     R1rho = R1_cos_theta2 + R1rho_prime_sin_theta2 + hat_sin_theta2 * numer 
/ denom / gamma
 
@@ -141,6 +162,4 @@
     if not isfinite(sum(R1rho)):
         R1rho = array([1e100]*num_points)
 
-    # Parse back the value to update the back_calc class object.
-    for i in range(num_points):
-        back_calc[i] = R1rho[i]
+    return R1rho

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=23271&r1=23270&r2=23271&view=diff
==============================================================================
--- branches/disp_speed/target_functions/relax_disp.py  (original)
+++ branches/disp_speed/target_functions/relax_disp.py  Tue May 20 22:29:41 
2014
@@ -1823,7 +1823,7 @@
                 # Loop over the offsets.
                 for oi in range(self.num_offsets[0][si][mi]):
                     # Back calculate the R1rho values.
-                    r1rho_TAP03(r1rho_prime=R20[r20_index], 
omega=self.chemical_shifts[0][si][mi], offset=self.offset[0][si][mi][oi], 
pA=pA, pB=pB, dw=dw_frq, kex=kex, R1=self.r1[si, mi], 
spin_lock_fields=self.spin_lock_omega1[0][mi][oi], 
spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][oi], 
back_calc=self.back_calc[0][si][mi][oi], 
num_points=self.num_disp_points[0][si][mi][oi])
+                    self.back_calc[0][si][mi][oi] = 
r1rho_TAP03(r1rho_prime=R20[r20_index], 
omega=self.chemical_shifts[0][si][mi], offset=self.offset[0][si][mi][oi], 
pA=pA, pB=pB, dw=dw_frq, kex=kex, R1=self.r1[si, mi], 
spin_lock_fields=self.spin_lock_omega1[0][mi][oi], 
spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][oi], 
num_points=self.num_disp_points[0][si][mi][oi])
 
                     # 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][oi]):




Related Messages


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