from modules import UtilityAnalysis # from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget if __name__ == "__main__": # ---------------------------Files reading--------------------------------- variables = Utility.read_inputFile("./inputFile.txt") elementList = Utility.molToelemList(variables.molecule) elementParameters = Utility.read_parameters(elementList, variables.element_params_path) path = Utility.path_xyz_file(variables.molecule) numAtoms, element, x, y, z = Utility.read_xyz_file(path) Q, I_Q = Utility.read_file(variables.data_file) Qbkg, Ibkg_Q = Utility.read_file(variables.bkg_file) # -------------------Preliminary calculation------------------------------- 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)
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()
app.exit() return filename if __name__ == "__main__": #---------------------------Files reading---------------------------------- # inputFile_path = open_file("./") inputVariables = Utility.read_inputFile("./inputFile.txt") elementList = Utility.molToElemList(inputVariables["molecule"]) elementParameters = Utility.read_parameters( elementList, inputVariables["elementParamsPath"]) elementPosition = Utility.read_xyz_file(inputVariables["xyzPath"]) Q, I_Q = Utility.read_file(inputVariables["dataFile"]) Qbkg, Ibkg_Q = Utility.read_file(inputVariables["bkgFile"]) # plt.plot(Q, I_Q) # plt.plot(Qbkg, Ibkg_Q) # plt.show #--------------------Preliminary calculation------------------------------- Q, I_Q = UtilityAnalysis.data_interpolation(Q, I_Q, inputVariables["minQ"], inputVariables["maxQ"], inputVariables["numPoints"]) Qbkg, Ibkg_Q = UtilityAnalysis.data_interpolation( Qbkg, Ibkg_Q, inputVariables["minQ"], inputVariables["maxQ"],