Coverage for biobb_pdb_tools/pdb_tools/biobb_pdb_keepcoord.py: 94%

32 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 Pdbkeepcoord 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 Pdbkeepcoord(BiobbObject): 

12 """ 

13 | biobb_pdb_tools Pdbkeepcoord 

14 | Removes all non-coordinate records from the file. 

15 | Keeps only MODEL, ENDMDL, END, ATOM, HETATM, CONECT records from a PDB file. 

16 

17 Args: 

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

19 output_file_path (str): PDB file with only coordinate records. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_pdb_tools/master/biobb_pdb_tools/test/reference/pdb_tools/ref_pdb_keepcoord.pdb>`_. Accepted formats: pdb (edam:format_1476). 

20 properties (dic): 

21 * **binary_path** (*str*) - ("pdb_keepcoord") Path to the pdb_keepcoord executable binary. 

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

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

24 

25 Examples: 

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

27 

28 from biobb_pdb_tools.pdb_tools.biobb_pdb_keepcoord import biobb_pdb_keepcoord 

29 

30 # Keep only coordinate records 

31 biobb_pdb_keepcoord(input_file_path='/path/to/input.pdb', 

32 output_file_path='/path/to/output.pdb') 

33 

34 Info: 

35 * wrapped_software: 

36 * name: pdb_tools 

37 * version: >=2.5.0 

38 * license: Apache-2.0 

39 * ontology: 

40 * name: EDAM 

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

42 

43 """ 

44 

45 def __init__( 

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

47 ) -> None: 

48 properties = properties or {} 

49 

50 super().__init__(properties) 

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

52 

53 self.io_dict = { 

54 "in": {"input_file_path": input_file_path}, 

55 "out": {"output_file_path": output_file_path}, 

56 } 

57 

58 self.binary_path = properties.get("binary_path", "pdb_keepcoord") 

59 self.properties = properties 

60 self.check_init(properties) 

61 

62 @launchlogger 

63 def launch(self) -> int: 

64 """Execute the :class:`Pdbkeepcoord <biobb_pdb_tools.pdb_tools.pdb_keepcoord>` object.""" 

65 

66 if self.check_restart(): 

67 return 0 

68 self.stage_files() 

69 

70 self.cmd = [ 

71 self.binary_path, 

72 self.stage_io_dict["in"]["input_file_path"], 

73 ">", 

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

75 ] 

76 

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

78 

79 fu.log( 

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

81 self.out_log, 

82 self.global_log, 

83 ) 

84 

85 self.run_biobb() 

86 self.copy_to_host() 

87 self.remove_tmp_files() 

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

89 

90 return self.return_code 

91 

92 

93def biobb_pdb_keepcoord( 

94 input_file_path: str, 

95 output_file_path: str, 

96 properties: Optional[dict] = None, 

97 **kwargs, 

98) -> int: 

99 """Create :class:`Pdbkeepcoord <biobb_pdb_tools.pdb_tools.pdb_keepcoord>` class and 

100 execute the :meth:`launch() <biobb_pdb_tools.pdb_tools.pdb_keepcoord.launch>` method.""" 

101 

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

103 

104 

105biobb_pdb_keepcoord.__doc__ = Pdbkeepcoord.__doc__ 

106main = Pdbkeepcoord.get_main(biobb_pdb_keepcoord, "Removes all non-coordinate records from the file. Keeps only MODEL, ENDMDL, END, ATOM, HETATM, CONECT records.") 

107 

108if __name__ == "__main__": 

109 main()