Coverage for biobb_io/api/ideal_sdf.py: 94%
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 IdealSdf 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_ideal_sdf,
13 write_sdf,
14)
17class IdealSdf(BiobbObject):
18 """
19 | biobb_io IdealSdf
20 | This class is a wrapper for downloading an ideal SDF ligand from the Protein Data Bank.
21 | Wrapper for the `Protein Data Bank in Europe <https://www.ebi.ac.uk/pdbe/>`_ and the `Protein Data Bank <https://www.rcsb.org/>`_ for downloading a single ideal SDF ligand.
23 Args:
24 output_sdf_path (str): Path to the output SDF file. File type: output. `Sample file <https://github.com/bioexcel/biobb_io/raw/master/biobb_io/test/reference/api/ref_output.sdf>`_. Accepted formats: sdf (edam:format_3814).
25 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
26 * **ligand_code** (*str*) - (None) RSCB PDB ligand code.
27 * **api_id** (*str*) - ("pdbe") Identifier of the PDB REST API from which the SDF 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/>`_).
28 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
29 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
30 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
32 Examples:
33 This is a use example of how to use the building block from Python::
35 from biobb_io.api.ideal_sdf import ideal_sdf
36 prop = {
37 'ligand_code': 'HYZ',
38 'api_id': 'pdbe'
39 }
40 ideal_sdf(output_sdf_path='/path/to/newStructure.sdf',
41 properties=prop)
43 Info:
44 * wrapped_software:
45 * name: Protein Data Bank
46 * license: Apache-2.0
47 * ontology:
48 * name: EDAM
49 * schema: http://edamontology.org/EDAM.owl
51 """
53 def __init__(self, output_sdf_path, 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_sdf_path": output_sdf_path}}
63 # Properties specific for BB
64 self.api_id = properties.get("api_id", "pdbe")
65 self.ligand_code = properties.get("ligand_code", None)
66 self.properties = properties
68 # Check the properties
69 self.check_properties(properties)
70 self.check_arguments()
72 def check_data_params(self, out_log, err_log):
73 """Checks all the input/output paths and parameters"""
74 self.output_sdf_path = check_output_path(
75 self.io_dict["out"]["output_sdf_path"],
76 "output_sdf_path",
77 False,
78 out_log,
79 self.__class__.__name__,
80 )
82 @launchlogger
83 def launch(self) -> int:
84 """Execute the :class:`IdealSdf <api.ideal_sdf.IdealSdf>` api.ideal_sdf.IdealSdf object."""
86 # check input/output paths and parameters
87 self.check_data_params(self.out_log, self.err_log)
89 # Setup Biobb
90 if self.check_restart():
91 return 0
93 check_mandatory_property(
94 self.ligand_code, "ligand_code", self.out_log, self.__class__.__name__
95 )
97 self.ligand_code = self.ligand_code.strip()
99 # Downloading PDB file
100 sdf_string = download_ideal_sdf(
101 self.ligand_code, self.api_id, self.out_log, self.global_log
102 )
103 write_sdf(sdf_string, self.output_sdf_path, self.out_log, self.global_log)
105 self.check_arguments(output_files_created=True, raise_exception=False)
107 return 0
110def ideal_sdf(output_sdf_path: str, properties: Optional[dict] = None, **kwargs) -> int:
111 """Execute the :class:`IdealSdf <api.ideal_sdf.IdealSdf>` class and
112 execute the :meth:`launch() <api.ideal_sdf.IdealSdf.launch>` method."""
113 return IdealSdf(**dict(locals())).launch()
116ideal_sdf.__doc__ = IdealSdf.__doc__
117main = IdealSdf.get_main(ideal_sdf, "This class is a wrapper for downloading an ideal SDF ligand from the Protein Data Bank.")
119if __name__ == "__main__":
120 main()