Source code for metafalcon.gui.gui

#!/usr/bin/env python2

from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
import sys
import os
import json
import webbrowser

from .multiinput import Ui_MainWindow
from .configure_therm import Ui_dialog_thermcfg
from .configure_base import Ui_dialog_base
from ..interfaces.types import types as ifacetypes
from ..interfaces.types import types_specific as ifacespec
from ..cvs.types import types as cvtypes
from ..cvs.types import types_specific as cvspec
from .. import initial as init

[docs]class metafalcon_app(QtWidgets.QMainWindow, Ui_MainWindow): configfile = "meta-config.json" def __init__(self, parent=None): super(metafalcon_app, self).__init__(parent) self.setupUi(self) self.read_config(self.configfile) self.init_menubar() self.cmb_md_calc.addItems(ifacetypes.keys()) self.cmb_cv_type.addItems(cvtypes.keys()) self.chk_meta_do.stateChanged.connect(self.enable_meta_widgets) self.chk_multi_do.stateChanged.connect(self.toggle_multistate) self.chk_wt_do.stateChanged.connect(self.toggle_wt) self.chk_wall_only.stateChanged.connect(self.enable_onlywall) self.rad_init_gen.toggled.connect(self.enable_init_gen_widgets) self.rad_init_exist.toggled.connect(self.enable_init_exist_widgets) self.rad_init_use.toggled.connect(self.enable_init_use_widgets) self.cmb_md_calc.activated[str].connect(self.enable_calccfg) self.cmb_wall_type.activated[str].connect(self.enable_wall) self.but_init_xyz.clicked.connect(self.set_xyz_filename) self.cmb_md_therm.activated[str].connect(self.enable_thermcfg) self.but_init_dir.clicked.connect(self.set_logdir) self.but_md_thermcfg.clicked.connect(self.set_thermcfg) self.but_md_calccfg.clicked.connect(self.set_ifacecfg) self.but_cv_conf.clicked.connect(self.set_cvcfg) self.but_cv_add.clicked.connect(self.add_cv) self.but_cv_edit.clicked.connect(self.edit_cv) self.but_cv_del.clicked.connect(self.delete_cv) self.but_cv_cancel.clicked.connect(self.cancel_cv_edit) self.but_cv_save.clicked.connect(self.save_cv_edit) self.set_keys_and_dtypes() self.ifacecfg = {} self.thermcfg = {} self.fill_forms() self.active_cv = None
[docs] def set_keys_and_dtypes(self): self.md_keys = {self.txt_md_tstep: "tstep", self.txt_md_nsteps: "nsteps", self.chk_meta_do: "do_meta"} self.md_dtypes = {self.txt_md_tstep: float, self.txt_md_nsteps: int, self.chk_meta_do: bool} self.init_keys = {self.txt_init_xyz: "xyz", self.txt_init_temp: "temperature", self.txt_init_dir: "logdir", self.txt_init_step: "step"} self.init_dtypes = {self.txt_init_xyz: str, self.txt_init_temp: float, self.txt_init_dir: str, self.txt_init_step: int} self.thermcfg_dtypes = {"temperature": float, "tau": float} self.meta_keys = {self.txt_meta_height: "height", self.cmb_meta_heightunit: "height_unit", self.txt_meta_taug: "tau_g"} self.meta_dtypes = {self.txt_meta_height: float, self.cmb_meta_heightunit: str, self.txt_meta_taug: int} self.multi_keys = {self.txt_multi_height: "height", self.cmb_multi_heightunit: "height_unit"} self.multi_dtypes = {self.txt_multi_height: float, self.cmb_multi_heightunit: str} self.multicv_keys = {self.txt_multi_state1: "state1", self.txt_multi_state2: "state2", self.txt_multi_width: "width", self.cmb_multi_widthunit: "width_unit"} self.multinooncv_keys = {self.txt_multi_state1: "no_index1", self.txt_multi_state2: "no_index2", self.txt_multi_width: "width", self.cmb_multi_widthunit: "width_unit"} self.multicv_dtypes = {self.txt_multi_state1: int, self.txt_multi_state2: int, self.txt_multi_width: float, self.cmb_multi_widthunit: str} self.multithr_keys = {self.txt_multi_eps: "value", self.cmb_multi_epsunit: "unit"} self.multithr_dtypes = {self.txt_multi_eps: float, self.cmb_multi_epsunit: str} self.cvgeneral_keys = {self.txt_cv_name: "name", self.cmb_cv_type: "type", self.txt_cv_width: "width", self.chk_wall_only: "wall only"} self.cvgeneral_dtypes = {self.txt_cv_name: str, self.cmb_cv_type: str, self.txt_cv_width: float, self.chk_wall_only: bool} self.cvwall_keys = {self.cmb_wall_type: "type", self.txt_wall_exp: "exp", self.txt_wall_scale: "s", self.txt_wall_offset: "offset", self.txt_wall_weight: "c1", self.txt_wall_stren: "c2"} self.cvwall_dtypes = {self.cmb_wall_type: str, self.txt_wall_exp: float, self.txt_wall_scale: float, self.txt_wall_offset: float, self.txt_wall_weight: float, self.txt_wall_stren: float} self.cvplot_keys = {self.txt_plot_min: "min", self.txt_plot_max: "max", self.txt_plot_npoints: "npoints", self.txt_plot_ticks: "ticks"} self.cvplot_dtypes = {self.txt_plot_min: float, self.txt_plot_max: float, self.txt_plot_npoints: int, self.txt_plot_ticks: float}
[docs] def toggle_multistate(self, state): if state == Qt.Checked: self.enable_widgets(self.get_grid_children(self.grid_multi)) self.enable_widgets(self.get_grid_children(self.grid_multicv)) else: self.disable_widgets(self.get_grid_children(self.grid_multi)) self.disable_widgets(self.get_grid_children(self.grid_multicv))
[docs] def toggle_wt(self, state): if state == Qt.Checked: self.enable_widgets(self.get_grid_children(self.grid_wt)) else: self.disable_widgets(self.get_grid_children(self.grid_wt))
[docs] def enable_calccfg(self, text): if text == "None": self.but_md_calccfg.setEnabled(False) else: self.but_md_calccfg.setEnabled(True)
[docs] def enable_thermcfg(self, text): if text == "None": self.but_md_thermcfg.setEnabled(False) else: self.but_md_thermcfg.setEnabled(True)
[docs] def enable_wall(self, text): poly_forms = [self.txt_wall_exp, self.txt_wall_scale] log_forms = [self.txt_wall_weight, self.txt_wall_stren] if text == "None": self.disable_widgets(poly_forms + log_forms + [self.txt_wall_offset]) elif "polynomial" in text: self.enable_widgets(poly_forms + [self.txt_wall_offset]) self.disable_widgets(log_forms) elif "logarithmic" in text: self.enable_widgets(log_forms + [self.txt_wall_offset]) self.disable_widgets(poly_forms)
[docs] def enable_init_gen_widgets(self, state): if state: self.enable_widgets(self.get_grid_children(self.grid_init_gen)) self.disable_widgets(self.get_grid_children(self.grid_init_use))
[docs] def enable_init_use_widgets(self, state): if state: self.disable_widgets(self.get_grid_children(self.grid_init_gen)) self.enable_widgets(self.get_grid_children(self.grid_init_use))
[docs] def enable_init_exist_widgets(self, state): if state: self.disable_widgets(self.get_grid_children(self.grid_init_gen)) self.disable_widgets(self.get_grid_children(self.grid_init_use))
[docs] def enable_meta_widgets(self, state): if state == Qt.Checked: self.enable_widgets(self.get_grid_children(self.grid_meta)) self.enable_widgets(self.get_grid_children(self.grid_cv_list)) self.enable_widgets([self.list_cv]) self.enable_widgets([self.chk_multi_do]) if self.chk_multi_do.isChecked(): self.toggle_multistate(Qt.Checked) self.enable_widgets([self.chk_wt_do]) if self.chk_wt_do.isChecked(): self.toggle_wt(Qt.Checked) else: self.disable_widgets(self.get_grid_children(self.grid_meta)) self.disable_widgets(self.get_grid_children(self.grid_cv_list)) self.disable_widgets([self.list_cv]) self.disable_widgets([self.chk_multi_do]) self.disable_widgets([self.chk_wt_do]) self.toggle_multistate(False) self.toggle_wt(False)
[docs] def enable_onlywall(self, state): if state == Qt.Checked: self.disable_widgets([self.txt_cv_width] + self.get_tab_children(self.tab_plot)) else: self.enable_widgets([self.txt_cv_width] + self.get_tab_children(self.tab_plot))
[docs] def get_tab_children(self, tab): return tab.findChildren(QtWidgets.QWidget)
[docs] def get_grid_children(self, grid): return [grid.itemAt(i).widget() for i in range(grid.count())]
[docs] def enable_widgets(self, widgets): for widget in widgets: widget.setEnabled(True)
[docs] def disable_widgets(self, widgets): for widget in widgets: widget.setEnabled(False)
[docs] def init_menubar(self): self.action_save.triggered.connect(self.save_config) self.action_reset_all.triggered.connect(self.reset_forms) self.action_import.triggered.connect(self.import_forms) self.action_quit.triggered.connect(QtWidgets.QApplication.instance().quit) self.action_view_docs.triggered.connect(self.view_docs)
[docs] def set_cvcfg(self): dialog = QtWidgets.QDialog() dialog.ui = Ui_dialog_base() dialog.ui.setupUi(dialog) spec_config = cvspec[self.cmb_cv_type.currentText()] labels = [] txts = [] for i, key in enumerate(spec_config): labels.append(QtWidgets.QLabel(dialog)) txts.append(QtWidgets.QLineEdit(dialog)) labels[-1].setText(key) if key in self.cvs[self.active_cv]: txts[-1].setText(str(self.cvs[self.active_cv][key])) dialog.ui.grid_conf.addWidget(labels[-1], i, 0, 1, 1) dialog.ui.grid_conf.addWidget(txts[-1], i, 1, 1, 1) dialog.exec_() dialog.show() for i, key in enumerate(spec_config): if len(txts[i].text()): self.cvs[self.active_cv][key] = eval(txts[i].text())
[docs] def set_ifacecfg(self): dialog = QtWidgets.QDialog() dialog.ui = Ui_dialog_base() dialog.ui.setupUi(dialog) spec_config = ifacespec[self.cmb_md_calc.currentText()] labels = [] txts = [] for i, key in enumerate(spec_config): labels.append(QtWidgets.QLabel(dialog)) txts.append(QtWidgets.QLineEdit(dialog)) labels[-1].setText(key) if key in self.ifacecfg: txts[-1].setText(str(self.ifacecfg[key])) dialog.ui.grid_conf.addWidget(labels[-1], i, 0, 1, 1) dialog.ui.grid_conf.addWidget(txts[-1], i, 1, 1, 1) dialog.exec_() dialog.show() for i, key in enumerate(spec_config): if len(txts[i].text()): self.ifacecfg[key] = eval(txts[i].text())
[docs] def set_thermcfg(self): dialog = QtWidgets.QDialog() dialog.ui = Ui_dialog_thermcfg() dialog.ui.setupUi(dialog) thermcfg_keys = {dialog.ui.txt_temp: "temperature", dialog.ui.txt_tau: "tau"} thermcfg_dtypes = {dialog.ui.txt_temp: float, dialog.ui.txt_tau: float} for (widget, key) in thermcfg_keys.items(): if key in self.thermcfg.keys(): widget.setText(str(self.thermcfg[key])) else: widget.setText("") dialog.exec_() dialog.show() for (widget, key) in thermcfg_keys.items(): if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): self.thermcfg[key] = thermcfg_dtypes[widget](widget.text())
[docs] def set_xyz_filename(self): name, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Choose xyz-File", os.getcwd() , "*.xyz") if len(name): self.txt_init_xyz.setText(name)
[docs] def set_logdir(self): name = QtWidgets.QFileDialog.getExistingDirectory(self, "Choose Results Directory", os.getcwd()) if len(name): self.txt_init_dir.setText(name)
[docs] def enter_edit_mode(self): self.active_cv = self.list_cv.currentRow() self.enable_widgets(self.get_grid_children(self.grid_cv_save)) self.enable_widgets([self.tabs_cv_edit] + self.get_tab_children(self.tabs_cv_edit)) self.disable_widgets(self.get_grid_children(self.grid_cv_list) + [self.list_cv]) cv_config = self.cvs[self.active_cv] self.fill_cv_general(cv_config) self.fill_cv_wall(cv_config) self.fill_cv_plot(cv_config)
[docs] def fill_cv_general(self, cv_config): for (widget, key) in self.cvgeneral_keys.items(): if isinstance(widget, QtWidgets.QLineEdit): if key in cv_config.keys(): widget.setText(str(cv_config[key])) else: widget.setText("") elif isinstance(widget, QtWidgets.QComboBox): if key in cv_config.keys(): widget.setCurrentIndex(widget.findText(cv_config[key])) else: widget.setCurrentIndex(0) elif isinstance(widget, QtWidgets.QCheckBox): if key in cv_config.keys(): widget.setChecked(cv_config[key]) else: widget.setChecked(False)
[docs] def fill_cv_wall(self, cv_config): if "wall" in cv_config.keys(): wall_config = cv_config["wall"]["prm"] wall_config["type"] = cv_config["wall"]["type"] else: wall_config = {} for (widget, key) in self.cvwall_keys.items(): if isinstance(widget, QtWidgets.QLineEdit): if key in wall_config.keys(): widget.setText(str(wall_config[key])) else: widget.setText("") elif isinstance(widget, QtWidgets.QComboBox): if key in wall_config.keys(): widget.setCurrentIndex(widget.findText(wall_config[key])) else: widget.setCurrentIndex(0) self.enable_wall(self.cmb_wall_type.currentText())
[docs] def fill_cv_plot(self, cv_config): if "plot" in cv_config.keys(): plot_config = cv_config["plot"] else: plot_config = {} for (widget, key) in self.cvplot_keys.items(): if isinstance(widget, QtWidgets.QLineEdit): if key in plot_config.keys(): widget.setText(str(plot_config[key])) else: widget.setText("")
[docs] def leave_edit_mode(self): # self.active_cv = self.list_cv.currentRow() self.disable_widgets(self.get_grid_children(self.grid_cv_save)) self.disable_widgets([self.tabs_cv_edit] + self.get_tab_children(self.tabs_cv_edit)) self.enable_widgets(self.get_grid_children(self.grid_cv_list) + [self.list_cv]) self.enable_widgets([self.but_cv_edit, self.but_cv_del]) self.fill_cv_general({}) self.fill_cv_wall({}) self.fill_cv_plot({}) self.tabs_cv_edit.setCurrentIndex(0)
[docs] def add_cv(self): self.list_cv.addItem("new CV") self.cvs.append({"name": "new CV"}) lastindex = self.list_cv.count()-1 self.list_cv.setCurrentRow(lastindex) self.enter_edit_mode()
[docs] def edit_cv(self): self.active_cv = self.list_cv.currentRow() self.enter_edit_mode()
[docs] def delete_cv(self): self.active_cv = self.list_cv.currentRow() self.list_cv.takeItem(self.active_cv) del self.cvs[self.active_cv] if len(self.list_cv) == 0: self.disable_widgets([self.but_cv_edit, self.but_cv_del]) self.active_cv = None
[docs] def cancel_cv_edit(self): self.leave_edit_mode()
[docs] def save_cv_edit(self): self.collect_cv_general() self.collect_cv_wall() self.collect_cv_plot() self.list_cv.item(self.active_cv).setText(self.cvs[self.active_cv]["name"]) self.leave_edit_mode()
[docs] def collect_cv_general(self): cv_config = self.cvs[self.active_cv] for (widget, key) in self.cvgeneral_keys.items(): if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): cv_config[key] = self.cvgeneral_dtypes[widget](widget.text()) elif isinstance(widget, QtWidgets.QComboBox) and widget.currentText() != "None": cv_config[key] = self.cvgeneral_dtypes[widget](widget.currentText()) elif isinstance(widget, QtWidgets.QCheckBox): cv_config[key] = self.cvgeneral_dtypes[widget](widget.isChecked()) if cv_config: self.cvs[self.active_cv] = cv_config pass
[docs] def collect_cv_wall(self): if "wall" in self.cvs[self.active_cv].keys(): wall_config = self.cvs[self.active_cv]["wall"]["prm"] wall_config["type"] = self.cvs[self.active_cv]["wall"]["type"] else: wall_config = {} for (widget, key) in self.cvwall_keys.items(): if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): wall_config[key] = self.cvwall_dtypes[widget](widget.text()) elif isinstance(widget, QtWidgets.QComboBox) and widget.currentText() != "None": wall_config[key] = self.cvwall_dtypes[widget](widget.currentText()) if wall_config: self.cvs[self.active_cv]["wall"] = {} self.cvs[self.active_cv]["wall"]["type"] = wall_config.pop("type", None) self.cvs[self.active_cv]["wall"]["prm"] = wall_config
[docs] def collect_cv_plot(self): if "plot" in self.cvs[self.active_cv].keys(): plot_config = self.cvs[self.active_cv]["plot"] else: plot_config = {} for (widget, key) in self.cvplot_keys.items(): if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): plot_config[key] = self.cvplot_dtypes[widget](widget.text()) if plot_config: self.cvs[self.active_cv]["plot"] = plot_config
[docs] def read_config(self, path): if os.path.exists(path): with open(path) as f: self.config = json.load(f) else: self.config = {}
[docs] def save_config(self): self.cancel_cv_edit() self.collect_forms() with open(self.configfile, "w") as f: json.dump(self.config, f, indent=2) if not self.rad_init_exist.isChecked(): init.generate_initial(self.config)
[docs] def import_forms(self): path = QtWidgets.QFileDialog.getExistingDirectory(self, "Import Input Information", os.getcwd()) self.read_config(path + "/" + self.configfile) self.fill_forms()
[docs] def reset_forms(self): self.cancel_cv_edit() self.config = {} self.fill_forms()
[docs] def fill_forms(self): self.fill_forms_md() self.fill_forms_init() self.fill_forms_meta() self.fill_forms_cv()
[docs] def fill_forms_md(self): if "molecular dynamics" in self.config.keys(): md_config = self.config["molecular dynamics"] else: md_config = {} for (widget, key) in self.md_keys.items(): if isinstance(widget, QtWidgets.QLineEdit): if key in md_config.keys(): widget.setText(str(md_config[key])) else: widget.setText("") if "interface" in md_config.keys() and "type" in md_config["interface"].keys(): iface = md_config["interface"]["type"]#.lower() else: iface = "None" if "interface" in md_config.keys() and "configure" in md_config["interface"].keys(): self.ifacecfg = md_config["interface"]["configure"] self.cmb_md_calc.setCurrentIndex(self.cmb_md_calc.findText(iface)) self.enable_calccfg(iface) therm = "None" if "thermostat" in md_config.keys(): self.thermcfg = md_config["thermostat"] if "type" in md_config["thermostat"].keys(): therm = md_config["thermostat"]["type"].capitalize() self.cmb_md_therm.setCurrentIndex(self.cmb_md_therm.findText(therm)) self.enable_thermcfg(therm) if "do_meta" in md_config.keys(): self.chk_meta_do.setChecked(md_config["do_meta"]) else: self.chk_meta_do.setChecked(False)
[docs] def fill_forms_init(self): if "molecular dynamics" in self.config.keys() and \ "initial" in self.config["molecular dynamics"].keys(): init_config = self.config["molecular dynamics"]["initial"] else: init_config = {} for (widget, key) in self.init_keys.items(): if isinstance(widget, QtWidgets.QLineEdit): if key in init_config.keys(): widget.setText(str(init_config[key])) else: widget.setText("") if "source" in init_config.keys(): if init_config["source"] == "new": self.rad_init_gen.toggle() elif init_config["source"] == "log": self.rad_init_use.toggle() elif init_config["source"] == "existing": self.rad_init_exist.toggle() else: self.rad_init_exist.toggle() if os.path.exists("initial.xyz") and os.path.exists("initial.vel"): self.rad_init_exist.toggle()
[docs] def fill_forms_meta(self): if "metadynamics" in self.config.keys(): meta_config = self.config["metadynamics"] if "metadynamics_multistate" in self.config.keys(): multi_config = meta_config meta_config = self.config["metadynamics_multistate"] else: multi_config = {} else: meta_config = {} multi_config = {} if "collective variables" in meta_config.keys(): self.cvs = meta_config["collective variables"] else: self.cvs = [] for (widget, key) in self.meta_keys.items(): if isinstance(widget, QtWidgets.QLineEdit): if key in meta_config.keys(): widget.setText(str(meta_config[key])) else: widget.setText("") elif isinstance(widget, QtWidgets.QComboBox): if key in meta_config.keys(): widget.setCurrentIndex(widget.findText(meta_config[key])) else: widget.setCurrentIndex(0) if "well-tempered" in meta_config.keys(): self.chk_wt_do.setChecked(True) if "delta_T" in meta_config["well-tempered"].keys(): self.txt_wt_deltat.setText(str(meta_config["well-tempered"]["delta_T"])) else: self.txt_wt_deltat.setText("") else: self.chk_wt_do.setChecked(False) self.txt_wt_deltat.setText("") if ("collective variables" in multi_config.keys() and "do_multistate" in multi_config["collective variables"][0].keys()): self.chk_multi_do.setChecked(multi_config["collective variables"][0]["do_multistate"]) else: self.chk_multi_do.setChecked(False) for (widget, key) in self.multi_keys.items(): if isinstance(widget, QtWidgets.QLineEdit): if key in multi_config.keys(): widget.setText(str(multi_config[key])) else: widget.setText("") elif isinstance(widget, QtWidgets.QComboBox): if key in multi_config.keys(): widget.setCurrentIndex(widget.findText(multi_config[key])) else: widget.setCurrentIndex(0) if "collective variables" in multi_config.keys(): cv_config = multi_config["collective variables"][0] if cv_config["type"] == "noongap": self.rad_multi_ngap.setChecked(True) widgetkeys = self.multinooncv_keys.items() elif cv_config["type"] == "energygap": self.rad_multi_egap.setChecked(True) widgetkeys = self.multicv_keys.items() else: cv_config = {} widgetkeys = self.multicv_keys.items() for (widget, key) in widgetkeys: if isinstance(widget, QtWidgets.QLineEdit): if key in cv_config.keys(): widget.setText(str(cv_config[key])) else: widget.setText("") elif isinstance(widget, QtWidgets.QComboBox): if key in cv_config.keys(): widget.setCurrentIndex(widget.findText(cv_config[key])) else: widget.setCurrentIndex(0) if "thresh" in cv_config.keys(): for (widget, key) in self.multithr_keys.items(): if isinstance(widget, QtWidgets.QLineEdit): if key in cv_config["thresh"].keys(): widget.setText(str(cv_config["thresh"][key])) else: widget.setText("") elif isinstance(widget, QtWidgets.QComboBox): if key in cv_config["thresh"].keys(): widget.setCurrentIndex(widget.findText(cv_config["thresh"][key])) else: widget.setCurrentIndex(0) elif len(self.txt_multi_eps.text()): self.txt_multi_eps.setText("")
[docs] def fill_forms_cv(self): cv_names = [cv["name"] for cv in self.cvs if "name" in cv.keys()] self.list_cv.clear() self.list_cv.addItems(cv_names) self.list_cv.setCurrentRow(0) if len(self.list_cv) == 0: self.disable_widgets([self.but_cv_edit, self.but_cv_del])
[docs] def collect_forms(self): self.collect_forms_md() self.collect_forms_init() self.collect_forms_meta()
[docs] def collect_forms_md(self): if "molecular dynamics" in self.config.keys(): md_config = self.config["molecular dynamics"] else: md_config = {} for (widget, key) in self.md_keys.items(): if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): md_config[key] = self.md_dtypes[widget](widget.text()) elif isinstance(widget, QtWidgets.QCheckBox): md_config[key] = self.md_dtypes[widget](widget.isChecked()) if md_config["do_meta"] and not "metadynamics" in self.config.keys(): self.config["metadynamics"] = {} if not "interface" in md_config: md_config["interface"] = {} md_config["interface"]["type"] = self.cmb_md_calc.currentText() md_config["interface"]["configure"] = self.ifacecfg if not "thermostat" in md_config: md_config["thermostat"] = {} md_config["thermostat"]["type"] = self.cmb_md_therm.currentText().lower() if "temperature" in self.thermcfg.keys(): md_config["thermostat"]["temperature"] = self.thermcfg["temperature"] if "tau" in self.thermcfg.keys(): md_config["thermostat"]["tau"] = self.thermcfg["tau"] self.config["molecular dynamics"] = md_config
[docs] def collect_forms_init(self): if "initial" in self.config["molecular dynamics"]: init_config = self.config["molecular dynamics"]["initial"] else: init_config = {} for (widget, key) in self.init_keys.items(): if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): init_config[key] = self.init_dtypes[widget](widget.text()) if self.rad_init_gen.isChecked(): init_config["source"] = "new" elif self.rad_init_use.isChecked(): init_config["source"] = "log" elif self.rad_init_exist.isChecked(): init_config["source"] = "existing" self.config["molecular dynamics"]["initial"] = init_config
[docs] def collect_forms_meta(self): if "metadynamics" in self.config.keys(): if "metadynamics_multistate" in self.config.keys(): meta_config = self.config["metadynamics_multistate"] multi_config = self.config["metadynamics"] else: meta_config = self.config["metadynamics"] multi_config = {} else: meta_config = {} for (widget, key) in self.meta_keys.items(): if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): meta_config[key] = self.meta_dtypes[widget](widget.text()) elif isinstance(widget, QtWidgets.QComboBox): meta_config[key] = self.meta_dtypes[widget](widget.currentText()) meta_config["collective variables"] = self.cvs if self.chk_wt_do.isChecked(): meta_config["well-tempered"] = {} if len(self.txt_wt_deltat.text()): meta_config["well-tempered"]["delta_T"] = float(self.txt_wt_deltat.text()) else: meta_config.pop("well-tempered", None) if self.chk_multi_do.isChecked(): for (widget, key) in self.multi_keys.items(): if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): multi_config[key] = self.multi_dtypes[widget](widget.text()) elif isinstance(widget, QtWidgets.QComboBox): multi_config[key] = self.multi_dtypes[widget](widget.currentText()) if not "collective variables" in multi_config: multi_config["collective variables"] = [{}] cv_config = multi_config["collective variables"][0] cv_config["do_multistate"] = True if self.rad_multi_egap.isChecked(): cv_config["name"] = "energy gap" cv_config["type"] = "energygap" widgetkeys = self.multicv_keys.items() elif self.rad_multi_ngap.isChecked(): cv_config["name"] = "noon gap" cv_config["type"] = "noongap" cv_config["nproc"] = 1 widgetkeys = self.multinooncv_keys.items() for (widget, key) in widgetkeys: if isinstance(widget, QtWidgets.QLineEdit) and len(widget.text()): cv_config[key] = self.multicv_dtypes[widget](widget.text()) elif isinstance(widget, QtWidgets.QComboBox): cv_config[key] = self.multicv_dtypes[widget](widget.currentText()) cv_config[key] = self.multicv_dtypes[widget](widget.currentText()) multi_config["collective variables"][0] = cv_config if self.rad_multi_ngap.isChecked(): lowernoonwall = {"name": "lower noon wall", "wall": {"prm": {"s": 1.0, "exp": 2.0, "offset": 1.8}, "type": "polynomial_lower"}, "no_index": cv_config["no_index2"]-1, "nproc": 1, "wall only": True, "type": "noon"} uppernoonwall = {"name": "upper noon wall", "wall": {"prm": {"s": 1.0, "exp": 2.0, "offset": 0.2}, "type": "polynomial_upper"}, "no_index": cv_config["no_index1"]+1, "nproc": 1, "wall only": True, "type": "noon"} if len(multi_config["collective variables"]) == 3: multi_config["collective variables"][1] = lowernoonwall multi_config["collective variables"][2] = uppernoonwall elif len(multi_config["collective variables"]) == 2: multi_config["collective variables"][1] = lowernoonwall multi_config["collective variables"].append(uppernoonwall) elif len(multi_config["collective variables"]) == 1: multi_config["collective variables"].append(lowernoonwall) multi_config["collective variables"].append(uppernoonwall) elif self.rad_multi_egap.isChecked(): multi_config["collective variables"] = [multi_config["collective variables"][0]] if len(self.txt_multi_eps.text()): for cv in [multi_config["collective variables"][0]]: if not "thresh" in cv.keys(): cv["thresh"] = {} if self.rad_multi_egap.isChecked(): cv["thresh"]["type"] = "lower" elif self.rad_multi_ngap.isChecked(): cv["thresh"]["type"] = "noon_lower" cv["thresh"]["value"] = float(self.txt_multi_eps.text()) cv["thresh"]["unit"] = self.cmb_multi_epsunit.currentText() for cv in meta_config["collective variables"]: if not "thresh" in cv.keys(): cv["thresh"] = {} if self.rad_multi_egap.isChecked(): cv["thresh"]["type"] = "upper" elif self.rad_multi_ngap.isChecked(): cv["thresh"]["type"] = "noon_upper" cv["thresh"]["value"] = float(self.txt_multi_eps.text()) cv["thresh"]["unit"] = self.cmb_multi_epsunit.currentText() if "tau_g" in meta_config.keys(): multi_config["tau_g"] = meta_config["tau_g"] self.config["metadynamics_multistate"] = meta_config self.config["metadynamics"] = multi_config self.config["metadynamics"]["collective variables"][0]["do_multistate"] = True else: self.config["metadynamics"] = meta_config for cv in self.config["metadynamics"]["collective variables"]: cv.pop("thresh", None) self.config.pop("metadynamics_multistate", None)
[docs] def view_docs(self): webbrowser.open("http://metafalcon.chemie.uni-wuerzburg.de/")
[docs]def main(): app = QtWidgets.QApplication(sys.argv) form = metafalcon_app() form.show() app.exec_()
if __name__ == '__main__': main()