Exemplo n.º 1
0
    def __init__(self):  # noqa
        QtWidgets.QMainWindow.__init__(self)
        self.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks
                            | QtWidgets.QMainWindow.AllowNestedDocks)

        # resize Window before it is shown
        options = pymol.invocation.options
        self.resize(options.win_x + (220 if options.internal_gui else 0),
                    options.win_y + (246 if options.external_gui else 18))

        # for thread-safe viewport command
        self.viewportsignal.connect(self.pymolviewport)

        # reusable dialogs
        self.dialog_png = None
        self.advanced_settings_dialog = None
        self.props_dialog = None
        self.builder = None

        # setting index -> callable
        self.setting_callbacks = defaultdict(list)

        # "session_file" setting in window title
        self.setting_callbacks[440].append(lambda v: self.setWindowTitle(
            "PyMOL (" + os.path.basename(v) + ")"))

        # "External" Command Line and Loggin Widget
        self._setup_history()
        self.lineedit = CommandLineEdit()
        self.lineedit.setObjectName("command_line")
        self.browser = QtWidgets.QPlainTextEdit()
        self.browser.setObjectName("feedback_browser")
        self.browser.setReadOnly(True)

        # convenience: clicking into feedback browser gives focus to command
        # line. Drawback: Copying with CTRL+C doesn't work in feedback
        # browser -> clear focus proxy while text selected
        self.browser.setFocusProxy(self.lineedit)

        @self.browser.copyAvailable.connect
        def _(yes):
            self.browser.setFocusProxy(None if yes else self.lineedit)
            self.browser.setFocus()

        # Font
        self.browser.setFont(getMonospaceFont())
        connectFontContextMenu(self.browser)

        lineeditlayout = QtWidgets.QHBoxLayout()
        command_label = QtWidgets.QLabel("PyMOL>")
        command_label.setObjectName("command_label")
        lineeditlayout.addWidget(command_label)
        lineeditlayout.addWidget(self.lineedit)
        self.lineedit.setToolTip('''Command Input Area

Get the list of commands by hitting <TAB>

Get the list of arguments for one command with a question mark:
PyMOL> color ?

Read the online help for a command with "help":
PyMOL> help color

Get autocompletion for many arguments by hitting <TAB>
PyMOL> color ye<TAB>    (will autocomplete "yellow")
''')

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.browser)
        layout.addLayout(lineeditlayout)

        quickbuttonslayout = QtWidgets.QVBoxLayout()
        quickbuttonslayout.setSpacing(2)

        extguilayout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.LeftToRight)
        extguilayout.setContentsMargins(2, 2, 2, 2)
        extguilayout.addLayout(layout)
        extguilayout.addLayout(quickbuttonslayout)

        class ExtGuiFrame(QtWidgets.QFrame):
            def mouseDoubleClickEvent(_, event):
                self.toggle_ext_window_dockable(True)

        dockWidgetContents = ExtGuiFrame(self)
        dockWidgetContents.setLayout(extguilayout)
        dockWidgetContents.setObjectName("extgui")

        self.ext_window = \
            dockWidget = QtWidgets.QDockWidget(self)
        dockWidget.setWindowTitle("External GUI")
        dockWidget.setWidget(dockWidgetContents)
        if options.external_gui:
            dockWidget.setTitleBarWidget(QtWidgets.QWidget())
        else:
            dockWidget.hide()

        self.addDockWidget(Qt.TopDockWidgetArea, dockWidget)

        # rearrange vertically if docking left or right
        @dockWidget.dockLocationChanged.connect
        def _(area):
            if area == Qt.LeftDockWidgetArea or area == Qt.RightDockWidgetArea:
                extguilayout.setDirection(QtWidgets.QBoxLayout.BottomToTop)
                quickbuttonslayout.takeAt(quickbuttons_stretch_index)
            else:
                extguilayout.setDirection(QtWidgets.QBoxLayout.LeftToRight)
                if quickbuttons_stretch_index >= quickbuttonslayout.count():
                    quickbuttonslayout.addStretch()

        # OpenGL Widget
        self.pymolwidget = PyMOLGLWidget(self)
        self.setCentralWidget(self.pymolwidget)

        cmd = self.cmd = self.pymolwidget.cmd
        '''
        # command completion
        completer = QtWidgets.QCompleter(cmd.kwhash.keywords, self)
        self.lineedit.setCompleter(completer)
        '''

        # overload <Tab> action
        self.lineedit.installEventFilter(self)
        self.pymolwidget.installEventFilter(self)

        # Quick Buttons
        for row in [
            [
                ('Reset', cmd.reset),
                ('Zoom', lambda: cmd.zoom(animate=1.0)),
                ('Orient', lambda: cmd.orient(animate=1.0)),

                # render dialog will be constructed when the menu is shown
                # for the first time. This way it's populated with the current
                # viewport and settings. Also defers parsing of the ui file.
                ('Draw/Ray', WidgetMenu(self).setSetupUi(self.render_dialog)),
            ],
            [
                ('Unpick', cmd.unpick),
                ('Deselect', cmd.deselect),
                ('Rock', cmd.rock),
                ('Get View', self.get_view),
            ],
            [
                ('|<', cmd.rewind),
                ('<', cmd.backward),
                ('Stop', cmd.mstop),
                ('Play', cmd.mplay),
                ('>', cmd.forward),
                ('>|', cmd.ending),
                ('MClear', cmd.mclear),
            ],
            [
                ('Builder', self.open_builder_panel),
                ('Properties', self.open_props_dialog),
                ('Rebuild', cmd.rebuild),
            ],
        ]:
            hbox = QtWidgets.QHBoxLayout()
            hbox.setSpacing(2)

            for name, callback in row:
                btn = QtWidgets.QPushButton(name)
                btn.setProperty("quickbutton", True)
                btn.setAttribute(Qt.WA_LayoutUsesWidgetRect)  # OS X workaround
                hbox.addWidget(btn)

                if callback is None:
                    btn.setEnabled(False)
                elif isinstance(callback, QtWidgets.QMenu):
                    btn.setMenu(callback)
                else:
                    btn.released.connect(callback)

            quickbuttonslayout.addLayout(hbox)

        quickbuttonslayout.addStretch()
        quickbuttons_stretch_index = quickbuttonslayout.count() - 1

        # menu top level
        self.menubar = menubar = self.menuBar()

        # action groups
        actiongroups = {}

        def _addmenu(data, menu):
            '''Fill a menu from "data"'''
            menu.setTearOffEnabled(True)
            menu.setWindowTitle(menu.title())  # needed for Windows
            for item in data:
                if item[0] == 'separator':
                    menu.addSeparator()
                elif item[0] == 'menu':
                    _addmenu(item[2], menu.addMenu(item[1].replace('&', '&&')))
                elif item[0] == 'command':
                    command = item[2]
                    if command is None:
                        print('warning: skipping', item)
                    else:
                        if isinstance(command, str):
                            command = lambda c=command: cmd.do(c)
                        menu.addAction(item[1], command)
                elif item[0] == 'check':
                    if len(item) > 4:
                        menu.addAction(
                            SettingAction(self, cmd, item[2], item[1], item[3],
                                          item[4]))
                    else:
                        menu.addAction(
                            SettingAction(self, cmd, item[2], item[1]))
                elif item[0] == 'radio':
                    label, name, value = item[1:4]
                    try:
                        group, type_, values = actiongroups[item[2]]
                    except KeyError:
                        group = QtWidgets.QActionGroup(self)
                        type_, values = cmd.get_setting_tuple(name)
                        actiongroups[item[2]] = group, type_, values
                    action = QtWidgets.QAction(label, self)
                    action.triggered.connect(lambda _=0, args=(name, value):
                                             cmd.set(*args, log=1, quiet=0))

                    self.setting_callbacks[cmd.setting._get_index(
                        name)].append(
                            lambda v, V=value, a=action: a.setChecked(v == V))

                    group.addAction(action)
                    menu.addAction(action)
                    action.setCheckable(True)
                    if values[0] == value:
                        action.setChecked(True)
                elif item[0] == 'open_recent_menu':
                    self.open_recent_menu = menu.addMenu('Open Recent...')
                else:
                    print('error:', item)

        # recent files menu
        self.open_recent_menu = None

        # for plugins
        self.menudict = {'': menubar}

        # menu
        for _, label, data in self.get_menudata(cmd):
            assert _ == 'menu'
            menu = menubar.addMenu(label)
            self.menudict[label] = menu
            _addmenu(data, menu)

        # hack for macOS to hide "Edit > Start Dictation"
        # https://bugreports.qt.io/browse/QTBUG-43217
        if pymol.IS_MACOS:
            self.menudict['Edit'].setTitle('Edit_')
            QtCore.QTimer.singleShot(
                10, lambda: self.menudict['Edit'].setTitle('Edit'))

        # recent files menu
        if self.open_recent_menu:

            @self.open_recent_menu.aboutToShow.connect
            def _():
                self.open_recent_menu.clear()
                for fname in self.recent_filenames:
                    self.open_recent_menu.addAction(
                        fname if len(fname) < 128 else '...' + fname[-120:],
                        lambda fname=fname: self.load_dialog(fname))

        # some experimental window control
        menu = self.menudict['Display'].addSeparator()
        menu = self.menudict['Display'].addMenu('External GUI')
        menu.addAction('Toggle floating', self.toggle_ext_window_dockable,
                       QtGui.QKeySequence('Ctrl+E'))
        ext_vis_action = self.ext_window.toggleViewAction()
        ext_vis_action.setText('Visible')
        menu.addAction(ext_vis_action)

        # extra key mappings (MacPyMOL compatible)
        QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+O'),
                            self).activated.connect(self.file_open)
        QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+S'),
                            self).activated.connect(self.session_save)

        # feedback
        self.feedback_timer = QtCore.QTimer()
        self.feedback_timer.setSingleShot(True)
        self.feedback_timer.timeout.connect(self.update_feedback)
        self.feedback_timer.start(100)

        # legacy plugin system
        self.menudict['Plugin'].addAction('Initialize Plugin System',
                                          self.initializePlugins)

        # focus in command line
        if options.external_gui:
            self.lineedit.setFocus()
        else:
            self.pymolwidget.setFocus()

        # Apply PyMOL stylesheet
        try:
            with open(
                    cmd.exp_path('$PYMOL_DATA/pmg_qt/styles/pymol.sty')) as f:
                style = f.read()
        except IOError:
            print('Could not read PyMOL stylesheet.')
            print('DEBUG: PYMOL_DATA=' + repr(os.getenv('PYMOL_DATA')))
            style = ""

        if style:
            self.setStyleSheet(style)
Exemplo n.º 2
0
    def __init__(self, parent, protocol):

        super(Similarity_searches_results_window_qt, self).__init__(parent)
        self.protocol = protocol

        #########################
        # Configure the window. #
        #########################

        self.setWindowTitle(self._get_window_title())

        # Sets the central widget.
        self.central_widget = QtWidgets.QWidget()
        self.setCentralWidget(self.central_widget)

        # The window has a main vbox layout.
        self.main_vbox = QtWidgets.QVBoxLayout()


        ################
        # Upper frame. #
        ################

        title_text = self._get_upper_frame_title()

        self.upper_frame_title = QtWidgets.QLabel(title_text)
        self.main_vbox.addWidget(self.upper_frame_title)


        #################
        # Middle frame. #
        #################

        # Scroll area which contains the widgets, set as the centralWidget.
        self.middle_scroll = QtWidgets.QScrollArea()
        self.main_vbox.addWidget(self.middle_scroll)
        # Widget that contains the collection of Vertical Box.
        self.middle_widget = QtWidgets.QWidget()
        # Scroll area properties.
        self.middle_scroll.setWidgetResizable(True)
        self.middle_scroll.setWidget(self.middle_widget)

        # QFormLayout in the middle frame.
        self.middle_formlayout = QtWidgets.QFormLayout()
        self.middle_widget.setLayout(self.middle_formlayout)


        #-----------------
        # Buttons frame. -
        #-----------------

        # Set the frame and its layout.
        self.buttons_frame = QtWidgets.QFrame()
        self.middle_formlayout.addRow(self.buttons_frame)
        self.buttons_hbox = QtWidgets.QHBoxLayout()
        self.buttons_frame.setLayout(self.buttons_hbox)

        # Build the control buttons.
        self.blast_select_all_button = QtWidgets.QPushButton(text="Select All")
        self.blast_select_all_button.clicked.connect(self.blast_select_all)
        self.blast_select_none_button = QtWidgets.QPushButton(text="Select None")
        self.blast_select_none_button.clicked.connect(self.blast_select_none)
        self.blast_select_n_button = QtWidgets.QPushButton(text="Select Top:")
        self.blast_select_n_button.clicked.connect(self.blast_select_n)
        for button in [self.blast_select_all_button, self.blast_select_none_button, self.blast_select_n_button]:
            self.buttons_hbox.addWidget(button)

        # Build the line-edit for selecting only top entries.
        self.blast_select_n_enf = PyMod_entryfield_qt(label_text="", value="10",
                                                      validate={'validator': 'integer',
                                                                'min': 1, 'max': 5000})
        self.blast_select_n_enf.entry.setFixedWidth(70)
        self.buttons_hbox.addWidget(self.blast_select_n_enf.entry)

        # Align to the left all these widgets.
        self.buttons_hbox.setAlignment(QtCore.Qt.AlignLeft)
        for button in [self.blast_select_all_button, self.blast_select_none_button, self.blast_select_n_button]:
            button.setFixedWidth(button.sizeHint().width()+30)

        #-----------------
        # Results frame. -
        #-----------------

        # Set the frame and its layout.
        self.results_frame = QtWidgets.QFrame()
        self.middle_formlayout.addRow(self.results_frame)
        self.results_grid = QtWidgets.QGridLayout()
        self.results_frame.setLayout(self.results_grid)

        # Calls a method which actually displays the similarity searches results.
        self.display_blast_hits()

        # Align the gridded widgets to the left.
        self.results_grid.setAlignment(QtCore.Qt.AlignLeft)
        self.results_grid.setHorizontalSpacing(30)


        #################
        # Bottom frame. #
        #################

        self.main_button = QtWidgets.QPushButton("Submit")
        self.main_button.clicked.connect(lambda a=None: self.protocol.blast_results_state())
        self.main_vbox.addWidget(self.main_button)
        self.main_button.setFixedWidth(self.main_button.sizeHint().width())


        # Sets the main vertical layout.
        self.central_widget.setLayout(self.main_vbox)
        self.main_vbox.setAlignment(self.main_button, QtCore.Qt.AlignCenter)
Exemplo n.º 3
0
    def initialize_map(self,
                       pymod,
                       data_array,
                       pymod_elements,
                       ref_residues,
                       ref_selectors,
                       title=None,
                       pixel_size=5,
                       feature_type="contact",
                       threshold=8.0,
                       interaction_center="ca"):

        # Sets the attributes.
        self.data_array = data_array
        self.pixel_size = pixel_size
        self.feature_type = feature_type
        self.threshold = threshold
        self.interaction_center = interaction_center
        if self.feature_type in ("contact", "distance"):
            self.pymod_elements = pymod_elements
            self.pymod_element = self.pymod_elements[0]
        else:
            self.pymod_elements = pymod_elements
        # Get the PyMod residues for each residue having an interaction center and the PyMOL selectors
        # for each residue.
        self.ref_residues = ref_residues
        self.ref_selectors = ref_selectors

        # Assign the methods to get the labels.
        if self.feature_type == "contact":
            self.get_value_label = self._get_value_label_contact
        elif self.feature_type == "distance":
            self.get_value_label = self._get_value_label_distance
        elif self.feature_type == "distances_difference":
            self.get_value_label = self._get_value_label_distance_diff
        elif self.feature_type == "distances_mean":
            self.get_value_label = self._get_value_label_distance_mean
        elif self.feature_type == "distances_std":
            self.get_value_label = self._get_value_label_distance_std
        else:
            raise KeyError(self.feature_type)

        # Set the canvas size.
        min_size = 150
        h = self.pixel_size * len(self.data_array)
        win_size = min((910, h))
        win_size = max((min_size, win_size))

        if title:
            self.setWindowTitle(title)

        # Set some appearance parameters.
        self.controls_padding = 4
        if self.feature_type in ("contact", "distance"):
            self.controls_font = "helvetica 11 bold"
        else:
            self.controls_font = "helvetica 10 bold"
        self.controls_config = {
            "fg": "black",
            "font": self.controls_font,
            "padx": self.controls_padding,
            "pady": self.controls_padding
        }
        self.labels_pack_config = {
            "side": "left",
            "pady": (0, 5),
            "padx": (5, 0)
        }
        self.buttons_pack_config = {
            "side": "left",
            "pady": (0, 5),
            "padx": (1, 0)
        }

        # Frame of the window containing a row for some control buttons, a row for
        # the plot and a row for a messagebar.
        self.plot_frame = QtWidgets.QWidget()
        self.plot_frame_layout = QtWidgets.QGridLayout()
        self.plot_frame.setLayout(self.plot_frame_layout)
        self.setCentralWidget(self.plot_frame)

        # Control frame.
        self.controls_frame = QtWidgets.QWidget()
        self.controls_frame_layout = QtWidgets.QGridLayout()
        self.controls_frame.setLayout(self.controls_frame_layout)
        self.plot_frame_layout.addWidget(self.controls_frame)

        self.delete_distances_button = QtWidgets.QPushButton(
            "Delete all distances in PyMOL")
        self.delete_distances_button.setEnabled(False)
        self.delete_distances_button.clicked.connect(
            lambda a=None: self.clear_plot())
        self.controls_frame_layout.addWidget(self.delete_distances_button, 0,
                                             0)

        self.scale_factor = 0
        self.scale_down_button = QtWidgets.QPushButton("Zoom out")
        try:
            self.scale_down_button.setIcon(QtGui.QIcon.fromTheme("go-down"))
        except:
            pass
        self.scale_down_button.clicked.connect(
            lambda a=None: self.scale_plot_down())
        self.controls_frame_layout.addWidget(self.scale_down_button, 0, 1)

        self.scale_up_button = QtWidgets.QPushButton("Zoom in")
        try:
            self.scale_up_button.setIcon(QtGui.QIcon.fromTheme("go-up"))
        except:
            pass
        self.scale_up_button.clicked.connect(
            lambda a=None: self.scale_plot_up())
        self.controls_frame_layout.addWidget(self.scale_up_button, 0, 2)

        self.controls_frame_layout.setAlignment(QtCore.Qt.AlignLeft)

        # Frame containing the plot (with a scrollbar).
        self.canvas_plot_frame = QtWidgets.QWidget()
        self.canvas_plot_frame.setStyleSheet("background-color: white")
        self.canvas_plot_frame_layout = QtWidgets.QGridLayout()
        self.canvas_plot_frame.setLayout(self.canvas_plot_frame_layout)

        self.canvas_plot_scrollarea = QtWidgets.QScrollArea()
        self.canvas_plot_scrollarea.setWidgetResizable(True)
        self.canvas_plot_scrollarea.setWidget(self.canvas_plot_frame)
        self.plot_frame_layout.addWidget(self.canvas_plot_scrollarea)

        # Builds the scene where to draw the contact map.
        self.canvas_plot_scene = QtWidgets.QGraphicsScene()
        # Builds the graphics view containing the scene above.
        self.canvas_plot_view = Contact_map_graphics_view(
            self.canvas_plot_scene)
        self.canvas_plot_frame_layout.addWidget(self.canvas_plot_view)

        # A bottom frame fo the window, containing some buttons to interact with the graph.
        self.message_frame = QtWidgets.QFrame()
        self.message_frame_layout = QtWidgets.QHBoxLayout()
        self.message_frame.setLayout(self.message_frame_layout)
        self.plot_frame_layout.addWidget(self.message_frame)

        # Label to show which residue/position pair is currently being hovered by the mouse pointer.
        if self.feature_type in ("contact", "distance"):
            view_label_text = "Couple:"
        else:
            view_label_text = "Alignment positions:"
        self.view_label = QtWidgets.QLabel(view_label_text)
        # self.view_label.setStyleSheet(self.controls_config)
        self.message_frame_layout.addWidget(self.view_label)

        # Actually draws the contact map.
        self.draw_map()
Exemplo n.º 4
0
def create_dialog():

    dialog = QtWidgets.QDialog()
    dialog.setWindowTitle('Lighting Settings')

    setting = plugins.get_pmgapp().skin.setting

    sliders = [
        "Diffuse Reflection",
        ('ambient', 0, 1, None),
        ('reflect', -1, 1, None),
        "Direct Light from Front",
        ('direct (+reflect)', -1, 1, None),  # diffuse, coupled with "reflect"
        ('spec_direct', 0, 1, None),
        ('spec_direct_power', 0, 100, 1),
        "Free placeable directed Lights",
        ('light_count', 1, 8, 1),
        ('edit_light', 1, 7, 1),
        "Specular Reflection",
        ('spec_count', -1, 8, 1),
        # ('spec_power', -1, 200, 1), # deprecated since v1.5
        ('shininess', 0, 100, None),  # same as spec_power
        ('spec_reflect', -0.01, 1, None),
        ('specular', 0, 1, None),
        ('specular_intensity (=specular)', 0, 1, None),  # same as specular
        "Ambient Occlusion (Surface only)",
        ('ambient_occlusion_mode', 0, 2, 1),
        ('ambient_occlusion_scale', 1.0, 50., None),
        ('ambient_occlusion_smooth', 1, 20, 1),
        "Ray trace only",
        ('power', 1, 10, None),
        ('reflect_power', 1, 10, None),
    ]

    layout = QtWidgets.QVBoxLayout(dialog)

    button_layout = QtWidgets.QHBoxLayout()
    layout.addLayout(button_layout)
    layout.setContentsMargins(5, 0, 5, 0)
    button_layout.addWidget(
        QtWidgets.QLabel("<font color=red>Presets:</font>"))

    presets = [
        ("Default", preset_default),
        ("Metal", preset_metal),
        ("Plastic", preset_plastic),
        ("Rubber", preset_rubber),
        ("X-Ray", preset_xray),
    ]

    for name, fun in presets:
        btn = QtWidgets.QPushButton(name, dialog)
        btn.pressed.connect(fun)
        btn.setAutoDefault(False)
        button_layout.addWidget(btn)

    form_layout = QtWidgets.QFormLayout()
    form_layout.setContentsMargins(0, 0, 0, 0)
    form_layout.setVerticalSpacing(0)
    form_layout.setLabelAlignment(Qt.AlignLeft)
    layout.addLayout(form_layout)

    for i, item in enumerate(sliders, 1):
        if isinstance(item, str):
            label = QtWidgets.QLabel("<font color=blue>" + item + "</font>")
            form_layout.addRow(label)
            continue

        name, min, max, res = item
        if res is None:
            res = 0.01 if (max - min < 100) else 0.1

        line_edit = QtWidgets.QLineEdit(dialog)
        slider = SettingSlider(dialog,
                               name.split()[0], min, max, res, line_edit)

        h_layout = QtWidgets.QHBoxLayout()
        h_layout.addWidget(slider, 3)
        h_layout.addWidget(line_edit, 1)

        form_layout.addRow(name, h_layout)

    return dialog
Exemplo n.º 5
0
    def __init__(self, parent=None, app=None):
        super(_BuilderPanel, self).__init__(parent)

        self.setWindowTitle("Builder")
        self.setObjectName("builder")
        self.cmd = app.pymol.cmd

        self.layout = QtWidgets.QVBoxLayout()
        self.setLayout(self.layout)
        self.buttons_layout = QtWidgets.QVBoxLayout()

        self.tabs = QtWidgets.QTabWidget(self)
        self.layout.setContentsMargins(5, 5, 5, 5);
        self.layout.setSpacing(5);
        self.layout.addWidget(self.tabs)
        self.layout.addLayout(self.buttons_layout)
        self.layout.addStretch()

        self.fragments_layout = QtWidgets.QGridLayout()
        self.fragments_layout.setContentsMargins(5, 5, 5, 5);
        self.fragments_layout.setSpacing(5);
        self.fragments_tab = QtWidgets.QWidget()
        self.fragments_tab.setLayout(self.fragments_layout)
        self.protein_layout = QtWidgets.QGridLayout()
        self.protein_layout.setContentsMargins(5, 5, 5, 5);
        self.protein_layout.setSpacing(5);
        self.protein_tab = QtWidgets.QWidget()
        self.protein_tab.setLayout(self.protein_layout)

        self.tabs.addTab(self.fragments_tab, "Chemical")
        self.tabs.addTab(self.protein_tab, "Protein")

        self.getIcons()

        buttons = [
            [ ("H", "Hydrogen", lambda: self.replace("H", 1, 1, "Hydrogen")),
              ("C", "Carbon", lambda: self.replace("C", 4, 4, "Carbon")),
              ("N", "Nitrogen", lambda: self.replace("N", 4, 3, "Nitrogen")),
              ("O", "Oxygen", lambda: self.replace("O", 4, 2, "Oxygen")),
              ("P", "Phosphorus", lambda: self.replace("P",4,3, "Phosphorous")),
              ("S", "Sulfur", lambda: self.replace("S",2,2, "Sulfur")),
              ("F", "Fluorine", lambda: self.replace("F",1,1, "Fluorine")),
              ("Cl", "Chlorrine", lambda: self.replace("Cl",1,1, "Chlorine")),
              ("Br", "Bromine", lambda: self.replace("Br",1,1, "Bromine")),
              ("I", "Iodine", lambda: self.replace("I",1,1, "Iodine")),
              ("-CF3", "Trifluoromethane", lambda: self.replace("trifluoromethane",4,0, "trifluoro")),
              ("-OMe", "Methanol", lambda: self.replace("methanol",5,0, "methoxy")),
            ],
            [ ("CH4", "Methyl", lambda: self.grow("methane",1,0,"methyl")),
              ("C=C", "Ethylene", lambda: self.grow("ethylene",4,0,"vinyl")),
              ("C#C", "Acetylene", lambda: self.grow("acetylene",2,0,"alkynl")),
              ("C#N", "Cyanide", lambda: self.grow("cyanide",2,0,"cyano")),
              ("C=O", "Aldehyde", lambda: self.grow("formaldehyde",2,0,"carbonyl",)),
              ("C=OO", "Formic Acid", lambda: self.grow("formic",4,0,"carboxyl")),
              ("C=ON", "C->N amide", lambda: self.grow("formamide",5,0,"C->N amide")),
              ("NC=O", "N->C amide", lambda: self.grow("formamide",3,1,"N->C amide")),
              ("S=O2", "Sulfone", lambda: self.grow("sulfone",3,1,"sulfonyl")),
              ("P=O3", "Phosphite", lambda: self.grow("phosphite",4,0,"phosphoryl")),
              ("N=O2", "Nitro", lambda: self.grow("nitro",3,0,"nitro")),
            ],
            [
              ("#cyc3", "Cyclopropane", lambda: self.grow("cyclopropane",4,0,"cyclopropyl")),
              ("#cyc4", "Cyclobutane", lambda: self.grow("cyclobutane",4,0,"cyclobutyl")),
              ("#cyc5", "Cyclopentane", lambda: self.grow("cyclopentane",5,0,"cyclopentyl")),
              ("#cyc6", "Cyclohexane", lambda: self.grow("cyclohexane",7,0,"cyclohexyl")),
              ("#cyc7", "Cycloheptane", lambda: self.grow("cycloheptane",8,0,"cycloheptyl")),
              ("#aro5", "Cyclopentadiene", lambda: self.grow("cyclopentadiene",5,0,"cyclopentadienyl")),
              ("#aro6", "Benzene", lambda: self.grow("benzene",6,0,"phenyl")),
              ("#aro65", "Indane", lambda: self.grow("indane",12,0,"indanyl")),
              ("#aro66", "Napthylene", lambda: self.grow("napthylene",13,0,"napthyl")),
              ("#aro67", "Benzocycloheptane", lambda: self.grow("benzocycloheptane",13,0, "benzocycloheptyl")),
            ]
        ]

        self.btn_icons = {}

        requestsize = QtCore.QSize(48, 48)
        for row, btn_row in enumerate(buttons):
            for col, bb in enumerate(btn_row):
                btn_label, btn_tooltip, btn_command = bb
                btn = makeFragmentButton()
                if btn_label.startswith('#'):
                    icons = self.icons[btn_label[1:]]
                    btn.setIcon(icons[0])
                    btn.setIconSize(icons[1].actualSize(requestsize))
                    self.btn_icons[btn] = icons
                else:
                    btn.setText(btn_label)
                btn.setToolTip(btn_tooltip)
                btn.clicked.connect(btn_command)
                self.fragments_layout.addWidget(btn, row, col)

        buttons = [
            [ 'Ace', 'Ala', 'Arg', 'Asn', 'Asp', 'Cys', 'Gln', 'Glu', 'Gly', 'His', 'Ile', 'Leu' ],
            [ 'Lys', 'Met', 'Phe', 'Pro', 'Ser', 'Thr', 'Trp', 'Tyr', 'Val', 'NMe', 'NHH' ]
        ]
        for row, btn_row in enumerate(buttons):
            for col, btn_label in enumerate(btn_row):
                btn = makeFragmentButton()
                btn.setText(btn_label)
                btn.setToolTip("Build %s residue" % btn_label)
                res = btn_label.lower()
                slot = lambda val=None, s=self,r=res: s.attach(r)
                btn.clicked.connect(slot)
                self.protein_layout.addWidget(btn, row, col)

        lab = QtWidgets.QLabel('Secondary Structure:')
        lab_cols = 3
        self.ss_cbox = QtWidgets.QComboBox()
        self.ss_cbox.addItem("Alpha Helix")
        self.ss_cbox.addItem("Beta Sheet (Anti-Parallel)")
        self.ss_cbox.addItem("Beta Sheet (Parallel)")
        self.protein_layout.addWidget(lab, 2, 0, 1, lab_cols)
        self.protein_layout.addWidget(self.ss_cbox, 2, lab_cols, 1, 4)
        self.ss_cbox.currentIndexChanged[int].connect(self.ssIndexChanged)

        buttons = [
            [
              ( "@Atoms:", None, None),
              ( "Fix H", "Fix hydrogens on picked atoms", self.fixH),
              ( "Add H", "Add hydrogens to entire molecule", self.addH),
              ( "Invert", "Invert stereochemistry around pk1 (pk2 and pk3 will remain fixed)", self.invert),
              ( "Delete", "Remove atoms", self.removeAtom),
              ( "Clear", "Delete everything", self.clear),
              ( "@   Charge:", None, None),
              ( " +1 ", "Positive Charge", lambda: self.setCharge(1,"+1")),
              ( "  0 ", "Neutral Charge", lambda: self.setCharge(0,"neutral")),
              ( " -1 ", "Negative Charge", lambda: self.setCharge(-1,"-1")),
            ],
            [
              ( "@Bonds:", None, None),
              ( "Create", "Create bond between pk1 and pk2", self.createBond),
              ( "Delete", "Delete bond between pk1 and pk2", self.deleteBond),
              ( "Cycle", "Cycle bond valence", self.cycleBond),
              ( "  |  ", "Create single bond", lambda: self.setOrder("1", "single")),
              ( " || ", "Create double bond", lambda: self.setOrder("2", "double")),
              ( " ||| ", "Create triple bond", lambda: self.setOrder("3", "triple")),
              ( "Arom", "Create aromatic bond", lambda: self.setOrder("4", "aromatic")),
              ( "@   Model:", None, None),
              ( "Clean", "Cleanup structure", self.clean),
              ( "Sculpt", "Molecular sculpting", self.sculpt),
              ( "Fix", "Fix atom positions", self.fix),
              ( "Rest", "Restrain atom positions", self.rest),
            ],
            [
              ( "$El-stat", "Electrostatics term for 'Clean' action", "clean_electro_mode"),
              ( "@   ", None, None),
              ( "$Bumps", "Show VDW contacts during sculpting", "sculpt_vdw_vis_mode"),
              ( "@   ", None, None),
              ( "#Undo Enabled", "", "suspend_undo"),
              ( "Undo", "Undo last change", self.undo),
              ( "Redo", "Redo last change", self.redo),
            ]
        ]

        for row, btn_row in enumerate(buttons):
            btn_row_layout = QtWidgets.QHBoxLayout()
            self.buttons_layout.addLayout(btn_row_layout)
            for col, bb in enumerate(btn_row):
                btn_label, btn_tooltip, btn_command = bb
                if btn_label[0] == '@':
                    btn = QtWidgets.QLabel(btn_label[1:])
                elif btn_label[0] in ('#', '$'):
                    btn = QtWidgets.QCheckBox(btn_label[1:])
                    setting = btn_command
                    value = self.cmd.get_setting_int(setting)
                    if btn_label[0] == '$':
                        btn.setChecked(bool(value))
                        @btn.toggled.connect
                        def _(checked, n=setting):
                            self.cmd.set(n, checked, quiet=0)
                    else:
                        btn.setChecked(not value)
                        @btn.toggled.connect
                        def _(checked, n=setting):
                            self.cmd.set(n, not checked, quiet=0)
                else:
                    btn = makeFragmentButton()
                    btn.setText(btn_label)
                    btn.clicked.connect(btn_command)
                if btn_tooltip:
                    btn.setToolTip(btn_tooltip)
                btn_row_layout.addWidget(btn)
            btn_row_layout.addStretch()
Exemplo n.º 6
0
    def setupUi(self, UpdateDialog):
        UpdateDialog.setObjectName("UpdateDialog")
        UpdateDialog.resize(950, 470)
        self.verticalLayout = QtWidgets.QVBoxLayout(UpdateDialog)
        self.verticalLayout.setObjectName("verticalLayout")
        self.select_comp_label = QtWidgets.QLabel(UpdateDialog)
        self.select_comp_label.setObjectName("select_comp_label")
        self.verticalLayout.addWidget(self.select_comp_label)
        self.components_tableWidget = QtWidgets.QTableWidget(UpdateDialog)
        default_font = QtGui.QFont()
        default_font.setPointSize(default_font.pointSize()-1)
        self.components_tableWidget.setFont(default_font)
        self.components_tableWidget.setProperty("showDropIndicator", False)
        self.components_tableWidget.setDragDropOverwriteMode(False)
        self.components_tableWidget.setAlternatingRowColors(True)
        self.components_tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.components_tableWidget.setGridStyle(QtCore.Qt.NoPen)
        self.components_tableWidget.setColumnCount(self.n_cols)
        self.components_tableWidget.setObjectName("components_tableWidget")
        self.components_tableWidget.setRowCount(1)
        vertical_header_item = QtWidgets.QTableWidgetItem()
        self.components_tableWidget.setVerticalHeaderItem(0, vertical_header_item)
        for i in range(self.n_cols):
            item = QtWidgets.QTableWidgetItem()
            self.components_tableWidget.setHorizontalHeaderItem(i, item)

        item = QtWidgets.QTableWidgetItem()
        self.components_tableWidget.setItem(0, self.component_col_idx, item)
        item = QtWidgets.QTableWidgetItem()
        self.components_tableWidget.setItem(0, self.databases_col_idx, item)
        self.components_tableWidget.horizontalHeader().setVisible(True)
        self.components_tableWidget.horizontalHeader().setCascadingSectionResizes(False)
        self.components_tableWidget.setColumnWidth(self.component_col_idx, 210)
        self.components_tableWidget.setColumnWidth(self.databases_col_idx, 180)
        self.components_tableWidget.setColumnWidth(self.status_col_idx, 190)
        # self.components_tableWidget.setColumnWidth(self.source_col_idx, 390)
        # self.components_tableWidget.setColumnWidth(self.last_download_col_idx, 250)

        self.components_tableWidget.horizontalHeader().setStretchLastSection(True)
        self.components_tableWidget.verticalHeader().setVisible(False)
        self.components_tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.verticalLayout.addWidget(self.components_tableWidget)
        self.statusLabel = QtWidgets.QLabel(UpdateDialog)
        self.statusLabel.setObjectName("statusLabel")
        self.verticalLayout.addWidget(self.statusLabel)
        self.installation_progressBar = QtWidgets.QProgressBar(UpdateDialog)
        self.installation_progressBar.setEnabled(True)
        self.installation_progressBar.setProperty("value", 10)
        self.installation_progressBar.setObjectName("installation_progressBar")
        self.verticalLayout.addWidget(self.installation_progressBar)
        self.buttonsHorizontalLayout = QtWidgets.QHBoxLayout()
        self.buttonsHorizontalLayout.setObjectName("buttonsHorizontalLayout")
        self.installSel_button = QtWidgets.QPushButton(UpdateDialog)
        self.installSel_button.setObjectName("installSel_button")
        self.buttonsHorizontalLayout.addWidget(self.installSel_button)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.buttonsHorizontalLayout.addItem(spacerItem)
        self.cancel_button = QtWidgets.QPushButton(UpdateDialog)
        self.cancel_button.setObjectName("cancel_button")
        self.buttonsHorizontalLayout.addWidget(self.cancel_button)
        self.verticalLayout.addLayout(self.buttonsHorizontalLayout)

        UpdateDialog.setWindowTitle("Install and update databases")
        self.select_comp_label.setText("Select components to install or update")
        self.components_tableWidget.setSortingEnabled(True)
        self.components_tableWidget.horizontalHeaderItem(self.component_col_idx).setText("Component")
        self.components_tableWidget.horizontalHeaderItem(self.databases_col_idx).setText("Databases Names")
        self.components_tableWidget.horizontalHeaderItem(self.status_col_idx).setText("Status")
        self.components_tableWidget.horizontalHeaderItem(self.source_col_idx).setText("Source")
        self.components_tableWidget.horizontalHeaderItem(self.last_download_col_idx).setText("Last Downloaded")
        __sortingEnabled = self.components_tableWidget.isSortingEnabled()
        self.components_tableWidget.setSortingEnabled(False)
        self.components_tableWidget.setSortingEnabled(__sortingEnabled)
        self.statusLabel.setText("")
        self.cancel_button.setText("Cancel")
        self.installSel_button.setText("Install Selected")

        QtCore.QMetaObject.connectSlotsByName(UpdateDialog)
Exemplo n.º 7
0
    def initUI(self):

        #----------------------------
        # Left frame (for headers). -
        #----------------------------

        self.sequence_ID_groupbox = QtWidgets.QGroupBox('SEQUENCE ID')
        # self.sequence_ID_groupbox.setStyleSheet("QLabel {font: 14pt COURIER NEW font-weight: bold} ")
        id_frame_stylesheet = "QLabel {font: %spt %s; font-weight: %s; color: white}" % (
            self.main_window.font_size, self.main_window.font,
            self.main_window.font_weight)
        self.sequence_ID_groupbox.setStyleSheet(id_frame_stylesheet)

        self.id_form_layout = QtWidgets.QFormLayout()
        #self.left_scroll
        self.left_scroll = QtWidgets.QScrollArea()
        self.left_scroll.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOn)
        self.left_scroll.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAsNeeded)
        self.left_scroll.resize(200, 400)
        self.left_scroll.setWidget(
            self.sequence_ID_groupbox
        )  # sequence_ID_groupbox dentro left_scroll area
        self.left_scroll.setWidgetResizable(True)
        #self.left_frame
        self.left_frame = QtWidgets.QFrame(self)
        self.left_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.left_frame.resize(200, 400)
        self.left_frame.setStyleSheet(self.style)
        self.left_frame.setFrameShadow(QtWidgets.QFrame.Sunken)
        #self.left_frame_layout
        self.left_frame_layout = QtWidgets.QVBoxLayout(self)
        self.left_frame_layout.addWidget(self.left_scroll)
        self.left_frame.setLayout(
            self.left_frame_layout)  # left_frame_layout dentro left_frame

        #-------------------------------
        # Right frame (for sequences). -
        #-------------------------------

        # This groupbox
        self.sequence_SEQ_groupbox = QtWidgets.QGroupBox('SEQUENCES')
        seq_frame_stylesheet = "QLabel {font: %spt %s; font-weight: %s; color: white}" % (
            self.main_window.font_size, self.main_window.font,
            self.main_window.font_weight)
        self.sequence_SEQ_groupbox.setStyleSheet(seq_frame_stylesheet)
        self.seq_form_layout = QtWidgets.QFormLayout()

        #self.right_scroll
        self.right_scroll = QtWidgets.QScrollArea()
        self.right_scroll.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOn)
        self.right_scroll.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAsNeeded)
        self.right_scroll.resize(900, 400)
        self.right_scroll.setWidget(
            self.sequence_SEQ_groupbox
        )  # sequence_ID_groupbox dentro left_scroll area
        self.right_scroll.setWidgetResizable(True)
        #self.right_frame
        self.right_frame = QtWidgets.QFrame(self)
        self.right_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.right_frame.resize(900, 400)
        self.right_frame.setStyleSheet(self.style)
        self.right_frame.setFrameShadow(QtWidgets.QFrame.Sunken)
        #self.right_frame_layout
        self.right_frame_layout = QtWidgets.QVBoxLayout(self)
        self.right_frame_layout.addWidget(self.right_scroll)
        self.right_frame.setLayout(
            self.right_frame_layout)  # left_frame_layout dentro left_frame

        #connect the two Vertical Bars to move them togheter
        self.left_scroll.verticalScrollBar().valueChanged.connect(
            self.right_scroll.verticalScrollBar().setValue)
        self.right_scroll.verticalScrollBar().valueChanged.connect(
            self.left_scroll.verticalScrollBar().setValue)

        #----------------------------------
        # Bottom part of the main window. -
        #----------------------------------

        self.splitter1 = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
        self.splitter1.addWidget(self.left_frame)
        self.splitter1.addWidget(self.right_frame)

        # creating sequence and position labels
        self.label_sequence = QtWidgets.QLabel(self)
        self.label_sequence.setText('Sequence:')
        self.label_sequence.setStyleSheet(small_font_style)
        self.textbox_sequence = QtWidgets.QLineEdit(self)
        self.textbox_sequence.setStyleSheet(self.style + "; " +
                                            small_font_style)
        self.textbox_sequence.setReadOnly(True)

        self.label_position = QtWidgets.QLabel(self)
        self.label_position.setText('Position:')
        self.label_position.setStyleSheet(small_font_style)
        self.textbox_position = QtWidgets.QLineEdit(self)
        self.textbox_position.setReadOnly(True)
        self.textbox_position.setStyleSheet(self.style + "; " +
                                            small_font_style)
        self.textbox_position.setMinimumWidth(
            675)  # Width of the residues message bar width.

        # creating an horizontal layout with sequence and position labels
        self.text_layout = QtWidgets.QHBoxLayout()
        self.text_layout.addWidget(self.label_sequence)
        self.text_layout.addWidget(self.textbox_sequence)
        self.text_layout.addWidget(self.label_position)
        self.text_layout.addWidget(self.textbox_position)

        # creating a layout with sequence window and labels
        self.grid = QtWidgets.QVBoxLayout()
        self.grid.addWidget(self.splitter1)
        self.grid.addLayout(self.text_layout)
        self.setLayout(self.grid)
Exemplo n.º 8
0
        def __init__(self):
            QtWidgets.QWidget.__init__(self, parent, Qt.Window)
            self.setMinimumSize(400, 500)
            self.setWindowTitle('Register File Extensions')

            self.model = QtGui.QStandardItemModel(self)

            layout = QtWidgets.QVBoxLayout(self)
            self.setLayout(layout)

            label = QtWidgets.QLabel(
                "Select file types to register them with PyMOL", self)
            layout.addWidget(label)

            alluserslayout = QtWidgets.QHBoxLayout()
            alluserslayout.setObjectName("alluserslayout")
            layout.addLayout(alluserslayout)

            buttonlayout = QtWidgets.QHBoxLayout()
            buttonlayout.setObjectName("buttonlayout")
            layout.addLayout(buttonlayout)

            self.table = QtWidgets.QTableView(self)
            self.table.setModel(self.model)
            layout.addWidget(self.table)

            button = QtWidgets.QPushButton("Register Recommended (*)", self)
            buttonlayout.addWidget(button)
            button.pressed.connect(self.setRecommended)

            button = QtWidgets.QPushButton("Register All", self)
            buttonlayout.addWidget(button)
            button.pressed.connect(self.setAll)

            button = QtWidgets.QPushButton("Clear", self)
            button.setToolTip("Clean up Registry")
            buttonlayout.addWidget(button)
            button.pressed.connect(self.clear)

            if isAdmin():
                r0 = QtWidgets.QRadioButton("Only for me")
                r0.setToolTip("HKEY_CURRENT_USER registry branch")
                r0.setChecked(True)
                r1 = QtWidgets.QRadioButton("For all users")
                r1.setToolTip("HKEY_LOCAL_MACHINE registry branch")
                allusersgroup = QtWidgets.QButtonGroup(self)
                allusersgroup.addButton(r0)
                allusersgroup.addButton(r1)
                allusersgroup.buttonClicked.connect(self.populateData)
                alluserslayout.addWidget(r0)
                alluserslayout.addWidget(r1)
                alluserslayout.addStretch()
                self.allusersbutton = r1
            else:
                self.allusersbutton = None

            self.finalize_timer = QtCore.QTimer()
            self.finalize_timer.setSingleShot(True)
            self.finalize_timer.setInterval(500)
            self.finalize_timer.timeout.connect(finalize)

            self.populateData()

            # keep reference to window, otherwise Qt will auto-close it
            self._self_ref = self