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

40 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-28 11:54 +0000

1#!/usr/bin/env python3 

2 

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

4 

5import argparse 

6from typing import Optional 

7 

8from biobb_common.configuration import settings 

9from biobb_common.generic.biobb_object import BiobbObject 

10from biobb_common.tools.file_utils import launchlogger 

11 

12 

13class RemovePdbWater(BiobbObject): 

14 """ 

15 | biobb_structure_utils RemovePdbWater 

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

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

18 

19 Args: 

20 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). 

21 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). 

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

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

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

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

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

27 

28 Examples: 

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

30 

31 from biobb_structure_utils.utils.remove_pdb_water import remove_pdb_water 

32 prop = { } 

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

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

35 properties=prop) 

36 

37 Info: 

38 * wrapped_software: 

39 * name: Structure Checking from MDWeb 

40 * version: >=3.0.3 

41 * license: Apache-2.0 

42 * ontology: 

43 * name: EDAM 

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

45 

46 """ 

47 

48 def __init__( 

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

50 ) -> None: 

51 properties = properties or {} 

52 

53 # Call parent class constructor 

54 super().__init__(properties) 

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

56 

57 # Input/Output files 

58 self.io_dict = { 

59 "in": {"input_pdb_path": input_pdb_path}, 

60 "out": {"output_pdb_path": output_pdb_path}, 

61 } 

62 

63 # Properties specific for BB 

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

65 

66 # Check the properties 

67 self.check_properties(properties) 

68 self.check_arguments() 

69 

70 @launchlogger 

71 def launch(self) -> int: 

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

73 

74 # Setup Biobb 

75 if self.check_restart(): 

76 return 0 

77 self.stage_files() 

78 

79 self.cmd = [ 

80 self.binary_path, 

81 "-i", 

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

83 "-o", 

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

85 "--force_save", 

86 "water", 

87 "--remove", 

88 "yes", 

89 ] 

90 

91 # Run Biobb block 

92 self.run_biobb() 

93 

94 # Copy files to host 

95 self.copy_to_host() 

96 

97 # Remove temporal files 

98 # self.tmp_files.append(self.stage_io_dict.get("unique_dir", "")) 

99 self.remove_tmp_files() 

100 

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

102 

103 return self.return_code 

104 

105 

106def remove_pdb_water( 

107 input_pdb_path: str, 

108 output_pdb_path: str, 

109 properties: Optional[dict] = None, 

110 **kwargs, 

111) -> int: 

112 """Execute the :class:`RemovePdbWater <utils.remove_pdb_water.RemovePdbWater>` class and 

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

114 

115 return RemovePdbWater( 

116 input_pdb_path=input_pdb_path, 

117 output_pdb_path=output_pdb_path, 

118 properties=properties, 

119 **kwargs, 

120 ).launch() 

121 

122 remove_pdb_water.__doc__ = RemovePdbWater.__doc__ 

123 

124 

125def main(): 

126 """Command line execution of this building block. Please check the command line documentation.""" 

127 parser = argparse.ArgumentParser( 

128 description="Remove the water molecules from a PDB 3D structure.", 

129 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999), 

130 ) 

131 parser.add_argument( 

132 "-c", 

133 "--config", 

134 required=False, 

135 help="This file can be a YAML file, JSON file or JSON string", 

136 ) 

137 

138 # Specific args of each building block 

139 required_args = parser.add_argument_group("required arguments") 

140 required_args.add_argument( 

141 "-i", "--input_pdb_path", required=True, help="Input pdb file name" 

142 ) 

143 required_args.add_argument( 

144 "-o", "--output_pdb_path", required=True, help="Output pdb file name" 

145 ) 

146 

147 args = parser.parse_args() 

148 config = args.config if args.config else None 

149 properties = settings.ConfReader(config=config).get_prop_dic() 

150 

151 # Specific call of each building block 

152 remove_pdb_water( 

153 input_pdb_path=args.input_pdb_path, 

154 output_pdb_path=args.output_pdb_path, 

155 properties=properties, 

156 ) 

157 

158 

159if __name__ == "__main__": 

160 main()