Coverage for biobb_amber / ambpdb / amber_to_pdb.py: 94%

36 statements  

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

1#!/usr/bin/env python3 

2 

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

4 

5from typing import Optional 

6from biobb_common.generic.biobb_object import BiobbObject 

7from biobb_common.tools.file_utils import launchlogger 

8from biobb_amber.ambpdb.common import check_input_path, check_output_path 

9 

10 

11class AmberToPDB(BiobbObject): 

12 """ 

13 | biobb_amber AmberToPDB 

14 | Wrapper of the `AmberTools (AMBER MD Package) ambpdb tool <https://ambermd.org/AmberTools.php>`_ module. 

15 | Generates a PDB structure from AMBER topology (parmtop) and coordinates (crd) files, using the ambpdb tool from the AmberTools MD package. 

16 

17 Args: 

18 input_top_path (str): AMBER topology file. File type: input. `Sample file <https://github.com/bioexcel/biobb_amber/raw/master/biobb_amber/test/data/ambpdb/structure.leap.top>`_. Accepted formats: top (edam:format_3881), parmtop (edam:format_3881), prmtop (edam:format_3881). 

19 input_crd_path (str): AMBER coordinates file. File type: input. `Sample file <https://github.com/bioexcel/biobb_amber/raw/master/biobb_amber/test/data/ambpdb/structure.leap.crd>`_. Accepted formats: crd (edam:format_3878), mdcrd (edam:format_3878), inpcrd (edam:format_3878), rst (edam:format_3886). 

20 output_pdb_path (str): Structure PDB file. File type: output. `Sample file <https://github.com/bioexcel/biobb_amber/raw/master/biobb_amber/test/reference/ambpdb/structure.ambpdb.pdb>`_. Accepted formats: pdb (edam:format_1476). 

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

22 * **binary_path** (*str*) - ("ambpdb") Path to the ambpdb executable binary. 

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

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

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

26 * **container_path** (*str*) - (None) Container path definition. 

27 * **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition. 

28 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition. 

29 * **container_working_dir** (*str*) - (None) Container working directory definition. 

30 * **container_user_id** (*str*) - (None) Container user_id definition. 

31 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container. 

32 

33 Examples: 

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

35 

36 from biobb_amber.ambpdb.amber_to_pdb import amber_to_pdb 

37 prop = { 

38 'remove_tmp': True 

39 } 

40 amber_to_pdb(input_top_path='/path/to/topology.top', 

41 input_crd_path='/path/to/coordinates.crd', 

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

43 properties=prop) 

44 

45 Info: 

46 * wrapped_software: 

47 * name: AmberTools ambpdb 

48 * version: >20.9 

49 * license: LGPL 2.1 

50 * ontology: 

51 * name: EDAM 

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

53 

54 """ 

55 

56 def __init__(self, input_top_path, input_crd_path, output_pdb_path, properties: Optional[dict] = None, **kwargs): 

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': {'input_top_path': input_top_path, 

66 'input_crd_path': input_crd_path}, 

67 'out': {'output_pdb_path': output_pdb_path} 

68 } 

69 

70 # Properties specific for BB 

71 self.properties = properties 

72 self.binary_path = properties.get('binary_path', 'ambpdb') 

73 

74 # Check the properties 

75 self.check_properties(properties) 

76 self.check_arguments() 

77 

78 def check_data_params(self, out_log, err_log): 

79 """ Checks input/output paths correctness """ 

80 

81 # Check input(s) 

82 self.io_dict["in"]["input_top_path"] = check_input_path(self.io_dict["in"]["input_top_path"], "input_top_path", False, out_log, self.__class__.__name__) 

83 self.io_dict["in"]["input_crd_path"] = check_input_path(self.io_dict["in"]["input_crd_path"], "input_crd_path", False, out_log, self.__class__.__name__) 

84 

85 # Check output(s) 

86 self.io_dict["out"]["output_pdb_path"] = check_output_path(self.io_dict["out"]["output_pdb_path"], "output_pdb_path", False, out_log, self.__class__.__name__) 

87 

88 @launchlogger 

89 def launch(self): 

90 

91 # check input/output paths and parameters 

92 self.check_data_params(self.out_log, self.err_log) 

93 

94 # Setup Biobb 

95 if self.check_restart(): 

96 return 0 

97 self.stage_files() 

98 

99 # Command line 

100 self.cmd = [self.binary_path, 

101 '-p', self.stage_io_dict['in']['input_top_path'], 

102 '-c', self.stage_io_dict['in']['input_crd_path'], 

103 '> ', self.stage_io_dict['out']['output_pdb_path'] 

104 ] 

105 

106 # Run Biobb block 

107 self.run_biobb() 

108 

109 # Copy files to host 

110 self.copy_to_host() 

111 

112 # Remove temporary file(s) 

113 self.remove_tmp_files() 

114 

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

116 

117 return self.return_code 

118 

119 

120def amber_to_pdb(input_top_path: str, input_crd_path: str, output_pdb_path: str, 

121 properties: Optional[dict] = None, **kwargs) -> int: 

122 """Create the :class:`AmberToPDB <amber.amber_to_pdb.AmberToPDB>` class and 

123 execute the :meth:`launch() <amber.amber_to_pdb.AmberToPDB.launch>` method.""" 

124 return AmberToPDB(**dict(locals())).launch() 

125 

126 

127amber_to_pdb.__doc__ = AmberToPDB.__doc__ 

128main = AmberToPDB.get_main(amber_to_pdb, "Generates a PDB structure from AMBER topology (parmtop) and coordinates (crd) files, using the ambpdb tool from the AmberTools MD package.") 

129 

130if __name__ == '__main__': 

131 main()