-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathview_simulation_module.py
204 lines (179 loc) · 6.16 KB
/
view_simulation_module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# Title : View for module 1a
# Objective : View setup of module 1a
# Written by: Saskia Kutz
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
from PyQt5 import QtWidgets as qtw
class ViewSim(qtw.QWidget):
"""View part of module 1a"""
submitted = qtc.pyqtSignal(object)
startsim = qtc.pyqtSignal()
# noinspection PyArgumentList
def __init__(self):
"""Setup of all GUI sections and options"""
super().__init__()
self.setLayout(qtw.QFormLayout())
self.roi_x_min = qtw.QSpinBox(
self,
minimum=0,
maximum=10000,
value=0
)
self.roi_x_max = qtw.QSpinBox(
self,
minimum=1,
maximum=100000,
value=3000
)
# form.layout().addRow(self.roi_x_min, self.roi_x_max)
roi_layout_x = qtw.QHBoxLayout()
roi_layout_x.layout().addWidget(self.roi_x_min)
roi_layout_x.layout().addWidget(self.roi_x_max)
self.roi_y_min = qtw.QSpinBox(
self,
minimum=0,
maximum=10000,
value=0
)
self.roi_y_max = qtw.QSpinBox(
self,
minimum=1,
maximum=100000,
value=3000
)
# form.layout().addRow(self.roi_x_min, self.roi_x_max)
roi_layout_y = qtw.QHBoxLayout()
roi_layout_y.layout().addWidget(self.roi_y_min)
roi_layout_y.layout().addWidget(self.roi_y_max)
self.alpha = qtw.QDoubleSpinBox(
self,
minimum=0,
maximum=100,
singleStep=1,
value=5
)
self.beta = qtw.QDoubleSpinBox(
self,
minimum=0,
maximum=100,
decimals=6,
singleStep=0.000001,
value=0.166667
)
gamma_layout = qtw.QHBoxLayout()
gamma_layout.layout().addWidget(self.alpha)
gamma_layout.layout().addWidget(self.beta)
self.beta_a = qtw.QDoubleSpinBox(
self,
minimum=0,
maximum=100,
value=1
)
self.beta_b = qtw.QDoubleSpinBox(
self,
minimum=0,
maximum=100,
value=1
)
beta_layout = qtw.QHBoxLayout()
beta_layout.layout().addWidget(self.beta_a)
beta_layout.layout().addWidget(self.beta_b)
self.inputs = {
"number of clusters": qtw.QSpinBox(
self,
value=10,
minimum=1,
maximum=1000,
singleStep=1
),
"number of molecules per cluster": qtw.QSpinBox(
self,
minimum=1,
maximum=10000,
singleStep=1,
value=100
),
"model": qtw.QComboBox(),
"standard deviation [nm]": qtw.QSpinBox(
self,
minimum=0,
maximum=10000,
singleStep=1,
value=50
),
"background percentage": qtw.QDoubleSpinBox(
self,
minimum=0,
maximum=1,
singleStep=0.1,
value=0.5
),
"number of simulations": qtw.QSpinBox(
self,
minimum=1,
maximum=1000000,
singleStep=1,
value=10
),
"ROI x size [nm]": roi_layout_x,
"ROI y size [nm]": roi_layout_y,
"Gamma parameters (\u03B1, \u03B2)": gamma_layout,
"background distribution": beta_layout
}
models = ('Gaussian', 'no other model implemented')
self.inputs["model"].addItems(models)
self.inputs["model"].model().item(1).setEnabled(False)
for label, widget in self.inputs.items():
self.layout().addRow(label, widget)
self.dir_btn = qtw.QPushButton("Select directory")
self.dir_btn.clicked.connect(self.saveFile)
self.dir_line = qtw.QLineEdit("select directory")
self.dir_line.setReadOnly(True)
self.dir_line.textChanged.connect(lambda x: self.dir_line.setReadOnly(x == ''))
self.layout().addRow(self.dir_btn, self.dir_line)
self.start_btn = qtw.QPushButton(
'simulate',
clicked=self.start_sim
)
self.start_btn.setFont(qtg.QFont('Arial', 15))
self.start_btn.setDisabled(True)
self.dir_line.textChanged.connect(lambda x: self.start_btn.setDisabled(x == ''))
self.layout().addRow(self.start_btn)
def saveFile(self):
"""directory selection for storage"""
filename = qtw.QFileDialog.getExistingDirectory(
self,
"Select directory",
qtc.QDir.homePath()
)
self.dir_line.setText(filename)
def start_sim(self):
"""start simulation:
- data collection from input
- data emission
"""
data = {
'directory': self.dir_line.text(),
'nclusters': self.inputs['number of clusters'].value(),
'molspercluster': self.inputs['number of molecules per cluster'].value(),
'model': self.inputs['model'].currentText(),
'sdcluster': self.inputs['standard deviation [nm]'].value(),
'background': self.inputs['background percentage'].value(),
'nsim': self.inputs['number of simulations'].value(),
'roixmin': self.roi_x_min.value(),
'roixmax': self.roi_x_max.value(),
'roiymin': self.roi_y_min.value(),
'roiymax': self.roi_y_max.value(),
'alpha': self.alpha.value(),
'beta': self.beta.value(),
'a': self.beta_a.value(),
'b': self.beta_b.value()
}
self.start_btn.setDisabled(True)
self.startsim.emit()
print(data)
self.submitted.emit(data)
def show_error(self, error):
"""error message in separate window"""
qtw.QMessageBox.critical(None, 'Error', error)
# TODO: multimerisation as a checkbox option, if chosen: option to state number of molecules, proportion multimers,