From 9f6d4e0d0cec17320311dc99afd8b6f65abacd04 Mon Sep 17 00:00:00 2001
From: Dominik Demuth
Date: Mon, 5 Jun 2023 19:57:42 +0200
Subject: [PATCH] split ficitive cp and tnmh
---
src/gui_qt/_py/tnmh_dialog.py | 54 ++++++++++++------
src/gui_qt/dsc/glass_dialog.py | 49 +++++++++++++---
src/resources/_ui/tnmh_dialog.ui | 98 +++++++++++++++++++++++---------
3 files changed, 149 insertions(+), 52 deletions(-)
diff --git a/src/gui_qt/_py/tnmh_dialog.py b/src/gui_qt/_py/tnmh_dialog.py
index 58933b0..dee2ee0 100644
--- a/src/gui_qt/_py/tnmh_dialog.py
+++ b/src/gui_qt/_py/tnmh_dialog.py
@@ -14,9 +14,39 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
- Dialog.resize(842, 683)
+ Dialog.resize(1042, 683)
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
+ self.verticalLayout_2 = QtWidgets.QVBoxLayout()
+ self.verticalLayout_2.setObjectName("verticalLayout_2")
+ self.label = QtWidgets.QLabel(Dialog)
+ sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
+ sizePolicy.setHorizontalStretch(0)
+ sizePolicy.setVerticalStretch(0)
+ sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
+ self.label.setSizePolicy(sizePolicy)
+ self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
+ self.label.setObjectName("label")
+ self.verticalLayout_2.addWidget(self.label)
+ self.label_3 = QtWidgets.QLabel(Dialog)
+ sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
+ sizePolicy.setHorizontalStretch(0)
+ sizePolicy.setVerticalStretch(0)
+ sizePolicy.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth())
+ self.label_3.setSizePolicy(sizePolicy)
+ self.label_3.setText("")
+ self.label_3.setObjectName("label_3")
+ self.verticalLayout_2.addWidget(self.label_3)
+ self.label_4 = QtWidgets.QLabel(Dialog)
+ self.label_4.setObjectName("label_4")
+ self.verticalLayout_2.addWidget(self.label_4)
+ self.label_5 = QtWidgets.QLabel(Dialog)
+ self.label_5.setText("")
+ self.label_5.setObjectName("label_5")
+ self.verticalLayout_2.addWidget(self.label_5)
+ spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
+ self.verticalLayout_2.addItem(spacerItem)
+ self.gridLayout.addLayout(self.verticalLayout_2, 0, 3, 2, 1)
self.graphicsView = PlotWidget(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
@@ -28,20 +58,6 @@ class Ui_Dialog(object):
self.graphicsView_2 = PlotWidget(Dialog)
self.graphicsView_2.setObjectName("graphicsView_2")
self.gridLayout.addWidget(self.graphicsView_2, 1, 2, 1, 1)
- self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
- self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
- self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
- self.buttonBox.setObjectName("buttonBox")
- self.gridLayout.addWidget(self.buttonBox, 3, 2, 1, 1)
- self.label = QtWidgets.QLabel(Dialog)
- sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Preferred)
- sizePolicy.setHorizontalStretch(0)
- sizePolicy.setVerticalStretch(0)
- sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
- self.label.setSizePolicy(sizePolicy)
- self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
- self.label.setObjectName("label")
- self.gridLayout.addWidget(self.label, 2, 2, 1, 1)
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.listWidget = QtWidgets.QListWidget(Dialog)
@@ -76,6 +92,11 @@ class Ui_Dialog(object):
self.pushButton_3.setObjectName("pushButton_3")
self.verticalLayout.addWidget(self.pushButton_3)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 3, 1)
+ self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
+ self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
+ self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
+ self.buttonBox.setObjectName("buttonBox")
+ self.gridLayout.addWidget(self.buttonBox, 3, 2, 1, 2)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
@@ -85,7 +106,8 @@ class Ui_Dialog(object):
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "SImba, everything the light touches is our kingdom"))
- self.label.setText(_translate("Dialog", "sdff"))
+ self.label.setText(_translate("Dialog", "
Tg values:
"))
+ self.label_4.setText(_translate("Dialog", "TNMH parameter:
"))
self.pushButton.setText(_translate("Dialog", "Calculate Tg"))
self.pushButton_2.setText(_translate("Dialog", "Fictive Cp"))
self.label_2.setText(_translate("Dialog", "Tg for TNMH"))
diff --git a/src/gui_qt/dsc/glass_dialog.py b/src/gui_qt/dsc/glass_dialog.py
index 5a23cc1..b5fc2e0 100644
--- a/src/gui_qt/dsc/glass_dialog.py
+++ b/src/gui_qt/dsc/glass_dialog.py
@@ -1,6 +1,6 @@
from itertools import cycle
-from numpy import array
+from numpy import array, nan
from pyqtgraph import mkPen, mkBrush
from nmreval.lib.colors import Tab10
@@ -22,6 +22,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
self._dsc = {}
self._plots = {}
self._tg_value = {}
+ self._fit = {}
self.limits = RegionItem(), RegionItem()
for lim in self.limits:
@@ -43,6 +44,11 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
self.graphicsView.removeItem(val)
self.graphicsView_2.removeItem(val)
+ self._dsc = {}
+ self._plots = {}
+ self._tg_value = {}
+ self._fit = {}
+
def add_sets(self):
min_x = 10_000_000
max_x = -10_000_000
@@ -60,7 +66,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
item.setForeground(mkBrush(c.rgb()))
self.listWidget.addItem(item)
- self._dsc[key] = data
+ self._dsc[key] = (data, None)
data_plot = PlotItem(x=data.x, y=data.y, pen=mkPen(c.rgb()))
self.graphicsView.addItem(data_plot)
@@ -88,6 +94,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
self.graphicsView_2.addItem(tnmh_fit)
self._plots[key] = (data_plot, tg_plot, glass, liquid, tangent, fictive_cp, tnmh_fit)
+ self._tg_value[key] = {'onset': (nan, nan), 'mid': (nan, nan), 'end': (nan, nan), 'inflection': (nan, nan), 'fictive': (nan, nan)}
if self._limitless:
dist = max_x - min_x
@@ -108,22 +115,27 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
key = item.data(QtCore.Qt.UserRole)
plot = self._plots[key]
- data = self._dsc[key]
+ data, _ = self._dsc[key]
tg_results, glass, liquid, tangent = data.glass_transition(*baselines)
for i, line in enumerate((glass, liquid, tangent)):
plot[i+2].setData(x=line[:, 0], y=line[:, 1])
- plot[1].setData(array(list(tg_results.values())))
- self._tg_value[key] = tg_results
+ self._tg_value[key].update(tg_results)
+
+ plot[1].setData(array(list(self._tg_value[key].values())))
def show_tg_values(self, item):
values = self._tg_value.get(item.data(QtCore.Qt.UserRole))
if values is not None:
label = '\n'.join((f'{name.capitalize()}: {pos[0]:.2f} K' for name, pos in values.items()))
- self.label.setText(label)
+ self.label_3.setText(label)
+
+ fit = self._fit.get(item.data(QtCore.Qt.UserRole))
+ if fit is not None:
+ self.label_5.setText(fit._parameter_string())
@QtCore.pyqtSlot(QtWidgets.QListWidgetItem, name='on_listWidget_itemChanged')
def change_visibility(self, item: QtWidgets.QListWidgetItem):
@@ -145,18 +157,37 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
key = item.data(QtCore.Qt.UserRole)
plot = self._plots[key]
- data = self._dsc[key]
+ data, _ = self._dsc[key]
cp, tg = data.get_fictive_cp(*baselines)
plot[5].setData(cp.x, cp.y)
+ self._dsc[key] = (data, cp)
self._tg_value[key]['fictive'] = (tg, 0)
plot[1].setData(array(list(self._tg_value[key].values())))
- res = cp.calculate_tnmh([60, 0.5, 1, 2e5], *baselines, return_fictive=False)
- print(res.pprint())
+ @QtCore.pyqtSlot(name='on_pushButton_3_clicked')
+ def make_tnmh(self):
+ baselines = tuple(lim.getRegion() for lim in self.limits)
+ if baselines[0][0] > baselines[1][0]:
+ baselines = baselines[1], baselines[0]
+
+ for idx in range(self.listWidget.count()):
+ item = self.listWidget.item(idx)
+ if item.checkState() == QtCore.Qt.Unchecked:
+ continue
+
+ key = item.data(QtCore.Qt.UserRole)
+ plot = self._plots[key]
+ _, data = self._dsc[key]
+
+ if data is None:
+ continue
+
+ res = data.calculate_tnmh([60, 0.5, 1, 2e5], *baselines, return_fictive=False)
+ self._fit[key] = res
plot[-1].setData(res.x, res.y)
def close(self) -> bool:
diff --git a/src/resources/_ui/tnmh_dialog.ui b/src/resources/_ui/tnmh_dialog.ui
index 1367664..9e218cb 100644
--- a/src/resources/_ui/tnmh_dialog.ui
+++ b/src/resources/_ui/tnmh_dialog.ui
@@ -6,7 +6,7 @@
0
0
- 842
+ 1042
683
@@ -14,6 +14,66 @@
SImba, everything the light touches is our kingdom
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ <html><head/><body><p><span style=" font-weight:600;">Tg values:</span></p></body></html>
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+ -
+
+
+ <html><head/><body><p><span style=" font-weight:600;">TNMH parameter:</span></p></body></html>
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
-
@@ -27,32 +87,6 @@
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Ok
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
- sdff
-
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
-
-
-
-
-
@@ -128,6 +162,16 @@
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+