Ejemplo n.º 1
0
    def get_args(self, input_function: t.Callable):
        '''
         get_args(...) should be overridden by every subclass of Exporter. It will assign all necessary varaibles using input_function

         For Gromos_Importer: in_path

         :param input_function: a function that will provide the arguments for the selection in the necessary format.
         :type input_function: t.Callable[[str],t.Any]
         :return: -
         :rtype: None
         :raises BadArgument Excpetion if the input function does not deliver the arguments as needed
        :raises NotImplementedError if _Importer.get_args is called directly

        '''

        input = input_function(
            'Which file should the restrants be read from? ')
        self.in_path = u.check_or_convert_argument(input, str)
        if self.in_path == '' or self.in_path == 'None':
            raise u.BadArgumentException(
                "Empty filename. (Unless you actually wanted to call your file 'None'. \n"
                "In which case you have to blame Python's promiscuous type conversion.  And yourself, for not using file extensions.)"
            )
        if (not os.path.isfile(self.in_path)):
            raise IOError("Could not find File in import path: " +
                          str(self.in_path))
Ejemplo n.º 2
0
    def get_args(self, input_function: t.Callable[[str], t.Any]):
        """should be overridden by every subclass of Exporter. It will assign all necessary varaibles using input_function

        For Gromos_Exporter: out_path

        Parameters
        ----------
        input_function:  t.Callable[[str],t.Any]
            a function that will provide the arguments for the selection in the necessary format.

        Returns
        -------
        NoReturn

        Raises
        ------
         u.BadArgumentException
        """

        # Error checking can only be done when we try to acess the file
        self.out_path = u.check_or_convert_argument(
            input_function('Name of the output File:'), str)
        if self.out_path == '' or self.out_path == 'None':
            raise u.BadArgumentException(
                "Empty filename. (Unless you actually wanted to call your file None. \n"
                "In which case you have to blame Python's promiscuous type conversion.  And yourself, for not using file extensions.)"
            )
        self.out_path = ".".join(self.out_path.split(".")[:-1]) if (len(
            ".".join(self.out_path.split(".")[:-1])) > 0) else self.out_path
    def react_to_event(self, event_type: program_states.EventType, **kw_args: t.Any):
        """
                react_to_event should be called by the GUI-module to report an event

            react_to_event will then call the relevant update function of the active selection and refresh all atom lists etc.

         @Waring react_to_event will change the state of the program (i.e. selected_atoms, selected_restraints, mode and actions states)
         It is strongly recommended to wrap react_to_event into a function of the GUI-module, which will check these and redraw the scene and de?activate buttons, if necessary/.


        Parameters
        ----------
        event_type : program_states.EventType
             What kind of event was triggered?
        kw_args :  dict
             Arguments the relevant update function will need

        Returns
        -------
        NoReturn

        Raises
        ------
        BadArgumentException
            if args to not match the the corresponding logic_handler.react_to_*_event_function
        NotImplementedError
            if a new event_type is used, which the function does not know about.

        """
        if self.my_selection == None or self.my_selection.has_finished:
            return

        try:
            if event_type == program_states.EventType.SELECT:
                self.my_selection._update_select(**kw_args)
            elif event_type == program_states.EventType.MOVE:
                self.my_selection._update_move(**kw_args)
            elif event_type == program_states.EventType.SIZE:
                self.my_selection._update_size(**kw_args)
            elif event_type == program_states.EventType.CONFIRM:
                self.my_selection._update_confirm(**kw_args)
            else:
                raise NotImplementedError('No action defined for event_type ' + str(event_type))

        except TypeError as err:
            raise u.BadArgumentException(
                'The provided arguments do not fit the function logic_handler.react to_ ' + str(
                    event_type) + ' _event') from err

        self._check_selection_status()
        self.set_action_states()
Ejemplo n.º 4
0
    def react_to_event(self, event_type: u.EventType, **kw_args: t.Any):
        '''
        react_to_event should be called by the GUI-module to report an event

        react_to_event will then call the relevant update function of the active selection and refresh all atom lists etc.

        :warning: react_to_event will change the state of the program (i.e. selected_atoms, selected_restraints, mode and actions states)
        It is strongly recommended to wrap react_to_event into a function of the GUI-module, which will check these and redraw the scene and de?activate buttons, if necessary/.

        :param event_type: What kind of event was triggered?
        :type event_type: u.EventType
        :param kw_args: Arguments the relevant update function will need
        :type kw_args: t.Any
        :raises u.BadArgumentException if args to not match the the corresponding logic_handler.react_to_*_event_function
        :raises NotImplementedError if a new event_type is used, which the function does not know about.
        :return: None
        :rtype: None
        '''

        # Note: Wierd python Syntax:  The * operator means two different things here: in the function definition **kw_args indicates, that I want to take an arbitrary number of keyword arguments and pack them all INTO a dict called args.
        #                                                in the function calls ** kw_args means, that I want to UNPACK a dict called kwargs s and pass each value as a separate keyword-argument.

        if self.my_selection == None or self.my_selection.has_finished:
            return

        try:
            if event_type == u.EventType.SELECT:
                self.my_selection._update_select(**kw_args)
            elif event_type == u.EventType.MOVE:
                self.my_selection._update_move(**kw_args)
            elif event_type == u.EventType.SIZE:
                self.my_selection._update_size(**kw_args)
            elif event_type == u.EventType.CONFIRM:
                self.my_selection._update_confirm(**kw_args)
            else:
                raise NotImplementedError('No action defined for event_type ' + str(event_type))

        except TypeError as err:
            raise u.BadArgumentException(
                'The provided arguments do not fit the function logic_handler.react to_ ' + str(
                    event_type) + ' _event') from err

        self._check_selection_status()
        self.set_action_states()
Ejemplo n.º 5
0
    def get_args(self, input_function: t.Callable):
        """
            get_args(...) Needs to be called, before filter() can be used. For the Property_Filter it finds out which
                property should be filter-criterion and then which value it should have.

            Todo: think about multiple property selections

        Parameters
        ----------
        input_function : function(str)
            A function that will find the input needed ofr the filter.
        message : str
            A string that is displayed if if input function needs to communicate with the user

        Returns
        -------
        NoReturn

        Raises
        ------
        BadArgumentException
            if the input function does not provide all arguments in the necessary format

        """

        input = input_function(
            'Which atom-property should be the filter criterion?\nPossible criteria are: '
            + ", ".join(u.Atom._fields))
        self.criterion: str = u.check_or_convert_argument(input, str)
        if not self.criterion in u.Atom._fields:
            raise u.BadArgumentException(
                "The filter criterion \' " + self.criterion +
                " \' provided by the input function is not an attribute of an Atom."
            )

        input = input_function('What value should ' + self.criterion +
                               ' have?')
        try:
            self.value = u.check_or_convert_argument(
                input,
                self.atoms[0].__getattribute__(self.criterion).__class__)
        except IndexError:  # Happens when len(self.atoms) is 0. No special handling necessary. It just means no atoms will be selected.
            pass
Ejemplo n.º 6
0
    def get_args(self, input_function: t.Callable):
        """
        should be overridden by every subclass of Exporter. It will assign all necessary varaibles using input_function

         For Gromos_Importer: in_path

        Parameters
        ----------
        input_function : t.Callable[[str], t.Any]
             a function that will provide the arguments for the selection in the necessary format.

        Returns
        -------
        NoReturn

        Raises
        ------
        BadArgument
            Excpetion if the input function does not deliver the arguments as needed
        NotImplementedError
            if _Importer.get_args is called directly
        """

        input = input_function(
            'Which file should the restrants be read from? ')
        self.in_path = u.check_or_convert_argument(input, str)

        if (self.in_path.endswith(self.file_ending)):
            warnings.warn(
                "I could not find the correct file ending. However I will try importing! File ending should be: "
                + str(self.file_ending))

        if self.in_path == '' or self.in_path == 'None':
            raise u.BadArgumentException(
                "Empty filename. (Unless you actually wanted to call your file 'None'. \n"
                "In which case you have to blame Python's promiscuous type conversion.  And yourself, for not using file extensions.)"
            )

        if (not os.path.isfile(self.in_path)):
            raise IOError("Could not find File in import path: " +
                          str(self.in_path))
Ejemplo n.º 7
0
    def get_args(self, input_function: t.Callable[[str], t.Any]):
        '''
        get_args(...) should be overridden by every subclass of Exporter. It will assign all necessary varaibles using input_function

        For Gromos_Exporter: out_path

        :param input_function: a function that will provide the arguments for the selection in the necessary format.
        :type input_function: t.Callable[[str],t.Any]
        :return: -
        :rtype: None
        :raises: u.BadArgumentException
        '''

        # Error checking can only be done when we try to acess the file
        self.out_path = u.check_or_convert_argument(
            input_function('Name of the output File:'), str)
        if self.out_path == '' or self.out_path == 'None':
            raise u.BadArgumentException(
                "Empty filename. (Unless you actually wanted to call your file None. \n"
                "In which case you have to blame Python's promiscuous type conversion.  And yourself, for not using file extensions.)"
            )