Author: tlinnet Date: Tue Jun 24 16:35:05 2014 New Revision: 24287 URL: http://svn.gna.org/viewcvs/relax?rev=24287&view=rev Log: Speeded up ns r1rho 3site, by preforming the evolution matrices, and the M0 matrix in the init part of the target function. 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_r1rho_3site.py branches/disp_spin_speed/target_functions/relax_disp.py Modified: branches/disp_spin_speed/lib/dispersion/ns_r1rho_3site.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/ns_r1rho_3site.py?rev=24287&r1=24286&r2=24287&view=diff ============================================================================== --- branches/disp_spin_speed/lib/dispersion/ns_r1rho_3site.py (original) +++ branches/disp_spin_speed/lib/dispersion/ns_r1rho_3site.py Tue Jun 24 16:35:05 2014 @@ -57,7 +57,7 @@ # Python module imports. from math import atan2 -from numpy import array, cos, dot, float64, log, multiply, sin, sum +from numpy import array, cos, dot, einsum, float64, log, multiply, sin, sum # relax module imports. from lib.float import isNaN @@ -396,6 +396,9 @@ # This matrix is a propagator that will evolve the magnetization with the matrix R. Rexpo_mat = matrix_exponential_rank_NE_NS_NM_NO_ND_x_x(R_mat) + # Magnetization evolution. + Rexpo_M0_mat = einsum('...ij,...jk', Rexpo_mat, M0) + # Loop over spins. for si in range(NS): # Loop over the spectrometer frequencies. @@ -407,19 +410,17 @@ # Loop over the time points, back calculating the R2eff values. for j in range(num_points_i): - # Offset of spin-lock from A. - dA = omega[0, si, mi, oi, j] - offset[0, si, mi, oi, j] - - # The following lines rotate the magnetization previous to spin-lock into the weff frame. - theta = atan2(spin_lock_fields[0, si, mi, oi, j], dA) - M0[0] = sin(theta) # The A state initial X magnetisation. - M0[2] = cos(theta) # The A state initial Z magnetisation. + # Extract the preformed matrix that rotate the magnetization previous to spin-lock into the weff frame. + M0_i= M0[0, si, mi, oi, j, :, 0] # This matrix is a propagator that will evolve the magnetization with the matrix R. - Rexpo_j = Rexpo_mat[0, si, mi, oi, j] + Rexpo_i = Rexpo_mat[0, si, mi, oi, j] + + # Extract from the pre-formed Magnetization evolution matrix. + Rexpo_M0_mat_i = Rexpo_M0_mat[0, si, mi, oi, j, :, 0] # Magnetization evolution. - MA = dot(M0, dot(Rexpo_j, M0)) + MA = dot(M0_i, Rexpo_M0_mat_i) # The next lines calculate the R1rho using a two-point approximation, i.e. assuming that the decay is mono-exponential. if MA <= 0.0 or isNaN(MA): Modified: branches/disp_spin_speed/target_functions/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/target_functions/relax_disp.py?rev=24287&r1=24286&r2=24287&view=diff ============================================================================== --- branches/disp_spin_speed/target_functions/relax_disp.py (original) +++ branches/disp_spin_speed/target_functions/relax_disp.py Tue Jun 24 16:35:05 2014 @@ -417,6 +417,19 @@ self.M0 = M0_sin + M0_cos if model in [MODEL_NS_R1RHO_3SITE, MODEL_NS_R1RHO_3SITE_LINEAR]: self.M0 = zeros(9, float64) + # Offset of spin-lock from A. + da_mat = self.chemical_shifts - self.offset + # The following lines rotate the magnetization previous to spin-lock into the weff frame. + theta_mat = arctan2(self.spin_lock_omega1, da_mat) + M0_0 = zeros([9, 1], float64) + M0_0[0, 0] = 1 + # The A state initial X magnetisation. + M0_sin = multiply.outer( sin(theta_mat), M0_0 ) + M0_2 = zeros([9, 1], float64) + M0_2[2, 0] = 1 + # The A state initial Z magnetisation. + M0_cos = multiply.outer( cos(theta_mat), M0_2 ) + self.M0 = M0_sin + M0_cos # Set up the model. if model == MODEL_NOREX: