Coverage for biobb_chemistry/babelm/babel_add_hydrogens.py: 73%

11 statements  

« prev     ^ index     » next       coverage.py v7.18.0, created at 2026-12-02 09:19 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the BabelAddHydrogens class and the command line interface.""" 

4from typing import Optional 

5from biobb_common.generic.biobb_object import launcher 

6from biobb_chemistry.babelm import common 

7 

8 

9class BabelAddHydrogens(common.BabelBase): 

10 """ 

11 | biobb_chemistry BabelAddHydrogens 

12 | This class is a wrapper of the Open Babel tool. 

13 | Adds hydrogens to a given structure or trajectory. Open Babel is a chemical toolbox designed to speak the many languages of chemical data. It's an open, collaborative project allowing anyone to search, convert, analyze, or store data from molecular modeling, chemistry, solid-state materials, biochemistry, or related areas. `Visit the official page <http://openbabel.org/wiki/Main_Page>`_. 

14 

15 Args: 

16 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/babelm/babel.no.H.pdb>`_. Accepted formats: dat (edam:format_1637), ent (edam:format_1476), fa (edam:format_1929), fasta (edam:format_1929), gro (edam:format_2033), inp (edam:format_3878), log (edam:format_2030), mcif (edam:format_1477), mdl (edam:format_3815), mmcif (edam:format_1477), mol (edam:format_3815), mol2 (edam:format_3816), pdb (edam:format_1476), pdbqt (edam:format_1476), png (edam:format_3603), sdf (edam:format_3814), smi (edam:format_1196), smiles (edam:format_1196), txt (edam:format_2033), xml (edam:format_2332), xtc (edam:format_3875). 

17 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/babelm/ref_babel.hydrogens.pdb>`_. Accepted formats: ent (edam:format_1476), fa (edam:format_1929), fasta (edam:format_1929), gro (edam:format_2033), inp (edam:format_3878), mcif (edam:format_1477), mdl (edam:format_3815), mmcif (edam:format_1477), mol (edam:format_3815), mol2 (edam:format_3816), pdb (edam:format_1476), pdbqt (edam:format_1476), png (edam:format_3603), sdf (edam:format_3814), smi (edam:format_1196), smiles (edam:format_1196), txt (edam:format_2033), dat (edam:format_1637), log (edam:format_2330), xml (edam:format_2332), xtc (edam:format_3875). 

18 properties (dic - Python dictionary object containing the tool parameters, not input/output files): 

19 * **input_format** (*str*) - (None) Format of input file. If not provided, input_path extension will be taken. Values: dat (Information represented in a data record), ent (Protein Data Bank format), fa (FASTA sequence format), fasta (FASTA sequence format), gro (GROMACS structure), inp (AMBER trajectory format), log (Events file), mcif (Entry format of PDB database in mmCIF format), mdl (file format for holding information about the atoms; bonds; connectivity and coordinates of a molecule), mmcif (Entry format of PDB database in mmCIF format), mol (file format for holding information about the atoms; bonds; connectivity and coordinates of a molecule), mol2 (Complete and portable representation of a SYBYL molecule), pdb (Protein Data Bank format), pdbqt (Protein Data Bank format with charges), png (File format for image compression), sdf (One of a family of chemical-data file formats developed by MDL Information Systems), smi (Chemical structure specified in Simplified Molecular Input Line Entry System line notation.), smiles (Chemical structure specified in Simplified Molecular Input Line Entry System line notation.), txt (Textual format), xml (eXtensible Markup Language), xtc (Portable binary format for trajectories produced by GROMACS package). 

20 * **output_format** (*str*) - (None) Format of output file. If not provided, output_path extension will be taken. Values: ent (Protein Data Bank format), fa (FASTA sequence format), fasta (FASTA sequence format), gro (GROMACS structure), inp (AMBER trajectory format), mcif (Entry format of PDB database in mmCIF format), mdl (file format for holding information about the atoms; bonds; connectivity and coordinates of a molecule), mmcif (Entry format of PDB database in mmCIF format), mol (file format for holding information about the atoms; bonds; connectivity and coordinates of a molecule), mol2 (Complete and portable representation of a SYBYL molecule), pdb (Protein Data Bank format), pdbqt (Protein Data Bank format with charges), png (File format for image compression), sdf (One of a family of chemical-data file formats developed by MDL Information Systems), smi (Chemical structure specified in Simplified Molecular Input Line Entry System line notation.), smiles (Chemical structure specified in Simplified Molecular Input Line Entry System line notation.), txt (Textual format), xtc (Portable binary format for trajectories produced by GROMACS package). 

21 * **fs_input** (*list*) - (None) Format-specific input options. Values: b (disable automatic bonding), d (input file is in dlg -AutoDock docking log- format). 

22 * **fs_output** (*list*) - (["h"]) Format-specific output options. Values: b (enable automatic bonding), r (output as a rigid molecule), c (combine separate molecular pieces of input into a single rigid molecule), s (output as a flexible residue), p (preserve atom indices from input file), h (preserve hydrogens), n (preserve atom names). 

23 * **coordinates** (*int*) - (None) Type of coordinates: 2D or 3D. Values: 2 (2D coordinates), 3 (3D coordinates). 

24 * **effort** (*str*) - ("medium") Computational effort wanted to dedicate for the conformer generation coordinates calculations, only for 3D coordinates. Values: fastest (only generate coordinates, no force field or conformer search), fast (perform quick forcefield optimization), medium (forcefield optimization + fast conformer search), better (more optimization + fast conformer search), best (more optimization + significant conformer search). 

25 * **ph** (*float*) - (None) [0~14|0.1] Add hydrogens appropriate for pH. 

26 * **binary_path** (*str*) - ("obabel") Path to the obabel executable binary. 

27 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files. 

28 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist. 

29 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory. 

30 * **container_path** (*str*) - (None) Container path definition. 

31 * **container_image** (*str*) - ('informaticsmatters/obabel:latest') Container image definition. 

32 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition. 

33 * **container_user_id** (*str*) - (None) Container user_id definition. 

34 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container. 

35 

36 Examples: 

37 This is a use example of how to use the building block from Python:: 

38 

39 from biobb_chemistry.babelm.babel_add_hydrogens import babel_add_hydrogens 

40 prop = { 

41 'input_format': 'pdb', 

42 'output_format': 'pdb', 

43 'coordinates': 3, 

44 'ph': 7.4 

45 } 

46 babel_add_hydrogens(input_path='/path/to/myStructure.pdb', 

47 output_path='/path/to/newStructure.pdb', 

48 properties=prop) 

49 

50 Info: 

51 * wrapped_software: 

52 * name: Open Babel 

53 * version: 2.4.1 

54 * license: GNU 

55 * ontology: 

56 * name: EDAM 

57 * schema: http://edamontology.org/EDAM.owl 

58 

59 """ 

60 

61 def __init__(self, input_path: str, output_path: str, properties: Optional[dict] = None, **kwargs) -> None: 

62 super().__init__(**locals()) 

63 

64 def obabel_flags(self) -> list[str]: 

65 """Goes from the pH property to the -p flag, or -h to add the hydrogens without pH""" 

66 return ["-p " + str(self.ph)] if self.ph is not None else ["-h"] 

67 

68 

69babel_add_hydrogens = launcher(BabelAddHydrogens) 

70 

71 

72if __name__ == "__main__": 

73 BabelAddHydrogens.main()