# -------------------------------------------------------------------------------------------------------------------------------------# Following code curated for PoseBench: (https://github.com/BioinfoMachineLearning/PoseBench)# -------------------------------------------------------------------------------------------------------------------------------------importsubprocess# nosecfrompathlibimportPathfrombeartype.typingimportList
[docs]deffind_protein_files(protein_file_dir:Path,extension:str="pdb")->List[Path]:"""Find all protein files in the specified directory. :param protein_file_dir: The directory containing the protein files. :param extension: The file extension of the protein files. :return: A list of `Path` objects representing the protein files. """returnlist(protein_file_dir.rglob(f"*.{extension}"))
[docs]deffind_ligand_files(ligand_file_dir:Path,extension:str="sdf")->List[Path]:"""Find all ligand files in the specified directory. :param ligand_file_dir: The directory containing the ligand files. :param extension: The file extension of the ligand files. :return: A list of `Path` objects representing the ligand files. """returnlist(ligand_file_dir.rglob(f"*.{extension}"))
[docs]defrun_command_with_timeout(command:str,timeout:int)->int:"""Run a command with a specified timeout in seconds. :param command: The command to run. :param timeout: The timeout for the command. :return: The return code of the command. """try:result=subprocess.run(command,shell=True,timeout=timeout,check=True)# nosecreturnresult.returncodeexceptsubprocess.TimeoutExpired:print(f"Command timed out: {command}")return-1exceptsubprocess.CalledProcessErrorase:print(f"Command failed with error: {e}")returne.returncodeexceptExceptionase:print(f"Command failed with error: {e}")return-1