source: palm/trunk/SCRIPTS/palm_gf @ 4901

Last change on this file since 4901 was 4869, checked in by schwenkel, 3 years ago

update palm_gf to python3

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 11.0 KB
Line 
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#--------------------------------------------------------------------------------#
4# This file is part of the PALM model system.
5#
6# PALM is free software: you can redistribute it and/or modify it under the terms
7# of the GNU General Public License as published by the Free Software Foundation,
8# either version 3 of the License, or (at your option) any later version.
9#
10# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# PALM. If not, see <http://www.gnu.org/licenses/>.
16#
17# Copyright 1997-2021  Leibniz Universitaet Hannover
18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
23#
24# Former revisions:
25# -----------------
26# $Id: palm_gf 4869 2021-02-08 16:14:27Z banzhafs $
27# Modified palm_gf using python3 (edited by JR and RM)
28#
29# 4843 2021-01-15 15:22:11Z schwenkel
30# Removed PALM_BIN dependency
31#
32# 2825 2018-02-20 21:48:27Z maronga
33# Modified header
34#
35# 2718 2018-01-02 08:49:38Z maronga
36# Corrected "Former revisions" section
37#
38# 2696 2017-12-14 17:12:51Z kanani
39# Change in file header (GPL part)
40#
41# 2309 2017-07-10 15:55:55Z gronemeier
42# some further bugfixes for palm_gf
43#
44# 2308 2017-07-10 12:15:43Z gronemeier
45# new version of palm_gf (bugfixes, changes and new options)
46#
47# 2116 2017-01-16 16:15:24Z maronga
48# Initial revision
49#
50#
51#
52# Description:
53# ------------
54#
55#
56# Instructions:
57# -------------
58#
59#------------------------------------------------------------------------------!
60
61from PyQt5 import QtWidgets, uic
62from PyQt5.QtWidgets import QDesktopWidget
63from palm_gf_files.palm_gf_conf import cfg_write, cfg_read
64import sys
65import os
66from palm_gf_files.palm_gf_exec import MyThread
67from palm_gf_files.palm_gf_tools import MyTable
68
69try:
70   devnull = open(os.devnull, 'w')
71   palm_dir = os.getcwd()
72   palm_bin = palm_dir + '/trunk/SCRIPTS'
73   job_dir = palm_dir + '/JOBS'
74   user_dir = palm_dir + '/USER_CODE'
75   with open(palm_bin + '/palmrungui', 'r') as fh:
76      # file found
77      out = None
78except:
79   print ('Error. palm_gf probably called in wrong directory.')
80   raise SystemExit
81
82class AppMain(QtWidgets.QMainWindow):
83    def __init__(self):
84        super(AppMain, self).__init__()
85        uic.loadUi(palm_bin + '/palm_gf_files/palm_gf.ui', self)
86        self.center_window()
87       
88       
89        # initial hiding of results ui elements
90        self.result_visibility(False)
91        # dis/enable ui elements when un/checked
92        self.strict_matching_check.stateChanged.connect(self.strict_matching_able)
93        self.npex_npey_ratio_check.stateChanged.connect(self.npex_npey_ratio_able)
94        self.nx_ny_ratio_check.stateChanged.connect(self.nx_ny_ratio_able)
95        self.psolver_combo_box.currentIndexChanged.connect(self.fft_method_able)
96        # loading last used values into ui
97        self.startup_values()
98        # making sure max is not less than min
99        self.nx_min_box.valueChanged.connect(self.input_min_max_check)
100        self.ny_min_box.valueChanged.connect(self.input_min_max_check)
101        self.nz_min_box.valueChanged.connect(self.input_min_max_check)
102        self.proc_min_box.valueChanged.connect(self.input_min_max_check)
103        # connects main buttons to subroutines
104        self.start_button.clicked.connect(self.initialize)
105        self.view_button.clicked.connect(self.load_table)
106        self.reset_button.clicked.connect(self.reset_values)
107
108    def load_table(self):
109        # opens table Ui
110        self.table = MyTable()
111        self.table.show()
112
113    def initialize(self):
114        # translating Ui input into checks used during calculation
115        if self.psolver_combo_box.currentIndex() != 0:
116            if self.psolver_combo_box.currentIndex() == 1:
117                poisfft = True
118                switch = True
119                if self.fft_combo_box.currentIndex() == 2:
120                    temperton = True
121                else:
122                    temperton = False
123            else:
124                poisfft = False
125                temperton = False
126                switch = False
127
128            if self.psolver_combo_box.currentIndex() == 2:
129                multigrid = True
130            else:
131                multigrid = False
132
133            if self.spectra_box.checkState() == 2:
134                spectra = True
135                poisfft = True
136            else:
137                spectra = False
138
139            if self.nx_ny_ratio_check.checkState() == 2:
140                dnxny = self.nx_ny_ratio_box.value()
141            else:
142                dnxny = 0
143
144            if self.npex_npey_ratio_check.checkState() == 2:
145                dpxpy = self.npex_npey_ratio_box.value()
146                dpxpy_dev = self.npex_npey_deviation_box.value()
147            else:
148                dpxpy = 0
149                dpxpy_dev = 0
150
151            if self.strict_matching_check.checkState() == 2:
152                tpn = self.strict_matching_box.value()
153            else:
154                tpn = 0
155
156            # writing the config
157            cfg_write(self.nx_min_box.value(), self.nx_max_box.value(), self.ny_min_box.value(),
158                      self.ny_max_box.value(), self.nz_min_box.value(), self.nz_max_box.value(),
159                      self.proc_min_box.value(), self.proc_max_box.value(), tpn,
160                      poisfft, switch, temperton, multigrid, spectra, dnxny, dpxpy, dpxpy_dev)
161
162            self.progressbar.setVisible(True)
163            self.progressbar.setValue(0)
164            # connects PyQtsignals to subroutines
165            self.thread = MyThread()
166            self.thread.change_value.connect(self.setprogressval)
167            self.thread.completed.connect(self.result_label_update)
168            self.thread.busy.connect(self.info_label_update)
169            # starts thread to calculate
170            self.thread.start()
171
172    def info_label_update(self):
173        # standby information during search of the limits of all results
174        self.results_information_label.setText('Standby please.')
175        self.results_information_label.setVisible(True)
176
177    def result_label_update(self, counter, timer):
178        self.result_visibility(True)
179        self.progressbar.setVisible(False)
180        if int(timer) == 0:
181            self.results_information_label.setText('Success! Gridfinder found ' + str(counter) +
182                                                   ' results in less than 1 second.')
183        else:
184            self.results_information_label.setText('Success! Gridfinder found ' + str(counter) +
185                                                   ' results in ' + str(timer) + ' seconds.')
186
187    def setprogressval(self, val):
188        # updates the value of the progressbar, data received from PyQtsignal
189        self.progressbar.setValue(val)
190
191    def startup_values(self):
192        # reads the .ini and updates default values to last used values
193        if os.path.exists('./palm_gf_config.ini') is False:
194            pass
195        else:
196            value_list = cfg_read()
197            self.nx_min_box.setValue(int(value_list[0]))
198            self.nx_max_box.setValue(int(value_list[1]))
199            self.ny_min_box.setValue(int(value_list[2]))
200            self.ny_max_box.setValue(int(value_list[3]))
201            self.nz_min_box.setValue(int(value_list[4]))
202            self.nz_max_box.setValue(int(value_list[5]))
203            self.proc_min_box.setValue(int(value_list[6]))
204            self.proc_max_box.setValue(int(value_list[7]))
205            if int(value_list[8]) != 0:
206                self.strict_matching_check.setCheckState(2)
207                self.strict_matching_box.setValue(int(value_list[8]))
208            if float(value_list[9]) != 0:
209                self.nx_ny_ratio_check.setCheckState(2)
210                self.nx_ny_ratio_box.setValue(float(value_list[9]))
211            if float(value_list[10]) != 0:
212                self.npex_npey_ratio_check.setCheckState(2)
213                self.npex_npey_ratio_box.setValue(float(value_list[10]))
214                self.npex_npey_deviation_box.setValue(float(value_list[11]))
215
216    def reset_values(self):
217        # resets values to default, does not update .ini
218        self.nx_min_box.setValue(0)
219        self.nx_max_box.setValue(1)
220        self.ny_min_box.setValue(0)
221        self.ny_max_box.setValue(1)
222        self.nz_min_box.setValue(0)
223        self.nz_max_box.setValue(1)
224        self.proc_min_box.setValue(0)
225        self.proc_max_box.setValue(1)
226        self.strict_matching_check.setCheckState(0)
227        self.nx_ny_ratio_check.setCheckState(0)
228        self.nx_ny_ratio_box.setValue(1.00)
229        self.npex_npey_ratio_check.setCheckState(0)
230        self.npex_npey_ratio_box.setValue(1.00)
231        self.npex_npey_deviation_box.setValue(1)
232
233    def input_min_max_check(self):
234        # setting chosen min values as minimum of maxima
235        self.nx_max_box.setMinimum(self.nx_min_box.value())
236        self.ny_max_box.setMinimum(self.ny_min_box.value())
237        self.nz_max_box.setMinimum(self.nz_min_box.value())
238        self.proc_max_box.setMinimum(self.proc_min_box.value())
239
240    def center_window(self):
241        # moving window to middle of the screen
242        frame = self.frameGeometry()
243        center = QDesktopWidget().availableGeometry().center()
244        frame.moveCenter(center)
245        self.move(frame.topLeft())
246
247    def fft_method_able(self):
248        # enable/disable QComboBox of fft method
249        if self.psolver_combo_box.currentIndex() == 1:
250            self.fft_combo_box.setEnabled(True)
251        else:
252            self.fft_combo_box.setEnabled(False)
253            self.fft_combo_box.setCurrentIndex(0)
254
255    def nx_ny_ratio_able(self):
256        # enable/disable QSpinBox of nx/ny-ratio
257        if int(self.nx_ny_ratio_check.checkState()) == 0:
258            self.nx_ny_ratio_box.setEnabled(False)
259        else:
260            self.nx_ny_ratio_box.setEnabled(True)
261
262    def strict_matching_able(self):
263        # enable/disable QSpinBox of strict matching
264        if int(self.strict_matching_check.checkState()) == 0:
265            self.strict_matching_box.setEnabled(False)
266        else:
267            self.strict_matching_box.setEnabled(True)
268
269    def npex_npey_ratio_able(self):
270        # enable/disable UI elements of npex/npey-ratio
271        if int(self.npex_npey_ratio_check.checkState()) == 0:
272            self.npex_npey_ratio_box.setEnabled(False)
273            self.npex_npey_deviation_slider.setEnabled(False)
274            self.npex_npey_deviation_box.setEnabled(False)
275        else:
276            self.npex_npey_ratio_box.setEnabled(True)
277            self.npex_npey_deviation_slider.setEnabled(True)
278            self.npex_npey_deviation_box.setEnabled(True)
279
280    def result_visibility(self, boolean):
281        # making certain ui elements in/visible
282        self.progressbar.setVisible(boolean)
283        self.results_information_label.setVisible(boolean)
284        self.view_button.setVisible(boolean)
285
286
287if __name__ == "__main__":
288    app = QtWidgets.QApplication(sys.argv)
289    window = AppMain()
290    window.setWindowTitle('palm_gf')
291    window.show()
292    sys.exit(app.exec_())
Note: See TracBrowser for help on using the repository browser.