mailr20334 - in /branches/relax_disp/lib/dispersion: __init__.py ns_2site.py


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

Header


Content

Posted by edward on July 16, 2013 - 15:17:
Author: bugman
Date: Tue Jul 16 15:17:43 2013
New Revision: 20334

URL: http://svn.gna.org/viewcvs/relax?rev=20334&view=rev
Log:
Added the 'NS 2-site' R2eff calculating function to the relax library.

This is the model of the numerical solution for the 2-site Bloch-McConnell 
equations.  It originates
as optimization function number 1 from the fitting_main_kex.py script from 
Mathilde Lescanne, Paul
Schanda, and Dominique Marion (see 
http://thread.gmane.org/gmane.science.nmr.relax.devel/4138,
https://gna.org/task/?7712#comment2 and 
https://gna.org/support/download.php?file_id=18262).

This commit follows step 3 of the relaxation dispersion model addition 
tutorial
(http://thread.gmane.org/gmane.science.nmr.relax.devel/3907).


Added:
    branches/relax_disp/lib/dispersion/ns_2site.py
      - copied, changed from r20327, 
branches/relax_disp/lib/dispersion/ns_2site_star.py
Modified:
    branches/relax_disp/lib/dispersion/__init__.py

Modified: branches/relax_disp/lib/dispersion/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/lib/dispersion/__init__.py?rev=20334&r1=20333&r2=20334&view=diff
==============================================================================
--- branches/relax_disp/lib/dispersion/__init__.py (original)
+++ branches/relax_disp/lib/dispersion/__init__.py Tue Jul 16 15:17:43 2013
@@ -29,6 +29,7 @@
     'lm63',
     'm61',
     'm61b',
+    'ns_2site',
     'ns_2site_star',
     'ns_matrices',
     'two_point'

Copied: branches/relax_disp/lib/dispersion/ns_2site.py (from r20327, 
branches/relax_disp/lib/dispersion/ns_2site_star.py)
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/lib/dispersion/ns_2site.py?p2=branches/relax_disp/lib/dispersion/ns_2site.py&p1=branches/relax_disp/lib/dispersion/ns_2site_star.py&r1=20327&r2=20334&rev=20334&view=diff
==============================================================================
--- branches/relax_disp/lib/dispersion/ns_2site_star.py (original)
+++ branches/relax_disp/lib/dispersion/ns_2site.py Tue Jul 16 15:17:43 2013
@@ -23,44 +23,47 @@
 # Module docstring.
 """This function performs a numerical fit of 2-site Bloch-McConnell 
equations for CPMG-type experiments.
 
-The function uses an explicit matrix that contains relaxation, exchange and 
chemical shift terms. It does the 180deg pulses in the CPMG train with 
conjugate complex matrices.  The approach of Bloch-McConnell can be found in 
chapter 3.1 of Palmer, A. G. Chem Rev 2004, 104, 3623-3640.  This function 
was written, initially in MATLAB, in 2010.
+The function uses an explicit matrix that contains relaxation, exchange and 
chemical shift terms.  It does the 180deg pulses in the CPMG train.  The 
approach of Bloch-McConnell can be found in chapter 3.1 of Palmer, A. G. Chem 
Rev 2004, 104, 3623-3640.  This function was written, initially in MATLAB, in 
2010.
 
-The code was submitted at 
http://thread.gmane.org/gmane.science.nmr.relax.devel/4132 by Paul Schanda.
+This is the model of the numerical solution for the 2-site Bloch-McConnell 
equations.  It originates as optimization function number 1 from the 
fitting_main_kex.py script from Mathilde Lescanne, Paul Schanda, and 
Dominique Marion (see 
http://thread.gmane.org/gmane.science.nmr.relax.devel/4138, 
https://gna.org/task/?7712#comment2 and 
https://gna.org/support/download.php?file_id=18262).
 """
 
 # Dependency check module.
 import dep_check
 
 # Python module imports.
-from math import log
-from numpy import add, complex, conj, dot
-from numpy.linalg import matrix_power
+from math import fabs, log
 if dep_check.scipy_module:
     from scipy.linalg import expm
 
+# relax module imports.
+from lib.dispersion.ns_matrices import r180x_3d, rcpmg_3d
 
-def r2eff_ns_2site_star(Rr=None, Rex=None, RCS=None, R=None, M0=None, 
r20a=None, r20b=None, fA=None, inv_tcpmg=None, tcp=None, back_calc=None, 
num_points=None, power=None):
-    """The 2-site numerical solution to the Bloch-McConnell equation using 
complex conjugate matrices.
+
+def r2eff_ns_2site_star(M0=None, r10a=None, r10b=None, r20a=None, r20b=None, 
pA=None, dw=None, k_AB=None, k_BA=None, inv_tcpmg=None, tcp=None, 
back_calc=None, num_points=None, power=None):
+    """The 2-site numerical solution to the Bloch-McConnell equation.
 
     This function calculates and stores the R2eff values.
 
 
-    @keyword Rr:            The matrix that contains only the R2 relaxation 
terms ("Redfield relaxation", i.e. non-exchange broadening).
-    @type Rr:               numpy complex64, rank-2, 2D array
-    @keyword Rex:           The matrix that contains the exchange terms 
between the two states A and B.
-    @type Rex:              numpy complex64, rank-2, 2D array
-    @keyword RCS:           The matrix that contains the chemical shift 
evolution.  It works here only with X magnetization, and the complex notation 
allows to evolve in the transverse plane (x, y).
-    @type RCS:              numpy complex64, rank-2, 2D array
-    @keyword R:             The matrix that contains all the contributions 
to the evolution, i.e. relaxation, exchange and chemical shift evolution.
-    @type R:                numpy complex64, rank-2, 2D array
     @keyword M0:            This is a vector that contains the initial 
magnetizations corresponding to the A and B state transverse magnetizations.
     @type M0:               numpy float64, rank-1, 2D array
+    @keyword r10a:          The R1 value for state A.
+    @type r10a:             float
+    @keyword r10b:          The R1 value for state B.
+    @type r10b:             float
     @keyword r20a:          The R2 value for state A in the absence of 
exchange.
     @type r20a:             float
     @keyword r20b:          The R2 value for state B in the absence of 
exchange.
     @type r20b:             float
-    @keyword fA:            The frequency of state A.
-    @type fA:               float
+    @keyword pA:            The population of state A.
+    @type pA:               float
+    @keyword dw:            The chemical exchange difference between states 
A and B in rad/s.
+    @type dw:               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 inv_tcpmg:     The inverse of the total duration of the CPMG 
element (in inverse seconds).
     @type inv_tcpmg:        float
     @keyword tcp:           The tau_CPMG times (1 / 4.nu1).
@@ -73,36 +76,25 @@
     @type power:            numpy int16, rank-1 array
     """
 
-    # The matrix that contains only the R2 relaxation terms ("Redfield 
relaxation", i.e. non-exchange broadening).
-    Rr[0, 0] = -r20a
-    Rr[1, 1] = -r20b
-
-    # The matrix that contains the chemical shift evolution.  It works here 
only with X magnetization, and the complex notation allows to evolve in the 
transverse plane (x, y).
-    RCS[1, 1] = complex(0.0, -fA)
-
     # The matrix R that contains all the contributions to the evolution, 
i.e. relaxation, exchange and chemical shift evolution.
-    add(Rr, Rex, out=R)
-    add(R, RCS, out=R)
-
-    # This is the complex conjugate of the above.  It allows the chemical 
shift to run in the other direction, i.e. it is used to evolve the shift 
after a 180 deg pulse.  The factor of 2 is to minimise the number of 
multiplications for the prop_2 matrix calculation.
-    cR2 = conj(R) * 2.0
+    R = rcpmg_3d(R1A=r10a, R1B=r10b, R2A=r20a, R2B=r20b, df=dw, k_AB=k_AB, 
k_BA=k_BA)
 
     # Loop over the time points, back calculating the R2eff values.
     for i in range(num_points):
+        # Initial magnetisation.
+        Mint = M0
+
         # This matrix is a propagator that will evolve the magnetization 
with the matrix R for a delay tcp.
-        expm_R_tcp = expm(R*tcp[i])
+        Rexpo = expm(R*tcp[i])
 
-        # This is the propagator for an element of [delay tcp; 180 deg 
pulse; 2 times delay tcp; 180 deg pulse; delay tau], i.e. for 2 times 
tau-180-tau.
-        prop_2 = dot(dot(expm_R_tcp, expm(cR2*tcp[i])), expm_R_tcp)
-
-        # Now create the total propagator that will evolve the magnetization 
under the CPMG train, i.e. it applies the above tau-180-tau-tau-180-tau so 
many times as required for the CPMG frequency under consideration.
-        prop_total = matrix_power(prop_2, power[i])
-
-        # Now we apply the above propagator to the initial magnetization 
vector - resulting in the magnetization that remains after the full CPMG 
pulse train.  It is called M of t (t is the time after the CPMG train).
-        Moft = dot(prop_total, M0)
+        # Loop over the CPMG elements.
+        for j in range(2*power[i]):
+                       Mint = Rexpo * Mint
+                       Mint = r180x_3d(0.0) * Mint
+                       Mint = Rexpo * Mint
 
         # The next lines calculate the R2eff using a two-point 
approximation, i.e. assuming that the decay is mono-exponential.
-        Mgx = Moft[0].real / M0[0]
+        Mgx = fabs((Mint[1])/pA)
         if Mgx == 0.0:
             back_calc[i] = 1e99
         else:




Related Messages


Powered by MHonArc, Updated Tue Jul 16 17:20:02 2013