Coverage for biobb_model/model/fix_side_chain.py: 69%

51 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-13 17:26 +0000

1#!/usr/bin/env python3 

2 

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

4import argparse 

5from biobb_common.generic.biobb_object import BiobbObject 

6from biobb_common.configuration import settings 

7from biobb_common.tools import file_utils as fu 

8from biobb_common.tools.file_utils import launchlogger 

9from biobb_model.model.common import modeller_installed 

10 

11 

12class FixSideChain(BiobbObject): 

13 """ 

14 | biobb_model FixSideChain 

15 | Class to model the missing atoms in amino acid side chains of a PDB. 

16 | Model the missing atoms in amino acid side chains of a PDB using `biobb_structure_checking <https://anaconda.org/bioconda/biobb_structure_checking>`_ if the use_modeller property is added the `Modeller suite <https://salilab.org/modeller/>`_ will also be used to rebuild the missing atoms. 

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

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

22 * **use_modeller** (*bool*) - (False) Use `Modeller suite <https://salilab.org/modeller/>`_ to rebuild the missing side chain atoms. 

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 

28 Examples: 

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

30 

31 from biobb_model.model.fix_side_chain import fix_side_chain 

32 prop = { 'use_modeller': True } 

33 fix_side_chain(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: In house 

40 * license: Apache-2.0 

41 * ontology: 

42 * name: EDAM 

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

44 """ 

45 

46 def __init__(self, input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> None: 

47 properties = properties or {} 

48 

49 # Call parent class constructor 

50 super().__init__(properties) 

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

52 

53 # Input/Output files 

54 self.io_dict = { 

55 "in": {"input_pdb_path": input_pdb_path}, 

56 "out": {"output_pdb_path": output_pdb_path} 

57 } 

58 

59 # Properties specific for BB 

60 self.binary_path = properties.get('binary_path', 'check_structure') 

61 self.use_modeller = properties.get('use_modeller', False) 

62 self.modeller_key = properties.get('modeller_key') 

63 

64 # Check the properties 

65 self.check_properties(properties) 

66 self.check_arguments() 

67 

68 @launchlogger 

69 def launch(self) -> int: 

70 """Execute the :class:`FixSideChain <model.fix_side_chain.FixSideChain>` object.""" 

71 

72 # Setup Biobb 

73 if self.check_restart(): 

74 return 0 

75 self.stage_files() 

76 

77 # Create command line 

78 self.cmd = [self.binary_path, 

79 '-i', self.stage_io_dict["in"]["input_pdb_path"], 

80 '-o', self.stage_io_dict["out"]["output_pdb_path"], 

81 '--force_save', 

82 'fixside', '--fix', 'ALL'] 

83 

84 if self.modeller_key: 

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

86 self.cmd.insert(1, '--modeller_key') 

87 

88 if self.use_modeller: 

89 if modeller_installed(self.out_log, self.global_log): 

90 self.cmd.append('--rebuild') 

91 else: 

92 fu.log("Modeller is not installed --rebuild option can not be used proceeding without using it", self.out_log, self.global_log) 

93 

94 # Run Biobb block 

95 self.run_biobb() 

96 

97 # Copy files to host 

98 self.copy_to_host() 

99 

100 # Remove temporal files 

101 self.tmp_files.extend([self.stage_io_dict.get("unique_dir")]) 

102 self.remove_tmp_files() 

103 

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

105 return self.return_code 

106 

107 

108def fix_side_chain(input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> int: 

109 """Create :class:`FixSideChain <model.fix_side_chain.FixSideChain>` class and 

110 execute the :meth:`launch() <model.fix_side_chain.FixSideChain.launch>` method.""" 

111 return FixSideChain(input_pdb_path=input_pdb_path, 

112 output_pdb_path=output_pdb_path, 

113 properties=properties, **kwargs).launch() 

114 

115 

116def main(): 

117 parser = argparse.ArgumentParser(description="Model the missing atoms in amino acid side chains of a PDB.", 

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

119 parser.add_argument('-c', '--config', required=False, help="This file can be a YAML file, JSON file or JSON string") 

120 

121 # Specific args of each building block 

122 required_args = parser.add_argument_group('required arguments') 

123 required_args.add_argument('-i', '--input_pdb_path', required=True, help="Input PDB file name") 

124 required_args.add_argument('-o', '--output_pdb_path', required=True, help="Output PDB file name") 

125 

126 args = parser.parse_args() 

127 config = args.config if args.config else None 

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

129 

130 # Specific call of each building block 

131 fix_side_chain(input_pdb_path=args.input_pdb_path, 

132 output_pdb_path=args.output_pdb_path, 

133 properties=properties) 

134 

135 

136if __name__ == '__main__': 

137 main()