source: palm/trunk/SCRIPTS/palm_gf @ 4869

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

update palm_gf to python3

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 11.0 KB
RevLine 
[4869]1#!/usr/bin/env python3
[2116]2# -*- coding: utf-8 -*-
3#--------------------------------------------------------------------------------#
[2696]4# This file is part of the PALM model system.
[2116]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#
[4843]17# Copyright 1997-2021  Leibniz Universitaet Hannover
[2116]18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
[4869]22#
23#
[2116]24# Former revisions:
25# -----------------
26# $Id: palm_gf 4869 2021-02-08 16:14:27Z schwenkel $
[4869]27# Modified palm_gf using python3 (edited by JR and RM)
28#
29# 4843 2021-01-15 15:22:11Z schwenkel
[4393]30# Removed PALM_BIN dependency
[4869]31#
[4393]32# 2825 2018-02-20 21:48:27Z maronga
[2825]33# Modified header
[4869]34#
[2825]35# 2718 2018-01-02 08:49:38Z maronga
[2716]36# Corrected "Former revisions" section
[4869]37#
[2716]38# 2696 2017-12-14 17:12:51Z kanani
39# Change in file header (GPL part)
[2116]40#
[2716]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#
[2117]47# 2116 2017-01-16 16:15:24Z maronga
48# Initial revision
[2116]49#
[4869]50#
51#
[2116]52# Description:
53# ------------
54#
[4869]55#
[2116]56# Instructions:
57# -------------
58#
59#------------------------------------------------------------------------------!
60
[4869]61from PyQt5 import QtWidgets, uic
62from PyQt5.QtWidgets import QDesktopWidget
63from palm_gf_files.palm_gf_conf import cfg_write, cfg_read
[2116]64import sys
65import os
[4869]66from palm_gf_files.palm_gf_exec import MyThread
67from palm_gf_files.palm_gf_tools import MyTable
[2116]68
[4869]69try:
70   devnull = open(os.devnull, 'w')
[4393]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
[4869]78except:
[4393]79   print ('Error. palm_gf probably called in wrong directory.')
[2116]80   raise SystemExit
81
[4869]82class AppMain(QtWidgets.QMainWindow):
[2308]83    def __init__(self):
[4869]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)
[2116]107
[4869]108    def load_table(self):
109        # opens table Ui
110        self.table = MyTable()
111        self.table.show()
[2116]112
[4869]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
[2116]123            else:
[4869]124                poisfft = False
[2116]125                temperton = False
[4869]126                switch = False
[2116]127
[4869]128            if self.psolver_combo_box.currentIndex() == 2:
129                multigrid = True
130            else:
131                multigrid = False
[2116]132
[4869]133            if self.spectra_box.checkState() == 2:
134                spectra = True
135                poisfft = True
136            else:
137                spectra = False
[2308]138
[4869]139            if self.nx_ny_ratio_check.checkState() == 2:
140                dnxny = self.nx_ny_ratio_box.value()
141            else:
142                dnxny = 0
[2308]143
[4869]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
[2308]150
[4869]151            if self.strict_matching_check.checkState() == 2:
152                tpn = self.strict_matching_box.value()
153            else:
154                tpn = 0
[2308]155
[4869]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)
[2308]161
[4869]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()
[2116]171
[4869]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)
[2116]176
[4869]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.')
[2116]186
[4869]187    def setprogressval(self, val):
188        # updates the value of the progressbar, data received from PyQtsignal
189        self.progressbar.setValue(val)
[2116]190
[4869]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
[2116]195        else:
[4869]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]))
[2116]215
[4869]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)
[2116]232
[4869]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())
[2116]239
[4869]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())
[2116]246
[4869]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)
[2308]251        else:
[4869]252            self.fft_combo_box.setEnabled(False)
253            self.fft_combo_box.setCurrentIndex(0)
[2308]254
[4869]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)
[2308]259        else:
[4869]260            self.nx_ny_ratio_box.setEnabled(True)
[2308]261
[4869]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)
[2308]266        else:
[4869]267            self.strict_matching_box.setEnabled(True)
[2308]268
[4869]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)
[2308]275        else:
[4869]276            self.npex_npey_ratio_box.setEnabled(True)
277            self.npex_npey_deviation_slider.setEnabled(True)
278            self.npex_npey_deviation_box.setEnabled(True)
[2308]279
[4869]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)
[2308]285
286
[2116]287if __name__ == "__main__":
[4869]288    app = QtWidgets.QApplication(sys.argv)
289    window = AppMain()
290    window.setWindowTitle('palm_gf')
[2116]291    window.show()
292    sys.exit(app.exec_())
Note: See TracBrowser for help on using the repository browser.