Example #1
0
    def _set_filter_type(self, new_filter_type: type):
        '''
        _set_filter_type changes the current type of Filter and creates and applies a Filter of that type.

        :warning: Should only be called via set_action_type which handles type checking
        :param new_filter_type: type of the new Filter
        :type new_filter_type: t.Type[Filter]
        :return: None
        :rtype: None
        '''

        if new_filter_type == None:
            self.current_filter_type = None
            self.my_filter = None
            return

        # Check for erros the GUI module hsould already have dealt with
        if not new_filter_type in self.available_filter_types + [None]:
            raise TypeError(str(new_filter_type) + ' is not an available type of Filter')

        # Create list of all atoms in the current selection:

        self.my_filter = new_filter_type(self.selected_atoms)

        # Switchtable for different provider funcs
        # TODO STRUC: Remove special cases, use a generic input function

        input_function = u.do_nothing
        if isinstance(self.my_filter, Filter.PropertyFilter):
            input_function = u.create_input_dialog(parent_window=None, title='PropertyFilter')
        elif isinstance(self.my_filter, Filter.ElementFilter):
            input_function = u.create_input_dialog(parent_window=None, title='ElementFilter')
        elif isinstance(self.my_filter, Filter.RingFilter):
            # TODO: GET INDEPENDENT OF PYMOL HERE => Write an own pdb function
            input_function = lambda dummy_arg: _convert_molecules_to_pdb()

        if try_to_get_args(self.my_filter, input_function):
            self.selected_atoms = self.my_filter.filter()
        else:
            self.my_filter = None
            self.current_filter_type = None
Example #2
0
    def _set_selection_type(self, new_selection_type: type, ):
        '''
        _set_selection_type chagnes the current type of Selection and starts a new selection of that type.

        :warning: Should only be called via set_action_type which handles type checking
        :param new_selection_type: type of the new Selection
        :type new_selection_type: t.Type[Selection]
        :return: None
        :rtype: None
        '''

        if new_selection_type == None:
            self.current_selection_type = None
            self.my_selection = None
            return

        if not new_selection_type in self.available_selection_types:
            raise TypeError(str(new_selection_type) + ' is not an  available type of Selection')

        self.current_selection_type = new_selection_type
        self.my_selection = new_selection_type(self.all_atoms)

        # Switchtable for different provider funcs
        # TODO STRUC: Remove special cases, use a generic input function

        input_function = u.do_nothing
        if self.my_selection.__class__ == Selection.LimitedSelection:
            input_function = u.create_input_dialog(parent_window=None, title='Selection')
        elif isinstance(self.my_selection, Selection.SphericalSelection):
            input_function = lambda _: 5
        elif isinstance(self.my_selection, Selection.MCS_Selection):
            input_function = lambda dummy_arg: _convert_molecules_to_pdb()

        if not try_to_get_args(self.my_selection, input_function):
            self.my_selection = None
            self.current_selection_type = None