def update_complete_list(self, lines=None, extra=None):
        self.clear()
        if lines or extra:
            self.show_me()
            if lines:
                for i in [x for x in lines if not x.name == 'mro']:
                    item = QListWidgetItem(i.name)
                    item.setData(32, i)
                    self.addItem(item)
            if extra:
                font = self.font()
                font.setItalic(True)
                font.setPointSize(font.pointSize() * 0.8)
                for e in extra:
                    item = QListWidgetItem(e.name)
                    item.setData(32, e)
                    item.setFont(font)
                    self.addItem(item)

            font = QFont('monospace', self.line_height, False)
            fm = QFontMetrics(font)
            width = fm.width(' ') * max([len(x.name)
                                         for x in lines or extra]) + 40

            self.resize(max(250, width), 250)
            self.setCurrentRow(0)
        else:
            self.hide_me()
Example #2
0
    def _show_selected_unparameterised_residue(self, item):
        residue, by_name, by_comp = item.data(USER_ROLE)
        tlist = self._template_list
        tlist.clear()
        self._do_for_all.setCheckState(False)
        from Qt.QtWidgets import QListWidgetItem
        tlist.addItem(QListWidgetItem("Matches by residue name"))

        def get_ccd_template_and_name(session, tname):
            from ..openmm.amberff.template_utils import template_name_to_ccd_name
            from chimerax import mmcif
            ccd_name, extra_info = template_name_to_ccd_name(tname)
            if ccd_name is None:
                return (None, '')
            try:
                tmpl = mmcif.find_template_residue(session, ccd_name)
            except ValueError:
                return (None, "No CCD template found")
            description = tmpl.description
            if extra_info is not None:
                description += ', ' + extra_info
            return (tmpl, description)

        for (tname, score) in by_name:
            ccd_template, description = get_ccd_template_and_name(
                self.session, tname)
            entry_text = tname
            entry_text += " (Score: {:.3f})".format(score)
            if len(description):
                entry_text += " " + description
            entry = QListWidgetItem(entry_text)
            entry.setData(USER_ROLE, (residue, tname, ccd_template))
            tlist.addItem(entry)
        tlist.addItem(QListWidgetItem("Matches by similar topology"))
        for (tname, score) in by_comp:
            ccd_template, description = get_ccd_template_and_name(
                self.session, tname)
            entry_text = tname
            entry_text += " (Score: {:.3f})".format(score)
            if len(description):
                entry_text += " " + description
            entry = QListWidgetItem(entry_text)
            entry.setData(USER_ROLE, (residue, tname, ccd_template))
            tlist.addItem(entry)

        tlist.repaint()
        from ..view import focus_on_selection
        # show all atoms in the residue and its bonded neighbors, to help
        # diagnose bonding errors
        residue.atoms.displays = True
        for r in residue.neighbors:
            r.atoms.displays = True
        focus_on_selection(self.session, residue.atoms)