Coverage for biobb_io/api/memprotmd_sim.py: 74%
39 statements
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-14 18:20 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-14 18:20 +0000
1#!/usr/bin/env python
3"""Module containing the MemProtMDSim 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_io.api.common import check_output_path, check_mandatory_property, get_memprotmd_sim
11class MemProtMDSim(BiobbObject):
12 """
13 | biobb_io MemProtMDSim
14 | This class is a wrapper of the MemProtMD to download a simulation using its REST API.
15 | Wrapper for the `MemProtMD DB REST API <http://memprotmd.bioch.ox.ac.uk/>`_ to download a simulation.
17 Args:
18 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).
19 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
20 * **pdb_code** (*str*) - (None) RSCB PDB code.
21 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
22 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
23 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
25 Examples:
26 This is a use example of how to use the building block from Python::
28 from biobb_io.api.memprotmd_sim import memprotmd_sim
29 prop = {
30 'pdb_code': '2VGB'
31 }
32 memprotmd_sim(output_simulation='/path/to/newSimulation.zip',
33 properties=prop)
35 Info:
36 * wrapped_software:
37 * name: MemProtMD DB
38 * license: Creative Commons
39 * ontology:
40 * name: EDAM
41 * schema: http://edamontology.org/EDAM.owl
43 """
45 def __init__(self, output_simulation,
46 properties=None, **kwargs) -> None:
47 properties = properties or {}
49 # Call parent class constructor
50 super().__init__(properties)
51 self.locals_var_dict = locals().copy()
53 # Input/Output files
54 self.io_dict = {
55 "out": {"output_simulation": output_simulation}
56 }
58 # Properties specific for BB
59 self.pdb_code = properties.get('pdb_code', None)
60 self.properties = properties
62 # Check the properties
63 self.check_properties(properties)
64 self.check_arguments()
66 def check_data_params(self, out_log, err_log):
67 """ Checks all the input/output paths and parameters """
68 self.output_simulation = check_output_path(self.io_dict["out"]["output_simulation"], "output_simulation", False, out_log, self.__class__.__name__)
70 @launchlogger
71 def launch(self) -> int:
72 """Execute the :class:`MemProtMDSim <api.memprotmd_sim.MemProtMDSim>` api.memprotmd_sim.MemProtMDSim object."""
74 # check input/output paths and parameters
75 self.check_data_params(self.out_log, self.err_log)
77 # Setup Biobb
78 if self.check_restart():
79 return 0
81 check_mandatory_property(self.pdb_code, 'pdb_code', self.out_log, self.__class__.__name__)
83 # get simulation files and save to output
84 get_memprotmd_sim(self.pdb_code, self.output_simulation, self.out_log, self.global_log)
86 self.check_arguments(output_files_created=True, raise_exception=False)
88 return 0
91def memprotmd_sim(output_simulation: str, properties: dict = None, **kwargs) -> int:
92 """Execute the :class:`MemProtMDSim <api.memprotmd_sim.MemProtMDSim>` class and
93 execute the :meth:`launch() <api.memprotmd_sim.MemProtMDSim.launch>` method."""
95 return MemProtMDSim(output_simulation=output_simulation,
96 properties=properties, **kwargs).launch()
99def main():
100 """Command line execution of this building block. Please check the command line documentation."""
101 parser = argparse.ArgumentParser(description="Wrapper for the MemProtMD DB REST API (http://memprotmd.bioch.ox.ac.uk/) to download a simulation.", formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999))
102 parser.add_argument('-c', '--config', required=False, help="This file can be a YAML file, JSON file or JSON string")
104 # Specific args of each building block
105 required_args = parser.add_argument_group('required arguments')
106 required_args.add_argument('-o', '--output_simulation', required=True, help="Path to the output simulation in a ZIP file. Accepted formats: zip.")
108 args = parser.parse_args()
109 config = args.config if args.config else None
110 properties = settings.ConfReader(config=config).get_prop_dic()
112 # Specific call of each building block
113 memprotmd_sim(output_simulation=args.output_simulation,
114 properties=properties)
117if __name__ == '__main__':
118 main()