Coverage for biobb_cmip / cmip / cmip_prepare_pdb.py: 93%

44 statements  

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

1#!/usr/bin/env python3 

2 

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

4from typing import Optional 

5from biobb_common.generic.biobb_object import BiobbObject 

6from biobb_common.tools.file_utils import launchlogger 

7 

8 

9class CmipPreparePDB(BiobbObject): 

10 """ 

11 | biobb_cmip CmipPreparePDB 

12 | Class to add CMIP charges and atom types. 

13 | Add CMIP charges and atom types to a PDB structure using `biobb_structure_checking <https://anaconda.org/bioconda/biobb_structure_checking>`_. 

14 

15 Args: 

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

17 output_cmip_pdb_path (str): Output PDB file path. File type: output. `Sample file <https://github.com/bioexcel/biobb_cmip/raw/master/biobb_cmip/test/reference/cmip/egfr_cmip.pdb>`_. Accepted formats: pdb (edam:format_1476). 

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

19 * **remove_water** (*bool*) - (True) Remove Water molecules. 

20 * **add_hydrogen** (*bool*) - (True) Add Hydrogen atoms to the structure. 

21 * **keep_hydrogen** (*bool*) - (False) If **add_hydrogen** is True. All hydrogen atoms will be removed before adding the new ones unless this option is set True. 

22 * **fix_sidechains** (*bool*) - (True) Complete side chains (heavy atoms, protein only). 

23 * **fix_backbone_atoms** (*bool*) - (True) Add missing O, OXT backbone atoms. 

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

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

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

27 

28 

29 Examples: 

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

31 

32 from biobb_cmip.cmip.cmip_prepare_pdb import cmip_prepare_pdb 

33 prop = { 'restart': False } 

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

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

36 properties=prop) 

37 

38 Info: 

39 * wrapped_software: 

40 * name: CMIP cmip 

41 * version: 2.7.0 

42 * license: Apache-2.0 

43 * ontology: 

44 * name: EDAM 

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

46 """ 

47 

48 def __init__(self, input_pdb_path: str, output_cmip_pdb_path: str, properties: Optional[dict] = None, **kwargs) -> None: 

49 properties = properties or {} 

50 

51 # Call parent class constructor 

52 super().__init__(properties) 

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

54 

55 # Input/Output files 

56 self.io_dict = { 

57 "in": {"input_pdb_path": input_pdb_path}, 

58 "out": {"output_cmip_pdb_path": output_cmip_pdb_path} 

59 } 

60 

61 # Properties specific for BB 

62 self.check_structure_path = properties.get('check_structure_path', 'check_structure') 

63 self.remove_water = properties.get('remove_water', True) 

64 self.keep_hydrogen = properties.get('keep_hydrogen', False) 

65 self.fix_sidechains = properties.get('fix_sidechains', True) 

66 self.fix_backbone_atoms = properties.get('fix_backbone_atoms', True) 

67 

68 # Check the properties 

69 self.check_properties(properties) 

70 self.check_arguments() 

71 

72 @launchlogger 

73 def launch(self) -> int: 

74 """Execute the :class:`PreparePDB <cmip.prepare_pdb.PreparePDB>` object.""" 

75 

76 # Setup Biobb 

77 if self.check_restart(): 

78 return 0 

79 self.stage_files() 

80 

81 command_list = "" 

82 if self.remove_water: 

83 command_list += 'water --remove yes; ' 

84 

85 if self.fix_backbone_atoms: 

86 command_list += 'backbone --add_caps none; ' 

87 

88 if self.fix_sidechains: 

89 command_list += 'fixside --fix All; ' 

90 

91 command_list += 'add_hydrogen --add_mode auto ' 

92 if self.keep_hydrogen: 

93 command_list += ' -keep_h ' 

94 command_list += '--add_charges CMIP' 

95 

96 self.cmd = [self.check_structure_path, 

97 '-v', 

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

99 '-o', self.stage_io_dict["out"]["output_cmip_pdb_path"], 

100 '--output_format', 'cmip', 

101 '--non_interactive', 

102 'command_list', 

103 '--list', "'"+command_list+"'"] 

104 

105 # Run Biobb block 

106 self.run_biobb() 

107 

108 # Copy files to host 

109 self.copy_to_host() 

110 

111 # remove temporary folder(s) 

112 self.remove_tmp_files() 

113 

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

115 

116 return self.return_code 

117 

118 

119def cmip_prepare_pdb(input_pdb_path: str, output_cmip_pdb_path: str, properties: Optional[dict] = None, **kwargs) -> int: 

120 """Create :class:`PreparePDB <cmip.prepare_pdb.PreparePDB>` class and 

121 execute the :meth:`launch() <cmip.prepare_pdb.PreparePDB.launch>` method.""" 

122 return CmipPreparePDB(**dict(locals())).launch() 

123 

124 

125cmip_prepare_pdb.__doc__ = CmipPreparePDB.__doc__ 

126main = CmipPreparePDB.get_main(cmip_prepare_pdb, "Model the missing atoms in the backbone of a PDB structure.") 

127 

128if __name__ == '__main__': 

129 main()