Skip to content

Commit c3bc39e

Browse files
authored
Add files via upload
1 parent 18b0657 commit c3bc39e

1 file changed

Lines changed: 40 additions & 23 deletions

File tree

Python/main.py

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ def __init__(self):
3030
self.initUI()
3131

3232
def initUI(self):
33-
self.version = 'LG4X: lmfit gui for xps curve fitting ver. 0.083'
33+
self.version = 'LG4X: lmfit gui for xps curve fitting ver. 0.084'
3434
self.floating = '.2f'
3535

36-
# default window width 1400 (effective to BG and peak tables)
37-
# default window height 800 (effective to plot and peak tables)
3836
# window size can be adjustable in window_scale factor, default: 1
3937
window_scale = 1
40-
38+
# column width in the fit table, default: 55
39+
self.fitpColWidth = 55
40+
# default window width 1400, height 800
4141
self.setGeometry(300, 600, int(1400 * window_scale), int(800 * window_scale))
42+
4243
self.center()
4344
self.setWindowTitle(self.version)
4445
self.statusBar().showMessage('Copyright (C) 2021, Hideki NAKAJIMA, Synchrotron Light Research Institute, Nakhon Ratchasima, Thailand')
@@ -186,21 +187,21 @@ def initUI(self):
186187
for col in range(len(list_col)):
187188
comboBox = QtWidgets.QComboBox()
188189
comboBox.addItems(self.list_shape)
189-
#comboBox.setMaximumWidth(55)
190+
#comboBox.setMaximumWidth(self.fitpColWidth)
190191
self.fitp1.setCellWidget(0, 2*col+1, comboBox)
191192

192193
# set DropDown amp_ref peak section
193194
for col in range(len(list_col)):
194195
comboBox = QtWidgets.QComboBox()
195196
comboBox.addItems(self.list_peak)
196-
comboBox.setMaximumWidth(55)
197+
comboBox.setMaximumWidth(self.fitpColWidth)
197198
self.fitp1.setCellWidget(8, 2*col+1, comboBox)
198199

199200
# set DropDown ctr_ref peak selection
200201
for col in range(len(list_col)):
201202
comboBox = QtWidgets.QComboBox()
202203
comboBox.addItems(self.list_peak)
203-
comboBox.setMaximumWidth(55)
204+
comboBox.setMaximumWidth(self.fitpColWidth)
204205
self.fitp1.setCellWidget(10, 2*col+1, comboBox)
205206

206207
# set checkbox in fit table
@@ -235,7 +236,7 @@ def add_col(self):
235236
# add DropDown peak model
236237
comboBox = QtWidgets.QComboBox()
237238
comboBox.addItems(self.list_shape)
238-
#comboBox.setMaximumWidth(55)
239+
#comboBox.setMaximumWidth(self.fitpColWidth)
239240
self.fitp1.setCellWidget(0, colPosition+1, comboBox)
240241

241242
# setup new peak parameters (initial and additional)
@@ -266,7 +267,7 @@ def add_col(self):
266267
index = 0
267268
comboBox= QtWidgets.QComboBox()
268269
comboBox.addItems(self.list_peak)
269-
comboBox.setMaximumWidth(55)
270+
comboBox.setMaximumWidth(self.fitpColWidth)
270271
self.fitp1.setCellWidget(8, 2*col+1, comboBox)
271272
if index > 0 and col < int(colPosition/2):
272273
comboBox.setCurrentIndex(index)
@@ -278,7 +279,7 @@ def add_col(self):
278279
index = 0
279280
comboBox = QtWidgets.QComboBox()
280281
comboBox.addItems(self.list_peak)
281-
comboBox.setMaximumWidth(55)
282+
comboBox.setMaximumWidth(self.fitpColWidth)
282283
self.fitp1.setCellWidget(10, 2*col+1, comboBox)
283284
if index > 0 and col < int(colPosition/2):
284285
comboBox.setCurrentIndex(index)
@@ -415,7 +416,7 @@ def setPreset(self, index_bg, list_pre_bg, list_pre_pk):
415416

416417
# load preset for bg
417418
if len(list_pre_bg) != 0 and self.addition == 0:
418-
for row in range(len(list_pre_bg)):
419+
for row in range(len(list_pre_bg)):
419420
for col in range(len(list_pre_bg[0])):
420421
if (col % 2) != 0:
421422
item = QtWidgets.QTableWidgetItem(str(list_pre_bg[row][col]))
@@ -447,12 +448,13 @@ def setPreset(self, index_bg, list_pre_bg, list_pre_pk):
447448
for col in range(int(len(list_pre_pk[0])/2)):
448449
self.add_col()
449450

450-
for row in range(len(list_pre_pk)):
451+
for row in range(len(list_pre_pk)):
451452
for col in range(len(list_pre_pk[0])):
452453
if (col % 2) != 0:
453454
if row == 0 or row == 8 or row == 10:
454455
comboBox = QtWidgets.QComboBox()
455456
if row == 0:
457+
comboBox.setMaximumWidth(self.fitpColWidth) # set the width of column when preset is loaded
456458
comboBox.addItems(self.list_shape)
457459
else:
458460
comboBox.addItems(self.list_peak)
@@ -536,7 +538,7 @@ def savePreset(self):
536538
colPosition = self.fitp0.columnCount()
537539
list_pre_bg = []
538540
# save preset for bg
539-
for row in range(rowPosition):
541+
for row in range(rowPosition):
540542
new = []
541543
for col in range(colPosition):
542544
if (col % 2) != 0:
@@ -561,7 +563,7 @@ def savePreset(self):
561563
colPosition = self.fitp1.columnCount()
562564
list_pre_pk = []
563565
# save preset for peaks
564-
for row in range(rowPosition):
566+
for row in range(rowPosition):
565567
new = []
566568
for col in range(colPosition):
567569
if (col % 2) != 0:
@@ -1300,20 +1302,35 @@ def poly2vbm(x, ctr, d1, d2, d3, d4):
13001302
pktar = self.fitp1.cellWidget(8, 2*index_pk+1).currentIndex()
13011303
strtar = self.fitp1.cellWidget(0, 2*pktar-1).currentText()
13021304
strtar = strtar[0]
1303-
if self.fitp1.item(9, 2*index_pk+1) != None:
1304-
if len(self.fitp1.item(9, 2*index_pk+1).text()) > 0:
1305-
rtotar = float(self.fitp1.item(9, 2*index_pk+1).text())
1306-
pars[strind + str(index_pk+1) + '_amplitude'].expr = strtar + str(pktar) + '_amplitude * ' + str(rtotar)
1307-
1305+
# check self referenced because of recursionError
1306+
if pktar == index_pk+1:
1307+
print(2*index_pk+1, "column")
1308+
comboBox = QtWidgets.QComboBox()
1309+
comboBox.addItems(self.list_peak)
1310+
self.fitp1.setCellWidget(8, 2*index_pk+1, comboBox)
1311+
comboBox.setCurrentIndex(0) # set zero
1312+
else:
1313+
if self.fitp1.item(9, 2*index_pk+1) != None:
1314+
if len(self.fitp1.item(9, 2*index_pk+1).text()) > 0:
1315+
rtotar = float(self.fitp1.item(9, 2*index_pk+1).text())
1316+
pars[strind + str(index_pk+1) + '_amplitude'].expr = strtar + str(pktar) + '_amplitude * ' + str(rtotar)
1317+
13081318
# BE diff setup
13091319
if self.fitp1.cellWidget(10, 2*index_pk+1).currentIndex() > 0:
13101320
pktar = self.fitp1.cellWidget(10, 2*index_pk+1).currentIndex()
13111321
strtar = self.fitp1.cellWidget(0, 2*pktar-1).currentText()
13121322
strtar = strtar[0]
1313-
if self.fitp1.item(11, 2*index_pk+1) != None:
1314-
if len(self.fitp1.item(11, 2*index_pk+1).text()) > 0:
1315-
diftar = float(self.fitp1.item(11, 2*index_pk+1).text())
1316-
pars[strind + str(index_pk+1) + '_center'].expr = strtar + str(pktar) + '_center + ' + str(diftar)
1323+
# check self referenced because of recursionError
1324+
if pktar == index_pk+1:
1325+
comboBox = QtWidgets.QComboBox()
1326+
comboBox.addItems(self.list_peak)
1327+
self.fitp1.setCellWidget(10, 2*index_pk+1, comboBox)
1328+
comboBox.setCurrentIndex(0)
1329+
else:
1330+
if self.fitp1.item(11, 2*index_pk+1) != None:
1331+
if len(self.fitp1.item(11, 2*index_pk+1).text()) > 0:
1332+
diftar = float(self.fitp1.item(11, 2*index_pk+1).text())
1333+
pars[strind + str(index_pk+1) + '_center'].expr = strtar + str(pktar) + '_center + ' + str(diftar)
13171334

13181335
# evaluate model and optimize parameters for fitting in lmfit
13191336
init = mod.eval(pars, x=x)

0 commit comments

Comments
 (0)