Coverage for biobb_cmip/cmip/cmip_ignore_residues.py: 85%

46 statements  

« prev     ^ index     » next       coverage.py v7.10.4, created at 2025-12-15 18:28 +0000

1#!/usr/bin/env python3 

2 

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

4from typing import Optional 

5import shutil 

6from biobb_cmip.cmip.common import mark_residues 

7from biobb_common.generic.biobb_object import BiobbObject 

8from biobb_common.tools.file_utils import launchlogger 

9import biobb_common.tools.file_utils as fu 

10 

11 

12class CmipIgnoreResidues(BiobbObject): 

13 """ 

14 | biobb_cmip CmipIgnoreResidues 

15 | Class to ignore residues in CMIP potential calculations. 

16 | Mark residues which will be ignored in the CMIP potential calculations except for dielectric definition. 

17 

18 Args: 

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

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

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

22 * **residue_list** (*str*) - (None) Residue list in the format "Chain:Resnum" (no spaces between the elements) separated by commas. If no chain is provided all the residues in the pdb file will be market. ie: "A:3". 

23 * **ignore_all** (*bool*) - (False) Mark all the residues in the PDB file. 

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_ignore_residues import cmip_ignore_residues 

33 prop = { 'residue_list': "A:3" } 

34 cmip_ignore_residues(input_cmip_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_cmip_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_cmip_pdb_path": input_cmip_pdb_path}, 

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

59 } 

60 

61 # Properties specific for BB 

62 self.residue_list = properties.get('residue_list', None) 

63 self.ignore_all = properties.get('ignore_all', False) 

64 

65 # Check the properties 

66 self.check_properties(properties) 

67 self.check_arguments() 

68 

69 @launchlogger 

70 def launch(self) -> int: 

71 """Execute the :class:`IgnoreResidues <cmip.ignore_residues.IgnoreResidues>` object.""" 

72 

73 # Setup Biobb 

74 if self.check_restart(): 

75 return 0 

76 

77 if not self.ignore_all and not self.residue_list: 

78 fu.log("Residue_list is empty and ignore_all is false nothing will be done.", self.out_log, self.global_log) 

79 shutil.copyfile(self.io_dict["in"]["input_cmip_pdb_path"], self.io_dict["out"]["output_cmip_pdb_path"]) 

80 return self.return_code 

81 

82 if self.ignore_all: 

83 self.residue_list = None 

84 

85 if self.residue_list: 

86 if not isinstance(self.residue_list, list): 

87 self.residue_list = str(self.residue_list).split(",") 

88 for i in range(len(self.residue_list)): 

89 residue_code_list = str(self.residue_list[i]).split(":") 

90 if len(residue_code_list) < 2: 

91 resnum = residue_code_list[0] 

92 chain = '' 

93 else: 

94 chain, resnum = residue_code_list 

95 self.residue_list[i] = chain.strip().upper()+":"+str(resnum).strip() 

96 

97 mark_residues(residue_list=self.residue_list or [], input_cmip_pdb_path=self.io_dict["in"]["input_cmip_pdb_path"], output_cmip_pdb_path=self.io_dict["out"]["output_cmip_pdb_path"], out_log=self.out_log, global_log=self.global_log) 

98 

99 # remove temporary 

100 self.remove_tmp_files() 

101 

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

103 

104 return self.return_code 

105 

106 

107def cmip_ignore_residues(input_cmip_pdb_path: str, output_cmip_pdb_path: str, properties: Optional[dict] = None, **kwargs) -> int: 

108 """Create :class:`IgnoreResidues <cmip.ignore_residues.IgnoreResidues>` class and 

109 execute the :meth:`launch() <cmip.ignore_residues.IgnoreResidues.launch>` method.""" 

110 return CmipIgnoreResidues(**dict(locals())).launch() 

111 

112 

113cmip_ignore_residues.__doc__ = CmipIgnoreResidues.__doc__ 

114main = CmipIgnoreResidues.get_main(cmip_ignore_residues, "Mark residues which charges will be ignored in the CMIP potential calculations.") 

115 

116if __name__ == '__main__': 

117 main()