Coverage for biobb_chemistry / ambertools / reduce_remove_hydrogens.py: 95%
43 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 12:49 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 12:49 +0000
1#!/usr/bin/env python3
3"""Module containing the ReduceRemoveHydrogens class and the command line interface."""
4from typing import Optional
5from biobb_common.generic.biobb_object import BiobbObject
6from biobb_common.tools.file_utils import launchlogger
7from biobb_chemistry.ambertools.common import get_binary_path, check_input_path, check_output_path
10class ReduceRemoveHydrogens(BiobbObject):
11 """
12 | biobb_chemistry ReduceRemoveHydrogens
13 | This class is a wrapper of the `Ambertools <http://ambermd.org/doc12/AmberTools12.pdf>`_ reduce module for removing hydrogens from a given structure.
14 | Reduce is a program for `adding or removing hydrogens to a Protein DataBank (PDB) molecular structure file <http://ambermd.org/doc12/AmberTools12.pdf>`_.
16 Args:
17 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).
18 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).
19 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
20 * **binary_path** (*str*) - ("reduce") Path to the reduce executable binary.
21 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
22 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
23 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
24 * **container_path** (*str*) - (None) Container path definition.
25 * **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition.
26 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
27 * **container_working_dir** (*str*) - (None) Container working directory definition.
28 * **container_user_id** (*str*) - (None) Container user_id definition.
29 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
31 Examples:
32 This is a use example of how to use the building block from Python::
34 from biobb_chemistry.ambertools.reduce_remove_hydrogens import reduce_remove_hydrogens
35 prop = { }
36 reduce_remove_hydrogens(input_path='/path/to/myStructure.pdb',
37 output_path='/path/to/newStructure.pdb',
38 properties=prop)
40 Info:
41 * wrapped_software:
42 * name: AmberTools Reduce
43 * version: >=20.0
44 * license: GNU
45 * ontology:
46 * name: EDAM
47 * schema: http://edamontology.org/EDAM.owl
49 """
51 def __init__(self, input_path, output_path,
52 properties=None, **kwargs) -> None:
53 properties = properties or {}
55 # Call parent class constructor
56 super().__init__(properties)
57 self.locals_var_dict = locals().copy()
59 # Input/Output files
60 self.io_dict = {
61 "in": {"input_path": input_path},
62 "out": {"output_path": output_path}
63 }
65 # Properties specific for BB
66 self.binary_path = get_binary_path(properties, 'binary_path')
67 self.properties = properties
69 # Check the properties
70 self.check_properties(properties)
71 self.check_arguments()
73 def check_data_params(self, out_log, err_log):
74 """ Checks all the input/output paths and parameters """
75 self.io_dict["in"]["input_path"] = check_input_path(self.io_dict["in"]["input_path"], out_log, self.__class__.__name__)
76 self.io_dict["out"]["output_path"] = check_output_path(self.io_dict["out"]["output_path"], out_log, self.__class__.__name__)
78 def create_cmd(self, container_io_dict, out_log, err_log):
79 """Creates the command line instruction using the properties file settings"""
80 instructions_list = []
82 # executable path
83 instructions_list.append(self.binary_path)
85 instructions_list.append('-Trim')
87 instructions_list.append(container_io_dict["in"]["input_path"])
88 instructions_list.append('>')
89 instructions_list.append(container_io_dict["out"]["output_path"])
91 return instructions_list
93 @launchlogger
94 def launch(self) -> int:
95 """Execute the :class:`ReduceRemoveHydrogens <ambertools.reduce_remove_hydrogens.ReduceRemoveHydrogens>` ambertools.reduce_remove_hydrogens.ReduceRemoveHydrogens object."""
97 # check input/output paths and parameters
98 self.check_data_params(self.out_log, self.err_log)
100 # Setup Biobb
101 if self.check_restart():
102 return 0
103 self.stage_files()
105 # create command line instruction
106 self.cmd = self.create_cmd(self.stage_io_dict, self.out_log, self.err_log)
108 # Run Biobb block
109 self.run_biobb()
111 # Copy files to host
112 self.copy_to_host()
114 # remove temporary folder(s)
115 self.remove_tmp_files()
117 self.check_arguments(output_files_created=True, raise_exception=False)
119 return self.return_code
122def reduce_remove_hydrogens(input_path: str, output_path: str, properties: Optional[dict] = None, **kwargs) -> int:
123 """Create the :class:`ReduceRemoveHydrogens <ambertools.reduce_remove_hydrogens.ReduceRemoveHydrogens>` class and
124 execute the :meth:`launch() <ambertools.reduce_remove_hydrogens.ReduceRemoveHydrogens.launch>` method."""
125 return ReduceRemoveHydrogens(**dict(locals())).launch()
128reduce_remove_hydrogens.__doc__ = ReduceRemoveHydrogens.__doc__
129main = ReduceRemoveHydrogens.get_main(reduce_remove_hydrogens, "Removes hydrogen atoms to small molecules.")
132if __name__ == '__main__':
133 main()