Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bjheinen committed Dec 21, 2021
2 parents a91ad9b + 1bc8678 commit 1f6ef8b
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 13 deletions.
2 changes: 1 addition & 1 deletion LiquidDiffract/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
raise NameError('\'method\' must be one of either 1, 2, 3, or 0')
5 changes: 4 additions & 1 deletion LiquidDiffract/gui/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions LiquidDiffract/gui/plot_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions LiquidDiffract/gui/structure_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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'],
Expand Down
49 changes: 48 additions & 1 deletion LiquidDiffract/gui/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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__()
Expand Down
2 changes: 1 addition & 1 deletion LiquidDiffract/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '1.1.7'
__version__ = '1.1.8'
__appname__ = 'LiquidDiffract'

0 comments on commit 1f6ef8b

Please sign in to comment.