Skip to content

Commit

Permalink
fix Gr load and convert issues
Browse files Browse the repository at this point in the history
  • Loading branch information
y8z committed Oct 7, 2024
1 parent e266b96 commit d0fe6d5
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 11 deletions.
8 changes: 7 additions & 1 deletion addie/addiedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def calculate_sqAlt(self, ws_name, initType, outputType):
OutputWorkspace=ws_name,
From='F(Q)',
To='S(Q)')
out_x_tmp = simpleapi.mtd[ws_name].readX(0)
out_y_tmp = simpleapi.mtd[ws_name].readY(0)
if abs(out_x_tmp[0]) < 1.E-5:
out_y_copy = out_y_tmp.copy()
out_y_copy[0] = out_y_copy[1]
simpleapi.mtd[ws_name].setY(0, out_y_copy)

if outputType == 'S(Q)': # don't do anything
return ws_name
Expand Down Expand Up @@ -491,7 +497,7 @@ def load_sq(self, file_name):
# The S(Q) file is in fact S(Q)-1 in sq file. So need to add 1 to
# the workspace
out_ws = AnalysisDataService.retrieve(sq_ws_name)
out_ws += 1
# out_ws += 1
elif ext == 'SQ':
try:
simpleapi.LoadAscii(
Expand Down
50 changes: 43 additions & 7 deletions addie/calculate_gr/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def load_sq(main_window):
os.path.abspath(sq_file_names[0]))[0]
check_in_fixed_dir_structure(main_window, 'SofQ')

sq_type = str(main_window.calculategr_ui.comboBox_inSofQType.currentText())
main_window.sofq_type_in_mem = sq_type

# load S(q)
for sq_file_name in sq_file_names:
sq_file_name = str(sq_file_name)
Expand All @@ -105,20 +108,31 @@ def load_sq(main_window):
# plot S(Q) - TODO why is it getting the name again?
ws_name = main_window._myController.get_current_sq_name()

plot_sq(main_window, ws_name, color=color, clear_prev=False)
plot_sq(
main_window,
ws_name,
color=color,
clear_prev=False,
is_load=True
)

# calculate and calculate G(R)
generate_gr_step1(main_window)

check_widgets_status(main_window)


def plot_sq(main_window, ws_name, color, clear_prev):
def plot_sq(main_window,
ws_name,
color,
clear_prev,
is_load=False):
"""
Plot S(Q)
:param ws_name:
:param sq_color: S(Q) color (if None, find it from PDF color manager)
:param clear_prev:
:param is_load: initially loaded data to plot or not
:return:
"""
# clear previous lines
Expand All @@ -133,10 +147,25 @@ def plot_sq(main_window, ws_name, color, clear_prev):
color = main_window._pdfColorManager.add_sofq(ws_name)

# convert to the function to plot
sq_type = str(main_window.calculategr_ui.comboBox_SofQType.currentText())
plottable_name = main_window._myController.calculate_sqAlt(
ws_name, main_window.sofq_type_in_mem, sq_type)
main_window.sofq_type_in_mem = sq_type
if is_load:
sq_type_in = str(
main_window.calculategr_ui.comboBox_SofQType.currentText()
)
sq_type = str(
main_window.calculategr_ui.comboBox_inSofQType.currentText()
)
plottable_name = main_window._myController.calculate_sqAlt(
ws_name, sq_type_in, sq_type
)
main_window.sofq_type_in_mem = sq_type
else:
sq_type = str(
main_window.calculategr_ui.comboBox_inSofQType.currentText()
)
plottable_name = main_window._myController.calculate_sqAlt(
ws_name, main_window.sofq_type_in_mem, sq_type
)
main_window.sofq_type_in_mem = sq_type

main_window.calculategr_ui.graphicsView_sq.plot_sq(
plottable_name,
Expand Down Expand Up @@ -616,8 +645,15 @@ def do_save_sq(main_window):
# skip if the user cancel the operation on this S(Q)
continue

sq_type = str(
main_window.calculategr_ui.comboBox_inSofQType.currentText()
)
plottable_name = main_window._myController.calculate_sqAlt(
sq_name, "S(Q)", sq_type,
)

# save file
main_window._myController.save_ascii(sq_name, filename, filetype)
main_window._myController.save_ascii(plottable_name, filename, filetype)


def do_edit_sq(main_window):
Expand Down
10 changes: 9 additions & 1 deletion addie/calculate_gr/gofrtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,16 @@ def do_plot(self):
None, None, None, None, None,
auto=True)

self._mainWindow.calculategr_ui.comboBox_inSofQType.setCurrentIndex(0)
self._mainWindow.sofq_type_in_mem = "S(Q)"
for sq_name in sq_list:
event_handler.plot_sq(self._mainWindow, sq_name, None, False)
event_handler.plot_sq(
self._mainWindow,
sq_name,
None,
False
)


def do_remove_from_plot(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion addie/initialization/events/calculategr_tab.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def run(main_window=None):
main_window.calculategr_ui.pushButton_loadSQ.clicked.connect(main_window.do_load_sq)
main_window.calculategr_ui.comboBox_SofQType.currentIndexChanged.connect(main_window.evt_change_sq_type)
main_window.calculategr_ui.comboBox_inSofQType.currentIndexChanged.connect(main_window.evt_change_sq_type)
main_window.calculategr_ui.pushButton_rescaleSq.clicked.connect(main_window.do_rescale_sofq)
main_window.calculategr_ui.pushButton_rescaleGr.clicked.connect(main_window.do_rescale_gofr)
main_window.calculategr_ui.pushButton_clearSofQ.clicked.connect(main_window.do_clear_sq)
Expand Down
7 changes: 6 additions & 1 deletion addie/initialization/widgets/calculategr_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ def run(main_window=None):
as_current_index=False)

main_window.calculategr_ui.comboBox_SofQType.clear()
main_window.calculategr_ui.comboBox_SofQType.addItem('S(Q)')
main_window.calculategr_ui.comboBox_SofQType.addItem('S(Q)-1')
main_window.calculategr_ui.comboBox_SofQType.addItem('S(Q)')
main_window.calculategr_ui.comboBox_SofQType.addItem('Q[S(Q)-1]')
main_window.calculategr_ui.comboBox_SofQType.setCurrentIndex(0)
main_window.calculategr_ui.comboBox_inSofQType.clear()
main_window.calculategr_ui.comboBox_inSofQType.addItem('S(Q)')
main_window.calculategr_ui.comboBox_inSofQType.addItem('S(Q)-1')
main_window.calculategr_ui.comboBox_inSofQType.addItem('Q[S(Q)-1]')
main_window.calculategr_ui.comboBox_inSofQType.setCurrentIndex(0)

main_window.calculategr_ui.comboBox_pdfType.addItems(['G(r)', 'g(r)', 'RDF(r)'])

Expand Down
26 changes: 26 additions & 0 deletions addie/ui/splitui_calculategr_tab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,32 @@
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_SofQType">
<item>
<property name="text">
<string>S(Q)-1</string>
</property>
</item>
<item>
<property name="text">
<string>S(Q)</string>
</property>
</item>
<item>
<property name="text">
<string>Q[S(Q)-1]</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelConvertSofQ">
<property name="text">
<string>SQ Form to Present/Output</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBox_inSofQType">
<item>
<property name="text">
<string>S(Q)</string>
Expand Down

0 comments on commit d0fe6d5

Please sign in to comment.