Coverage for biobb_model/model/fix_ssbonds.py: 68%

44 statements  

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

1#!/usr/bin/env python3 

2 

3"""Module containing the FixSSBonds 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 FixSSBonds(BiobbObject): 

14 """ 

15 | biobb_model FixSSBonds 

16 | Fix SS bonds from residues. 

17 | Fix the SS bonds in a PDB structure. 

18 

19 Args: 

20 input_pdb_path (str): Input PDB file path. File type: input. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/data/model/1aki.pdb>`_. Accepted formats: pdb (edam:format_1476). 

21 output_pdb_path (str): Output PDB file path. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_model/master/biobb_model/test/reference/model/output_ssbonds.pdb>`_. Accepted formats: pdb (edam:format_1476). 

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

23 * **modeller_key** (*str*) - (None) Modeller license key. 

24 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary. 

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

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

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

28 

29 Examples: 

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

31 

32 from biobb_model.model.fix_ssbonds import fix_ssbonds 

33 prop = { 'restart': False } 

34 fix_ssbonds(input_pdb_path='/path/to/myStructure.pdb', 

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

36 properties=prop) 

37 

38 Info: 

39 * wrapped_software: 

40 * name: In house 

41 * license: Apache-2.0 

42 * ontology: 

43 * name: EDAM 

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

45 """ 

46 

47 def __init__( 

48 self, 

49 input_pdb_path: str, 

50 output_pdb_path: str, 

51 properties: Optional[dict] = None, 

52 **kwargs, 

53 ) -> None: 

54 properties = properties or {} 

55 

56 # Call parent class constructor 

57 super().__init__(properties) 

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

59 

60 # Input/Output files 

61 self.io_dict = { 

62 "in": {"input_pdb_path": input_pdb_path}, 

63 "out": {"output_pdb_path": output_pdb_path}, 

64 } 

65 

66 # Properties specific for BB 

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

68 self.modeller_key = properties.get("modeller_key") 

69 

70 # Check the properties 

71 self.check_properties(properties) 

72 self.check_arguments() 

73 

74 @launchlogger 

75 def launch(self) -> int: 

76 """Execute the :class:`FixSSBonds <model.fix_ssbonds.FixSSBonds>` object.""" 

77 

78 # Setup Biobb 

79 if self.check_restart(): 

80 return 0 

81 self.stage_files() 

82 

83 self.cmd = [ 

84 self.binary_path, 

85 "-i", 

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

87 "-o", 

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

89 "--force_save", 

90 "--non_interactive", 

91 "getss", 

92 "--mark", 

93 "All", 

94 ] 

95 

96 if self.modeller_key: 

97 self.cmd.insert(1, self.modeller_key) 

98 self.cmd.insert(1, "--modeller_key") 

99 

100 # Run Biobb block 

101 self.run_biobb() 

102 

103 # Copy files to host 

104 self.copy_to_host() 

105 

106 # Remove temporal files 

107 # self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")]) 

108 self.remove_tmp_files() 

109 

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

111 return self.return_code 

112 

113 

114def fix_ssbonds( 

115 input_pdb_path: str, 

116 output_pdb_path: str, 

117 properties: Optional[dict] = None, 

118 **kwargs, 

119) -> int: 

120 """Create :class:`FixSSBonds <model.fix_ssbonds.FixSSBonds>` class and 

121 execute the :meth:`launch() <model.fix_ssbonds.FixSSBonds.launch>` method.""" 

122 return FixSSBonds( 

123 input_pdb_path=input_pdb_path, 

124 output_pdb_path=output_pdb_path, 

125 properties=properties, 

126 **kwargs, 

127 ).launch() 

128 

129 fix_ssbonds.__doc__ = FixSSBonds.__doc__ 

130 

131 

132def main(): 

133 parser = argparse.ArgumentParser( 

134 description="Fix SS bonds from residues", 

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

136 ) 

137 parser.add_argument( 

138 "-c", 

139 "--config", 

140 required=False, 

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

142 ) 

143 

144 # Specific args of each building block 

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

146 required_args.add_argument( 

147 "-i", "--input_pdb_path", required=True, help="Input PDB file name" 

148 ) 

149 required_args.add_argument( 

150 "-o", "--output_pdb_path", required=True, help="Output PDB file name" 

151 ) 

152 

153 args = parser.parse_args() 

154 config = args.config if args.config else None 

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

156 

157 # Specific call of each building block 

158 fix_ssbonds( 

159 input_pdb_path=args.input_pdb_path, 

160 output_pdb_path=args.output_pdb_path, 

161 properties=properties, 

162 ) 

163 

164 

165if __name__ == "__main__": 

166 main()