Coverage for biobb_model / model / fix_backbone.py: 29%

42 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-22 13:18 +0000

1#!/usr/bin/env python3 

2 

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

4 

5from typing import Optional 

6 

7from biobb_common.generic.biobb_object import BiobbObject 

8from biobb_common.tools import file_utils as fu 

9from biobb_common.tools.file_utils import launchlogger 

10 

11 

12class FixBackbone(BiobbObject): 

13 """ 

14 | biobb_model FixBackbone 

15 | Class to model the missing atoms in the backbone of a PDB structure. 

16 | Model the missing atoms in the backbone of a PDB structure using `biobb_structure_checking <https://anaconda.org/bioconda/biobb_structure_checking>`_ and the `Modeller suite <https://salilab.org/modeller/>`_. 

17 

18 Args: 

19 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/2ki5.pdb>`_. Accepted formats: pdb (edam:format_1476). 

20 input_fasta_canonical_sequence_path (str): Input FASTA file path. File type: input. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/data/model/2ki5.fasta>`_. Accepted formats: fasta (edam:format_1476). 

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

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

23 * **add_caps** (*bool*) - (False) Add caps to terminal residues. 

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

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

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

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

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

29 

30 Examples: 

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

32 

33 from biobb_model.model.fix_backbone import fix_backbone 

34 prop = { 'restart': False } 

35 fix_backbone(input_pdb_path='/path/to/myStructure.pdb', 

36 input_fasta_canonical_sequence_path='/path/to/myCanonicalSequence.fasta', 

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

38 properties=prop) 

39 

40 Info: 

41 * wrapped_software: 

42 * name: In house 

43 * license: Apache-2.0 

44 * ontology: 

45 * name: EDAM 

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

47 """ 

48 

49 def __init__( 

50 self, 

51 input_pdb_path: str, 

52 input_fasta_canonical_sequence_path: str, 

53 output_pdb_path: str, 

54 properties: Optional[dict] = None, 

55 **kwargs, 

56 ) -> None: 

57 properties = properties or {} 

58 

59 # Call parent class constructor 

60 super().__init__(properties) 

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

62 

63 # Input/Output files 

64 self.io_dict = { 

65 "in": { 

66 "input_pdb_path": input_pdb_path, 

67 "input_fasta_canonical_sequence_path": input_fasta_canonical_sequence_path, 

68 }, 

69 "out": {"output_pdb_path": output_pdb_path}, 

70 } 

71 

72 # Properties specific for BB 

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

74 self.add_caps = properties.get("add_caps", False) 

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

76 

77 # Check the properties 

78 self.check_properties(properties) 

79 self.check_arguments() 

80 

81 @launchlogger 

82 def launch(self) -> int: 

83 """Execute the :class:`FixBackbone <model.fix_backbone.FixBackbone>` object.""" 

84 

85 self.io_dict["in"]["stdin_file_path"] = fu.create_stdin_file(f'{self.io_dict["in"]["input_fasta_canonical_sequence_path"]}') 

86 

87 # Setup Biobb 

88 if self.check_restart(): 

89 return 0 

90 self.stage_files() 

91 

92 # Create command line 

93 self.cmd = [ 

94 self.binary_path, 

95 "-i", 

96 self.io_dict["in"]["input_pdb_path"], 

97 "-o", 

98 self.io_dict["out"]["output_pdb_path"], 

99 "--force_save", 

100 "backbone", 

101 "--fix_atoms", 

102 "All", 

103 "--fix_chain", 

104 "All", 

105 "--add_caps", 

106 ] 

107 

108 if self.modeller_key: 

109 self.cmd.insert(5, self.modeller_key) 

110 self.cmd.insert(5, "--modeller_key") 

111 

112 if self.add_caps: 

113 self.cmd.append("All") 

114 else: 

115 self.cmd.append("None") 

116 

117 # Add stdin input file 

118 self.cmd.append("<") 

119 self.cmd.append(self.stage_io_dict["in"]["stdin_file_path"]) 

120 

121 # if not modeller_installed(self.out_log, self.global_log): 

122 # fu.log(f"Modeller is not installed, the execution of this block will be interrupted", self.out_log, self.global_log) 

123 # return 1 

124 

125 # Run Biobb block 

126 self.run_biobb() 

127 

128 # Copy files to host 

129 self.copy_to_host() 

130 

131 # Remove temporal files 

132 self.tmp_files.append(self.io_dict["in"].get("stdin_file_path", "")) 

133 self.remove_tmp_files() 

134 

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

136 return self.return_code 

137 

138 

139def fix_backbone( 

140 input_pdb_path: str, 

141 input_fasta_canonical_sequence_path: str, 

142 output_pdb_path: str, 

143 properties: Optional[dict] = None, 

144 **kwargs, 

145) -> int: 

146 """Create :class:`FixBackbone <model.fix_backbone.FixBackbone>` class and 

147 execute the :meth:`launch() <model.fix_backbone.FixBackbone.launch>` method.""" 

148 return FixBackbone(**dict(locals())).launch() 

149 

150 

151fix_backbone.__doc__ = FixBackbone.__doc__ 

152main = FixBackbone.get_main(fix_backbone, "Model the missing atoms in the backbone of a PDB structure.") 

153 

154if __name__ == "__main__": 

155 main()