Coverage for biobb_haddock/haddock/em_ref.py: 87%

30 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-03 15:55 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the HADDOCK3 EMRef class and the command line interface.""" 

4 

5from os.path import abspath 

6from typing import Optional 

7import biobb_haddock.haddock.common as common 

8 

9 

10class EMRef(common.HaddockStepBase): 

11 """ 

12 | biobb_haddock EMRef 

13 | Wrapper class for the HADDOCK3 EMRef module. 

14 | The EMRef module. `HADDOCK3 EMRef module <https://www.bonvinlab.org/haddock3/modules/refinement/haddock.modules.refinement.emref.html>`_ computes an energy minimization refinement over selected structures. 

15 

16 Args: 

17 input_haddock_wf_data (dir): Path to the input directory containing all the current Haddock workflow data. File type: input. `Sample file <https://github.com/bioexcel/biobb_haddock/raw/master/biobb_haddock/test/data/haddock/haddock_wf_data_topology.zip>`_. Accepted formats: directory (edam:format_1915). 

18 output_haddock_wf_data (dir): Path to the output directory containing all the current Haddock workflow data. File type: output. `Sample file <https://github.com/bioexcel/biobb_haddock/raw/master/biobb_haddock/test/data/haddock/haddock_wf_data_emref.zip>`_. Accepted formats: directory (edam:format_1915). 

19 refinement_output_zip_path (str) (Optional): Path to the output PDB file collection in zip format. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/reference/haddock/ref_rigidbody.zip>`_. Accepted formats: zip (edam:format_3987). 

20 ambig_restraints_table_path (str) (Optional): Path to the input TBL file containing a list of ambiguous restraints for docking. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/e2a-hpr_air.tbl>`_. Accepted formats: tbl (edam:format_2330). 

21 unambig_restraints_table_path (str) (Optional): Path to the input TBL file containing a list of unambiguous restraints for docking. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/e2a-hpr_air.tbl>`_. Accepted formats: tbl (edam:format_2330). 

22 hb_restraints_table_path (str) (Optional): Path to the input TBL file containing a list of hydrogen bond restraints for docking. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/e2a-hpr_air.tbl>`_. Accepted formats: tbl (edam:format_2330). 

23 haddock_config_path (str) (Optional): Haddock configuration CFG file path. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/run.cfg>`_. Accepted formats: cfg (edam:format_1476). 

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

25 * **cfg** (*dict*) - ({}) Haddock configuration options specification. 

26 * **global_cfg** (*dict*) - ({"postprocess": False}) `Global configuration options <https://www.bonvinlab.org/haddock3-user-manual/global_parameters.html>`_ specification. 

27 * **binary_path** (*str*) - ("haddock") Path to the haddock haddock executable binary. 

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

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

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

31 * **container_path** (*str*) - (None) Path to the binary executable of your container. 

32 * **container_image** (*str*) - (None) Container Image identifier. 

33 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container. 

34 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container. 

35 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container. 

36 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell. 

37 

38 

39 Examples: 

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

41 

42 from biobb_haddock.haddock.em_ref import em_ref 

43 prop = { 'binary_path': 'haddock' } 

44 em_ref(input_haddock_wf_data='/path/to/myInputData', 

45 output_haddock_wf_data='/path/to/myOutputData', 

46 properties=prop) 

47 

48 Info: 

49 * wrapped_software: 

50 * name: HADDOCK3 

51 * version: 2025.5 

52 * license: Apache-2.0 

53 * ontology: 

54 * name: EDAM 

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

56 """ 

57 

58 def __init__( 

59 self, 

60 input_haddock_wf_data: str, 

61 output_haddock_wf_data: str, 

62 refinement_output_zip_path: Optional[str] = None, 

63 ambig_restraints_table_path: Optional[str] = None, 

64 unambig_restraints_table_path: Optional[str] = None, 

65 hb_restraints_table_path: Optional[str] = None, 

66 haddock_config_path: Optional[str] = None, 

67 properties: Optional[dict] = None, 

68 **kwargs, 

69 ) -> None: 

70 properties = properties or {} 

71 

72 # Call parent class constructor 

73 super().__init__(properties) 

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

75 

76 # Input/Output files 

77 self.io_dict = { 

78 "in": { 

79 "input_haddock_wf_data": input_haddock_wf_data, 

80 "ambig_restraints_table_path": ambig_restraints_table_path, 

81 "unambig_restraints_table_path": unambig_restraints_table_path, 

82 "hb_restraints_table_path": hb_restraints_table_path, 

83 "haddock_config_path": haddock_config_path, 

84 }, 

85 "out": { 

86 "output_haddock_wf_data": output_haddock_wf_data, 

87 "refinement_output_zip_path": refinement_output_zip_path, 

88 }, 

89 } 

90 

91 # Properties specific for BB 

92 self.haddock_step_name = "emref" 

93 # Handle configuration options from properties 

94 self.cfg = {k: v for k, v in properties.get("cfg", dict()).items()} 

95 # Global HADDOCK configuration options 

96 self.global_cfg = properties.get("global_cfg", dict(postprocess=False)) 

97 # Properties specific for BB 

98 self.binary_path = properties.get("binary_path", "haddock3") 

99 # Check the properties 

100 self.check_init(properties) 

101 

102 def _handle_config_arguments(self): 

103 """Handle configuration options from arguments.""" 

104 if self.io_dict["in"].get("ambig_restraints_table_path"): 

105 self.cfg["ambig_fname"] = abspath(self.stage_io_dict["in"].get("ambig_restraints_table_path")) 

106 if self.io_dict["in"].get("unambig_restraints_table_path"): 

107 self.cfg["unambig_fname"] = abspath(self.stage_io_dict["in"].get("unambig_restraints_table_path")) 

108 if self.io_dict["in"].get("hb_restraints_table_path"): 

109 self.cfg["hbond_fname"] = abspath(self.stage_io_dict["in"].get("hb_restraints_table_path")) 

110 

111 def _handle_step_output(self): 

112 """Handle how the output files from the step are copied to host.""" 

113 if refinement_output_zip_path := self.io_dict["out"].get("refinement_output_zip_path"): 

114 self.copy_step_output( 

115 lambda path: path.match(self.haddock_step_name + r"*.pdb*"), 

116 refinement_output_zip_path 

117 ) 

118 

119 

120def em_ref( 

121 input_haddock_wf_data: str, 

122 output_haddock_wf_data: str, 

123 refinement_output_zip_path: Optional[str] = None, 

124 ambig_restraints_table_path: Optional[str] = None, 

125 unambig_restraints_table_path: Optional[str] = None, 

126 hb_restraints_table_path: Optional[str] = None, 

127 haddock_config_path: Optional[str] = None, 

128 properties: Optional[dict] = None, 

129 **kwargs, 

130) -> int: 

131 """Create :class:`EMRef <biobb_haddock.haddock.em_ref>` class and 

132 execute the :meth:`launch() <biobb_haddock.haddock.em_ref.launch>` method.""" 

133 # Launch method inherited from HaddockStepBase 

134 return EMRef(**dict(locals())).launch() 

135 

136 

137em_ref.__doc__ = EMRef.__doc__ 

138main = EMRef.get_main(em_ref, "Wrapper of the HADDOCK3 EMRef module.") 

139 

140 

141if __name__ == "__main__": 

142 main()