Coverage for biobb_structure_utils / utils / remove_pdb_water.py: 93%

29 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-16 14:59 +0000

1#!/usr/bin/env python3 

2 

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

4from typing import Optional 

5from biobb_common.generic.biobb_object import BiobbObject 

6from biobb_common.tools.file_utils import launchlogger 

7 

8 

9class RemovePdbWater(BiobbObject): 

10 """ 

11 | biobb_structure_utils RemovePdbWater 

12 | This class is a wrapper of the Structure Checking tool to remove water molecules from PDB 3D structures. 

13 | Wrapper for the `Structure Checking <https://github.com/bioexcel/biobb_structure_checking>`_ tool to remove water molecules from PDB 3D structures. 

14 

15 Args: 

16 input_pdb_path (str): Input PDB file path. File type: input. `Sample file <https://github.com/bioexcel/biobb_structure_utils/raw/master/biobb_structure_utils/test/data/utils/WT_aq4_md_WAT.pdb>`_. Accepted formats: pdb (edam:format_1476). 

17 output_pdb_path (str): Output PDB file path. File type: output. `Sample file <https://github.com/bioexcel/biobb_structure_utils/raw/master/biobb_structure_utils/test/reference/utils/WT_apo_no_wat.pdb>`_. Accepted formats: pdb (edam:format_1476). 

18 properties (dic - Python dictionary object containing the tool parameters, not input/output files): 

19 * **binary_path** (*string*) - ("check_structure") path to the check_structure application 

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

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

22 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory. 

23 

24 Examples: 

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

26 

27 from biobb_structure_utils.utils.remove_pdb_water import remove_pdb_water 

28 prop = { } 

29 remove_pdb_water(input_pdb_path='/path/to/myStructure.pdb', 

30 output_pdb_path='/path/to/newStructure.pdb', 

31 properties=prop) 

32 

33 Info: 

34 * wrapped_software: 

35 * name: Structure Checking from MDWeb 

36 * version: >=3.0.3 

37 * license: Apache-2.0 

38 * ontology: 

39 * name: EDAM 

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

41 

42 """ 

43 

44 def __init__( 

45 self, input_pdb_path, output_pdb_path, properties=None, **kwargs 

46 ) -> None: 

47 properties = properties or {} 

48 

49 # Call parent class constructor 

50 super().__init__(properties) 

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

52 

53 # Input/Output files 

54 self.io_dict = { 

55 "in": {"input_pdb_path": input_pdb_path}, 

56 "out": {"output_pdb_path": output_pdb_path}, 

57 } 

58 

59 # Properties specific for BB 

60 self.binary_path = properties.get("binary_path", "check_structure") 

61 

62 # Check the properties 

63 self.check_properties(properties) 

64 self.check_arguments() 

65 

66 @launchlogger 

67 def launch(self) -> int: 

68 """Execute the :class:`RemovePdbWater <utils.remove_pdb_water.RemovePdbWater>` utils.remove_pdb_water.RemovePdbWater object.""" 

69 

70 # Setup Biobb 

71 if self.check_restart(): 

72 return 0 

73 self.stage_files() 

74 

75 self.cmd = [ 

76 self.binary_path, 

77 "-i", 

78 self.stage_io_dict["in"]["input_pdb_path"], 

79 "-o", 

80 self.stage_io_dict["out"]["output_pdb_path"], 

81 "--force_save", 

82 "water", 

83 "--remove", 

84 "yes", 

85 ] 

86 

87 # Run Biobb block 

88 self.run_biobb() 

89 

90 # Copy files to host 

91 self.copy_to_host() 

92 

93 # Remove temporal files 

94 self.remove_tmp_files() 

95 

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

97 

98 return self.return_code 

99 

100 

101def remove_pdb_water( 

102 input_pdb_path: str, 

103 output_pdb_path: str, 

104 properties: Optional[dict] = None, 

105 **kwargs, 

106) -> int: 

107 """Create the :class:`RemovePdbWater <utils.remove_pdb_water.RemovePdbWater>` class and 

108 execute the :meth:`launch() <utils.remove_pdb_water.RemovePdbWater.launch>` method.""" 

109 

110 return RemovePdbWater(**dict(locals())).launch() 

111 

112 

113remove_pdb_water.__doc__ = RemovePdbWater.__doc__ 

114main = RemovePdbWater.get_main(remove_pdb_water, "Remove the water molecules from a PDB 3D structure.") 

115 

116if __name__ == "__main__": 

117 main()