Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_fetch.py: 89%

37 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-04 08:26 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the Pdbfetch class and the command line interface.""" 

4 

5from typing import Optional 

6from biobb_common.generic.biobb_object import BiobbObject 

7from biobb_common.tools import file_utils as fu 

8from biobb_common.tools.file_utils import launchlogger 

9 

10 

11class Pdbfetch(BiobbObject): 

12 """ 

13 | biobb_pdb_tools Pdbfetch 

14 | Downloads a structure in PDB format from the RCSB website. 

15 | This tool downloads a structure in PDB format from the RCSB website. It can be used to download a structure in PDB format from the RCSB website. 

16 

17 Args: 

18 output_file_path (str): PDB file of the protein selected. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_fetch.pdb>`_. Accepted formats: pdb (edam:format_1476). 

19 properties (dic): 

20 * **pdbid** (*string*) - ('1aki') ID of the protein. 

21 * **biounit** (*string*) - (False) Allows downloading the (first) biological structure if selected. 

22 * **binary_path** (*str*) - ("pdb_fetch") Path to the pdb_fetch executable binary. 

23 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files. 

24 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist. 

25 

26 Examples: 

27 This is a use example of how to use the building block from Python:: 

28 

29 from biobb_pdb_tools.pdb_tools.biobb_pdb_fetch import biobb_pdb_fetch 

30 

31 prop = { 

32 'biounit': False, 

33 'pdbid': '1aki' 

34 } 

35 biobb_pdb_fetch(output_file_path='/path/to/file.pdb', 

36 properties=prop) 

37 

38 Info: 

39 * wrapped_software: 

40 * name: pdb_tools 

41 * version: >=2.5.0 

42 * license: Apache-2.0 

43 * ontology: 

44 * name: EDAM 

45 * schema: http://edamontology.org/EDAM.owl 

46 

47 """ 

48 

49 def __init__(self, output_file_path, properties=None, **kwargs) -> None: 

50 properties = properties or {} 

51 

52 super().__init__(properties) 

53 self.locals_var_dict = locals().copy() 

54 self.io_dict = {"out": {"output_file_path": output_file_path}} 

55 

56 self.pdbid = properties.get("pdbid", "1aki") 

57 self.binary_path = properties.get("binary_path", "pdb_fetch") 

58 self.biounit = properties.get("biounit", False) 

59 self.properties = properties 

60 self.check_init(properties) 

61 

62 @launchlogger 

63 def launch(self) -> int: 

64 """Execute the :class:`Pdbfetch <biobb_pdb_tools.pdb_tools.pdb_fetch>` object.""" 

65 

66 if self.check_restart(): 

67 return 0 

68 instructions = [] 

69 if self.biounit: 

70 instructions.append("-biounit") 

71 fu.log("Appending optional boolean property", 

72 self.out_log, self.global_log) 

73 

74 self.cmd = [ 

75 self.binary_path, 

76 " ".join(instructions), 

77 self.pdbid, 

78 ">", 

79 self.io_dict["out"]["output_file_path"], 

80 ] 

81 

82 fu.log(" ".join(self.cmd), self.out_log, self.global_log) 

83 

84 fu.log( 

85 "Creating command line with instructions and required arguments", 

86 self.out_log, 

87 self.global_log, 

88 ) 

89 

90 self.run_biobb() 

91 self.copy_to_host() 

92 self.remove_tmp_files() 

93 self.check_arguments(output_files_created=True, raise_exception=False) 

94 return self.return_code 

95 

96 

97def biobb_pdb_fetch( 

98 output_file_path: str, properties: Optional[dict] = None, **kwargs 

99) -> int: 

100 """Create :class:`Pdbfetch <biobb_pdb_tools.pdb_tools.pdb_fetch>` class and 

101 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_fetch.launch>` method.""" 

102 return Pdbfetch(**dict(locals())).launch() 

103 

104 

105main = Pdbfetch.get_main(biobb_pdb_fetch, "Downloads a structure in PDB format from the RCSB website.") 

106biobb_pdb_fetch.__doc__ = Pdbfetch.__doc__ 

107 

108if __name__ == "__main__": 

109 main()