Coverage for biobb_io/api/memprotmd_sim.py: 73%
41 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-20 06:47 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-20 06:47 +0000
1#!/usr/bin/env python
3"""Module containing the MemProtMDSim class and the command line interface."""
5import argparse
6from typing import Optional
8from biobb_common.configuration import settings
9from biobb_common.generic.biobb_object import BiobbObject
10from biobb_common.tools.file_utils import launchlogger
12from biobb_io.api.common import (
13 check_mandatory_property,
14 check_output_path,
15 get_memprotmd_sim,
16)
19class MemProtMDSim(BiobbObject):
20 """
21 | biobb_io MemProtMDSim
22 | This class is a wrapper of the MemProtMD to download a simulation using its REST API.
23 | Wrapper for the `MemProtMD DB REST API <http://memprotmd.bioch.ox.ac.uk/>`_ to download a simulation.
25 Args:
26 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).
27 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
28 * **pdb_code** (*str*) - (None) RSCB PDB code.
29 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
30 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
31 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
33 Examples:
34 This is a use example of how to use the building block from Python::
36 from biobb_io.api.memprotmd_sim import memprotmd_sim
37 prop = {
38 'pdb_code': '2VGB'
39 }
40 memprotmd_sim(output_simulation='/path/to/newSimulation.zip',
41 properties=prop)
43 Info:
44 * wrapped_software:
45 * name: MemProtMD DB
46 * license: Creative Commons
47 * ontology:
48 * name: EDAM
49 * schema: http://edamontology.org/EDAM.owl
51 """
53 def __init__(self, output_simulation, properties=None, **kwargs) -> None:
54 properties = properties or {}
56 # Call parent class constructor
57 super().__init__(properties)
58 self.locals_var_dict = locals().copy()
60 # Input/Output files
61 self.io_dict = {"out": {"output_simulation": output_simulation}}
63 # Properties specific for BB
64 self.pdb_code = properties.get("pdb_code", None)
65 self.properties = properties
67 # Check the properties
68 self.check_properties(properties)
69 self.check_arguments()
71 def check_data_params(self, out_log, err_log):
72 """Checks all the input/output paths and parameters"""
73 self.output_simulation = check_output_path(
74 self.io_dict["out"]["output_simulation"],
75 "output_simulation",
76 False,
77 out_log,
78 self.__class__.__name__,
79 )
81 @launchlogger
82 def launch(self) -> int:
83 """Execute the :class:`MemProtMDSim <api.memprotmd_sim.MemProtMDSim>` api.memprotmd_sim.MemProtMDSim object."""
85 # check input/output paths and parameters
86 self.check_data_params(self.out_log, self.err_log)
88 # Setup Biobb
89 if self.check_restart():
90 return 0
92 check_mandatory_property(
93 self.pdb_code, "pdb_code", self.out_log, self.__class__.__name__
94 )
96 # get simulation files and save to output
97 get_memprotmd_sim(
98 self.pdb_code, self.output_simulation, self.out_log, self.global_log
99 )
101 self.check_arguments(output_files_created=True, raise_exception=False)
103 return 0
106def memprotmd_sim(
107 output_simulation: str, properties: Optional[dict] = None, **kwargs
108) -> int:
109 """Execute the :class:`MemProtMDSim <api.memprotmd_sim.MemProtMDSim>` class and
110 execute the :meth:`launch() <api.memprotmd_sim.MemProtMDSim.launch>` method."""
112 return MemProtMDSim(
113 output_simulation=output_simulation, properties=properties, **kwargs
114 ).launch()
116 memprotmd_sim.__doc__ = MemProtMDSim.__doc__
119def main():
120 """Command line execution of this building block. Please check the command line documentation."""
121 parser = argparse.ArgumentParser(
122 description="Wrapper for the MemProtMD DB REST API (http://memprotmd.bioch.ox.ac.uk/) to download a simulation.",
123 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
124 )
125 parser.add_argument(
126 "-c",
127 "--config",
128 required=False,
129 help="This file can be a YAML file, JSON file or JSON string",
130 )
132 # Specific args of each building block
133 required_args = parser.add_argument_group("required arguments")
134 required_args.add_argument(
135 "-o",
136 "--output_simulation",
137 required=True,
138 help="Path to the output simulation in a ZIP file. Accepted formats: zip.",
139 )
141 args = parser.parse_args()
142 config = args.config if args.config else None
143 properties = settings.ConfReader(config=config).get_prop_dic()
145 # Specific call of each building block
146 memprotmd_sim(output_simulation=args.output_simulation, properties=properties)
149if __name__ == "__main__":
150 main()