Author: tlinnet Date: Fri Jun 20 19:13:16 2014 New Revision: 24218 URL: http://svn.gna.org/viewcvs/relax?rev=24218&view=rev Log: Implemented multidimensional r1rho 3d 3site 3D exchange matrix. 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 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=24218&r1=24217&r2=24218&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:16 2014 @@ -977,4 +977,288 @@ matrix[5, 8] = k_CB matrix[6, 3] = k_BC matrix[7, 4] = k_BC - matrix[8, 5] = k_BC + matrix[8, 5] = k_BC + + +def rr1rho_3d_3site_rankN(R1=None, r1rho_prime=None, pA=None, pB=None, pC=None, dw_AB=None, dw_AC=None, omega=None, offset=None, w1=None, k_AB=None, k_BA=None, k_BC=None, k_CB=None, k_AC=None, k_CA=None, relax_time=None): + """Definition of the 3D exchange matrix. + + @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 pC: The population of state C. + @type pC: float + @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 [NE][NS][NM][NO][ND] + @keyword dw_AB: The chemical exchange difference between states A and B in rad/s. + @type dw_AB: numpy float array of rank [NE][NS][NM][NO][ND] + @keyword dw_AC: The chemical exchange difference between states A and C in rad/s. + @type dw_AC: numpy float array of rank [NE][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_BC: The forward exchange rate from state B to state C. + @type k_BC: float + @keyword k_CB: The reverse exchange rate from state C to state B. + @type k_CB: float + @keyword k_AC: The forward exchange rate from state A to state C. + @type k_AC: float + @keyword k_CA: The reverse exchange rate from state C to state A. + @type k_CA: 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 [NE][NS][NM][NO][ND] + """ + + # The AB auto-block. + #matrix[0, 0] = -r1rho_prime - k_AB - k_AC + #matrix[0, 1] = -wA + #matrix[1, 0] = wA + #matrix[1, 1] = -r1rho_prime - k_AB - k_AC + #matrix[1, 2] = -w1 + #matrix[2, 1] = w1 + #matrix[2, 2] = -R1 - k_AB - k_AC + + # The AC auto-block. + #matrix[3, 3] = -r1rho_prime - k_BA - k_BC + #matrix[3, 4] = -wB + #matrix[4, 3] = wB + #matrix[4, 4] = -r1rho_prime - k_BA - k_BC + #matrix[4, 5] = -w1 + #matrix[5, 4] = w1 + #matrix[5, 5] = -R1 - k_BA - k_BC + + # The BC auto-block. + #matrix[6, 6] = -r1rho_prime - k_CA - k_CB + #matrix[6, 7] = -wC + #matrix[7, 6] = wC + #matrix[7, 7] = -r1rho_prime - k_CA - k_CB + #matrix[7, 8] = -w1 + #matrix[8, 7] = w1 + #matrix[8, 8] = -R1 - k_CA - k_CB + + # 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 + + # The AC cross-block. + #matrix[0, 6] = k_CA + #matrix[1, 7] = k_CA + #matrix[2, 8] = k_CA + #matrix[6, 0] = k_AC + #matrix[7, 1] = k_AC + #matrix[8, 2] = k_AC + + # The BC cross-block. + #matrix[3, 6] = k_CB + #matrix[4, 7] = k_CB + #matrix[5, 8] = k_CB + #matrix[6, 3] = k_BC + #matrix[7, 4] = k_BC + #matrix[8, 5] = k_BC + + #m_x = 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, 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.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]]) + + # Repetitive calculations (to speed up calculations). + # The chemical shift offset of state A from the spin-lock. Larmor frequency for state A [s^-1]. + Wa = omega + # The chemical shift offset of state B from the spin-lock. Larmor frequency for state B [s^-1]. + Wb = omega + dw_AB + # The chemical shift offset of state C from the spin-lock. Larmor frequency for state C [s^-1]. + Wc = omega + dw_AC + + # Population-averaged Larmor frequency [s^-1]. + #W = pA*Wa + pB*Wb + pC*Wc + # Offset of spin-lock from A. + dA = Wa - offset + # Offset of spin-lock from B. + dB = Wb - offset + # Offset of spin-lock from C. + dC = Wc - offset + # Offset of spin-lock from population-average + #d = W - offset_i + + # Parameter alias. + wA=dA + wB=dB + wC=dC + + 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, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.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0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0]]) + + m_k_AC = array([ + [-1.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, -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, 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, 1.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]]) + + m_k_CA = array([ + [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, 1.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, 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, -1.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_R1 = multiply.outer( R1 * relax_time, m_R1 ) + 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_wC = multiply.outer( wC * relax_time, m_wC ) + 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_k_BC = multiply.outer( k_BC * relax_time, m_k_BC ) + + mat_k_CB = multiply.outer( k_CB * relax_time, m_k_CB ) + mat_k_AC = multiply.outer( k_AC * relax_time, m_k_AC ) + mat_k_CA = multiply.outer( k_CA * relax_time, m_k_CA ) + + # Collect matrix. + matrix = (mat_R1 + mat_r1rho_prime + + mat_wA + mat_wB + mat_wC + mat_w1 + + mat_k_AB + mat_k_BA + mat_k_BC + + mat_k_CB + mat_k_AC + mat_k_CA ) + + # Return the matrix. + return matrix