mailr23587 - in /branches/disp_speed: lib/dispersion/ target_functions/ test_suite/unit_tests/_lib/_dispersion/


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

Header


Content

Posted by tlinnet on May 29, 2014 - 12:33:
Author: tlinnet
Date: Thu May 29 12:33:34 2014
New Revision: 23587

URL: http://svn.gna.org/viewcvs/relax?rev=23587&view=rev
Log:
Converting back to having back_calc as a function argument to model TP02.

This is to clean up the API.
There can be bo no partial measures/implementations in the relax trunk.

The problem is, that many numerical models can't be optimised further, since 
they
evolve the spin-magnetisation in a matrix.  That spin evolvement can't be put 
into
a larger numpy array.

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

Modified:
    branches/disp_speed/lib/dispersion/tp02.py
    branches/disp_speed/target_functions/relax_disp.py
    branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_tp02.py

Modified: branches/disp_speed/lib/dispersion/tp02.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/tp02.py?rev=23587&r1=23586&r2=23587&view=diff
==============================================================================
--- branches/disp_speed/lib/dispersion/tp02.py  (original)
+++ branches/disp_speed/lib/dispersion/tp02.py  Thu May 29 12:33:34 2014
@@ -63,7 +63,7 @@
 from numpy import abs, arctan2, array, isfinite, min, sin, sum
 
 
-def r1rho_TP02(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):
+def r1rho_TP02(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):
     """Calculate the R1rho' values for the TP02 model.
 
     See the module docstring for details.  This is the Trott and Palmer 
(2002) equation according to Korzhnev (J. Biomol. NMR (2003), 26, 39-48).
@@ -89,7 +89,9 @@
     @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 num_points:        The number of points on the dispersion 
curve, equal to the length of the spin_lock_fields.
+    @keyword back_calc:         The array for holding the back calculated 
R1rho values.  Each element corresponds to the combination of offset and spin 
lock field.
+    @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.
     @type num_points:           int
     """
 
@@ -124,7 +126,8 @@
     # Catch zeros (to avoid pointless mathematical operations).
     # This will result in no exchange, returning flat lines.
     if numer == 0.0:
-        return R1_cos_theta2 + R1rho_prime_sin_theta2
+        back_calc[:] = R1_cos_theta2 + R1rho_prime_sin_theta2
+        return
 
     # Denominator.
     denom = waeff2 * wbeff2 / weff2 + kex2
@@ -138,4 +141,4 @@
     if not isfinite(sum(R1rho)):
         R1rho = array([1e100]*num_points)
 
-    return R1rho
+    back_calc[:] = 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=23587&r1=23586&r2=23587&view=diff
==============================================================================
--- branches/disp_speed/target_functions/relax_disp.py  (original)
+++ branches/disp_speed/target_functions/relax_disp.py  Thu May 29 12:33:34 
2014
@@ -1875,7 +1875,7 @@
                 # Loop over the offsets.
                 for oi in range(self.num_offsets[0][si][mi]):
                     # Back calculate the R1rho values.
-                    self.back_calc[0][si][mi][oi] = 
r1rho_TP02(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])
+                    r1rho_TP02(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])
 
                     # 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]):

Modified: 
branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_tp02.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_tp02.py?rev=23587&r1=23586&r2=23587&view=diff
==============================================================================
--- branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_tp02.py   
  (original)
+++ branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_tp02.py   
  Thu May 29 12:33:34 2014
@@ -59,6 +59,7 @@
 
         # Required data structures.
         self.num_points = 11
+        self.R1rho = zeros(self.num_points, float64)
 
 
     def calc_r1rho(self):
@@ -68,7 +69,7 @@
         pB, dw_frq, spin_lock_omega1, spin_lock_omega1_squared = 
self.param_conversion(pA=self.pA, dw=self.dw, sfrq=self.sfrq, 
spin_lock_nu1=self.spin_lock_nu1)
 
         # Calculate the R1rho values.
-        R1rho = r1rho_TP02(r1rho_prime=self.r1rho_prime, omega=self.omega, 
offset=self.offset, pA=self.pA, pB=pB, dw=dw_frq, kex=self.kex, R1=self.r1, 
spin_lock_fields=spin_lock_omega1, 
spin_lock_fields2=spin_lock_omega1_squared, num_points=self.num_points)
+        r1rho_TP02(r1rho_prime=self.r1rho_prime, omega=self.omega, 
offset=self.offset, pA=self.pA, pB=pB, dw=dw_frq, kex=self.kex, R1=self.r1, 
spin_lock_fields=spin_lock_omega1, 
spin_lock_fields2=spin_lock_omega1_squared, back_calc=self.R1rho, 
num_points=self.num_points)
 
         # Compare to function value.
         # Larmor frequency [s^-1].
@@ -89,7 +90,7 @@
 
         # Check all R1rho values.
         for i in range(self.num_points):
-            self.assertAlmostEqual(R1rho[i], r1rho_no_rex[i])
+            self.assertAlmostEqual(self.R1rho[i], r1rho_no_rex[i])
 
 
     def param_conversion(self, pA=None, dw=None, sfrq=None, 
spin_lock_nu1=None):




Related Messages


Powered by MHonArc, Updated Thu May 29 12:40:03 2014