Author: tlinnet Date: Fri Jun 20 19:13:14 2014 New Revision: 24217 URL: http://svn.gna.org/viewcvs/relax?rev=24217&view=rev Log: Renamed some numerical matrices, to get consistency in naming. Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion models for Clustered analysis. Modified: branches/disp_spin_speed/lib/dispersion/ns_matrices.py branches/disp_spin_speed/lib/dispersion/ns_r1rho_2site.py Modified: branches/disp_spin_speed/lib/dispersion/ns_matrices.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/ns_matrices.py?rev=24217&r1=24216&r2=24217&view=diff ============================================================================== --- branches/disp_spin_speed/lib/dispersion/ns_matrices.py (original) +++ branches/disp_spin_speed/lib/dispersion/ns_matrices.py Fri Jun 20 19:13:14 2014 @@ -700,6 +700,194 @@ + m_k_AB_tcp + m_k_BA_tcp + m_k_BC_tcp + m_k_CB_tcp + m_k_AC_tcp + m_k_CA_tcp) + return matrix + + +def rr1rho_3d_2site(matrix=None, R1=None, r1rho_prime=None, pA=None, pB=None, wA=None, wB=None, w1=None, k_AB=None, k_BA=None): + """Definition of the 3D exchange matrix. + + This code originates from the funNumrho.m file from the Skrynikov & Tollinger code (the sim_all.tar file https://gna.org/support/download.php?file_id=18404 attached to https://gna.org/task/?7712#comment5). + + + @keyword matrix: The matrix to fill. + @type matrix: numpy rank-2 6D array + @keyword R1: The longitudinal, spin-lattice relaxation rate. + @type R1: float + @keyword r1rho_prime: The R1rho transverse, spin-spin relaxation rate in the absence of exchange. + @type r1rho_prime: float + @keyword pA: The population of state A. + @type pA: float + @keyword pB: The population of state B. + @type pB: float + @keyword wA: The chemical shift offset of state A from the spin-lock. + @type wA: float + @keyword wB: The chemical shift offset of state A from the spin-lock. + @type wB: float + @keyword w1: The spin-lock field strength in rad/s. + @type w1: float + @keyword k_AB: The forward exchange rate from state A to state B. + @type k_AB: float + @keyword k_BA: The reverse exchange rate from state B to state A. + @type k_BA: float + """ + + # The AB auto-block. + matrix[0, 0] = -r1rho_prime - k_AB + matrix[0, 1] = -wA + matrix[1, 0] = wA + matrix[1, 1] = -r1rho_prime - k_AB + matrix[1, 2] = -w1 + matrix[2, 1] = w1 + matrix[2, 2] = -R1 - k_AB + + # The BA auto-block. + matrix[3, 3] = -r1rho_prime - k_BA + matrix[3, 4] = -wB + matrix[4, 3] = wB + matrix[4, 4] = -r1rho_prime - k_BA + matrix[4, 5] = -w1 + matrix[5, 4] = w1 + matrix[5, 5] = -R1 - k_BA + + # The AB cross-block. + matrix[0, 3] = k_BA + matrix[1, 4] = k_BA + matrix[2, 5] = k_BA + matrix[3, 0] = k_AB + matrix[4, 1] = k_AB + matrix[5, 2] = k_AB + + +def rr1rho_3d_2site_rankN(R1=None, r1rho_prime=None, pA=None, pB=None, dw=None, omega=None, offset=None, w1=None, k_AB=None, k_BA=None, relax_time=None): + """Definition of the multidimensional 3D exchange matrix, of rank [NE][NS][NM][NO][ND][6][6]. + + This code originates from the funNumrho.m file from the Skrynikov & Tollinger code (the sim_all.tar file https://gna.org/support/download.php?file_id=18404 attached to https://gna.org/task/?7712#comment5). + + + @keyword R1: The longitudinal, spin-lattice relaxation rate. + @type R1: numpy float array of rank [NE][NS][NM][NO][ND] + @keyword r1rho_prime: The R1rho transverse, spin-spin relaxation rate in the absence of exchange. + @type r1rho_prime: numpy float array of rank [NE][NS][NM][NO][ND] + @keyword pA: The population of state A. + @type pA: float + @keyword pB: The population of state B. + @type pB: float + @keyword dw: The chemical exchange difference between states A and B in rad/s. + @type dw: numpy float array of rank [NS][NM][NO][ND] + @keyword omega: The chemical shift for the spin in rad/s. + @type omega: numpy float array of rank [NS][NM][NO][ND] + @keyword offset: The spin-lock offsets for the data. + @type offset: numpy float array of rank [NS][NM][NO][ND] + @keyword w1: The spin-lock field strength in rad/s. + @type w1: numpy float array of rank [NE][NS][NM][NO][ND] + @keyword k_AB: The forward exchange rate from state A to state B. + @type k_AB: float + @keyword k_BA: The reverse exchange rate from state B to state A. + @type k_BA: float + @keyword k_BA: The reverse exchange rate from state B to state A. + @type k_BA: float + @keyword relax_time: The total relaxation time period for each spin-lock field strength (in seconds). + @type relax_time: numpy float array of rank [NS][NM][NO][ND] + @return: The relaxation matrix. + @rtype: numpy float array of rank [NE][NS][NM][NO][ND][6][6] + """ + + # Wa: The chemical shift offset of state A from the spin-lock. Larmor frequency [s^-1]. + Wa = omega + # Wb: The chemical shift offset of state A from the spin-lock. Larmor frequency [s^-1]. + Wb = omega + dw + + # Population-averaged Larmor frequency [s^-1]. + W = pA*Wa + pB*Wb + + # Offset of spin-lock from A. + dA = Wa - offset + + # Offset of spin-lock from B. + dB = Wb - offset + + # Offset of spin-lock from population-average. + d = W - offset + + # Alias to original parameter name. + wA=dA + wB=dB + + m_r1rho_prime = array([ + [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, -1.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, -1.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, -1.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]) + + m_wA = array([ + [0.0, -1.0, 0.0, 0.0, 0.0, 0.0], + [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]) + + m_wB = array([ + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, -1.0, 0.0], + [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]) + + m_w1 = array([ + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, -1.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, -1.0], + [0.0, 0.0, 0.0, 0.0, 1.0, 0.0]]) + + m_k_AB = array([ + [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, -1.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, -1.0, 0.0, 0.0, 0.0], + [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0, 0.0, 0.0]]) + + m_k_BA = array([ + [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 1.0], + [0.0, 0.0, 0.0, -1.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, -1.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, -1.0]]) + + m_R1 = array([ + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, -1.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 0.0, -1.0]]) + + # Multiply and expand. + mat_r1rho_prime = multiply.outer( r1rho_prime * relax_time, m_r1rho_prime ) + + mat_wA = multiply.outer( wA * relax_time, m_wA ) + mat_wB = multiply.outer( wB * relax_time, m_wB ) + + mat_w1 = multiply.outer( w1 * relax_time, m_w1 ) + + mat_k_AB = multiply.outer( k_AB * relax_time, m_k_AB ) + mat_k_BA = multiply.outer( k_BA * relax_time, m_k_BA ) + + mat_R1 = multiply.outer( R1 * relax_time, m_R1 ) + + # Collect matrix. + matrix = (mat_r1rho_prime + mat_wA + mat_wB + + mat_w1 + mat_k_AB + mat_k_BA + + mat_R1) + + # Return the matrix. return matrix @@ -789,192 +977,4 @@ matrix[5, 8] = k_CB matrix[6, 3] = k_BC matrix[7, 4] = k_BC - matrix[8, 5] = k_BC - - -def rr1rho_3d(matrix=None, R1=None, r1rho_prime=None, pA=None, pB=None, wA=None, wB=None, w1=None, k_AB=None, k_BA=None): - """Definition of the 3D exchange matrix. - - This code originates from the funNumrho.m file from the Skrynikov & Tollinger code (the sim_all.tar file https://gna.org/support/download.php?file_id=18404 attached to https://gna.org/task/?7712#comment5). - - - @keyword matrix: The matrix to fill. - @type matrix: numpy rank-2 6D array - @keyword R1: The longitudinal, spin-lattice relaxation rate. - @type R1: float - @keyword r1rho_prime: The R1rho transverse, spin-spin relaxation rate in the absence of exchange. - @type r1rho_prime: float - @keyword pA: The population of state A. - @type pA: float - @keyword pB: The population of state B. - @type pB: float - @keyword wA: The chemical shift offset of state A from the spin-lock. - @type wA: float - @keyword wB: The chemical shift offset of state A from the spin-lock. - @type wB: float - @keyword w1: The spin-lock field strength in rad/s. - @type w1: float - @keyword k_AB: The forward exchange rate from state A to state B. - @type k_AB: float - @keyword k_BA: The reverse exchange rate from state B to state A. - @type k_BA: float - """ - - # The AB auto-block. - matrix[0, 0] = -r1rho_prime - k_AB - matrix[0, 1] = -wA - matrix[1, 0] = wA - matrix[1, 1] = -r1rho_prime - k_AB - matrix[1, 2] = -w1 - matrix[2, 1] = w1 - matrix[2, 2] = -R1 - k_AB - - # The BA auto-block. - matrix[3, 3] = -r1rho_prime - k_BA - matrix[3, 4] = -wB - matrix[4, 3] = wB - matrix[4, 4] = -r1rho_prime - k_BA - matrix[4, 5] = -w1 - matrix[5, 4] = w1 - matrix[5, 5] = -R1 - k_BA - - # The AB cross-block. - matrix[0, 3] = k_BA - matrix[1, 4] = k_BA - matrix[2, 5] = k_BA - matrix[3, 0] = k_AB - matrix[4, 1] = k_AB - matrix[5, 2] = k_AB - - -def rr1rho_3d_rankN(R1=None, r1rho_prime=None, pA=None, pB=None, dw=None, omega=None, offset=None, w1=None, k_AB=None, k_BA=None, relax_time=None): - """Definition of the multidimensional 3D exchange matrix, of rank [NE][NS][NM][NO][ND][6][6]. - - This code originates from the funNumrho.m file from the Skrynikov & Tollinger code (the sim_all.tar file https://gna.org/support/download.php?file_id=18404 attached to https://gna.org/task/?7712#comment5). - - - @keyword R1: The longitudinal, spin-lattice relaxation rate. - @type R1: numpy float array of rank [NE][NS][NM][NO][ND] - @keyword r1rho_prime: The R1rho transverse, spin-spin relaxation rate in the absence of exchange. - @type r1rho_prime: numpy float array of rank [NE][NS][NM][NO][ND] - @keyword pA: The population of state A. - @type pA: float - @keyword pB: The population of state B. - @type pB: float - @keyword dw: The chemical exchange difference between states A and B in rad/s. - @type dw: numpy float array of rank [NS][NM][NO][ND] - @keyword omega: The chemical shift for the spin in rad/s. - @type omega: numpy float array of rank [NS][NM][NO][ND] - @keyword offset: The spin-lock offsets for the data. - @type offset: numpy float array of rank [NS][NM][NO][ND] - @keyword w1: The spin-lock field strength in rad/s. - @type w1: numpy float array of rank [NE][NS][NM][NO][ND] - @keyword k_AB: The forward exchange rate from state A to state B. - @type k_AB: float - @keyword k_BA: The reverse exchange rate from state B to state A. - @type k_BA: float - @keyword k_BA: The reverse exchange rate from state B to state A. - @type k_BA: float - @keyword relax_time: The total relaxation time period for each spin-lock field strength (in seconds). - @type relax_time: numpy float array of rank [NS][NM][NO][ND] - @return: The relaxation matrix. - @rtype: numpy float array of rank [NE][NS][NM][NO][ND][6][6] - """ - - # Wa: The chemical shift offset of state A from the spin-lock. Larmor frequency [s^-1]. - Wa = omega - # Wb: The chemical shift offset of state A from the spin-lock. Larmor frequency [s^-1]. - Wb = omega + dw - - # Population-averaged Larmor frequency [s^-1]. - W = pA*Wa + pB*Wb - - # Offset of spin-lock from A. - dA = Wa - offset - - # Offset of spin-lock from B. - dB = Wb - offset - - # Offset of spin-lock from population-average. - d = W - offset - - # Alias to original parameter name. - wA=dA - wB=dB - - m_r1rho_prime = array([ - [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, -1.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, -1.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, -1.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]) - - m_wA = array([ - [0.0, -1.0, 0.0, 0.0, 0.0, 0.0], - [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]) - - m_wB = array([ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, -1.0, 0.0], - [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]) - - m_w1 = array([ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, -1.0, 0.0, 0.0, 0.0], - [0.0, 1.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, -1.0], - [0.0, 0.0, 0.0, 0.0, 1.0, 0.0]]) - - m_k_AB = array([ - [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, -1.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, -1.0, 0.0, 0.0, 0.0], - [1.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 1.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 1.0, 0.0, 0.0, 0.0]]) - - m_k_BA = array([ - [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 1.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 1.0], - [0.0, 0.0, 0.0, -1.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, -1.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, -1.0]]) - - m_R1 = array([ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, -1.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, -1.0]]) - - # Multiply and expand. - mat_r1rho_prime = multiply.outer( r1rho_prime * relax_time, m_r1rho_prime ) - - mat_wA = multiply.outer( wA * relax_time, m_wA ) - mat_wB = multiply.outer( wB * relax_time, m_wB ) - - mat_w1 = multiply.outer( w1 * relax_time, m_w1 ) - - mat_k_AB = multiply.outer( k_AB * relax_time, m_k_AB ) - mat_k_BA = multiply.outer( k_BA * relax_time, m_k_BA ) - - mat_R1 = multiply.outer( R1 * relax_time, m_R1 ) - - # Collect matrix. - matrix = (mat_r1rho_prime + mat_wA + mat_wB - + mat_w1 + mat_k_AB + mat_k_BA - + mat_R1) - - # Return the matrix. - return matrix + matrix[8, 5] = k_BC Modified: branches/disp_spin_speed/lib/dispersion/ns_r1rho_2site.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/ns_r1rho_2site.py?rev=24217&r1=24216&r2=24217&view=diff ============================================================================== --- branches/disp_spin_speed/lib/dispersion/ns_r1rho_2site.py (original) +++ branches/disp_spin_speed/lib/dispersion/ns_r1rho_2site.py Fri Jun 20 19:13:14 2014 @@ -54,7 +54,7 @@ from numpy import dot, sum # relax module imports. -from lib.dispersion.ns_matrices import rr1rho_3d, rr1rho_3d_rankN +from lib.dispersion.ns_matrices import rr1rho_3d_2site_rankN from lib.float import isNaN from lib.linear_algebra.matrix_exponential import matrix_exponential, matrix_exponential_rankN @@ -102,7 +102,7 @@ NE, NS, NM, NO = num_points.shape # The matrix that contains all the contributions to the evolution, i.e. relaxation, exchange and chemical shift evolution. - R_mat = rr1rho_3d_rankN(R1=r1, r1rho_prime=r1rho_prime, pA=pA, pB=pB, dw=dw, omega=omega, offset=offset, w1=spin_lock_fields, k_AB=k_AB, k_BA=k_BA, relax_time=relax_time) + R_mat = rr1rho_3d_2site_rankN(R1=r1, r1rho_prime=r1rho_prime, pA=pA, pB=pB, dw=dw, omega=omega, offset=offset, w1=spin_lock_fields, k_AB=k_AB, k_BA=k_BA, relax_time=relax_time) # This matrix is a propagator that will evolve the magnetization with the matrix R. Rexpo_mat = matrix_exponential_rankN(R_mat)