Author: tlinnet Date: Tue Jun 17 14:53:49 2014 New Revision: 24033 URL: http://svn.gna.org/viewcvs/relax?rev=24033&view=rev Log: More fixes for numpy index in lib functions. 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_cpmg_2site_3d.py branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_star.py branches/disp_spin_speed/lib/dispersion/ns_mmq_2site.py Modified: branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py?rev=24033&r1=24032&r2=24033&view=diff ============================================================================== --- branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py (original) +++ branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py Tue Jun 17 14:53:49 2014 @@ -133,10 +133,10 @@ for mi in range(NM): # Extract the values from the higher dimensional arrays. - R2A_si_mi=r20a[0][si][mi][0][0] - R2B_si_mi=r20b[0][si][mi][0][0] - dw_si_mi = dw[0][si][mi][0][0] - num_points_si_mi = int(num_points[0][si][mi][0]) + R2A_si_mi=r20a[0, si, mi, 0, 0] + R2B_si_mi=r20b[0, si, mi, 0, 0] + dw_si_mi = dw[0, si, mi, 0, 0] + num_points_si_mi = int(num_points[0, si, mi, 0]) # The matrix R that contains all the contributions to the evolution, i.e. relaxation, exchange and chemical shift evolution. R = rcpmg_3d(R1A=r10a, R1B=r10b, R2A=R2A_si_mi, R2B=R2B_si_mi, pA=pA, pB=pB, dw=dw_si_mi, k_AB=k_AB, k_BA=k_BA) @@ -144,10 +144,10 @@ # Loop over the time points, back calculating the R2eff values. for di in range(num_points_si_mi): # Extract the values from the higher dimensional arrays. - tcp_si_mi_di = tcp[0][si][mi][0][di] - inv_tcpmg_si_mi_di = inv_tcpmg[0][si][mi][0][di] - power_si_mi_di = int(power[0][si][mi][0][di]) - r20a_si_mi_di = r20a[0][si][mi][0][di] + tcp_si_mi_di = tcp[0, si, mi, 0, di] + inv_tcpmg_si_mi_di = inv_tcpmg[0, si, mi, 0, di] + power_si_mi_di = int(power[0, si, mi, 0, di]) + r20a_si_mi_di = r20a[0, si, mi, 0, di] # Initial magnetisation. Mint = M0 @@ -169,9 +169,9 @@ # The next lines calculate the R2eff using a two-point approximation, i.e. assuming that the decay is mono-exponential. Mx = Mint[1] / pA if Mx <= 0.0 or isNaN(Mx): - back_calc[0][si][mi][0][di] = r20a_si_mi_di + back_calc[0, si, mi, 0, di] = r20a_si_mi_di else: - back_calc[0][si][mi][0][di] = - inv_tcpmg_si_mi_di * log(Mx) + back_calc[0, si, mi, 0, di] = - inv_tcpmg_si_mi_di * log(Mx) # Replace data in array. # If dw is zero. Modified: branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_star.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_star.py?rev=24033&r1=24032&r2=24033&view=diff ============================================================================== --- branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_star.py (original) +++ branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_star.py Tue Jun 17 14:53:49 2014 @@ -142,10 +142,10 @@ for mi in range(NM): # Extract the values from the higher dimensional arrays. - R2A_si_mi=r20a[0][si][mi][0][0] - R2B_si_mi=r20b[0][si][mi][0][0] - dw_si_mi = dw[0][si][mi][0][0] - num_points_si_mi = int(num_points[0][si][mi][0]) + R2A_si_mi=r20a[0, si, mi, 0, 0] + R2B_si_mi=r20b[0, si, mi, 0, 0] + dw_si_mi = dw[0, si, mi, 0, 0] + num_points_si_mi = int(num_points[0, si, mi, 0]) # The matrix that contains only the R2 relaxation terms ("Redfield relaxation", i.e. non-exchange broadening). Rr[0, 0] = -R2A_si_mi @@ -164,10 +164,10 @@ # Loop over the time points, back calculating the R2eff values. for di in range(num_points_si_mi): # Extract the values from the higher dimensional arrays. - tcp_si_mi_di = tcp[0][si][mi][0][di] - inv_tcpmg_si_mi_di = inv_tcpmg[0][si][mi][0][di] - power_si_mi_di = int(power[0][si][mi][0][di]) - r20a_si_mi_di = r20a[0][si][mi][0][di] + tcp_si_mi_di = tcp[0, si, mi, 0, di] + inv_tcpmg_si_mi_di = inv_tcpmg[0, si, mi, 0, di] + power_si_mi_di = int(power[0, si, mi, 0, di]) + r20a_si_mi_di = r20a[0, si, mi, 0, di] # This matrix is a propagator that will evolve the magnetization with the matrix R for a delay tcp. eR_tcp = matrix_exponential(R*tcp_si_mi_di) @@ -184,9 +184,9 @@ # The next lines calculate the R2eff using a two-point approximation, i.e. assuming that the decay is mono-exponential. Mx = Moft[0].real / M0[0] if Mx <= 0.0 or isNaN(Mx): - back_calc[0][si][mi][0][di] = 1e99 + back_calc[0, si, mi, 0, di] = 1e99 else: - back_calc[0][si][mi][0][di]= -inv_tcpmg_si_mi_di * log(Mx) + back_calc[0, si, mi, 0, di]= -inv_tcpmg_si_mi_di * log(Mx) # Replace data in array. # If dw is zero. Modified: branches/disp_spin_speed/lib/dispersion/ns_mmq_2site.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/ns_mmq_2site.py?rev=24033&r1=24032&r2=24033&view=diff ============================================================================== --- branches/disp_spin_speed/lib/dispersion/ns_mmq_2site.py (original) +++ branches/disp_spin_speed/lib/dispersion/ns_mmq_2site.py Tue Jun 17 14:53:49 2014 @@ -142,11 +142,11 @@ # Loop over offsets: for oi in range(NO): - r20a_si_mi_oi = R20A[si][mi][oi][0] - r20b_si_mi_oi = R20B[si][mi][oi][0] - dw_si_mi_oi = dw[si][mi][oi][0] - dwH_si_mi_oi = dwH[si][mi][oi][0] - num_points_si_mi_oi = num_points[si][mi][oi] + r20a_si_mi_oi = R20A[si, mi, oi, 0] + r20b_si_mi_oi = R20B[si, mi, oi, 0] + dw_si_mi_oi = dw[si, mi, oi, 0] + dwH_si_mi_oi = dwH[si, mi, oi, 0] + num_points_si_mi_oi = num_points[si, mi, oi] # Populate the m1 and m2 matrices (only once per function call for speed). populate_matrix(matrix=m1, R20A=r20a_si_mi_oi, R20B=r20b_si_mi_oi, dw=-dw_si_mi_oi - dwH_si_mi_oi, k_AB=k_AB, k_BA=k_BA) # D+ matrix component. @@ -155,8 +155,8 @@ # Loop over the time points, back calculating the R2eff values. for i in range(num_points_si_mi_oi): # The M1 and M2 matrices. - M1 = matrix_exponential(m1*tcp[si][mi][oi][i]) # Equivalent to D+. - M2 = matrix_exponential(m2*tcp[si][mi][oi][i]) # Equivalent to Z-. + M1 = matrix_exponential(m1*tcp[si, mi, oi, i]) # Equivalent to D+. + M2 = matrix_exponential(m2*tcp[si, mi, oi, i]) # Equivalent to Z-. # The complex conjugates M1* and M2* M1_star = conj(M1) # Equivalent to D+*. @@ -173,7 +173,7 @@ M2_M1_M1_M2_star = dot(M2_M1_star, M1_M2_star) # Special case of 1 CPMG block - the power is zero. - if power[si][mi][oi][i] == 1: + if power[si, mi, oi, i] == 1: # M1.M2. A = M1_M2 @@ -187,9 +187,9 @@ D = M2_M1_star # Matrices for even number of CPMG blocks. - elif power[si][mi][oi][i] % 2 == 0: + elif power[si, mi, oi, i] % 2 == 0: # The power factor (only calculate once). - fact = int(floor(power[si][mi][oi][i] / 2)) + fact = int(floor(power[si, mi, oi, i] / 2)) # (M1.M2.M2.M1)^(n/2). A = square_matrix_power(M1_M2_M2_M1, fact) @@ -206,7 +206,7 @@ # Matrices for odd number of CPMG blocks. else: # The power factor (only calculate once). - fact = int(floor((power[si][mi][oi][i] - 1) / 2)) + fact = int(floor((power[si, mi, oi, i] - 1) / 2)) # (M1.M2.M2.M1)^((n-1)/2).M1.M2. A = square_matrix_power(M1_M2_M2_M1, fact) @@ -230,9 +230,9 @@ Mx = dot(dot(F_vector, (A_B + C_D)), M0) Mx = Mx.real / 2.0 if Mx <= 0.0 or isNaN(Mx): - back_calc[si][mi][oi][i] = 1e99 + back_calc[si, mi, oi, i] = 1e99 else: - back_calc[si][mi][oi][i]= -inv_tcpmg[si][mi][oi][i] * log(Mx / pA) + back_calc[si, mi, oi, i]= -inv_tcpmg[si, mi, oi, i] * log(Mx / pA) def r2eff_ns_mmq_2site_sq_dq_zq(M0=None, F_vector=array([1, 0], float64), m1=None, m2=None, R20A=None, R20B=None, pA=None, pB=None, dw=None, dwH=None, k_AB=None, k_BA=None, inv_tcpmg=None, tcp=None, back_calc=None, num_points=None, power=None): @@ -292,10 +292,10 @@ # Loop over offsets: for oi in range(NO): - r20a_si_mi_oi = R20A[si][mi][oi][0] - r20b_si_mi_oi = R20B[si][mi][oi][0] - dw_si_mi_oi = dw[si][mi][oi][0] - num_points_si_mi_oi = num_points[si][mi][oi] + r20a_si_mi_oi = R20A[si, mi, oi, 0] + r20b_si_mi_oi = R20B[si, mi, oi, 0] + dw_si_mi_oi = dw[si, mi, oi, 0] + num_points_si_mi_oi = num_points[si, mi, oi] # Populate the m1 and m2 matrices (only once per function call for speed). populate_matrix(matrix=m1, R20A=r20a_si_mi_oi , R20B=r20b_si_mi_oi, dw=dw_si_mi_oi, k_AB=k_AB, k_BA=k_BA) @@ -304,19 +304,19 @@ # Loop over the time points, back calculating the R2eff values. for i in range(num_points_si_mi_oi): # The A+/- matrices. - A_pos = matrix_exponential(m1*tcp[si][mi][oi][i]) - A_neg = matrix_exponential(m2*tcp[si][mi][oi][i]) + A_pos = matrix_exponential(m1*tcp[si, mi, oi, i]) + A_neg = matrix_exponential(m2*tcp[si, mi, oi, i]) # The evolution for one n. evol_block = dot(A_pos, dot(A_neg, dot(A_neg, A_pos))) # The full evolution. - evol = square_matrix_power(evol_block, power[si][mi][oi][i]) + evol = square_matrix_power(evol_block, power[si, mi, oi, i]) # The next lines calculate the R2eff using a two-point approximation, i.e. assuming that the decay is mono-exponential. Mx = dot(F_vector, dot(evol, M0)) Mx = Mx.real if Mx <= 0.0 or isNaN(Mx): - back_calc[si][mi][oi][i] = 1e99 + back_calc[si, mi, oi, i] = 1e99 else: - back_calc[si][mi][oi][i] = -inv_tcpmg[si][mi][oi][i] * log(Mx / pA) + back_calc[si, mi, oi, i] = -inv_tcpmg[si, mi, oi, i] * log(Mx / pA)