Author: tlinnet Date: Sun Jun 15 15:15:19 2014 New Revision: 23961 URL: http://svn.gna.org/viewcvs/relax?rev=23961&view=rev Log: Changed the target function of NS CPMG 2site STAR, to reflect the input to the function. Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion models for Clustered analysis. Modified: branches/disp_spin_speed/target_functions/relax_disp.py 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=23961&r1=23960&r2=23961&view=diff ============================================================================== --- branches/disp_spin_speed/target_functions/relax_disp.py (original) +++ branches/disp_spin_speed/target_functions/relax_disp.py Sun Jun 15 15:15:19 2014 @@ -396,7 +396,7 @@ # Setup special numpy array structures, for higher dimensional computation. - test_models = [MODEL_B14, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NS_CPMG_2SITE_3D, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_TAP03, MODEL_TP02, MODEL_TSMFK01] + test_models = [MODEL_B14, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NS_CPMG_2SITE_3D, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_STAR, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_TAP03, MODEL_TP02, MODEL_TSMFK01] if model in test_models + [MODEL_NOREX]: # Get the shape of back_calc structure. @@ -666,47 +666,26 @@ @rtype: float """ - # Once off parameter conversions. - pB = 1.0 - pA - k_BA = pA * kex - k_AB = pB * kex - - # Set up the matrix that contains the exchange terms between the two states A and B. - self.Rex[0, 0] = -k_AB - self.Rex[0, 1] = k_BA - self.Rex[1, 0] = k_AB - self.Rex[1, 1] = -k_BA - - # This is a vector that contains the initial magnetizations corresponding to the A and B state transverse magnetizations. - self.M0[0] = pA - self.M0[1] = pB - - # Chi-squared initialisation. - chi2_sum = 0.0 - - # Loop over the spins. - for si in range(self.num_spins): - # Loop over the spectrometer frequencies. - for mi in range(self.num_frq): - # The R20 index. - r20_index = mi + si*self.num_frq - - # Convert dw from ppm to rad/s. - dw_frq = dw[si] * self.frqs[0][si][mi] - - # Back calculate the R2eff values. - r2eff_ns_cpmg_2site_star(Rr=self.Rr, Rex=self.Rex, RCS=self.RCS, R=self.R, M0=self.M0, r20a=R20A[r20_index], r20b=R20B[r20_index], dw=dw_frq, inv_tcpmg=self.inv_relax_times[0][mi], tcp=self.tau_cpmg[0][mi], back_calc=self.back_calc[0][si][mi][0], num_points=self.num_disp_points[0][si][mi][0], power=self.power[0][mi]) - - # For all missing data points, set the back-calculated value to the measured values so that it has no effect on the chi-squared value. - for di in range(self.num_disp_points[0][si][mi][0]): - if self.missing[0][si][mi][0][di]: - self.back_calc[0][si][mi][0][di] = self.values[0][si][mi][0][di] - - # Calculate and return the chi-squared value. - chi2_sum += chi2(self.values[0][si][mi][0], self.back_calc[0][si][mi][0], self.errors[0][si][mi][0]) - - # Return the total chi-squared value. - return chi2_sum + # Convert dw from ppm to rad/s. Use the out argument, to pass directly to structure. + multiply( multiply.outer( dw.reshape(self.NE, self.NS), self.nm_no_nd_struct ), self.frqs_a, out=self.dw_struct ) + + # Reshape R20A and R20B to per experiment, spin and frequency. + self.r20a_struct[:] = multiply.outer( R20A.reshape(self.NE, self.NS, self.NM), self.no_nd_struct ) + self.r20b_struct[:] = multiply.outer( R20B.reshape(self.NE, self.NS, self.NM), self.no_nd_struct ) + + # Back calculate the R2eff values. + r2eff_ns_cpmg_2site_star(Rr=self.Rr, Rex=self.Rex, RCS=self.RCS, R=self.R, M0=self.M0, r20a=self.r20a_struct, r20b=self.r20b_struct, pA=pA, dw=self.dw_struct, dw_orig=dw, kex=kex, inv_tcpmg=self.inv_relax_times_a, tcp=self.tau_cpmg_a, back_calc=self.back_calc_a, num_points=self.num_disp_points_a, power=self.power_a) + + # Clean the data for all values, which is left over at the end of arrays. + self.back_calc_a = self.back_calc_a*self.disp_struct + + ## For all missing data points, set the back-calculated value to the measured values so that it has no effect on the chi-squared value. + if self.has_missing: + # Replace with values. + self.back_calc_a[self.mask_replace_blank.mask] = self.values_a[self.mask_replace_blank.mask] + + ## Calculate the chi-squared statistic. + return chi2_rankN(self.values_a, self.back_calc_a, self.errors_a) def calc_ns_mmq_3site_chi2(self, R20A=None, R20B=None, R20C=None, dw_AB=None, dw_BC=None, dwH_AB=None, dwH_BC=None, pA=None, pB=None, kex_AB=None, kex_BC=None, kex_AC=None):