Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_tidy.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 Pdbtidy 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 Pdbtidy(BiobbObject): 

12 """ 

13 | biobb_pdb_tools Pdbtidy 

14 | Modifies the file to adhere (as much as possible) to the format specifications. 

15 | This tool modifies the file to adhere (as much as possible) to the format specifications. It can be used to fix a PDB file that does not adhere to the format specifications. 

16 

17 Args: 

18 input_file_path (str): Input PDB file. File type: input. `Sample file <https://github.com/bioexcel/biobb_pdb_tools/blob/master/biobb_pdb_tools/test/data/pdb_tools/1AKI.pdb>`_. Accepted formats: pdb (edam:format_1476). 

19 output_file_path (str): PDB file modified according to the specifications. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_tidy.pdb>`_. Accepted formats: pdb (edam:format_1476). 

20 properties (dic): 

21 * **strict** (*bool*) - (False) Does not add TER on chain breaks. 

22 * **binary_path** (*str*) - ("pdb_tidy") Path to the pdb_tidy 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_tidy import biobb_pdb_tidy 

30 

31 prop = { 

32 'strict': False 

33 } 

34 biobb_pdb_tidy(input_file_path='/path/to/input.pdb', 

35 output_file_path='/path/to/output.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__( 

50 self, input_file_path, output_file_path, properties=None, **kwargs 

51 ) -> None: 

52 properties = properties or {} 

53 

54 super().__init__(properties) 

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

56 

57 self.io_dict = { 

58 "in": {"input_file_path": input_file_path}, 

59 "out": {"output_file_path": output_file_path}, 

60 } 

61 

62 self.binary_path = properties.get("binary_path", "pdb_tidy") 

63 self.strict = properties.get("strict", False) 

64 self.properties = properties 

65 self.check_init(properties) 

66 

67 @launchlogger 

68 def launch(self) -> int: 

69 """Execute the :class:`Pdbtidy <biobb_pdb_tools.pdb_tools.pdb_tidy>` object.""" 

70 

71 if self.check_restart(): 

72 return 0 

73 self.stage_files() 

74 

75 instructions = [] 

76 if self.strict: 

77 instructions.append("-strict") 

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

79 self.out_log, self.global_log) 

80 

81 self.cmd = [ 

82 self.binary_path, 

83 " ".join(instructions), 

84 self.io_dict["in"]["input_file_path"], 

85 ">", 

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

87 ] 

88 

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

90 

91 fu.log( 

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

93 self.out_log, 

94 self.global_log, 

95 ) 

96 

97 self.run_biobb() 

98 self.copy_to_host() 

99 self.remove_tmp_files() 

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

101 

102 return self.return_code 

103 

104 

105def biobb_pdb_tidy( 

106 input_file_path: str, 

107 output_file_path: str, 

108 properties: Optional[dict] = None, 

109 **kwargs, 

110) -> int: 

111 """Create :class:`Pdbtidy <biobb_pdb_tools.pdb_tools.pdb_tidy>` class and 

112 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_tidy.launch>` method.""" 

113 

114 return Pdbtidy(**dict(locals())).launch() 

115 

116 

117biobb_pdb_tidy.__doc__ = Pdbtidy.__doc__ 

118main = Pdbtidy.get_main(biobb_pdb_tidy, "Modifies the file to adhere (as much as possible) to the format specifications.") 

119 

120 

121if __name__ == "__main__": 

122 main()