Esempio n. 1
0
    def get_args(self, input_function: t.Callable):
        """
            should be overridden by every subclass of _Selection. It will assign all necessart variables using input function.
            For MCS_Selection the argument is a list of the Molecules in the pdb format.

        Parameters
        ----------
        input_function : t.Callable (str)
            a function that will provide the arguments for the selection in the necessary format. Here: Not necessesary. Just pass an 'empty' function or any function at all. It will not be called.

        Returns
        -------
        NoReturn

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

        """

        input = input_function("A List of Molecules in the PDB FORMAT:")
        input = u.check_or_convert_argument(input, list)
        molecules_pdb = [u.check_or_convert_argument(i, str) for i in input]
        self.molecules_rdk = Rdkit_Functions.parse_pdb_blocks_to_rdkit(
            molecules_pdb)

        self.update()
Esempio n. 2
0
    def get_args(self, input_function: t.Callable):
        """
            get_args(...) Needs to be called, before filter() can be used. It uses an input function to find all arguments required by a certain instance of a _Filter.

            For RingFilter that is a List of all Molecules in the pdb format (CAREFULL: The Molecules need to contain ALL atoms in the Molecules, not just the selected one.)

            TODO: What Kind of Error will I get if tools_Rdkit conversion fails?/ Catch it here

        Parameters
        ----------
        input_function: function(str)
            A function that can get the input
        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("A List of Molecules in the PDB FORMAT:")
        input = u.check_or_convert_argument(input, list)
        molecules_pdb = [u.check_or_convert_argument(i, str) for i in input]
        self.molecules_rdk = Rdkit_Functions.parse_pdb_blocks_to_rdkit(
            molecules_pdb)
Esempio n. 3
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
Esempio n. 4
0
    def get_args(self, input_function: t.Callable = lambda *args: 'C'):
        """
            get_args(...) Needs to be called, before filter() can be used.
             For the Element_Filter it finds out which element should be filtered

        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

        """

        input: str = input_function(
            "Which Element do do you want to filter for?\n (select multiple elements seperated by , ; e.g. 'O, N')"
        )

        if (len(input) > 1):
            input = list(map(lambda x: x.strip(), input.split(",")))
        else:
            input = [input]

        self.in_path = u.check_or_convert_argument(input, str)
        self.elem = input
Esempio n. 5
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))
Esempio n. 6
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
Esempio n. 7
0
    def get_args(self, input_function: t.Callable):
        """
        get_args(...) Needs to be called, before filter() can be used. It uses an input function to find all arguments required by a certain instance of a _Filter.

        For RingFilter that is a List of all Molecules in the pdb format (CAREFULL: The Molecules need to contain ALL atoms in the Molecules, not just the selected one.)


        :param input_function: A function that can get the input
        :type input_function: function(str)
        :param message: A string that is displayed if if input function needs to communicate with the user
        :type message: String
        :return: -
        :rtype: -
        :raises: BadArgumentException if the input function does not provide all arguments in the necessary format
        """

        input = input_function("A List of Molecules in the PDB FORMAT:")
        input = u.check_or_convert_argument(input, list)
        molecules_pdb = [u.check_or_convert_argument(i, str) for i in input]
        self.molecules_rdk = Rdkit_Functions.parse_pdb_blocks_to_rdkit(molecules_pdb)
Esempio n. 8
0
    def get_args(self, input_function: t.Callable):
        """
        get_args(...) should be overridden by every subclass of _Selection. It will assign all necessart variables using input function.
        For Limited_Filter those are: max_size: int - Maximal number of atoms in selection.
        :param input_function: a function that will provide the arguments for the selection in the necessary format: int
        :type input_function: t.Callable (str)
        :return: -
        :rtype: -
        :raises BadArgumentException: if the input function does not provide all arguments in the necessary format
        """

        input = input_function(
            "Maximal Number of Atoms in Limited Selection (int):")
        self.max_size = u.check_or_convert_argument(input, int)
Esempio n. 9
0
    def get_args(self, input_function: t.Callable = lambda *args: 'C'):
        """
        get_args(...) Needs to be called, before filter() can be used.

         For the Element_Filter it finds out which element should be filtered
        :param input_function: A function that will find the input needed ofr the filter.
        :type input_function: function(str)
        :param message: A string that is displayed if if input function needs to communicate with the user
        :type message: String
        :return: -
        :rtype: -
        """
        input: str = input_function("Which Element do do you want to filter for?")
        self.in_path = u.check_or_convert_argument(input, str)
        self.elem = input
Esempio n. 10
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))
Esempio n. 11
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.)"
            )