Coverage for biobb_io/api/pdb.py: 94%
35 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 Pdb 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_pdb,
13 write_pdb,
14)
17class Pdb(BiobbObject):
18 """
19 | biobb_io Pdb
20 | This class is a wrapper for downloading a PDB structure from the Protein Data Bank.
21 | Wrapper for the `Protein Data Bank in Europe <https://www.ebi.ac.uk/pdbe/>`_, the `Protein Data Bank <https://www.rcsb.org/>`_ and the `MMB PDB mirror <http://mmb.irbbarcelona.org/api/>`_ for downloading a single PDB structure.
23 Args:
24 output_pdb_path (str): Path to the output PDB file. File type: output. `Sample file <https://github.com/bioexcel/biobb_io/raw/master/biobb_io/test/reference/api/output_pdb.pdb>`_. Accepted formats: pdb (edam:format_1476).
25 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
26 * **pdb_code** (*str*) - (None) RSCB PDB code.
27 * **filter** (*str*) - (["ATOM", "MODEL", "ENDMDL"]) Array of groups to be kept. If value is None or False no filter will be applied. All the possible values are defined in the `official PDB specification <http://www.wwpdb.org/documentation/file-format-content/format33/v3.3.html)>`_.
28 * **api_id** (*str*) - ("pdbe") Identifier of the PDB REST API from which the PDB structure will be downloaded. Values: pdbe (`PDB in Europe REST API <https://www.ebi.ac.uk/pdbe/pdbe-rest-api>`_), pdb (`RCSB PDB REST API <https://data.rcsb.org/>`_), mmb (`MMB PDB mirror API <http://mmb.irbbarcelona.org/api/>`_).
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.pdb import pdb
37 prop = {
38 'pdb_code': '2VGB',
39 'filter': ['ATOM', 'MODEL', 'ENDMDL'],
40 'api_id': 'pdbe'
41 }
42 pdb(output_pdb_path='/path/to/newStructure.pdb',
43 properties=prop)
45 Info:
46 * wrapped_software:
47 * name: Protein Data Bank
48 * license: Apache-2.0
49 * ontology:
50 * name: EDAM
51 * schema: http://edamontology.org/EDAM.owl
53 """
55 def __init__(self, output_pdb_path, properties=None, **kwargs) -> None:
56 properties = properties or {}
58 # Call parent class constructor
59 super().__init__(properties)
60 self.locals_var_dict = locals().copy()
62 # Input/Output files
63 self.io_dict = {"out": {"output_pdb_path": output_pdb_path}}
65 # Properties specific for BB
66 self.api_id = properties.get("api_id", "pdbe")
67 self.pdb_code = properties.get("pdb_code", None)
68 self.filter = properties.get("filter", ["ATOM", "MODEL", "ENDMDL"])
69 self.properties = properties
71 # Check the properties
72 self.check_properties(properties)
73 self.check_arguments()
75 def check_data_params(self, out_log, err_log):
76 """Checks all the input/output paths and parameters"""
77 self.output_pdb_path = check_output_path(
78 self.io_dict["out"]["output_pdb_path"],
79 "output_pdb_path",
80 False,
81 out_log,
82 self.__class__.__name__,
83 )
85 @launchlogger
86 def launch(self) -> int:
87 """Execute the :class:`Pdb <api.pdb.Pdb>` api.pdb.Pdb object."""
89 # check input/output paths and parameters
90 self.check_data_params(self.out_log, self.err_log)
92 # Setup Biobb
93 if self.check_restart():
94 return 0
96 check_mandatory_property(
97 self.pdb_code, "pdb_code", self.out_log, self.__class__.__name__
98 )
100 self.pdb_code = self.pdb_code.strip().lower()
102 # Downloading PDB file
103 pdb_string = download_pdb(
104 self.pdb_code, self.api_id, self.out_log, self.global_log
105 )
106 write_pdb(
107 pdb_string, self.output_pdb_path, self.filter, self.out_log, self.global_log
108 )
110 self.check_arguments(output_files_created=True, raise_exception=False)
112 return 0
115def pdb(output_pdb_path: str, properties: Optional[dict] = None, **kwargs) -> int:
116 """Execute the :class:`Pdb <api.pdb.Pdb>` class and
117 execute the :meth:`launch() <api.pdb.Pdb.launch>` method."""
118 return Pdb(**dict(locals())).launch()
121pdb.__doc__ = Pdb.__doc__
122main = Pdb.get_main(pdb, "This class is a wrapper for downloading a PDB structure from the Protein Data Bank.")
124if __name__ == "__main__":
125 main()