Coverage for biobb_io/api/memprotmd_sim.py: 94%

31 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-04 08:31 +0000

1#!/usr/bin/env python 

2 

3"""Module containing the MemProtMDSim 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 

8 

9from biobb_io.api.common import ( 

10 check_mandatory_property, 

11 check_output_path, 

12 get_memprotmd_sim, 

13) 

14 

15 

16class MemProtMDSim(BiobbObject): 

17 """ 

18 | biobb_io MemProtMDSim 

19 | This class is a wrapper of the MemProtMD to download a simulation using its REST API. 

20 | Wrapper for the `MemProtMD DB REST API <http://memprotmd.bioch.ox.ac.uk/>`_ to download a simulation. 

21 

22 Args: 

23 output_simulation (str): Path to the output simulation in a ZIP file. File type: output. `Sample file <https://github.com/bioexcel/biobb_io/raw/master/biobb_io/test/reference/api/output_sim.zip>`_. Accepted formats: zip (edam:format_3987). 

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

25 * **pdb_code** (*str*) - (None) RSCB PDB code. 

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

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

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

29 

30 Examples: 

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

32 

33 from biobb_io.api.memprotmd_sim import memprotmd_sim 

34 prop = { 

35 'pdb_code': '2VGB' 

36 } 

37 memprotmd_sim(output_simulation='/path/to/newSimulation.zip', 

38 properties=prop) 

39 

40 Info: 

41 * wrapped_software: 

42 * name: MemProtMD DB 

43 * license: Creative Commons 

44 * ontology: 

45 * name: EDAM 

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

47 

48 """ 

49 

50 def __init__(self, output_simulation, properties=None, **kwargs) -> None: 

51 properties = properties or {} 

52 

53 # Call parent class constructor 

54 super().__init__(properties) 

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

56 

57 # Input/Output files 

58 self.io_dict = {"out": {"output_simulation": output_simulation}} 

59 

60 # Properties specific for BB 

61 self.pdb_code = properties.get("pdb_code", None) 

62 self.properties = properties 

63 

64 # Check the properties 

65 self.check_properties(properties) 

66 self.check_arguments() 

67 

68 def check_data_params(self, out_log, err_log): 

69 """Checks all the input/output paths and parameters""" 

70 self.output_simulation = check_output_path( 

71 self.io_dict["out"]["output_simulation"], 

72 "output_simulation", 

73 False, 

74 out_log, 

75 self.__class__.__name__, 

76 ) 

77 

78 @launchlogger 

79 def launch(self) -> int: 

80 """Execute the :class:`MemProtMDSim <api.memprotmd_sim.MemProtMDSim>` api.memprotmd_sim.MemProtMDSim object.""" 

81 

82 # check input/output paths and parameters 

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

84 

85 # Setup Biobb 

86 if self.check_restart(): 

87 return 0 

88 

89 check_mandatory_property( 

90 self.pdb_code, "pdb_code", self.out_log, self.__class__.__name__ 

91 ) 

92 

93 # get simulation files and save to output 

94 get_memprotmd_sim( 

95 self.pdb_code, self.output_simulation, self.out_log, self.global_log 

96 ) 

97 

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

99 

100 return 0 

101 

102 

103def memprotmd_sim( 

104 output_simulation: str, properties: Optional[dict] = None, **kwargs 

105) -> int: 

106 """Execute the :class:`MemProtMDSim <api.memprotmd_sim.MemProtMDSim>` class and 

107 execute the :meth:`launch() <api.memprotmd_sim.MemProtMDSim.launch>` method.""" 

108 return MemProtMDSim(**dict(locals())).launch() 

109 

110 

111memprotmd_sim.__doc__ = MemProtMDSim.__doc__ 

112main = MemProtMDSim.get_main(memprotmd_sim, "Wrapper for the MemProtMD DB REST API (http://memprotmd.bioch.ox.ac.uk/) to download a simulation.") 

113 

114if __name__ == "__main__": 

115 main()