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

48 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-07 08:11 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the AmberToPDB 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.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 * **container_path** (*str*) - (None) Container path definition. 

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

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

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

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

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

31 

32 Examples: 

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

34 

35 from biobb_amber.ambpdb.amber_to_pdb import amber_to_pdb 

36 prop = { 

37 'remove_tmp': True 

38 } 

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

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

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

42 properties=prop) 

43 

44 Info: 

45 * wrapped_software: 

46 * name: AmberTools ambpdb 

47 * version: >20.9 

48 * license: LGPL 2.1 

49 * ontology: 

50 * name: EDAM 

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

52 

53 """ 

54 

55 def __init__(self, input_top_path, input_crd_path, output_pdb_path, properties: dict = None, **kwargs): 

56 properties = properties or {} 

57 

58 # Call parent class constructor 

59 super().__init__(properties) 

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

61 

62 # Input/Output files 

63 self.io_dict = { 

64 'in': {'input_top_path': input_top_path, 

65 'input_crd_path': input_crd_path}, 

66 'out': {'output_pdb_path': output_pdb_path} 

67 } 

68 

69 # Properties specific for BB 

70 self.properties = properties 

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

72 

73 # Check the properties 

74 self.check_properties(properties) 

75 self.check_arguments() 

76 

77 def check_data_params(self, out_log, err_log): 

78 """ Checks input/output paths correctness """ 

79 

80 # Check input(s) 

81 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__) 

82 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__) 

83 

84 # Check output(s) 

85 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__) 

86 

87 @launchlogger 

88 def launch(self): 

89 

90 # check input/output paths and parameters 

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

92 

93 # Setup Biobb 

94 if self.check_restart(): 

95 return 0 

96 self.stage_files() 

97 

98 # Command line 

99 self.cmd = [self.binary_path, 

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

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

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

103 ] 

104 

105 # Run Biobb block 

106 self.run_biobb() 

107 

108 # Copy files to host 

109 self.copy_to_host() 

110 

111 # Remove temporary file(s) 

112 self.tmp_files.extend([ 

113 self.stage_io_dict.get("unique_dir") 

114 ]) 

115 self.remove_tmp_files() 

116 

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

118 

119 return self.return_code 

120 

121 

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

123 properties: dict = None, **kwargs) -> int: 

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

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

126 

127 return AmberToPDB(input_top_path=input_top_path, 

128 input_crd_path=input_crd_path, 

129 output_pdb_path=output_pdb_path, 

130 properties=properties).launch() 

131 

132 

133def main(): 

134 """Command line execution of this building block. Please check the command line documentation.""" 

135 parser = argparse.ArgumentParser(description='Generates a PDB structure from AMBER topology (parmtop) and coordinates (crd) files, using the ambpdb tool from the AmberTools MD package.', formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999)) 

136 parser.add_argument('--config', required=False, help='Configuration file') 

137 

138 # Specific args 

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

140 required_args.add_argument('--input_top_path', required=True, help='AMBER topology file. Accepted formats: top, parmtop, prmtop.') 

141 required_args.add_argument('--input_crd_path', required=True, help='AMBER coordinates file. Accepted formats: crd, mdcrd, inpcrd.') 

142 required_args.add_argument('--output_pdb_path', required=True, help='Structure PDB file. Accepted formats: pdb.') 

143 

144 args = parser.parse_args() 

145 config = args.config if args.config else None 

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

147 

148 # Specific call 

149 amber_to_pdb(input_top_path=args.input_top_path, 

150 input_crd_path=args.input_crd_path, 

151 output_pdb_path=args.output_pdb_path, 

152 properties=properties) 

153 

154 

155if __name__ == '__main__': 

156 main()