From ae24bbb31b42b1da7f6697cbd2f18337fb170233 Mon Sep 17 00:00:00 2001 From: bjheinen Date: Tue, 21 Dec 2021 15:39:08 +0000 Subject: [PATCH 1/4] Fix newline char at end of file --- LiquidDiffract/core/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LiquidDiffract/core/core.py b/LiquidDiffract/core/core.py index 38507ad..f137df0 100644 --- a/LiquidDiffract/core/core.py +++ b/LiquidDiffract/core/core.py @@ -1131,4 +1131,4 @@ def integrate_coordination_sphere(r, rdf, return N_c else: - raise NameError('\'method\' must be one of either 1, 2, 3, or 0') \ No newline at end of file + raise NameError('\'method\' must be one of either 1, 2, 3, or 0') From 83d1f318f1281380a4e794fc533e1fee8d79a582 Mon Sep 17 00:00:00 2001 From: bjheinen Date: Tue, 21 Dec 2021 15:40:16 +0000 Subject: [PATCH 2/4] Fix gauss fit plot viewbox reset on add peak --- LiquidDiffract/gui/plot_widgets.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/LiquidDiffract/gui/plot_widgets.py b/LiquidDiffract/gui/plot_widgets.py index e0429d8..4ec13b3 100644 --- a/LiquidDiffract/gui/plot_widgets.py +++ b/LiquidDiffract/gui/plot_widgets.py @@ -858,7 +858,7 @@ def update_plots(self, _data): self.tr_int_layout.update() self.fit_layout.update() - def update_plot_windows(self, _data): + def update_plot_windows(self, _data, _reset_view): _rdf_cut = np.nan_to_num(_data['rdf_y'][np.where(_data['rdf_x'] < self.x_max)]) self.y_min_rdf = np.min(_rdf_cut) self.y_max_rdf = np.max(_rdf_cut) @@ -871,10 +871,11 @@ def update_plot_windows(self, _data): self.y_min_fit = np.min(_obj_fun_cut) self.y_max_fit = np.max(_obj_fun_cut) - self.set_rdf_window() - self.set_tr_window() - self.set_fit_window() - self.set_res_window(_data) + if _reset_view: + self.set_rdf_window() + self.set_tr_window() + self.set_fit_window() + self.set_res_window(_data) def set_rdf_window(self): try: From 4607795b7990f84c08234bb6b53559ec3bfcd82f Mon Sep 17 00:00:00 2001 From: bjheinen Date: Tue, 21 Dec 2021 15:43:21 +0000 Subject: [PATCH 3/4] Set default behaviour to calc x-ray weights with Kp at Q=0 and add option to change to Kp(Q_data) in preferences dialog --- LiquidDiffract/gui/main_widget.py | 5 ++- LiquidDiffract/gui/structure_ui.py | 14 ++++++--- LiquidDiffract/gui/utility.py | 49 +++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/LiquidDiffract/gui/main_widget.py b/LiquidDiffract/gui/main_widget.py index e6be924..6239d7b 100644 --- a/LiquidDiffract/gui/main_widget.py +++ b/LiquidDiffract/gui/main_widget.py @@ -93,7 +93,8 @@ def set_default_preferences(self): 'niter': 100, 'T': 1.0, 'stepsize': 0.01, - 'interval': 50} + 'interval': 50}, + 'xray_weight_mode': 0 } self.set_preferences() @@ -130,6 +131,8 @@ def set_preferences(self): self.table_widget.bkg_ui.data_units = self.preferences['data_units'] # Set preferences for rescaling Ashcroft-Langreth S(Q)/g(r) plots self.table_widget.results_ui.rescale_AL = self.preferences['rescale_AL'] + # Set preferences for x-ray weight mode (0: calc Kp at Q=0, 1: calc Q-dependent Kp) + self.table_widget.structure_ui.xray_weight_mode = self.preferences['xray_weight_mode'] def call_about_dialog(self): self.about_dialog = utility.AboutDialog() diff --git a/LiquidDiffract/gui/structure_ui.py b/LiquidDiffract/gui/structure_ui.py index 2132a2d..5e15db2 100755 --- a/LiquidDiffract/gui/structure_ui.py +++ b/LiquidDiffract/gui/structure_ui.py @@ -138,6 +138,7 @@ def clear_data(self): self.data = {'rdf_x': np.asarray([]), 'rdf_y': np.asarray([]), 'tr_x': np.asarray([]), 'tr_y': np.asarray([]), + 'r0': 0.0, 'rmax': 0.0, 'rpmax': 0.0, 'rmin': 0.0, 'fit_r': np.asarray([]), 'obj_fun': np.asarray([]), 'gauss_peaks': [], @@ -159,9 +160,9 @@ def set_atoms(self): for _peak in self.structure_config_widget.polyatomic_gb.peak_dict.values(): _peak.populate_atom_list(_atom_list) - def plot_data(self): + def plot_data(self, _reset_view=1): self.update_plot_data() - self.structure_plot_widget.update_plot_windows(self.data) + self.structure_plot_widget.update_plot_windows(self.data, _reset_view) def update_plot_data(self): self.data['r0'] = self.structure_config_widget.monatomic_gb.r0_input.value() @@ -258,7 +259,12 @@ def calc_integrals(self): self.data['N_c'] = _Nc def set_weights(self): - self.weights, self.c_dict = core.calculate_weights(self.data['composition'], self.data['sq_x']) + if self.xray_weight_mode == 1: + self.weights, self.c_dict = core.calculate_weights(self.data['composition'], self.data['sq_x']) + elif self.xray_weight_mode == 0: + self.weights, self.c_dict = core.calculate_weights(self.data['composition'], [0]) + else: + raise ValueError # TODO - Proper guess peak implement plain gauss! def guess_peak_params(self, _idx): @@ -512,7 +518,7 @@ def make_peak_plots(self): self.structure_plot_widget.clear_gauss_curves() self.data['gauss_model'] = np.asarray([]) self.data['gauss_peaks'] = [] - self.plot_data() + self.plot_data(_reset_view=0) return # Evaluate objective function over whole r range self.data['gauss_model'] = peak_fit.gauss_obj_func(self.peak_fit_dict['obj_params'], diff --git a/LiquidDiffract/gui/utility.py b/LiquidDiffract/gui/utility.py index e26d359..0d98aae 100644 --- a/LiquidDiffract/gui/utility.py +++ b/LiquidDiffract/gui/utility.py @@ -97,12 +97,14 @@ def __init__(self, preferences): self.ref_proc_settings_gb = IterativeProcedureSettingsGroupBox(preferences) self.refine_settings_gb = SolverSettingsGroupBox(preferences) self.global_min_settings_gb = GlobalMinSettingsGroupBox(preferences) + self.gaussian_fit_settings_gb = GaussianFittingSettingsGroupBox(preferences) self.vlayout.addWidget(self.app_settings_gb) self.vlayout.addWidget(self.data_settings_gb) self.vlayout.addWidget(self.ref_proc_settings_gb) self.vlayout.addWidget(self.refine_settings_gb) self.vlayout.addWidget(self.global_min_settings_gb) + self.vlayout.addWidget(self.gaussian_fit_settings_gb) self.pref_widget.setLayout(self.vlayout) self.scroll_area = QScrollArea() @@ -163,6 +165,8 @@ def accept_preferences(self): _bh_temp = np.float(self.global_min_settings_gb.temp_basin_input.text()) _bh_step_size = np.float(self.global_min_settings_gb.stepsize_basin_input.text()) _bh_interval = np.int(self.global_min_settings_gb.interval_basin_input.text()) + # Get Gaussiant fitting options + _xray_weight_mode = np.int(self.gaussian_fit_settings_gb.xray_weight_mode_input.isChecked()) # Handle for missing values except ValueError: @@ -218,7 +222,8 @@ def accept_preferences(self): 'op_method': _op_method, 'minimisation_options': _minimisation_options, 'global_minimisation': _global_minimisation, - 'global_min_options': _global_min_options + 'global_min_options': _global_min_options, + 'xray_weight_mode': _xray_weight_mode } # handle for ValueError if nothing entered @@ -664,6 +669,48 @@ def create_layout(self): self.setLayout(self.main_layout) +class GaussianFittingSettingsGroupBox(QGroupBox): + + def __init__(self, preferences): + super(GaussianFittingSettingsGroupBox, self).__init__() + self.setTitle('Gaussian Fitting Options') + self.setAlignment(Qt.AlignLeft) + self.setStyleSheet('GroupBox::title{subcontrol-origin: margin; subcontrol-position: top left;}') + + self.create_widgets() + self.set_data(preferences) + self.style_widgets() + self.create_layout() + + def create_widgets(self): + self.xray_weight_mode_label = QLabel('Use Q-dependent x-ray weighting factors?: ') + self.xray_weight_mode_input = QCheckBox() + + def set_data(self, preferences): + self.xray_weight_mode_input.setChecked(preferences['xray_weight_mode']) + + def style_widgets(self): + self.xray_weight_mode_label.setAlignment(Qt.AlignVCenter | Qt.AlignLeft) + _tooltip = ('Default behaviour is to use the effective atomic number, Kp, \n' + 'of each species given by the Warren-Krutter-Morningstar approximation at Q=0.\n' + 'Check this box to calculate Kp as an average of the entire Q-range used.' + ) + self.xray_weight_mode_label.setToolTip(_tooltip) + + def create_layout(self): + self.main_layout = QVBoxLayout() + self.main_layout.setContentsMargins(20, 10, 20, 7) + self.main_layout.setSpacing(25) + + self.grid_layout = QGridLayout() + self.grid_layout.setSpacing(15) + self.grid_layout.addWidget(self.xray_weight_mode_label, 0, 0) + self.grid_layout.addWidget(self.xray_weight_mode_input, 0, 1) + + self.main_layout.addLayout(self.grid_layout) + self.setLayout(self.main_layout) + + class ErrorMessageBox(QMessageBox): def __init__(self, _message): super(ErrorMessageBox, self).__init__() From 1bc86781e95c9abd74c87033965f0a7b4bf9fd0b Mon Sep 17 00:00:00 2001 From: bjheinen Date: Tue, 21 Dec 2021 15:50:30 +0000 Subject: [PATCH 4/4] v1.1.8 --- LiquidDiffract/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LiquidDiffract/version.py b/LiquidDiffract/version.py index 67c0dbc..5d9f26a 100644 --- a/LiquidDiffract/version.py +++ b/LiquidDiffract/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -__version__ = '1.1.7' +__version__ = '1.1.8' __appname__ = 'LiquidDiffract'