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)
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()
def filter(self): ''' filter should be overridden by every subclass of _Filter. Returns a filtered List of atoms In the case of Ring Filter: All atoms which are in rings :return: Filtered atom list :rtype: t.List[u.Atom] ''' ids_of_atoms_in_rings = Rdkit_Functions.ring_atom_filter(selected=None, mols=self.molecules_rdk, selected_mols=None) return [a for a in self.atoms if a.id in ids_of_atoms_in_rings]
def update(self): """ general update function Returns ------- NoReturn """ print( "EXECUTING MCS Selection: please Wait - this can take a bit longer.", mv=5) mcs_ids = Rdkit_Functions.mcs_selection(self.molecules_rdk) self.atoms = list(filter(lambda a: a.id in mcs_ids, self.all_atoms)) self.has_finished = True print("EXECUTING MCS Selection: DONE", mv=5)
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)
def _update(self): mcs_ids = Rdkit_Functions.mcs_selection(self.molecules_rdk) self.atoms = list(filter(lambda a: a.id in mcs_ids, self.all_atoms)) self.has_finished = True