"obabel -h/-d" - Add/Remove Hydrogens in Molecule Data

This section provides a tutorial example on how to add or remove implicit hydrogen atoms in molecule data using Open Babel 'obabel' command.

It is very common that hydrogen atoms are not provided in molecule data, because they can be added automatically by calculating the difference of atom's valence and the total valence of connected bonds.

But if you want to add those implicit hydrogen atoms back during the molecule data conversion process, you can use the "obabel" generic option "-h" as shown in the example below:

herong$ obabel -:c1ccccc1 -o sdf --gen2D -h

 OpenBabel05212009372D

 12 12  0  0  0  0  0  0  0  0999 V2000
   -0.8660   -0.5000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7321   -0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7321    1.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.8660    1.5000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0000    1.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.8660   -1.5320    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6258   -0.5160    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6258    1.5160    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.8660    2.5320    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.8937    1.5160    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.8937   -0.5160    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
  1  6  1  0  0  0  0
  1  2  2  0  0  0  0
  1  7  1  0  0  0  0
  2  3  1  0  0  0  0
  2  8  1  0  0  0  0
  3  4  2  0  0  0  0
  3  9  1  0  0  0  0
  4  5  1  0  0  0  0
  4 10  1  0  0  0  0
  5  6  2  0  0  0  0
  5 11  1  0  0  0  0
  6 12  1  0  0  0  0
M  END
$$$$

1 molecule converted

As you can see from the output, 6 hydrogen atoms were added back to the benzene molecule, because of the "-h" option. Without the "-h" option, "obabel" command converts only carbon atoms of the benzene molecule that are specified in the input SMILES string.

As a comparison, here is the output of the above "obabel" command without the "-h" option:

herong$ obabel -:c1ccccc1 -o sdf --gen2D

 OpenBabel05212009382D

  6  6  0  0  0  0  0  0  0  0999 V2000
   -0.8660   -0.5000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7321   -0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7321    1.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.8660    1.5000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0000    1.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  6  1  0  0  0  0
  1  2  2  0  0  0  0
  2  3  1  0  0  0  0
  3  4  2  0  0  0  0
  4  5  1  0  0  0  0
  5  6  2  0  0  0  0
M  END
$$$$

1 molecule converted

If hydrogen atoms of a molecule are explicitly included in the input data source, you can use the Open Babel "obabel ... -d" command to remove those hydrogen atoms during the molecule data conversion process.

Here is an example of using the "-d" option in the "obabel" command.

1. Generate a benzene molecule with hydrogen atoms included and stored in a "sdf" file.

herong$ obabel -:c1ccccc1 -o sdf -O benzene.sdf --gen2D -h
1 molecule converted

herong$ more benzene.sdf

 OpenBabel05212009392D

 12 12  0  0  0  0  0  0  0  0999 V2000
   -0.8660   -0.5000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7321   -0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7321    1.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.8660    1.5000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0000    1.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.8660   -1.5320    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6258   -0.5160    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6258    1.5160    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.8660    2.5320    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.8937    1.5160    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.8937   -0.5160    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
  1  6  1  0  0  0  0
  1  2  2  0  0  0  0
  1  7  1  0  0  0  0
  2  3  1  0  0  0  0
  2  8  1  0  0  0  0
  3  4  2  0  0  0  0
  3  9  1  0  0  0  0
  4  5  1  0  0  0  0
  4 10  1  0  0  0  0
  5  6  2  0  0  0  0
  5 11  1  0  0  0  0
  6 12  1  0  0  0  0
M  END
$$$$

2. Convert the benzene molecule from "sdf" format to "svg" format with hydrogen atoms deleted using the "-d" option:

herong$ obabel benzene.sdf -o svg -d

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cml="http://www.xml-cml.org/schema"
width="149.283" height="159.999" x="0" y="0" font-family="sans-serif"
stroke="rgb(0,0,0)" stroke-width="1"  stroke-linecap="round">
<rect x="0%" y="0%" width="100%" height="100%" stroke-width="0" fill="rgb(255,255,255)"/>
<line x1="74.6" y1="120.0" x2="40.0" y2="100.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="73.0" y1="110.8" x2="48.8" y2="96.8" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="40.0" y1="100.0" x2="40.0" y2="60.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="40.0" y1="60.0" x2="74.6" y2="40.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="48.8" y1="63.2" x2="73.0" y2="49.2" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="74.6" y1="40.0" x2="109.3" y2="60.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="109.3" y1="60.0" x2="109.3" y2="100.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="102.1" y1="66.0" x2="102.1" y2="94.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="109.3" y1="100.0" x2="74.6" y2="120.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<text font-size="18.000000" fill ="black" font-family="sans-serif"
x="10.000000" y="20.000000" ></text>
<title> - OBDepict</title>
</svg>

As you can see from the output, 6 hydrogen atoms were deleted from the benzene molecule, because of the "-d" option.

As a comparison, here is the output of the above "obabel" command without the "-d" option:

herong$ obabel benzene.sdf -o svg

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cml="http://www.xml-cml.org/schema"
width="218.564" height="240.001" x="0" y="0" font-family="sans-serif"
stroke="rgb(0,0,0)" stroke-width="1"  stroke-linecap="round">
<rect x="0%" y="0%" width="100%" height="100%" stroke-width="0" fill="rgb(255,255,255)"/>
<line x1="109.3" y1="159.4" x2="109.3" y2="187.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="75.2" y1="139.7" x2="51.3" y2="153.5" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="75.2" y1="100.3" x2="51.3" y2="86.5" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="109.3" y1="80.6" x2="109.3" y2="53.0" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="143.4" y1="100.3" x2="167.3" y2="86.5" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="143.4" y1="139.7" x2="167.3" y2="153.5" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="109.3" y1="159.4" x2="75.2" y2="139.7" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="107.7" y1="150.1" x2="84.0" y2="136.4" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="75.2" y1="139.7" x2="75.2" y2="100.3" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="75.2" y1="100.3" x2="109.3" y2="80.6" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="84.0" y1="103.6" x2="107.7" y2="89.9" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="109.3" y1="80.6" x2="143.4" y2="100.3" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="143.4" y1="100.3" x2="143.4" y2="139.7" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="136.2" y1="106.3" x2="136.2" y2="133.7" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<line x1="143.4" y1="139.7" x2="109.3" y2="159.4" stroke="rgb(0,0,0)"  stroke-width="1.0"/>
<text x="103.283733" y="208.000619" fill="rgb(191,191,191)"
  stroke="rgb(191,191,191)" stroke-width="1" font-size="16" >H</text>
<text x="34.000000" y="168.000464" fill="rgb(191,191,191)"
  stroke="rgb(191,191,191)" stroke-width="1" font-size="16" >H</text>
<text x="34.000000" y="88.000155" fill="rgb(191,191,191)"
  stroke="rgb(191,191,191)" stroke-width="1" font-size="16" >H</text>
<text x="103.283733" y="48.000000" fill="rgb(191,191,191)"
  stroke="rgb(191,191,191)" stroke-width="1" font-size="16" >H</text>
<text x="172.563528" y="88.000155" fill="rgb(191,191,191)"
  stroke="rgb(191,191,191)" stroke-width="1" font-size="16" >H</text>
<text x="172.563528" y="168.000464" fill="rgb(191,191,191)"
  stroke="rgb(191,191,191)" stroke-width="1" font-size="16" >H</text>
<text font-size="18.000000" fill ="black" font-family="sans-serif"
x="10.000000" y="20.000000" ></text>
<title> - OBDepict</title>
</svg>

Table of Contents

 About This Book

 SMILES (Simplified Molecular-Input Line-Entry System)

 Open Babel: The Open Source Chemistry Toolbox

Using Open Babel Command: "obabel"

 What Is "obabel" Command

 "obabel -i ..." - Input Data Format and Source

 "obabel -o ... -O" - Output Data Format and Destination

 "obabel -... --..." - Generic Conversion Options

 "obabel" Command Option Argument Syntax

 "obabel ... --gen2D" - Calculated 2D Coordinates

 "obabel ... -f # -l #" - Split Large Molecule File

"obabel -h/-d" - Add/Remove Hydrogens in Molecule Data

 "obabel --append ..." - Calculate Molecule Properties

 "obabel -L formats" - List of File Formats Supported

 "obabel -a..." - Extra Options for Input Reading

 "obabel -x..." - Extra Options for Output Writing

 "obabel" vs. "babel" Open Babel Commands

 Generating SVG Pictures with Open Babel

 Substructure Search with Open Babel

 Similarity Search with Open Babel

 Fingerprint Index for Fastsearch with Open Babel

 Stereochemistry with Open Babel

 Command Line Tools Provided by Open Babel

 RDKit: Open-Source Cheminformatics Software

 rdkit.Chem.rdchem - The Core Module

 rdkit.Chem.rdmolfiles - Molecular File Module

 rdkit.Chem.rdDepictor - Compute 2D Coordinates

 rdkit.Chem.Draw - Handle Molecule Images

 Molecule Substructure Search with RDKit

 rdkit.Chem.rdmolops - Molecule Operations

 Daylight Fingerprint Generator in RDKit

 Morgan Fingerprint Generator in RDKit

 RDKit Performance on Substructure Search

 Introduction to Molecular Fingerprints

 OCSR (Optical Chemical Structure Recognition)

 AlphaFold - Protein Structure Prediction

 Resources and Tools

 Cheminformatics Related Terminologies

 References

 Full Version in PDF/EPUB