Coverage for biobb_haddock/haddock_restraints/haddock3_restrain_bodies.py: 85%

41 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 haddock class and the command line interface.""" 

4 

5from typing import Optional 

6from biobb_common.generic.biobb_object import BiobbObject 

7from biobb_common.tools.file_utils import launchlogger 

8 

9 

10class Haddock3RestrainBodies(BiobbObject): 

11 """ 

12 | biobb_haddock Haddock3RestrainBodies 

13 | Wrapper class for the Haddock-Restraints restrain_bodies module. 

14 | `Haddock-Restraints restrain_bodies <https://www.bonvinlab.org/haddock3/clients/haddock.clis.restraints.restrain_bodies.html>`_ creates distance restraints to lock several chains together. Useful to avoid unnatural flexibility or movement due to sequence/numbering gaps. 

15 

16 Args: 

17 input_structure_path (str): Path to the input PDB structure to be restrained. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock_restraints/4G6K_clean.pdb>`_. Accepted formats: pdb (edam:format_1476). 

18 output_tbl_path (str): Path to the output HADDOCK tbl file with Ambiguous Interaction Restraints (AIR) information. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/reference/haddock_restraints/antibody-unambig.tbl>`_. Accepted formats: tbl (edam:format_2330), txt (edam:format_2330), out (edam:format_2330). 

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

20 * **exclude** (*str*) - (None) Chains to exclude from the calculation. 

21 * **verbose** (*int*) - (0) Tune verbosity of the output. 

22 * **binary_path** (*str*) - ("haddock3-restraints") Path to the HADDOCK3 restraints 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 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory. 

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

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

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

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

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

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

32 

33 

34 Examples: 

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

36 

37 from biobb_haddock.haddock_restraints.haddock3_restrain_bodies import haddock3_restrain_bodies 

38 haddock3_restrain_bodies( 

39 input_structure_path='/path/to/structure.pdb', 

40 output_tbl_path='/path/to/body_restraints.tbl' 

41 ) 

42 

43 Info: 

44 * wrapped_software: 

45 * name: Haddock3-restraints 

46 * version: 2025.5 

47 * license: Apache-2.0 

48 * ontology: 

49 * name: EDAM 

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

51 """ 

52 

53 def __init__( 

54 self, 

55 input_structure_path: str, 

56 output_tbl_path: str, 

57 properties: Optional[dict] = None, 

58 **kwargs, 

59 ) -> None: 

60 properties = properties or {} 

61 

62 # Call parent class constructor 

63 super().__init__(properties) 

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

65 

66 # Input/Output files 

67 self.io_dict = { 

68 "in": { 

69 "input_structure_path": input_structure_path 

70 }, 

71 "out": { 

72 "output_tbl_path": output_tbl_path, 

73 }, 

74 } 

75 

76 # Properties specific for BB 

77 self.binary_path = properties.get("binary_path", "haddock3-restraints") 

78 self.exclude = properties.get("exclude", None) 

79 self.verbose = properties.get("verbose", 0) 

80 

81 # Check the properties 

82 self.check_init(properties) 

83 

84 @launchlogger 

85 def launch(self) -> int: 

86 """Execute the :class:`Haddock3RestrainBodies <biobb_haddock.haddock_restraints.haddock3_restrain_bodies>` object.""" 

87 

88 # Setup Biobb 

89 if self.check_restart(): 

90 return 0 

91 self.stage_files() 

92 

93 # haddock3-restraints restrain_bodies <structure> [--exclude] [--verbose] 

94 self.cmd = [self.binary_path, "restrain_bodies", 

95 self.stage_io_dict['in']['input_structure_path']] 

96 

97 if self.exclude is not None: 

98 self.cmd.extend(["--exclude", self.exclude]) 

99 

100 if self.verbose > 0: 

101 self.cmd.extend(["--verbose", str(self.verbose)]) 

102 

103 self.cmd.append(">") 

104 self.cmd.append(self.stage_io_dict['out']['output_tbl_path']) 

105 self.cmd.append("2>&1") 

106 

107 # Run Biobb block 

108 self.run_biobb() 

109 

110 # Remove deprecation warning if present 

111 with open(self.stage_io_dict['out']['output_tbl_path'], 'r') as file: 

112 lines = file.readlines() 

113 if lines and "DEPRECATION NOTICE" in lines[0]: 

114 with open(self.stage_io_dict['out']['output_tbl_path'], 'w') as file: 

115 file.writelines(lines[1:]) 

116 

117 # Copy files to host 

118 self.copy_to_host() 

119 

120 # Remove temporal files 

121 self.remove_tmp_files() 

122 

123 return self.return_code 

124 

125 

126def haddock3_restrain_bodies( 

127 input_structure_path: str, 

128 output_tbl_path: str, 

129 properties: Optional[dict] = None, 

130 **kwargs, 

131) -> int: 

132 """Create :class:`Haddock3RestrainBodies <biobb_haddock.haddock_restraints.haddock3_restrain_bodies>` class and 

133 execute the :meth:`launch() <biobb_haddock.haddock_restraints.haddock3_restrain_bodies.launch>` method.""" 

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

135 

136 

137haddock3_restrain_bodies.__doc__ = Haddock3RestrainBodies.__doc__ 

138main = Haddock3RestrainBodies.get_main(haddock3_restrain_bodies, "Wrapper of the HADDOCK3 restrain_bodies module.") 

139 

140 

141if __name__ == "__main__": 

142 main()