def plotMiddle(self): """Function to plot the graph on the Middle Canvas""" self.ui.factorPlot.canvas.ax.cla() self.ui.factorPlot.canvas.ax.grid(True) self.elementList = Utility.molToElemList(self.molecule) self.elementParameters = Utility.read_parameters( self.elementList, "./elementParameters.txt") if self.ui.formFactorCheck.isChecked(): # print("test fe check") self.Q, self.I_Q, self.Qbkg, self.Ibkg_Q = UtilityAnalysis.check_data_length( self.Q, self.I_Q, self.Qbkg, self.Ibkg_Q, self.ui.minQ.value(), self.ui.maxQ.value()) self.fe_Q, self.Ztot = MainFunctions.calc_eeff( self.elementList, self.Q, self.elementParameters) self.ui.factorPlot.canvas.ax.plot(self.Q, self.fe_Q, label=r"$f_e(Q)$") self.ui.factorPlot.canvas.ax.legend() self.ui.factorPlot.canvas.draw() # else: # # print("test unchecked") # self.ui.factorPlot.canvas.ax.lines.pop(0) # self.ui.factorPlot.canvas.draw() if self.ui.SQCheck.isChecked(): S_Q = self.SQ() self.ui.factorPlot.canvas.ax.plot(self.Q, S_Q, label=r"$S(Q)$") self.ui.factorPlot.canvas.ax.legend() self.ui.factorPlot.canvas.draw() if self.ui.incohCheck.isChecked(): self.Iincoh_Q = MainFunctions.calc_Iincoh(self.elementList, self.Q, self.elementParameters) self.ui.factorPlot.canvas.ax.plot(self.Q, self.Iincoh_Q, label=r"$I_{incoh}(Q)$") self.ui.factorPlot.canvas.ax.legend() self.ui.factorPlot.canvas.draw() if self.ui.QiQCheck.isChecked(): self.Sinf = MainFunctions.calc_Sinf(self.elementList, self.fe_Q, self.Q, self.Ztot, self.elementParameters) self.i_Q = MainFunctions.calc_iQ(S_Q, self.Sinf) # self.r = MainFunctions.calc_r(self.Q) Qi_Q = self.Q * self.i_Q self.ui.factorPlot.canvas.ax.plot(self.Q, Qi_Q, label=r"$Qi(Q)$") self.ui.factorPlot.canvas.ax.legend() self.ui.factorPlot.canvas.draw()
def SQ(self): """Function to calculate and plot the structure factor S(Q)""" self.elementList = Utility.molToElemList(self.molecule) # self.elementList = Utility.molToElemList("Ar") self.elementParameters = Utility.read_parameters( self.elementList, "./elementParameters.txt") # print(elementList) # print(elementParameters) self.Q, self.I_Q, self.Qbkg, self.Ibkg_Q = UtilityAnalysis.check_data_length( self.Q, self.I_Q, self.Qbkg, self.Ibkg_Q, self.ui.minQ.value(), self.ui.maxQ.value()) two_theta = UtilityAnalysis.Qto2theta(self.Q) absCorrFactor = Geometry.calcAbsCorrection( self.ui.absLength.value(), two_theta, self.ui.dacThickness.value(), self.ui.dacAngle.value()) self.I_Q = self.I_Q / absCorrFactor self.Ibkg_Q = self.Ibkg_Q / absCorrFactor self.fe_Q, self.Ztot = MainFunctions.calc_eeff(self.elementList, self.Q, self.elementParameters) self.Iincoh_Q = MainFunctions.calc_Iincoh(self.elementList, self.Q, self.elementParameters) self.J_Q = MainFunctions.calc_JQ(self.Iincoh_Q, self.Ztot, self.fe_Q) self.Sinf = MainFunctions.calc_Sinf(self.elementList, self.fe_Q, self.Q, self.Ztot, self.elementParameters) self.dampingFunct = UtilityAnalysis.calc_dampingFunction( self.Q, self.ui.dampingFactor.value(), self.ui.QmaxIntegrate.value(), self.ui.dampingFunction.currentText()) Isample_Q = MainFunctions.calc_IsampleQ( self.I_Q, self.ui.scaleFactorValue.value(), 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, self.ui.densityValue.value()) 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()) self.SsmoothDamp_Q = UtilityAnalysis.calc_SQdamp( Ssmooth_Q, self.Sinf, self.dampingFunct) # self.ui.factorPlot.canvas.ax.plot(self.Q, self.SsmoothDamp_Q, "b", label=r"$S(Q)$") # self.ui.factorPlot.canvas.ax.legend() # self.ui.factorPlot.canvas.draw() return self.SsmoothDamp_Q
filename, _ = QFileDialog.getOpenFileName(caption="Load Input File", directory=default_dir, filter="*txt") 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"],