Coverage for biobb_io/api/structure_info.py: 38%
34 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 08:31 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 08:31 +0000
1#!/usr/bin/env python
3"""Module containing the StructureInfo class and the command line interface."""
5from typing import Optional
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools.file_utils import launchlogger
9from biobb_io.api.common import (
10 check_mandatory_property,
11 check_output_path,
12 download_str_info,
13 write_json,
14)
17class StructureInfo(BiobbObject):
18 """
19 | biobb_io StructureInfo
20 | This class is a wrapper for getting all the available information of a structure from the Protein Data Bank.
21 | Wrapper for the `MMB PDB mirror <http://mmb.irbbarcelona.org/api/>`_ for getting all the available information of a structure from the Protein Data Bank.
23 Args:
24 output_json_path (str): Path to the output JSON file with all the structure information. File type: output. `Sample file <https://github.com/bioexcel/biobb_io/raw/master/biobb_io/test/reference/api/ref_str_info.json>`_. Accepted formats: json (edam:format_3464).
25 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
26 * **pdb_code** (*str*) - (None) RSCB PDB structure code.
27 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
28 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
29 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
31 Examples:
32 This is a use example of how to use the building block from Python::
34 from biobb_io.api.structure_info import structure_info
35 prop = {
36 'pdb_code': '2vgb'
37 }
38 structure_info(output_json_path='/path/to/newStructure.sdf',
39 properties=prop)
41 Info:
42 * wrapped_software:
43 * name: Protein Data Bank
44 * license: Apache-2.0
45 * ontology:
46 * name: EDAM
47 * schema: http://edamontology.org/EDAM.owl
49 """
51 def __init__(self, output_json_path, properties=None, **kwargs) -> None:
52 properties = properties or {}
54 # Call parent class constructor
55 super().__init__(properties)
56 self.locals_var_dict = locals().copy()
58 # Input/Output files
59 self.io_dict = {"out": {"output_json_path": output_json_path}}
61 # Properties specific for BB
62 self.pdb_code = properties.get("pdb_code", None)
63 self.properties = properties
65 # Check the properties
66 self.check_properties(properties)
67 self.check_arguments()
69 def check_data_params(self, out_log, err_log):
70 """Checks all the input/output paths and parameters"""
71 self.output_json_path = check_output_path(
72 self.io_dict["out"]["output_json_path"],
73 "output_json_path",
74 False,
75 out_log,
76 self.__class__.__name__,
77 )
79 @launchlogger
80 def launch(self) -> int:
81 """Execute the :class:`StructureInfo <api.structure_info.StructureInfo>` api.structure_info.StructureInfo object."""
83 # check input/output paths and parameters
84 self.check_data_params(self.out_log, self.err_log)
86 # Setup Biobb
87 if self.check_restart():
88 return 0
90 check_mandatory_property(
91 self.pdb_code, "pdb_code", self.out_log, self.__class__.__name__
92 )
94 self.pdb_code = self.pdb_code.strip().lower()
95 url = "http://mmb.irbbarcelona.org/api/pdb/%s.json"
97 # Downloading PDB file
98 json_string = download_str_info(
99 self.pdb_code, url, self.out_log, self.global_log
100 )
101 write_json(json_string, self.output_json_path, self.out_log, self.global_log)
103 self.check_arguments(output_files_created=True, raise_exception=False)
105 return 0
108def structure_info(
109 output_json_path: str, properties: Optional[dict] = None, **kwargs
110) -> int:
111 """Execute the :class:`StructureInfo <api.structure_info.StructureInfo>` class and
112 execute the :meth:`launch() <api.structure_info.StructureInfo.launch>` method."""
113 return StructureInfo(**dict(locals())).launch()
116structure_info.__doc__ = StructureInfo.__doc__
117main = StructureInfo.get_main(structure_info, "This class is a wrapper for getting all the available information of a structure from the Protein Data Bank.")
119if __name__ == "__main__":
120 main()