예제 #1
0
    # -------------------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)

    # ------------------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------------------------------
예제 #2
0
    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()
예제 #3
0
    # plt.plot(Qbkg, Ibkg_Q)
    # plt.show

    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, inputVariables["dampingFactor"], inputVariables["QmaxIntegrate"],
        inputVariables["typeFunction"])

    #-------------------Intra-molecular components-----------------------------

    iintra_Q = Optimization.calc_iintra(
        Q, fe_Q, Ztot, inputVariables["QmaxIntegrate"], inputVariables["maxQ"],
        elementList, elementPosition["element"], elementPosition["x"],
        elementPosition["y"], elementPosition["z"], elementParameters)
    iintradamp_Q = UtilityAnalysis.calc_iintradamp(iintra_Q, dampingFunction)
    Qiintradamp_Q = Q * iintradamp_Q
    rintra, Fintra_r = MainFunctions.calc_Fr(
        Q[Q <= inputVariables["QmaxIntegrate"]],
        Qiintradamp_Q[Q <= inputVariables["QmaxIntegrate"]])

    # ---------------------Geometrical correction------------------------------

    # global phi_matrix
    # global thickness_sampling

    if inputVariables["mccFlag"].lower() == "y":
        print("Start matrix calculation or reading")
        thickness_sampling, phi_matrix = Geometry.check_phi_matrix(