def _thread_fun(self, queue, device, show_q): self.queue = queue self.show_q = show_q if self.use_buffer: self.input_buffer = {} try: self.setup_connections() self.start(device) if DEBUG: print(f"{self.name} starting...") try: while True: try: FPS.update(self.name) if self.use_buffer: self.consume_queue_data() self.run() except StopNodeException: break finally: self.end(device) except Exception as e: traceback.print_exc() instance = self.getWrapper().canvasRef().pyFlowInstance threading.Thread(target=stop_pipeline, args=(instance, )).start() msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText("Error occured during node execution!") msg.setInformativeText(str(e)) msg.setDetailedText(traceback.format_exc()) msg.setWindowTitle("Node execution error!") msg.setStandardButtons(QMessageBox.Ok) msg.exec()
def failed_template_warning(residue): ''' Warning dialog handling the case where a template is not recognised by OpenMM when attempting to start a simulation. ''' from Qt.QtWidgets import QMessageBox, QPushButton msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msgtext = 'Residue {} {} of chain {} (shown) does not match any template'\ + ' in the molecular dynamics database. It may be missing atoms (have'\ + ' you added hydrogens?) or be an unusual residue that has not been'\ + ' parameterised. Choose what you wish to do with it from the options'\ + ' below.' msg.setText(msgtext.format(residue.name, residue.number, residue.chain_id)) addh = QPushButton('Add hydrogens and retry') msg.addButton(addh, QMessageBox.AcceptRole) exclude = QPushButton('Exclude residue from simulations and retry') msg.addButton(exclude, QMessageBox.RejectRole) abort = QPushButton('Abort') msg.addButton(abort, QMessageBox.NoRole) msg.exec_() btn = msg.clickedButton() # print("Button: {}".format(btn)) if btn == addh: return "addh" if btn == exclude: return "exclude" return "abort"
def generic_warning(message): from Qt.QtWidgets import QMessageBox msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setText(message) msg.setStandardButtons(QMessageBox.Ok) msg.exec_()
def show_info_dialog(self, msg, title='Info'): """ Shows a info dialog :param msg: str, message to show with the dialog :param title: str, title of the dialog """ dialog = QMessageBox() dialog.setIcon(QMessageBox.Information) dialog.setWindowTitle(title) dialog.setText(msg) dialog.exec_()
def libadd_ring(self): """add ring to library or open it in a new model""" selection = self.session.seqcrow_ordered_selection_manager.selection if not selection.single_structure: raise RuntimeError("selected atoms must be on the same model") rescol = ResidueCollection(selection[0].structure) walk_atoms = rescol.find( [AtomSpec(atom.atomspec) for atom in selection]) if len(walk_atoms) < 1: raise RuntimeError("no walk direction could be determined") ring_name = self.ring_name.text() ring = Ring(rescol, name=ring_name, end=walk_atoms) ring.comment = "E:%s" % ",".join( [str(rescol.atoms.index(atom) + 1) for atom in walk_atoms]) if len(ring_name) == 0: chimerax_ring = ResidueCollection(ring).get_chimera(self.session) chimerax_ring.name = "ring preview" self.session.models.add([chimerax_ring]) bild_obj = show_walk_highlight(ring, chimerax_ring, [0.9, 0.4, 0.3, 0.9], self.session) self.session.models.add(bild_obj, parent=chimerax_ring) else: check_aaronlib_dir() filename = os.path.join(AARONLIB, "Rings", ring_name + ".xyz") if os.path.exists(filename): exists_warning = QMessageBox() exists_warning.setIcon(QMessageBox.Warning) exists_warning.setText( "%s already exists.\nWould you like to overwrite?" % filename) exists_warning.setStandardButtons(QMessageBox.Yes | QMessageBox.No) rv = exists_warning.exec_() if rv == QMessageBox.Yes: ring.write(outfile=filename) self.tool_window.status("%s added to ring library" % ring_name) else: self.tool_window.status( "%s has not been added to ring library" % ring_name) else: ring.write(outfile=filename) self.tool_window.status("%s added to ring library" % ring_name)
class PopUpWarning(Error): """ display a popup error box with a custom message """ def __init__(self, _msg): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Warning") self.msg_box.setIcon(QMessageBox.Warning) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText(_msg) self.msg_box.exec_()
class SidNotValid(Error): """ Raised when the file can't be open """ def __init__(self): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Warning) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText("Sid not valid") self.msg_box.exec_()
class NoSelectionError(Error): """ Raised when the user don't select a file needed """ def __init__(self): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Critical) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText("Select a file !") self.msg_box.exec_()
class Error(Exception): """ Basic exeption class """ def __init__(self, msg): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Critical) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText(msg) self.msg_box.exec_()
def choice_warning(message): ''' Pop up a warning dialog box with the given message, and return True if the user wants to go ahead. ''' from Qt.QtWidgets import QMessageBox msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setText(message) msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) reply = msg.exec_() if reply == QMessageBox.Ok: return True return False
def show_warning_dialog(self, msg, detail=None): """ Shows a warning dialog :param msg: str, message to show with the dialog :param detail: str, detail information to show (optional) """ dialog = QMessageBox() dialog.setIcon(QMessageBox.Warning) dialog.setWindowTitle('Warning') dialog.setText(msg) if detail: dialog.setDetailedText(detail) dialog.exec_()
def show_confirm_dialog(self, msg, title='Title'): """ Shows a yes/no confirmation dialog :param msg: str, message to show with the dialog :param title: str, title of the dialog :return: bool, Whether the user has pressed yes(True) or No(False) """ dialog = QMessageBox() dialog.setIcon(QMessageBox.Question) result = dialog.question(self.parent_window, title, msg, QMessageBox.Yes, QMessageBox.No) if result == QMessageBox.Yes: return True return False
def _fun(self, device): try: self.setup_connections() self.run(device) except Exception as e: traceback.print_exc() self._terminate() msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText("Error occured during node execution!") msg.setInformativeText(str(e)) msg.setDetailedText(traceback.format_exc()) msg.setWindowTitle("Node execution error!") msg.setStandardButtons(QMessageBox.Ok) msg.exec()
def libadd_substituent(self): """add ligand to library or open it in a new model""" selection = selected_atoms(self.session) if not selection.single_structure: raise RuntimeError("selected atoms must be on the same model") residues = [] for atom in selection: if atom.residue not in residues: residues.append(atom.residue) rescol = ResidueCollection(selection[0].structure, convert_residues=residues) substituent_atoms = [ atom for atom in rescol.atoms if atom.chix_atom in selection ] start = None avoid = None for atom in substituent_atoms: for atom2 in atom.connected: if atom2 not in substituent_atoms: if start is None: start = atom avoid = atom2 else: raise RuntimeError( "substituent must only have one connection to the molecule" ) if start is None: raise RuntimeError( "substituent is not connected to a larger molecule") substituent_atoms.remove(start) substituent_atoms.insert(0, start) sub_name = self.sub_name.text() confs = self.sub_confs.value() angle = self.sub_angle.value() comment = "CF:%i,%i" % (confs, angle) if len(sub_name) == 0: sub = Substituent(substituent_atoms, name="test", conf_num=confs, conf_angle=angle) else: sub = Substituent(substituent_atoms, name=sub_name, conf_num=confs, conf_angle=angle) sub.comment = comment #align substituent bond to x axis sub.coord_shift(-avoid.coords) x_axis = np.array([1., 0., 0.]) n = np.linalg.norm(start.coords) vb = start.coords / n d = np.linalg.norm(vb - x_axis) theta = np.arccos((d**2 - 2) / -2) vx = np.cross(vb, x_axis) sub.rotate(vx, theta) add = False if len(sub_name) == 0: chimerax_sub = ResidueCollection(sub).get_chimera(self.session) chimerax_sub.name = "substituent preview" self.session.models.add([chimerax_sub]) bild_obj = ghost_connection_highlight( sub, [0.60784, 0.145098, 0.70196, 0.5], self.session) self.session.models.add(bild_obj, parent=chimerax_sub) else: check_aaronlib_dir() filename = os.path.join(AARONLIB, "Subs", sub_name + ".xyz") if os.path.exists(filename): exists_warning = QMessageBox() exists_warning.setIcon(QMessageBox.Warning) exists_warning.setText( "%s already exists.\nWould you like to overwrite?" % filename) exists_warning.setStandardButtons(QMessageBox.Yes | QMessageBox.No) rv = exists_warning.exec_() if rv == QMessageBox.Yes: add = True else: self.tool_window.status( "%s has not been added to substituent library" % sub_name) else: add = True if add: sub.write(outfile=filename) self.tool_window.status("%s added to substituent library" % sub_name) register_selectors(self.session.logger, sub_name) if self.session.ui.is_gui: if (sub_name not in ELEMENTS and sub_name[0].isalpha() and (len(sub_name) > 1 and not any(not (c.isalnum() or c in "+-") for c in sub_name[1:]))): add_submenu = self.session.ui.main_window.add_select_submenu add_selector = self.session.ui.main_window.add_menu_selector substituent_menu = add_submenu(['Che&mistry'], 'Substituents') add_selector(substituent_menu, sub_name, sub_name)
def libadd_ligand(self): """add ligand to library or open it in a new model""" selection = selected_atoms(self.session) if not selection.single_structure: raise RuntimeError("selected atoms must be on the same model") rescol = ResidueCollection(selection[0].structure) ligand_atoms = [ atom for atom in rescol.atoms if atom.chix_atom in selection ] key_chix_atoms = [ atom for atom in self.key_atomspec if not atom.deleted ] if len(key_chix_atoms) < 1: key_atoms = set([]) for atom in ligand_atoms: for atom2 in atom.connected: if atom2 not in ligand_atoms: key_atoms.add(atom) else: key_atoms = rescol.find( [AtomSpec(atom.atomspec) for atom in key_chix_atoms]) if len(key_atoms) < 1: raise RuntimeError("no key atoms could be determined") lig_name = self.ligand_name.text() ligand = Component(ligand_atoms, name=lig_name, key_atoms=key_atoms) ligand.comment = "K:%s" % ",".join( [str(ligand.atoms.index(atom) + 1) for atom in key_atoms]) if len(lig_name) == 0: chimerax_ligand = ResidueCollection(ligand).get_chimera( self.session) chimerax_ligand.name = "ligand preview" self.session.models.add([chimerax_ligand]) bild_obj = key_atom_highlight(ligand, [0.2, 0.5, 0.8, 0.5], self.session) self.session.models.add(bild_obj, parent=chimerax_ligand) else: check_aaronlib_dir() filename = os.path.join(AARONLIB, "Ligands", lig_name + ".xyz") if os.path.exists(filename): exists_warning = QMessageBox() exists_warning.setIcon(QMessageBox.Warning) exists_warning.setText( "%s already exists.\nWould you like to overwrite?" % filename) exists_warning.setStandardButtons(QMessageBox.Yes | QMessageBox.No) rv = exists_warning.exec_() if rv == QMessageBox.Yes: ligand.write(outfile=filename) self.tool_window.status("%s added to ligand library" % lig_name) else: self.tool_window.status( "%s has not been added to ligand library" % lig_name) else: ligand.write(outfile=filename) self.tool_window.status("%s added to ligand library" % lig_name)