Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Multiplicity Model Fixes #2647

Merged
merged 36 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b3a21cc
Simplify some of the logic for handling multiplicity models
krzywon Sep 21, 2023
076bb8e
Fix issue related to copy parameters to file (latex/excel) for multip…
krzywon Sep 21, 2023
d2f87cb
Merge branch 'main' into 2369-multiplicity-copy
krzywon Sep 21, 2023
816c4cf
Fix error thrown when multiplicity param is sent to F(Q)P(Q) calculation
krzywon Sep 21, 2023
ea28ca8
Fix addition to poly model to ensure the polydispersity type combobox…
krzywon Sep 22, 2023
58414a0
Only display `Show SLD Profile` button for multiplicity models with s…
krzywon Sep 22, 2023
c6179b8
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
Sep 27, 2023
62833e4
Missed replacement for variable removed from method call
krzywon Oct 2, 2023
de66a1b
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
Oct 6, 2023
11af8ed
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
Oct 26, 2023
a8c3b11
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
Nov 6, 2023
6554380
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
Dec 3, 2023
93a56e9
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
Dec 15, 2023
96bec1a
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
Jan 15, 2024
16a3db6
Add suppressed model list and apply it to FittingWidget and AddMultEd…
krzywon Mar 1, 2024
039b6ef
Create a list of built-in layered models
krzywon Mar 4, 2024
61700ea
Use list of layered models to generate a shortened list of models tha…
krzywon Mar 4, 2024
733bc85
Code cleanup and string reuse
krzywon Mar 4, 2024
521ef95
Move list_models generation into updateModels
krzywon Mar 4, 2024
b9d3eab
Check all models if multiplicity models and add them to add/multi edi…
krzywon Mar 4, 2024
1a6c012
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
krzywon Mar 5, 2024
0ec0552
Get name of parameter rather than form volume parameter name to preve…
krzywon Mar 5, 2024
7c4c8f7
Update add multiply editor documentation to better match current func…
krzywon Mar 5, 2024
8057060
Do not update FittingWidget.n_shells_row in FittingWidget.updateFitte…
krzywon Mar 5, 2024
c046134
Merge release_6.0.0 into 2369-multiplicity-copy and fix merge conflic…
krzywon Mar 12, 2024
933b252
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
krzywon Apr 1, 2024
a05ed2d
Small fixes for PD functionality
krzywon Apr 5, 2024
ff16216
Remove all if not dict: return statements from FittingWidget
krzywon Apr 11, 2024
12c55d8
Copy params before modifying shell models to retain values after chan…
krzywon Apr 15, 2024
6a512a6
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
krzywon Apr 15, 2024
812a10b
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
butlerpd Apr 23, 2024
54b4076
Use regex to check param names for SLD profile button
krzywon Apr 29, 2024
d9bcb75
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
krzywon Apr 29, 2024
befe75e
Fix regex for multiplicity models related to SLD profile button
krzywon Apr 30, 2024
322ec8f
Merge branch 'release_6.0.0' into 2369-multiplicity-copy
butlerpd Apr 30, 2024
a5972fe
Fix SLD params regex - only catches layered params where final chara…
krzywon Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 46 additions & 45 deletions src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,19 +881,23 @@ def formatParametersExcel(parameters: list):
check = ""
for parameter in parameters:
names += parameter[0]+tab
# Add the error column if fitted
if parameter[1] == "True" and parameter[3] is not None:
names += parameter[0]+"_err"+tab

values += parameter[2]+tab
check += parameter[1]+tab
if parameter[1] == "True" and parameter[3] is not None:
values += parameter[3]+tab
# add .npts and .nsigmas when necessary
if parameter[0][-6:] == ".width":
names += parameter[0].replace('.width', '.nsigmas') + tab
names += parameter[0].replace('.width', '.npts') + tab
values += parameter[5] + tab + parameter[4] + tab
if len(parameter) > 3:
# Add the error column if fitted
if parameter[1] == "True" and parameter[3] is not None:
names += parameter[0]+"_err"+tab

values += parameter[2]+tab
check += str(parameter[1])+tab
if parameter[1] == "True" and parameter[3] is not None:
values += parameter[3]+tab
# add .npts and .nsigmas when necessary
if parameter[0][-6:] == ".width":
names += parameter[0].replace('.width', '.nsigmas') + tab
names += parameter[0].replace('.width', '.npts') + tab
values += parameter[5] + tab + parameter[4] + tab
else:
# Empty statement for debugging purposes
pass

output_string = names + crlf + values + crlf + check
return output_string
Expand All @@ -912,46 +916,43 @@ def formatParametersLatex(parameters: list):
output_string += r'}\hline'
output_string += crlf

names = ""
values = ""

for index, parameter in enumerate(parameters):
name = parameter[0] # Parameter name
output_string += name.replace('_', r'\_') # Escape underscores
# Add the error column if fitted
if parameter[1] == "True" and parameter[3] is not None:
output_string += ' & '
output_string += parameter[0]+r'\_err'

if index < len(parameters) - 1:
output_string += ' & '

# add .npts and .nsigmas when necessary
if parameter[0][-6:] == ".width":
output_string += parameter[0].replace('.width', '.nsigmas') + ' & '
output_string += parameter[0].replace('.width', '.npts')
names += name.replace('_', r'\_') # Escape underscores
if len(parameter) > 3:
values += f" {parameter[2]}"
# Add the error column if fitted
if parameter[1] == "True" and parameter[3] is not None:
names += f" & {parameter[0]} " + r'\_err'
values += f' & {parameter[3]}'

if index < len(parameters) - 1:
output_string += ' & '
names += ' & '
values += ' & '

# add .npts and .nsigmas when necessary
if parameter[0][-6:] == ".width":
names += parameter[0].replace('.width', '.nsigmas') + ' & '
names += parameter[0].replace('.width', '.npts')
values += parameter[5] + ' & '
values += parameter[4]

if index < len(parameters) - 1:
names += ' & '
values += ' & '
elif len(parameter) > 2:
values += f' & {parameter[2]} &'
else:
values += f' & {parameter[1]} &'

output_string += names
output_string += r'\\ \hline'
output_string += crlf

# Construct row of values and errors
for index, parameter in enumerate(parameters):
output_string += parameter[2]
if parameter[1] == "True" and parameter[3] is not None:
output_string += ' & '
output_string += parameter[3]

if index < len(parameters) - 1:
output_string += ' & '

# add .npts and .nsigmas when necessary
if parameter[0][-6:] == ".width":
output_string += parameter[5] + ' & '
output_string += parameter[4]

if index < len(parameters) - 1:
output_string += ' & '

output_string += values
output_string += r'\\ \hline'
output_string += crlf
output_string += r'\end{tabular}'
Expand Down
71 changes: 23 additions & 48 deletions src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,8 +2161,6 @@ def updateModelFromList(self, param_dict):
Update the model with new parameters, create the errors column
"""
assert isinstance(param_dict, dict)
if not dict:
return

def updateFittedValues(row):
# Utility function for main model update
Expand Down Expand Up @@ -2879,7 +2877,8 @@ def onMainParamsChange(self, top, bottom):
# don't try to update multiplicity counters if they aren't there.
# Note that this will fail for proper bad update where the model
# doesn't contain multiplicity parameter
self.kernel_module.setParam(parameter_name, value)
if self.kernel_module.params.get(parameter_name, None):
self.kernel_module.setParam(parameter_name, value)
elif model_column == min_column:
# min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf]
self.kernel_module.details[parameter_name][1] = value
Expand Down Expand Up @@ -3433,12 +3432,12 @@ def setPolyModelParameters(self, i, param):
for ishell in range(1, self.current_shell_displayed+1):
# Remove [n] and add the shell numeral
name = param_name[0:param_name.index('[')] + str(ishell)
self.addNameToPolyModel(i, name)
self.addNameToPolyModel(name)
else:
# Just create a simple param entry
self.addNameToPolyModel(i, param_name)
self.addNameToPolyModel(param_name)

def addNameToPolyModel(self, i, param_name):
def addNameToPolyModel(self, param_name):
"""
Creates a checked row in the poly model with param_name
"""
Expand Down Expand Up @@ -3470,7 +3469,7 @@ def addNameToPolyModel(self, i, param_name):
func.addItems([str(name_disp) for name_disp in POLYDISPERSITY_MODELS.keys()])
# Set the default index
func.setCurrentIndex(func.findText(DEFAULT_POLYDISP_FUNCTION))
ind = self._poly_model.index(i,self.lstPoly.itemDelegate().poly_function)
ind = self._poly_model.index(all_items-1,self.lstPoly.itemDelegate().poly_function)
self.lstPoly.setIndexWidget(ind, func)
func.currentIndexChanged.connect(lambda: self.onPolyComboIndexChange(str(func.currentText()), i))

Expand Down Expand Up @@ -3712,10 +3711,17 @@ def addExtraShells(self):
# set the cell to be non-editable
item4.setFlags(item4.flags() ^ QtCore.Qt.ItemIsEditable)

# cell 4: SLD button
# cell 5: SLD button
item5 = QtGui.QStandardItem()
button = QtWidgets.QPushButton()
button.setText("Show SLD Profile")
button = None
for p in self.kernel_module.params.keys():
if 'sld' in p:
# Only display the SLD Profile button for models with SLD parameters
button = QtWidgets.QPushButton()
button.setText("Show SLD Profile")
# Respond to button press
button.clicked.connect(self.onShowSLDProfile)
break

self._model_model.appendRow([item1, item2, item3, item4, item5])

Expand Down Expand Up @@ -3767,8 +3773,6 @@ def addExtraShells(self):
## Respond to index change
#func.currentTextChanged.connect(self.modifyShellsInList)

# Respond to button press
button.clicked.connect(self.onShowSLDProfile)

# Available range of shells displayed in the combobox
func.addItems([str(i) for i in range(shell_min, shell_max+1)])
Expand Down Expand Up @@ -4288,40 +4292,26 @@ def gatherParams(row):
Create list of main parameters based on _model_model
"""
param_name = str(self._model_model.item(row, 0).text())
current_list = self.tabToList[self.tabFitting.currentIndex()]
model = self._model_model
if model.item(row, 0) is None:
return
# Assure this is a parameter - must contain a checkbox
if not model.item(row, 0).isCheckable():
# maybe it is a combobox item (multiplicity)
try:
index = model.index(row, 1)
widget = current_list.indexWidget(index)
if widget is None:
return
if isinstance(widget, QtWidgets.QComboBox):
# find the index of the combobox
current_index = widget.currentIndex()
param_list.append([param_name, 'None', str(current_index)])
except Exception as ex:
pass
return

param_checked = str(model.item(row, 0).checkState() == QtCore.Qt.Checked)
param_checked = None
else:
param_checked = str(model.item(row, 0).checkState() == QtCore.Qt.Checked)
# Value of the parameter. In some cases this is the text of the combobox choice.
param_value = str(model.item(row, 1).text())
param_error = None
param_min = None
param_max = None
_, param_min, param_max = self.kernel_module.details.get(param_name, ('', None, None))
column_offset = 0
if self.has_error_column:
column_offset = 1
param_error = str(model.item(row, 1+column_offset).text())
try:
param_min = str(model.item(row, 2+column_offset).text())
param_max = str(model.item(row, 3+column_offset).text())
except:
except Exception:
pass
# Do we have any constraints on this parameter?
constraint = self.getConstraintForRow(row, model_key="standard")
Expand Down Expand Up @@ -4434,10 +4424,9 @@ def updatePageWithParameters(self, line_dict, warn_user=True):
self.chk2DView.setChecked(line_dict['2D_params'][0]=='True')

# Create the context dictionary for parameters
# Exclude multiplicity and number of shells params from context
context = {k: v for (k, v) in line_dict.items() if len(v) > 3 and k != model}
context['model_name'] = model
for key, value in line_dict.items():
if len(value) > 2:
context[key] = value

if warn_user and str(self.cbModel.currentText()) != str(context['model_name']):
msg = QtWidgets.QMessageBox()
Expand Down Expand Up @@ -4513,20 +4502,6 @@ def updateFittedValues(row):
param_name = str(self._model_model.item(row, 0).text())
if param_name not in list(param_dict.keys()):
return
# Special case of combo box in the cell (multiplicity)
param_line = param_dict[param_name]
if len(param_line) == 1:
# modify the shells value
try:
combo_index = int(param_line[0])
except ValueError:
# quietly pass
return
index = self._model_model.index(row, 1)
widget = self.lstParams.indexWidget(index)
if widget is not None and isinstance(widget, QtWidgets.QComboBox):
#widget.setCurrentIndex(combo_index)
return
# checkbox state
param_checked = QtCore.Qt.Checked if param_dict[param_name][0] == "True" else QtCore.Qt.Unchecked
self._model_model.item(row, 0).setCheckState(param_checked)
Expand Down