Exemplo n.º 1
0
 def run_expanded_command(session):
     mall = session.models.list(type=model_class)
     msel = [m for m in mall if m.selected]
     mselvis = [m for m in msel if m.visible]
     if len(mselvis) == 0:
         # No selected visible models so run on all visible models.
         mvis = [m for m in mall if m.visible]
         if len(mvis) == len(mall):
             target = 'all'
         elif mvis:
             # No selected models so target all visible models.
             from chimerax.core.commands import concise_model_spec
             target = concise_model_spec(session, mvis)
         else:
             # No visible models
             target = None
     elif len(msel) == len(mselvis):
         # All selected models are visible.
         target = 'sel'
     else:
         # Some but not all selected models are visible.
         from chimerax.core.commands import concise_model_spec
         target = 'sel & %s' % concise_model_spec(session, mselvis)
     if target is None:
         return  # No visible models to run command on.
     cmd = all_command if target == 'all' else command.replace(
         ' %s', ' ' + target)
     run(session, cmd)
Exemplo n.º 2
0
 def _count_pbonds(self, query, finder, cat_name, column_name):
     # Create hydrogen bonds between receptor(s) and ligands
     from chimerax.core.commands import concise_model_spec, run
     from chimerax.atomic import AtomicStructure
     mine = concise_model_spec(self.session, self.structures)
     all = self.session.models.list(type=AtomicStructure)
     others = concise_model_spec(self.session,
                                 set(all) - set(self.structures))
     cmd = ("%s %s restrict %s "
            "reveal true intersubmodel true" % (finder, mine, others))
     run(self.session, cmd)
     self._count_pb(cat_name, column_name)
Exemplo n.º 3
0
 def _show_hide(self, on, off):
     if on or off:
         from chimerax.core.commands import concise_model_spec, run
         self._block_updates = True
         cmd = []
         if off:
             models = concise_model_spec(self.session, off)
             cmd.append("hide %s models" % models)
         if on:
             models = concise_model_spec(self.session, on)
             cmd.append("show %s models" % models)
         run(self.session, " ; ".join(cmd))
         self._block_updates = False
         self._update_display()
Exemplo n.º 4
0
 def fetch_additional_scores(self, refresh=False):
     self.scores_fetched = True
     from chimerax.core.commands import run, concise_model_spec
     run(
         self.session,
         "modeller scores %s refresh %s" % (concise_model_spec(
             self.session, self.models), str(refresh).lower()))
Exemplo n.º 5
0
def close(models, session):
    _mp.self_initiated = True
    from chimerax.core.models import Model
    # The 'close' command explicitly avoids closing grouping models where not
    # all the child models are being closed so that "close ~#1.1" doesn't 
    # close the #1 grouping model.  Therefore we need to change the '#!'s
    # generated by concise_model_spec to just '#'s
    run(session, "close %s" %
        concise_model_spec(session, [m for m in models if isinstance(m, Model)]).replace('#!', '#'))
Exemplo n.º 6
0
def shown_models_spec(session, model_class=None):
    mlist = [m for m in session.models.list(type=model_class)]
    mshown = [m for m in mlist if m.visible]
    if len(mlist) == len(mshown):
        spec = 'all' if mshown else ''
    elif len(mshown) == 0:
        spec = ''
    else:
        from chimerax.core.commands import concise_model_spec
        spec = concise_model_spec(session, mshown)
    return spec
Exemplo n.º 7
0
 def options_string(self):
     models = self.structure_list.value
     from chimerax.core.errors import UserError
     if not models:
         raise UserError("No models chosen for saving")
     from chimerax.atomic import Structure
     from chimerax.core.commands import concise_model_spec
     spec = concise_model_spec(self.session, models, relevant_types=Structure)
     if spec:
         cmd = "models " + spec
     else:
         cmd = ""
     if self.displayed_only.isChecked():
         if cmd:
             cmd += ' '
         cmd += "displayedOnly true"
     if self.selected_only.isChecked():
         if cmd:
             cmd += ' '
         cmd += "selectedOnly true"
     if self.rel_models.isChecked():
         if cmd:
             cmd += ' '
         if self.simple_rel_models:
             rel_model = models[0]
         else:
             rel_model = self.rel_model_menu.value
             if rel_model is None:
                 raise UserError("No model chosen to save relative to")
         cmd += "relModel #" + rel_model.id_string
     large_handling = self.large_mb.text()
     if large_handling == "Amber":
         if cmd:
             cmd += ' '
         cmd += "serialNumbering amber"
     return cmd
Exemplo n.º 8
0
def view(objs, session):
    from chimerax.core.models import Model
    models = [o for o in objs if isinstance(o, Model)]
    run(session, "view %s clip false" % concise_model_spec(session, models))
Exemplo n.º 9
0
def show(models, session):
    _mp.self_initiated = True
    run(session, "show %s target m" % concise_model_spec(session, models))
Exemplo n.º 10
0
def hide(models, session):
    _mp.self_initiated = True
    run(session, "hide %s target m" % concise_model_spec(session, models))
Exemplo n.º 11
0
    def get_command(self):
        """Used to generate the 'hbonds' command that can be run to produce the requested H-bonds.
           Returns three strings:
              1) The command name
              2) The atom spec to provide just after the command name
              3) The keyword/value pairs that follow that
           The atom spec will be an empty string if no bond or model restriction was requested
           (or those controls weren't shown).
        """
        from chimerax.core.errors import UserError
        settings = {}
        command_values = {}

        # never saved in settings
        if self.__show_values['model_restrict']:
            models = self.__model_restrict_option.value
            if models is None:
                atom_spec = ""
            else:
                if not models:
                    raise UserError("Model restriction enabled but no models chosen")
                from chimerax.core.commands import concise_model_spec
                atom_spec = concise_model_spec(self.session, models)
        else:
            atom_spec = ""

        if self.__show_values['bond_restrict']:
            bond_restrict = self.__bond_restrict_option.value
            if bond_restrict is not None:
                command_values['restrict'] = bond_restrict
                if atom_spec:
                    atom_spec += " & sel"
                else:
                    atom_spec = "sel"

        if self.__show_values['save_file']:
            if self.__save_file_option.value:
                from PyQt5.QtWidgets import QFileDialog
                fname = QFileDialog.getSaveFileName(self, "Save H-Bonds File")[0]
                if fname:
                    command_values['save_file'] = fname
                else:
                    from chimerax.core.errors import CancelOperation
                    raise CancelOperation("H-bonds save file cancelled")
            else:
                command_values['save_file'] = None
        else:
            command_values['save_file'] = None

        # may be saved in settings
        if self.__show_values['make_pseudobonds']:
            settings['make_pseudobonds'] = self.__make_pb_group.isChecked()
            if self.__show_values['color']:
                settings['color'] = self.__color_option.value
            if self.__show_values['radius']:
                settings['radius'] = self.__radius_option.value
            if self.__show_values['dashes']:
                settings['dashes'] = self.__dashes_option.value
            if self.__show_values['show_dist']:
                settings['show_dist'] = self.__show_dist_option.value
        else:
            settings['color'] = None
            settings['radius'] = None
            settings['dashes'] = None
            settings['show_dist'] = None

        if self.__show_values['inter_model']:
            settings['inter_model'] = self.__inter_model_option.value
        else:
            settings['inter_model'] = None

        if self.__show_values['intra_model']:
            settings['intra_model'] = self.__intra_model_option.value
        else:
            settings['intra_model'] = None

        if self.__show_values['relax']:
            settings['relax'] = self.__relax_group.isChecked()
            if self.__show_values['slop']:
                settings['dist_slop'] = self.__dist_slop_option.value
                settings['angle_slop'] = self.__angle_slop_option.value
            else:
                settings['dist_slop'] = settings['angle_slop'] = None
            if self.__show_values['slop_color']:
                slop_color_value = self.__slop_color_option.value
                if slop_color_value is None:
                    settings['two_colors'] = False
                    settings['slop_color'] = None
                else:
                    settings['two_colors'] = True
                    settings['slop_color'] = slop_color_value
            else:
                settings['two_colors'] = settings['slop_color'] = None
        else:
            settings['relax'] = settings['dist_slop'] = settings['angle_slop'] = None
            settings['two_colors'] = settings['slop_color'] = None

        if self.__show_values['salt_only']:
            settings['salt_only'] = self.__salt_only_option.value
        else:
            settings['salt_only'] = None

        if self.__show_values['intra_mol']:
            settings['intra_mol'] = self.__intra_mol_option.value
        else:
            settings['intra_mol'] = None

        if self.__show_values['intra_res']:
            settings['intra_res'] = self.__intra_res_option.value
        else:
            settings['intra_res'] = None

        if self.__show_values['inter_submodel']:
            settings['inter_submodel'] = self.__inter_submodel_option.value
        else:
            settings['inter_submodel'] = None

        if self.__show_values['select']:
            settings['select'] = self.__select_option.value
        else:
            settings['select'] = None

        if self.__show_values['reveal']:
            settings['reveal'] = self.__reveal_option.value
        else:
            settings['reveal'] = None

        if self.__show_values['retain_current']:
            settings['retain_current'] = self.__retain_current_option.value
        else:
            settings['retain_current'] = None

        if self.__show_values['log']:
            settings['log'] = self.__log_option.value
        else:
            settings['log'] = None

        if self.__settings:
            saveables = []
            for attr_name, value in settings.items():
                if value is not None:
                    setattr(self.__settings, attr_name, value)
                    saveables.append(attr_name)
            if saveables:
                self.__settings.save(settings=saveables)

        def val_to_str(ses, val, kw):
            from chimerax.core.commands import \
                BoolArg, IntArg, FloatArg, ColorArg, StringArg, SaveFileNameArg
            if type(val) == bool:
                return BoolArg.unparse(val, ses)
            if type(val) == int:
                return IntArg.unparse(val, ses)
            if type(val) == float:
                return FloatArg.unparse(val, ses)
            if kw.endswith('color'):
                from chimerax.core.colors import Color
                return ColorArg.unparse(Color(rgba=val), ses)
            if kw == 'save_file':
                return SaveFileNameArg.unparse(val, ses)
            return StringArg.unparse(str(val), ses)

        command_values.update(settings)
        from .cmd import cmd_hbonds
        kw_values = ""
        for kw, val in command_values.items():
            if val is None:
                continue
            if is_default(cmd_hbonds, kw, val):
                continue
            # 'dashes' default checking requires special handling
            if kw == 'dashes' and val == AtomicStructure.default_hbond_dashes \
            and not command_values['retain_current']:
                continue
            camel = ""
            next_upper = False
            for c in kw:
                if c == '_':
                    next_upper = True
                else:
                    if next_upper:
                        camel += c.upper()
                    else:
                        camel += c
                    next_upper = False
            kw_values += (" " if kw_values else "") + camel + " " + val_to_str(self.session, val, kw)
        return "hbonds", atom_spec, kw_values
Exemplo n.º 12
0
    def run_matchmaker(self):
        from chimerax.core.commands import StringArg, BoolArg, FloatArg, DynamicEnum, NoneArg
        from .settings import defaults, get_settings
        settings = get_settings(self.session)
        chain_pairing = self.chain_pairing_option.value
        ref_widget, match_widget = self.matching_widgets[chain_pairing]
        ref_value = ref_widget.value
        match_value = match_widget.value
        if chain_pairing == CP_SPECIFIC_SPECIFIC:
            ref_spec = "".join([rchain.atomspec for rchain, mchain in match_value])
        else:
            ref_spec = ref_value.atomspec
        if not ref_spec:
            raise UserError("No reference and/or match structure/chain chosen")
        if self.ref_sel_restrict.isChecked():
            ref_spec = ref_spec + " & sel"
        if chain_pairing == CP_SPECIFIC_SPECIFIC:
            match_spec = "".join([mchain.atomspec for rchain, mchain in match_value])
        else:
            from chimerax.core.commands import concise_model_spec
            match_spec = concise_model_spec(self.session, match_value)
        if not match_spec:
            raise UserError("No match structure/chain(s) chosen")
        if self.match_sel_restrict.isChecked():
            match_spec = match_spec + " & sel"

        cmd = "matchmaker " + match_spec + " to " + ref_spec
        if chain_pairing != defaults['chain_pairing']:
            cmd += ' pairing ' + chain_pairing

        alg = settings.alignment_algorithm
        if alg != defaults['alignment_algorithm']:
            cmd += ' alg ' + StringArg.unparse(alg)

        verbose = settings.verbose_logging
        if verbose != defaults['verbose_logging']:
            cmd += ' verbose ' + BoolArg.unparse(verbose)

        use_ss = settings.use_ss
        if use_ss:
            ss_fraction = settings.ss_mixture
            if ss_fraction != defaults['ss_mixture']:
                cmd += ' ssFraction ' + FloatArg.unparse(ss_fraction)
        else:
            cmd += ' ssFraction ' + BoolArg.unparse(use_ss)

        matrix = settings.matrix
        if matrix != defaults['matrix']:
            from chimerax import sim_matrices
            cmd += ' matrix ' + DynamicEnum(
                lambda ses=self.session: sim_matrices.matrices(ses.logger).keys()).unparse(matrix)

        gap_open = settings.gap_open
        if not use_ss and gap_open != defaults['gap_open']:
            cmd += ' gapOpen ' + FloatArg.unparse(gap_open)

        helix_open = settings.helix_open
        from chimerax.core.commands import run
        if helix_open != defaults['helix_open']:
            cmd += ' hgap ' + FloatArg.unparse(helix_open)

        strand_open = settings.strand_open
        from chimerax.core.commands import run
        if strand_open != defaults['strand_open']:
            cmd += ' sgap ' + FloatArg.unparse(strand_open)

        other_open = settings.other_open
        from chimerax.core.commands import run
        if other_open != defaults['other_open']:
            cmd += ' ogap ' + FloatArg.unparse(other_open)

        iterate = settings.iterate
        if iterate:
            iter_cutoff = settings.iter_cutoff
            if iter_cutoff != defaults['iter_cutoff']:
                cmd += ' cutoffDistance ' + FloatArg.unparse(iter_cutoff)
        else:
            cmd += ' cutoffDistance ' + NoneArg.unparse(None)

        gap_extend = settings.gap_extend
        if gap_extend != defaults['gap_extend']:
            cmd += ' gapExtend ' + FloatArg.unparse(gap_extend)

        if self.bring_model_list.isEnabled():
            models = self.bring_model_list.value
            if models:
                cmd += ' bring ' + concise_model_spec(self.session, models)

        show_alignment = settings.show_alignment
        if show_alignment != defaults['show_alignment']:
            cmd += ' showAlignment ' + BoolArg.unparse(show_alignment)

        compute_ss = settings.compute_ss
        if compute_ss != defaults['compute_ss']:
            cmd += ' computeSs ' + BoolArg.unparse(compute_ss)

        overwrite_ss = settings.overwrite_ss
        if compute_ss and overwrite_ss != defaults['overwrite_ss']:
            cmd += ' keepComputedSs ' + BoolArg.unparse(overwrite_ss)

        ss_matrix = settings.ss_scores
        if ss_matrix != defaults['ss_scores']:
            for key, val in ss_matrix.items():
                order = ['H', 'S', 'O']
                if val != defaults['ss_scores'][key]:
                    let1, let2 = key
                    if order.index(let1) > order.index(let2):
                        continue
                    cmd += ' mat' + let1 + let2.lower() + ' ' + FloatArg.unparse(val)

        run(self.session, cmd)