Coverage for biobb_chemistry/ambertools/reduce_remove_hydrogens.py: 78%
54 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 09:28 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 09:28 +0000
1#!/usr/bin/env python3
3"""Module containing the ReduceRemoveHydrogens class and the command line interface."""
4import argparse
5from typing import Optional
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.configuration import settings
8from biobb_common.tools.file_utils import launchlogger
9from biobb_chemistry.ambertools.common import get_binary_path, check_input_path, check_output_path
12class ReduceRemoveHydrogens(BiobbObject):
13 """
14 | biobb_chemistry ReduceRemoveHydrogens
15 | This class is a wrapper of the `Ambertools <http://ambermd.org/doc12/AmberTools12.pdf>`_ reduce module for removing hydrogens from a given structure.
16 | Reduce is a program for `adding or removing hydrogens to a Protein DataBank (PDB) molecular structure file <http://ambermd.org/doc12/AmberTools12.pdf>`_.
18 Args:
19 input_path (str): Path to the input file. File type: input. `Sample file <https://github.com/bioexcel/biobb_chemistry/raw/master/biobb_chemistry/test/data/ambertools/reduce.H.pdb>`_. Accepted formats: pdb (edam:format_1476).
20 output_path (str): Path to the output file. File type: output. `Sample file <https://github.com/bioexcel/biobb_chemistry/raw/master/biobb_chemistry/test/reference/ambertools/ref_reduce.remove.pdb>`_. Accepted formats: pdb (edam:format_1476).
21 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
22 * **binary_path** (*str*) - ("reduce") Path to the reduce executable binary.
23 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
24 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
25 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
26 * **container_path** (*str*) - (None) Container path definition.
27 * **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition.
28 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
29 * **container_working_dir** (*str*) - (None) Container working directory definition.
30 * **container_user_id** (*str*) - (None) Container user_id definition.
31 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
33 Examples:
34 This is a use example of how to use the building block from Python::
36 from biobb_chemistry.ambertools.reduce_remove_hydrogens import reduce_remove_hydrogens
37 prop = { }
38 reduce_remove_hydrogens(input_path='/path/to/myStructure.pdb',
39 output_path='/path/to/newStructure.pdb',
40 properties=prop)
42 Info:
43 * wrapped_software:
44 * name: AmberTools Reduce
45 * version: >=20.0
46 * license: GNU
47 * ontology:
48 * name: EDAM
49 * schema: http://edamontology.org/EDAM.owl
51 """
53 def __init__(self, input_path, output_path,
54 properties=None, **kwargs) -> None:
55 properties = properties or {}
57 # Call parent class constructor
58 super().__init__(properties)
59 self.locals_var_dict = locals().copy()
61 # Input/Output files
62 self.io_dict = {
63 "in": {"input_path": input_path},
64 "out": {"output_path": output_path}
65 }
67 # Properties specific for BB
68 self.binary_path = get_binary_path(properties, 'binary_path')
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.io_dict["in"]["input_path"] = check_input_path(self.io_dict["in"]["input_path"], out_log, self.__class__.__name__)
78 self.io_dict["out"]["output_path"] = check_output_path(self.io_dict["out"]["output_path"], out_log, self.__class__.__name__)
80 def create_cmd(self, container_io_dict, out_log, err_log):
81 """Creates the command line instruction using the properties file settings"""
82 instructions_list = []
84 # executable path
85 instructions_list.append(self.binary_path)
87 instructions_list.append('-Trim')
89 instructions_list.append(container_io_dict["in"]["input_path"])
90 instructions_list.append('>')
91 instructions_list.append(container_io_dict["out"]["output_path"])
93 return instructions_list
95 @launchlogger
96 def launch(self) -> int:
97 """Execute the :class:`ReduceRemoveHydrogens <ambertools.reduce_remove_hydrogens.ReduceRemoveHydrogens>` ambertools.reduce_remove_hydrogens.ReduceRemoveHydrogens object."""
99 # check input/output paths and parameters
100 self.check_data_params(self.out_log, self.err_log)
102 # Setup Biobb
103 if self.check_restart():
104 return 0
105 self.stage_files()
107 # create command line instruction
108 self.cmd = self.create_cmd(self.stage_io_dict, self.out_log, self.err_log)
110 # Run Biobb block
111 self.run_biobb()
113 # Copy files to host
114 self.copy_to_host()
116 # remove temporary folder(s)
117 '''self.tmp_files.extend([
118 self.stage_io_dict.get("unique_dir", "")
119 ])'''
120 self.remove_tmp_files()
122 self.check_arguments(output_files_created=True, raise_exception=False)
124 return self.return_code
127def reduce_remove_hydrogens(input_path: str, output_path: str, properties: Optional[dict] = None, **kwargs) -> int:
128 """Execute the :class:`ReduceRemoveHydrogens <ambertools.reduce_remove_hydrogens.ReduceRemoveHydrogens>` class and
129 execute the :meth:`launch() <ambertools.reduce_remove_hydrogens.ReduceRemoveHydrogens.launch>` method."""
131 return ReduceRemoveHydrogens(input_path=input_path,
132 output_path=output_path,
133 properties=properties, **kwargs).launch()
135 reduce_remove_hydrogens.__doc__ = ReduceRemoveHydrogens.__doc__
138def main():
139 """Command line execution of this building block. Please check the command line documentation."""
140 parser = argparse.ArgumentParser(description="Removes hydrogen atoms to small molecules.", formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999))
141 parser.add_argument('--config', required=False, help='Configuration file')
143 # Specific args of each building block
144 required_args = parser.add_argument_group('required arguments')
145 required_args.add_argument('--input_path', required=True, help='Path to the input file. Accepted formats: pdb.')
146 required_args.add_argument('--output_path', required=True, help='Path to the output file. Accepted formats: pdb.')
148 args = parser.parse_args()
149 args.config = args.config or "{}"
150 properties = settings.ConfReader(config=args.config).get_prop_dic()
152 # Specific call of each building block
153 reduce_remove_hydrogens(input_path=args.input_path,
154 output_path=args.output_path,
155 properties=properties)
158if __name__ == '__main__':
159 main()