def calc_intraComponentFZ(Q, fe_Q, Ztot, QmaxIntegrate, maxQ, elementList, element, \ x, y, z, elementParameters, damping_factor, aff_mean_squared): """Function to calculate the intra-molecular components. Parameters ---------- Q : numpy array momentum transfer (nm^-1) fe_Q : numpy array effective electric form factor Ztot : int total Z number QmaxIntegrate : float maximum Q value for the intagrations maxQ : float maximum Q value elementList : dictionary("element": multiplicity) chemical elements of the sample with their multiplicity element : string chemical element multiplicity : int chemical element multiplicity element : string array array with the elements in the xyz_file x, y, z : float array atomic coordinate in the xyz_file (nm) elementParameters : dictionary("element": parameters) chemical elements of the sample with their parameters element : string chemical element parameters : list list of the parameters (Z, a1, b1, a2, b2, a3, b3, a4, b4, c, M, K, L) damping_factor : float damp factor Returns ------- r : numpy array atomic distance (nm) Fintra_r : numpy array intramolecular contribution of F(r) """ iintra_Q = calc_iintraFZ(Q, QmaxIntegrate, maxQ, elementList, element, x, y, z, elementParameters, aff_mean_squared) iintradamp_Q = UtilityAnalysis.calc_iintradamp(iintra_Q, Q, QmaxIntegrate, damping_factor) r = MainFunctions.calc_r(Q) Fintra_r = MainFunctions.calc_Fr(r, Q[Q <= QmaxIntegrate], iintradamp_Q[Q <= QmaxIntegrate]) return (r, iintradamp_Q, Fintra_r)
def Optimization(self): """Function to optimize and plot F(r)""" #-------------------Intra-molecular components----------------------------- # numAtoms, element, x, y, z = Utility.read_xyz_file(self.XYZFilePath) numAtoms, element, x, y, z = Utility.read_xyz_file( "/Users/ciccio/work/ID27/LASDiA/xyzFiles/Ar.xyz") iintra_Q = Optimization.calc_iintra(self.Q, self.fe_Q, self.Ztot, self.ui.QmaxIntegrate.value(), self.ui.maxQ.value(), self.elementList, element, x, y, z, self.elementParameters) iintradamp_Q = UtilityAnalysis.calc_iintradamp(iintra_Q, self.dampingFunct) Qiintradamp_Q = self.Q * iintradamp_Q rintra, Fintra_r = MainFunctions.calc_Fr( self.Q[self.Q <= self.ui.QmaxIntegrate.value()], Qiintradamp_Q[self.Q <= self.ui.QmaxIntegrate.value()]) scaleFactor = self.ui.scaleFactorValue.value() density0 = self.ui.densityValue.value() # ----------------------First scale minimization--------------------------- scaleStep = 0.05 # sth = 0.008 # s0th = 0.006 sth = 0.0 s0th = 0.0 phi_matrix = 0.0 thickness_sampling = 0.0 scaleFactor = Minimization.OptimizeScale( self.Q, self.I_Q, self.Ibkg_Q, self.J_Q, self.Iincoh_Q, self.fe_Q, self.ui.maxQ.value(), self.ui.minQ.value(), self.ui.QmaxIntegrate.value(), self.Ztot, density0, scaleFactor, self.Sinf, self.ui.smoothingFactor.value(), self.ui.rmin.value(), self.dampingFunct, Fintra_r, self.ui.iterations.value(), scaleStep, sth, s0th, thickness_sampling, phi_matrix, "n") # ----------------------First density minimization------------------------- densityStep = density0 / 50 densityStepEnd = density0 / 250 density = Minimization.OptimizeDensity( self.Q, self.I_Q, self.Ibkg_Q, self.J_Q, self.Iincoh_Q, self.fe_Q, self.ui.maxQ.value(), self.ui.minQ.value(), self.ui.QmaxIntegrate.value(), self.Ztot, density0, scaleFactor, self.Sinf, self.ui.smoothingFactor.value(), self.ui.rmin.value(), self.dampingFunct, Fintra_r, self.ui.iterations.value(), densityStep, densityStepEnd, sth, s0th, thickness_sampling, phi_matrix, "n") # print("density0, density", density0, density) numLoopIteration = 0 while 1: if np.abs(density - density0) > density / 25: # print("First") scaleStep = 0.006 densityStep = density / 10 WSamplestep = 0.0008 WRefstep = 0.0008 elif np.abs(density - density0) > density / 75: # print("Second") scaleStep = 0.0006 densityStep = density / 100 WSamplestep = 0.0002 WRefstep = 0.0002 else: # print("Third") scaleStep = 0.00006 densityStep = density / 1000 WSamplestep = 0.0001 WRefstep = 0.0001 scaleFactor = Minimization.OptimizeScale( self.Q, self.I_Q, self.Ibkg_Q, self.J_Q, self.Iincoh_Q, self.fe_Q, self.ui.maxQ.value(), self.ui.minQ.value(), self.ui.QmaxIntegrate.value(), self.Ztot, density, scaleFactor, self.Sinf, self.ui.smoothingFactor.value(), self.ui.rmin.value(), self.dampingFunct, Fintra_r, self.ui.iterations.value(), scaleStep, sth, s0th, thickness_sampling, phi_matrix, "n") density0 = density density = Minimization.OptimizeDensity( self.Q, self.I_Q, self.Ibkg_Q, self.J_Q, self.Iincoh_Q, self.fe_Q, self.ui.maxQ.value(), self.ui.minQ.value(), self.ui.QmaxIntegrate.value(), self.Ztot, density0, scaleFactor, self.Sinf, self.ui.smoothingFactor.value(), self.ui.rmin.value(), self.dampingFunct, Fintra_r, self.ui.iterations.value(), densityStep, density / 250, sth, s0th, thickness_sampling, phi_matrix, "n") numLoopIteration += 1 # print("numLoopIteration", numLoopIteration, scaleFactor, density) if (np.abs(density - density0) > np.abs( density / 2500)) and (numLoopIteration <= 30): continue else: break # print("final scale", scaleFactor, "final density", density) self.ui.scaleFactorValue.setValue(scaleFactor) self.ui.densityValue.setValue(density) Isample_Q = MainFunctions.calc_IsampleQ(self.I_Q, scaleFactor, self.Ibkg_Q) alpha = MainFunctions.calc_alpha( self.J_Q[self.Q <= self.ui.QmaxIntegrate.value()], self.Sinf, self.Q[self.Q <= self.ui.QmaxIntegrate.value()], Isample_Q[self.Q <= self.ui.QmaxIntegrate.value()], self.fe_Q[self.Q <= self.ui.QmaxIntegrate.value()], self.Ztot, density) Icoh_Q = MainFunctions.calc_Icoh(alpha, Isample_Q, self.Iincoh_Q) S_Q = MainFunctions.calc_SQ(Icoh_Q, self.Ztot, self.fe_Q, self.Sinf, self.Q, self.ui.minQ.value(), self.ui.QmaxIntegrate.value(), self.ui.maxQ.value()) Ssmooth_Q = UtilityAnalysis.calc_SQsmoothing( self.Q, S_Q, self.Sinf, self.ui.smoothingFactor.value(), self.ui.minQ.value(), self.ui.QmaxIntegrate.value(), self.ui.maxQ.value()) SsmoothDamp_Q = UtilityAnalysis.calc_SQdamp(Ssmooth_Q, self.Sinf, self.dampingFunct) i_Q = MainFunctions.calc_iQ(SsmoothDamp_Q, self.Sinf) Qi_Q = self.Q * i_Q r, F_r = MainFunctions.calc_Fr( self.Q[self.Q <= self.ui.QmaxIntegrate.value()], Qi_Q[self.Q <= self.ui.QmaxIntegrate.value()]) Fopt_r, deltaFopt_r = Optimization.calc_optimize_Fr( self.ui.iterations.value(), F_r, Fintra_r, density, i_Q[self.Q <= self.ui.QmaxIntegrate.value()], self.Q[self.Q <= self.ui.QmaxIntegrate.value()], self.Sinf, self.J_Q[self.Q <= self.ui.QmaxIntegrate.value()], r, self.ui.rmin.value(), "n") Scorr_Q = MainFunctions.calc_SQCorr(Fopt_r, r, self.Q, self.Sinf) self.ui.distfuncPlot.canvas.ax.plot(r, Fopt_r, "g", label=r"$F_{opt}(r)$") self.ui.distfuncPlot.canvas.ax.legend() self.ui.distfuncPlot.canvas.draw() self.ui.factorPlot.canvas.ax.plot(self.Q, Scorr_Q, "g", label=r"$S_{opt}(Q)$") self.ui.factorPlot.canvas.ax.legend() self.ui.factorPlot.canvas.draw()
fe_Q, Ztot = MainFunctions.calc_eeff(elementList, Q, elementParameters) Iincoh_Q = MainFunctions.calc_Iincoh(elementList, Q, elementParameters) J_Q = MainFunctions.calc_JQ(Iincoh_Q, Ztot, fe_Q) Sinf = MainFunctions.calc_Sinf(elementList, fe_Q, Q, Ztot, elementParameters) dampingFunction = UtilityAnalysis.calc_dampingFunction( Q, variables.dampingFactor, variables.QmaxIntegrate, variables.typeFunction) # ------------------Intra-molecular components----------------------------- iintra_Q = Optimization.calc_iintra(Q, fe_Q, Ztot, variables.QmaxIntegrate, variables.maxQ, elementList, element, x, y, z, elementParameters) iintradamp_Q = UtilityAnalysis.calc_iintradamp(iintra_Q, dampingFunction) Qiintradamp_Q = Q * iintradamp_Q rintra, Fintra_r = MainFunctions.calc_Fr( Q[Q <= variables.QmaxIntegrate], Qiintradamp_Q[Q <= variables.QmaxIntegrate]) # _, Fintra_r = UtilityAnalysis.rebinning(rintra, Fintra_r, np.amin(Fintra_r), # np.amax(Fintra_r), 8192) # _, dampingFunction = UtilityAnalysis.rebinning(Q, dampingFunction, 0.0, # variables.maxQ, variables.NumPoints) # ---------------------Geometrical correction------------------------------ absCorrFactor = IgorFunctions.absorption(Q) I_Q = I_Q / (absCorrFactor)
# Q, I_Q, Qbkg, Ibkg_Q = UtilityAnalysis.check_data_length(Q, I_Q, Qbkg, Ibkg_Q, \ # variables.minQ, variables.maxQ) fe_Q, Ztot = MainFunctions.calc_eeff(elementList, Q, elementParameters) Iincoh_Q = MainFunctions.calc_Iincoh(elementList, Q, elementParameters) J_Q = IgorFunctions.calc_JQ(Iincoh_Q, fe_Q) Sinf = MainFunctions.calc_Sinf(elementList, fe_Q, Q, Ztot, elementParameters) dampingFunction = UtilityAnalysis.calc_dampingFunction(Q, variables.dampingFactor, variables.QmaxIntegrate, variables.typeFunction) #-------------------Intra-molecular components----------------------------- iintra_Q = Optimization.calc_iintra(Q, fe_Q, Ztot, variables.QmaxIntegrate, variables.maxQ, elementList, element, x, y, z, elementParameters) iintradamp_Q = UtilityAnalysis.calc_iintradamp(iintra_Q, Q, variables.QmaxIntegrate, dampingFunction) rintra, Fintra_r = IgorFunctions.calc_FFT_QiQ(Q, Q*iintradamp_Q, variables.QmaxIntegrate) _, Fintra_r = UtilityAnalysis.rebinning(rintra, Fintra_r, np.amin(rintra), np.amax(rintra), 8192) _, dampingFunction = UtilityAnalysis.rebinning(Q, dampingFunction, 0.0, variables.maxQ, variables.NumPoints) # ---------------------Geometrical correction------------------------------ absCorrFactor = IgorFunctions.absorption(Q) I_Q = I_Q/absCorrFactor Ibkg_Q = Ibkg_Q/absCorrFactor # ------------------------Starting minimization----------------------------