-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfn2nmr_gui.py
318 lines (291 loc) · 13.8 KB
/
gfn2nmr_gui.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import sys
import os
import torch
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox, QFileDialog, QWidget
from multiprocessing import cpu_count
from collections import deque
from gfn2nmr_core import calculation
current_dir = os.getcwd()
class Arguments():
charge = 0
crest_arg = ' -gfnff '
rdkit_arg = '0'
xyz = 'default.xyz'
exp_data = ' '
conf_search = True
customer = False
energy_cutoff = 3 # kcal/mol
pre_opt = False
device = torch.device('cpu')
continue_mode = True
draw3d = True
num_para = 1
class Job(QtCore.QThread):
finished_signal = QtCore.pyqtSignal() # Add signal for finished job
def __init__(self, args):
super().__init__()
self.args = args
def run(self):
calculation(self.args)
self.finished_signal.emit() # Emit signal when done
class mainwindow(QMainWindow): # The main window of UI
def __init__(self):
super(mainwindow, self).__init__()
self.setObjectName("MainWindow")
self.resize(1350, 592)
self.centralwidget = QtWidgets.QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(850, 110, 452, 311))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.pre_opt = QtWidgets.QCheckBox(self.verticalLayoutWidget)
self.pre_opt.setObjectName("pre_opt")
font = QtGui.QFont()
font.setFamily(u"Arial")
font.setBold(True)
font.setWeight(75)
self.pre_opt.setFont(font)
self.verticalLayout.addWidget(self.pre_opt)
self.no_cs = QtWidgets.QCheckBox(self.verticalLayoutWidget)
self.no_cs.setObjectName("no_cs")
self.no_cs.setFont(font)
self.verticalLayout.addWidget(self.no_cs)
self.draw3d = QtWidgets.QCheckBox(self.verticalLayoutWidget)
self.draw3d.setObjectName("draw3d")
self.draw3d.setFont(font)
self.draw3d.setChecked(True)
self.verticalLayout.addWidget(self.draw3d)
self.cmoff = QtWidgets.QCheckBox(self.verticalLayoutWidget)
self.cmoff.setObjectName("cmoff")
self.cmoff.setFont(font)
self.verticalLayout.addWidget(self.cmoff)
self.cus_con_ens = QtWidgets.QCheckBox(self.verticalLayoutWidget)
self.cus_con_ens.setObjectName(u"cus_con_ens")
self.cus_con_ens.setFont(font)
self.verticalLayout.addWidget(self.cus_con_ens)
self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(430, 110, 201, 321))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.m_cs = QtWidgets.QComboBox(self.verticalLayoutWidget_2)
self.m_cs.setObjectName("m_cs")
self.verticalLayout_2.addWidget(self.m_cs)
self.device_load = QtWidgets.QComboBox(self.verticalLayoutWidget_2)
self.device_load.setObjectName("device_load")
self.verticalLayout_2.addWidget(self.device_load)
self.Cutoff_E = QtWidgets.QSpinBox(self.verticalLayoutWidget_2)
self.Cutoff_E.setObjectName("Cutoff_E")
self.Cutoff_E.setSuffix(" Kcal/mol")
self.verticalLayout_2.addWidget(self.Cutoff_E)
self.chrg = QtWidgets.QSpinBox(self.verticalLayoutWidget_2)
self.chrg.setMinimum(-99)
self.chrg.setObjectName("chrg")
self.verticalLayout_2.addWidget(self.chrg)
self.Para_j = QtWidgets.QSpinBox(self.verticalLayoutWidget_2)
self.Para_j.setObjectName(u"Para_j")
self.Para_j.setMinimum(1)
self.Para_j.setMaximum(cpu_count())
self.Para_j.setValue(cpu_count() // 2)
self.verticalLayout_2.addWidget(self.Para_j)
self.select_file = QtWidgets.QPushButton(self.centralwidget)
self.select_file.setGeometry(QtCore.QRect(100, 40, 150, 46))
font = QtGui.QFont()
font.setFamily("Arial")
font.setBold(True)
font.setWeight(75)
self.select_file.setFont(font)
self.select_file.setObjectName("select_file")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(220, 140, 201, 31))
font = QtGui.QFont()
font.setFamily("Arial")
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(220, 250, 181, 31))
font = QtGui.QFont()
font.setFamily("Arial")
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(220, 190, 161, 31))
font = QtGui.QFont()
font.setFamily("Arial")
font.setBold(True)
font.setWeight(75)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(220, 310, 101, 31))
font = QtGui.QFont()
font.setFamily("Arial")
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(220, 380, 101, 16))
font = QtGui.QFont()
font.setFamily("Arial")
font.setBold(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setObjectName(u"label_6")
self.run = QtWidgets.QPushButton(self.centralwidget)
self.run.setGeometry(QtCore.QRect(610, 440, 150, 46))
self.run.setObjectName("run")
self.file_path = QtWidgets.QLineEdit(self.centralwidget)
self.file_path.setGeometry(QtCore.QRect(300, 50, 1001, 31))
self.file_path.setObjectName("file_path")
self.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(self)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1350, 37))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuHelp = QtWidgets.QMenu(self.menubar)
self.menuHelp.setObjectName("menuHelp")
self.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(self)
self.statusbar.setObjectName("statusbar")
self.setStatusBar(self.statusbar)
self.actionSelect_file = QtWidgets.QAction(self)
self.actionSelect_file.setObjectName("actionSelect_file")
self.actionExit = QtWidgets.QAction(self)
self.actionExit.setObjectName("actionExit")
self.actionDocument = QtWidgets.QAction(self)
self.actionDocument.setObjectName("actionDocument")
self.actionAbout = QtWidgets.QAction(self)
self.actionAbout.setObjectName("actionAbout")
self.menuFile.addAction(self.actionSelect_file)
self.menuFile.addAction(self.actionExit)
self.menuHelp.addAction(self.actionDocument)
self.menuHelp.addAction(self.actionAbout)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuHelp.menuAction())
self.retranslateUi(self)
QtCore.QMetaObject.connectSlotsByName(self)
# parameters for gfn2nmr stores here
self.path = " " # save the file path
self.wkdir = " "
self.file_q = deque() # Initialize the queue for file paths
# click to select xyz file
self.select_file.clicked.connect(self.select_file_)
self.actionSelect_file.triggered.connect(self.select_file_)
self.actionExit.triggered.connect(self.exit_)
self.device_load.addItems(["Auto", "CUDA", "CPU"])
self.m_cs.addItems(["rdkit_L1", "rdkit_L0"])
self.run.clicked.connect(self.run_next_file) # Connect run button to run_next_file function
self.actionAbout.triggered.connect(self.about)
self.actionDocument.triggered.connect(self.document)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "GFN2NMR v1.4 [email protected]"))
self.pre_opt.setText(_translate("MainWindow", "Pre-optimization"))
self.no_cs.setText(_translate("MainWindow", "No conformer searching"))
self.draw3d.setText(_translate("MainWindow", "Draw 3D structures to view results"))
self.cmoff.setText(_translate("MainWindow", "Switch off continue mode"))
self.cus_con_ens.setText(_translate("MainWindow", "Customer conformer ensemble"))
self.select_file.setText(_translate("MainWindow", "Select files"))
self.label.setText(_translate("MainWindow", "Method for conformer searching"))
self.label_2.setText(_translate("MainWindow", "Energy cut-off for conformers"))
self.label_3.setText(_translate("MainWindow", "Device for model loading"))
self.label_4.setText(_translate("MainWindow", "Charge"))
self.label_6.setText(_translate("MainWindow", "Parallel cores"))
self.run.setText(_translate("MainWindow", "Run"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuHelp.setTitle(_translate("MainWindow", "Help"))
self.actionSelect_file.setText(_translate("MainWindow", "Select files"))
self.actionExit.setText(_translate("MainWindow", "Exit"))
self.actionDocument.setText(_translate("MainWindow", "Document"))
self.actionAbout.setText(_translate("MainWindow", "About"))
self.Cutoff_E.setValue(3)
self.wkdir = os.getcwd()
def select_file_(self): # function to select xyz files
title = "Select coordinate files"
filter = "All Files (*);;XYZ Files (*.xyz)"
files, _ = QFileDialog.getOpenFileNames(self, title, self.wkdir, filter)
if files:
self.file_q.extend(files)
self.file_path.setText("; ".join(files)) # Display selected files
def exit_(self):
exit()
def about(self):
QMessageBox.about(self, "About", "Version 1.4. Author: Wen-Xuan Wang. Email: [email protected]")
def document(self):
path = os.path.join(current_dir, 'document.pdf')
os.system(f'start {path}')
def run_next_file(self): # Function to run the next file in the queue
if not self.file_q:
self.show_finished_message()
return
current_file = self.file_q.popleft()
self.file_path.setText(current_file) # Update display with the current file path
self.run_file(current_file)
def run_file(self, file_path): # Function to run a single file
if not file_path or not os.path.isfile(file_path):
QMessageBox.warning(self, "Warning", "The file does not exist", QMessageBox.Close)
return
args = Arguments() # Store the arguments to pass all parameters
args.xyz = file_path
args.charge = self.chrg.value()
args.energy_cutoff = self.Cutoff_E.value()
args.num_para = self.Para_j.value()
if self.device_load.currentText() == "Auto":
args.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
elif self.device_load.currentText() == "CUDA":
args.device = torch.device('cuda')
elif self.device_load.currentText() == "CPU":
pass
if self.m_cs.currentText() == "rdkit_L1":
args.rdkit_arg = "1"
elif self.m_cs.currentText() == "rdkit_L0":
args.rdkit_arg = "0"
if self.pre_opt.checkState() == 2:
args.pre_opt = True
if self.no_cs.checkState() == 2:
args.conf_search = False
if self.draw3d.checkState() == 0:
args.draw3d = False
if self.cmoff.checkState() == 2:
args.continue_mode = False
if self.cus_con_ens.checkState() == 2:
args.customer = True
self.run.setText("Running")
self.run.setEnabled(False)
self.select_file.setEnabled(False)
self.actionSelect_file.setEnabled(False)
self.job = Job(args)
#self.job.finished_signal.connect(self.show_finished_message) # Connect signal to slot
self.job.finished_signal.connect(self.reset_run_button) # Connect signal to reset run button
self.job.finished_signal.connect(self.run_next_file) # Connect signal to process next file
self.job.start()
def show_finished_message(self): # Slot to show message when job is done
QMessageBox.warning(self, "Message", "Calculation finished", QMessageBox.Close)
def reset_run_button(self): # Slot to reset run button
self.run.setText("Run")
self.run.setEnabled(True)
self.select_file.setEnabled(True)
self.actionSelect_file.setEnabled(True)
def closeEvent(self, event):
# Ensure all threads are finished before closing
for thread in QtCore.QThread.currentThread().children():
if isinstance(thread, QtCore.QThread):
thread.quit()
thread.wait()
event.accept() # Allow the window to close
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = mainwindow()
demo.show()
sys.exit(app.exec_())