def callResetSettings(self):
     if ConfirmDialog.confirmed(parent=self,
                                message="Confirm Reset of the Fields?"):
         try:
             self.resetSettings()
         except:
             pass
示例#2
0
    def generate_reflections(self):
        if self.widget.populate_parameter_in_widget(self, "a", "").function:
            QMessageBox.critical(
                self, "Error",
                "a0 value is a function, generation is not possibile",
                QMessageBox.Ok)
            return

        if not self.reflections is None and not self.reflections.strip() == "":
            if not ConfirmDialog.confirmed(
                    self, "Confirm overwriting of exisiting reflections?"):
                return

        if self.limit_type == 0:
            list = list_of_s_bragg(self.a,
                                   symmetry=self.cb_symmetry.currentText())
        elif self.limit_type == 1:
            list = list_of_s_bragg(self.a,
                                   symmetry=self.cb_symmetry.currentText(),
                                   n_peaks=int(self.limit))
        elif self.limit_type == 2:
            if not self.widget.fit_global_parameters is None \
               and not self.widget.fit_global_parameters.fit_initialization is None \
               and not self.widget.fit_global_parameters.fit_initialization.diffraction_patterns is None \
               and not self.widget.fit_global_parameters.fit_initialization.diffraction_patterns[self.index].wavelength.function:
                wavelength = self.widget.fit_global_parameters.fit_initialization.diffraction_patterns[
                    self.index].wavelength.value

                list = list_of_s_bragg(self.a,
                                       symmetry=self.cb_symmetry.currentText(),
                                       s_max=Utilities.s(
                                           numpy.radians(self.limit / 2),
                                           wavelength))
            else:
                QMessageBox.critical(
                    self, "Error",
                    "No wavelenght is available, 2theta limit is not possibile",
                    QMessageBox.Ok)
                return

        text = ""

        for index in range(0, len(list)):
            h = list[index][0][0]
            k = list[index][0][1]
            l = list[index][0][2]

            text += Reflection(
                h, k, l,
                FitParameter(
                    parameter_name="I" + str(h) + str(k) + str(l),
                    value=1000,
                    boundary=Boundary(min_value=0.0))).to_text() + "\n"

        self.text_area.setText(text)
示例#3
0
    def send_debye_waller(self):
        try:
            if not self.fit_global_parameters is None:
                send_data = True

                if self.use_debye_waller_factor == 1 and not self.debye_waller_factor_function == 1:
                    congruence.checkStrictlyPositiveNumber(
                        self.debye_waller_factor, "B")

                    if self.fit_global_parameters.fit_initialization.crystal_structures is None:
                        raise ValueError(
                            "Add Crystal Structure(s) before this widget")

                    if not self.fit_global_parameters.fit_initialization.crystal_structures[
                            0].use_structure:
                        send_data = ConfirmDialog.confirmed(
                            parent=self,
                            message=
                            "Debye-Waller factor is better refined when the structural model is activated.\nProceed anyway?"
                        )

                if send_data:
                    debye_waller_factor = None if self.use_debye_waller_factor == 0 else self.populate_parameter(
                        "debye_waller_factor",
                        ThermalPolarizationParameters.get_parameters_prefix())
                    if not debye_waller_factor is None:
                        debye_waller_factor.rescale(
                            0.01)  # CONVERSIONE from A-2 to nm-2

                    if self.fit_global_parameters.fit_initialization.thermal_polarization_parameters is None:
                        self.fit_global_parameters.fit_initialization.thermal_polarization_parameters = [
                            ThermalPolarizationParameters(
                                debye_waller_factor=debye_waller_factor)
                        ]
                    else:
                        self.fit_global_parameters.fit_initialization.thermal_polarization_parameters[
                            0].debye_waller_factor = debye_waller_factor

                    self.send("Fit Global Parameters",
                              self.fit_global_parameters)

        except Exception as e:
            QMessageBox.critical(self, "Error", str(e), QMessageBox.Ok)

            if self.IS_DEVELOP: raise e
示例#4
0
    def set_data(self, data):
        try:
            if not data is None:
                if self.fit_running: raise RuntimeError("Fit is Running: Input data are not accepted!")

                if self.is_incremental == 1 and not self.fit_global_parameters is None:
                    if not ConfirmDialog.confirmed(self, message="Warning: Fitter is in set in incremental mode, but received fit parameters will replace the already fitted ones. Do you accept them?"):
                        return

                self.current_iteration = 0

                self.fit_global_parameters = data.duplicate()

                # keep existing text!
                existing_free_output_parameters = FreeOutputParameters()
                existing_free_output_parameters.parse_formulas(self.free_output_parameters_text)

                received_free_output_parameters = self.fit_global_parameters.free_output_parameters.duplicate()
                received_free_output_parameters.append(existing_free_output_parameters)

                self.text_area_free_out.setText(received_free_output_parameters.to_python_code())

                parameters = self.fit_global_parameters.free_input_parameters.as_parameters()
                parameters.extend(self.fit_global_parameters.get_parameters())

                self.populate_table(self.table_fit_in, parameters, is_output=False)

                self.tabs.setCurrentIndex(0)

                if self.fit_global_parameters.instrumental_parameters is None:
                    self.show_ipf = 0
                    self.cb_show_ipf.setEnabled(False)
                    self.tab_plot_ipf.setEnabled(False)
                else:
                    self.cb_show_ipf.setEnabled(True)
                    self.tab_plot_ipf.setEnabled(True)

                if self.fit_global_parameters.get_shift_parameters(Lab6TanCorrection.__name__) is None:
                    self.show_shift = 0
                    self.cb_show_shift.setEnabled(False)
                    self.tab_plot_lab6.setEnabled(False)
                else:
                    self.cb_show_shift.setEnabled(True)
                    self.tab_plot_lab6.setEnabled(True)

                if self.fit_global_parameters.size_parameters is None:
                    self.show_size = 0
                    self.cb_show_size.setEnabled(False)
                    self.tab_plot_size.setEnabled(False)
                else:
                    self.cb_show_size.setEnabled(True)
                    self.tab_plot_size.setEnabled(True)

                if self.fit_global_parameters.strain_parameters is None:
                    self.show_warren = 0
                    self.cb_show_warren.setEnabled(False)
                    self.tab_plot_strain.setEnabled(False)
                else:
                    self.cb_show_warren.setEnabled(True)
                    self.tab_plot_strain.setEnabled(True)

                if self.is_incremental == 0 or (self.is_incremental == 1 and self.current_iteration == 0):
                    sys.stdout = EmittingStream(textWritten=self.write_stdout)

                    self.fitted_fit_global_parameters = self.fit_global_parameters.duplicate()
                    self.fitted_fit_global_parameters.evaluate_functions()

                    self.fitter = FitterFactory.create_fitter(fitter_name=self.cb_fitter.currentText())
                    self.fitter.init_fitter(self.fitted_fit_global_parameters)

                    self.fitted_patterns = self.fitter.build_fitted_diffraction_pattern(self.fitted_fit_global_parameters)
                    self.fit_data = None

                    self.show_data(is_init=True)

                    self.tabs.setCurrentIndex(1)
                    self.tabs_plot.setCurrentIndex(0)

                if self.is_automatic_run:
                    self.do_fit()
        except Exception as e:
            QMessageBox.critical(self, "Error during load",
                                 str(e),
                                 QMessageBox.Ok)

            if self.IS_DEVELOP: raise e
示例#5
0
 def stop_fit(self):
     if ConfirmDialog.confirmed(self, "Confirm STOP?"):
         self.stop_fit = True
示例#6
0
    def set_data(self, data):
        if not data is None:
            try:
                self.fit_global_parameters = data.duplicate()

                diffraction_patterns = self.fit_global_parameters.fit_initialization.diffraction_patterns
                crystal_structures = self.fit_global_parameters.fit_initialization.crystal_structures

                if diffraction_patterns is None: raise ValueError("No Diffraction Pattern in input data!")

                if len(diffraction_patterns) != len(self.crystal_structure_box_array):
                    recycle = ConfirmDialog.confirmed(message="Number of Diffraction Patterns changed:\ndo you want to use the existing structures where possible?\n\nIf yes, check for possible incongruences",
                                                      title="Warning")

                    self.crystal_structure_tabs.clear()
                    self.crystal_structure_box_array = []

                    for index in range(len(diffraction_patterns)):
                        crystal_structure_tab = gui.createTabPage(self.crystal_structure_tabs, "Diff. Patt. " + str(index + 1))

                        if recycle and index < len(self.a): #keep the existing
                            crystal_structure_box = CrystalStructureBox(widget=self,
                                                                        parent=crystal_structure_tab,
                                                                        index = index,
                                                                        a                                    = self.a[index],
                                                                        a_fixed                              = self.a_fixed[index],
                                                                        a_has_min                            = self.a_has_min[index],
                                                                        a_min                                = self.a_min[index],
                                                                        a_has_max                            = self.a_has_max[index],
                                                                        a_max                                = self.a_max[index],
                                                                        a_function                           = self.a_function[index],
                                                                        a_function_value                     = self.a_function_value[index],
                                                                        symmetry                             = self.symmetry[index],
                                                                        use_structure                        = self.use_structure[index],
                                                                        formula                              = self.formula[index],
                                                                        intensity_scale_factor               = self.intensity_scale_factor[index],
                                                                        intensity_scale_factor_fixed         = self.intensity_scale_factor_fixed[index],
                                                                        intensity_scale_factor_has_min       = self.intensity_scale_factor_has_min[index],
                                                                        intensity_scale_factor_min           = self.intensity_scale_factor_min[index],
                                                                        intensity_scale_factor_has_max       = self.intensity_scale_factor_has_max[index],
                                                                        intensity_scale_factor_max           = self.intensity_scale_factor_max[index],
                                                                        intensity_scale_factor_function      = self.intensity_scale_factor_function[index],
                                                                        intensity_scale_factor_function_value= self.intensity_scale_factor_function_value[index],
                                                                        reflections                          = self.reflections[index],
                                                                        limit                                = self.limit[index],
                                                                        limit_type                           = self.limit_type[index])
                        else:
                            crystal_structure_box = CrystalStructureBox(widget=self, parent=crystal_structure_tab, index = index)

                        self.crystal_structure_box_array.append(crystal_structure_box)

                elif not crystal_structures is None:
                    for index in range(len(crystal_structures)):
                        self.crystal_structure_box_array[index].set_data(crystal_structures[index])

                self.dumpSettings()

                if self.is_automatic_run:
                    self.send_fit_initialization()

            except Exception as e:
                QMessageBox.critical(self, "Error",
                                     str(e),
                                     QMessageBox.Ok)

                if self.IS_DEVELOP: raise e