Coverage for biobb_chemistry/ambertools/reduce_add_hydrogens.py: 14%
56 statements
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-02 09:19 +0000
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-02 09:19 +0000
1#!/usr/bin/env python3
3"""Module containing the ReduceAddHydrogens class and the command line interface."""
4from typing import Optional
5from biobb_common.generic.biobb_object import BiobbObject, launcher
8class ReduceAddHydrogens(BiobbObject):
9 """
10 | biobb_chemistry ReduceAddHydrogens
11 | This class is a wrapper of the `Ambertools <http://ambermd.org/doc12/AmberTools12.pdf>`_ reduce module for adding hydrogens to a given structure.
12 | Reduce is a program for `adding or removing hydrogens to a Protein DataBank (PDB) molecular structure file <http://ambermd.org/doc12/AmberTools12.pdf>`_.
14 Args:
15 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.no.H.pdb>`_. Accepted formats: pdb (edam:format_1476).
16 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.add.pdb>`_. Accepted formats: pdb (edam:format_1476).
17 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
18 * **flip** (*bool*) - (False) add H and rotate and flip NQH groups
19 * **noflip** (*bool*) - (False) add H and rotate groups with no NQH flips
20 * **nuclear** (*bool*) - (False) use nuclear X-H distances rather than default electron cloud distances
21 * **nooh** (*bool*) - (False) remove hydrogens on OH and SH groups
22 * **oh** (*bool*) - (True) add hydrogens on OH and SH groups (default)
23 * **his** (*bool*) - (False) create NH hydrogens on HIS rings (usually used with -HIS)
24 * **noheth** (*bool*) - (False) do not attempt to add NH proton on Het groups
25 * **rotnh3** (*bool*) - (True) allow lysine NH3 to rotate (default)
26 * **norotnh3** (*bool*) - (False) do not allow lysine NH3 to rotate
27 * **rotexist** (*bool*) - (False) allow existing rotatable groups (OH, SH, Met-CH3) to rotate
28 * **rotexoh** (*bool*) - (False) allow existing OH & SH groups to rotate
29 * **allalt** (*bool*) - (True) process adjustments for all conformations (default)
30 * **onlya** (*bool*) - (False) only adjust 'A' conformations
31 * **charges** (*bool*) - (False) output charge state for appropriate hydrogen records
32 * **dorotmet** (*bool*) - (False) allow methionine methyl groups to rotate (not recommended)
33 * **noadjust** (*bool*) - (False) do not process any rot or flip adjustments
34 * **metal_bump** (*float*) - (None) [0~5|0.005] H 'bumps' metals at radius plus this
35 * **non_metal_bump** (*float*) - (None) [0~5|0.005] 'bumps' nonmetal at radius plus this
36 * **build** (*bool*) - (False) add H, including His sc NH, then rotate and flip groups (except for pre-existing methionine methyl hydrogens)
37 * **binary_path** (*str*) - ("reduce") Path to the reduce executable binary.
38 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
39 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
40 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
41 * **container_path** (*str*) - (None) Container path definition.
42 * **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition.
43 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
44 * **container_user_id** (*str*) - (None) Container user_id definition.
45 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
47 Examples:
48 This is a use example of how to use the building block from Python::
50 from biobb_chemistry.ambertools.reduce_add_hydrogens import reduce_add_hydrogens
51 prop = {
52 'flip': False,
53 'charges': True,
54 'build': False
55 }
56 reduce_add_hydrogens(input_path='/path/to/myStructure.pdb',
57 output_path='/path/to/newStructure.pdb',
58 properties=prop)
60 Info:
61 * wrapped_software:
62 * name: AmberTools Reduce
63 * version: >=20.0
64 * license: GNU
65 * ontology:
66 * name: EDAM
67 * schema: http://edamontology.org/EDAM.owl
69 """
71 def __init__(self, input_path: str, output_path: str,
72 properties: Optional[dict] = None, **kwargs) -> None:
73 super().__init__(**locals())
75 # Properties specific for BB
77 def create_cmd(self, container_io_dict, out_log, err_log):
78 """Creates the command line instruction using the properties file settings"""
79 instructions_list = []
81 # executable path
82 instructions_list.append(self.binary_path)
84 if self.flip:
85 instructions_list.append('-FLIP')
86 if self.noflip:
87 instructions_list.append('-NOFLIP')
88 if self.nuclear:
89 instructions_list.append('-NUClear')
90 if self.nooh:
91 instructions_list.append('-NOOH')
92 if self.oh:
93 instructions_list.append('-OH')
94 if self.his:
95 instructions_list.append('-HIS')
96 if self.noheth:
97 instructions_list.append('-NOHETh')
98 if self.rotnh3:
99 instructions_list.append('-ROTNH3')
100 if self.norotnh3:
101 instructions_list.append('-NOROTNH3')
102 if self.rotexist:
103 instructions_list.append('-ROTEXist')
104 if self.rotexoh:
105 instructions_list.append('-ROTEXOH')
106 if self.allalt:
107 instructions_list.append('-ALLALT')
108 if self.onlya:
109 instructions_list.append('-ONLYA')
110 if self.charges:
111 instructions_list.append('-CHARGEs')
112 if self.dorotmet:
113 instructions_list.append('-DOROTMET')
114 if self.noadjust:
115 instructions_list.append('-NOADJust')
116 if self.build:
117 instructions_list.append('-BUILD')
119 if self.metal_bump:
120 instructions_list.append('-METALBump' + str(self.metal_bump))
122 if self.non_metal_bump:
123 instructions_list.append('-NONMETALBump' + str(self.non_metal_bump))
125 instructions_list.append(container_io_dict["in"]["input_path"])
126 instructions_list.append('>')
127 instructions_list.append(container_io_dict["out"]["output_path"])
129 return instructions_list
131 def run(self) -> None:
132 """Execute the :class:`ReduceAddHydrogens <ambertools.reduce_add_hydrogens.ReduceAddHydrogens>` ambertools.reduce_add_hydrogens.ReduceAddHydrogens object."""
134 # create command line instruction
135 self.cmd = self.create_cmd(self.stage_io_dict, self.out_log, self.err_log)
137 # Run Biobb block
138 self.run_biobb()
141reduce_add_hydrogens = launcher(ReduceAddHydrogens)
143if __name__ == '__main__':
144 ReduceAddHydrogens.main()