<p><code>conda install -c conda-forge openbabel</code></p>
<pre><code>from openbabel import pybel as pb
babel_mol = pb.readfile(format=&quot;pdb&quot;, filename=path_to_pdb).__next__()
babel_mol.addh()
babel_mol.write(format='pdb', filename=path_to_babel_pdbh, overwrite=True)
</code></pre>

CC BY-SA 4.0
2023-12-24T23:06:27.157Z
2023-12-24T23:06:27.157Z
Rubber Duck
<p>Not actually and answer as you cannot do it with <code>biopython.PDB</code>. But there are may other tools.</p>
<p>Several are online, for example: <a href="https://zhanggroup.org/HAAD/" rel="nofollow noreferrer">https://zhanggroup.org/HAAD/</a> by the folk who wrote I-Tasser.
Nearly every MD pipeline has their own protonation algorithm. The only hydrogens that are an issue are histidine protonation —<code>HIE</code> vs. <code>HID</code>— and protonation states of catalytic residues (<code>CYZ</code> vs. <code>CYS</code> etc).</p>
<p>The PyMOL python module is really good and can do a lot. Only issue is that the easiest way to install is via conda.</p>
<pre><code>conda install -c conda-forge -c schrodinger pymol-bundle
</code></pre>
<p>with which one can:</p>
<pre><code>import pymol2
pymol2.PyMOL() as pymol:
    pymol.cmd.load('.pdb', 'myprotein') # file
    # pymol.cmd.fetch('', 'myprotein') # PDB code
    pymol.cmd.h_add()
    pymol.cmd.save('.pdb')
</code></pre>
<p>One can find neighbours to a given atom too (see <a href="https://bioinformatics.stackexchange.com/questions/17548/pymol-output-polar-contacts-between-chains-to-text-file/17551">this Q&amp;A</a>), select by secondary structure, define secondary structure (<code>pymol.cmd.dss()</code>) etc. A caveat is that, bar for some commands like <code>pymol.cmd.get_model(selection).atom</code>, one does not interact directly with the atoms and everything is done via selections.</p>
<p>However, as this Q follows on from <a href="https://bioinformatics.stackexchange.com/questions/17913/how-can-i-get-a-list-of-neighboring-hydrogen-atoms-of-an-alpha-carbon">this unanswerable one</a> and in turn from several others about SS. I am guessing it is to determine the hydrogen bond distances between different sheets. These have a backbone amide nitrogen (name <code>N</code>) donating a hydrogen (<code>H</code>, not <code>HA</code> etc.) to an accepting backbone amide oxygen of another sheet (<code>O</code>). Unless you want an exact distance, you could simply use the distance between these heavy atoms, which would be slightly larger than the <code>H-N</code> bond plus the <code>H•O</code> hydrogen bond and the oxygen may not be coplanar with the planar amide.</p>

CC BY-SA 4.0
2021-10-23T20:40:59.780Z
thanks a lot...
user366312
CC BY-SA 4.0
2021-10-23T22:10:45.453Z
Would it be a realistic goal to implement HAAD protonation algorithm with BioPython?
user366312
CC BY-SA 4.0
2021-10-24T10:19:38.587Z
Doable totally, worth doing something that is implemented in many places elsewhere on a module that's a swiss-army knife, but limited in advanced functionality, definitely no...
Matteo Ferla
CC BY-SA 4.0
2022-10-03T20:21:40.063Z
The incorrect syntax `pymol2.PyMOL() as pymol:` should throw an error.
tommy.carstensen
CC BY-SA 4.0
2022-10-04T20:24:19.037Z
Not on python 3. In this case it's not the module `pymol` but an instance of multisession `pymol2.PyMOL` which behaves like the module but is way better
Matteo Ferla
CC BY-SA 4.0
2021-10-23T16:45:53.687Z
2021-10-23T16:45:53.687Z
Matteo Ferla
<p>I need to programmatically add Hydrogen atoms to a PDB file (say, 16PK.pdb) using BioPython.</p>
<p>What algorithm should I use for this?</p>

<python><proteins>
How can I programmatically add Hydrogen to a PDB structure using BioPython?
# How can I programmatically add Hydrogen to a PDB structure using BioPython?

(Asked by: username_0 on 2021-10-22)

I need to programmatically add Hydrogen atoms to a PDB file (say, 16PK.pdb) using BioPython.

What algorithm should I use for this?

**Tags:** python, proteins

---

## 2 answers

### Answer by username_2 on 2021-10-23. Score: 4 | Accepted answer

Not actually and answer as you cannot do it with biopython.PDB. But there are may other tools.
Several are online, for example: https://zhanggroup.org/HAAD/ by the folk who wrote I-Tasser.
Nearly every MD pipeline has their own protonation algorithm. The only hydrogens that are an issue are histidine protonation —HIE vs. HID— and protonation states of catalytic residues (CYZ vs. CYS etc).
The PyMOL python module is really good and can do a lot. Only issue is that the easiest way to install is via conda.
conda install -c conda-forge -c schrodinger pymol-bundle

with which one can:
import pymol2
pymol2.PyMOL() as pymol:
    pymol.cmd.load('.pdb', 'myprotein') # file
    # pymol.cmd.fetch('', 'myprotein') # PDB code
    pymol.cmd.h_add()
    pymol.cmd.save('.pdb')

One can find neighbours to a given atom too (see this Q&A), select by secondary structure, define secondary structure (pymol.cmd.dss()) etc. A caveat is that, bar for some commands like pymol.cmd.get_model(selection).atom, one does not interact directly with the atoms and everything is done via selections.
However, as this Q follows on from this unanswerable one and in turn from several others about SS. I am guessing it is to determine the hydrogen bond distances between different sheets. These have a backbone amide nitrogen (name N) donating a hydrogen (H, not HA etc.) to an accepting backbone amide oxygen of another sheet (O). Unless you want an exact distance, you could simply use the distance between these heavy atoms, which would be slightly larger than the H-N bond plus the H•O hydrogen bond and the oxygen may not be coplanar with the planar amide.

> **Comments:**
> **username_0**: thanks a lot...  
> **username_0**: Would it be a realistic goal to implement HAAD protonation algorithm with BioPython?  
> **username_2**: Doable totally, worth doing something that is implemented in many places elsewhere on a module that's a swiss-army knife, but limited in advanced functionality, definitely no...  
> **username_3**: The incorrect syntax `pymol2.PyMOL() as pymol:` should throw an error.  
> **username_2**: Not on python 3. In this case it's not the module `pymol` but an instance of multisession `pymol2.PyMOL` which behaves like the module but is way better  

---

### Answer by username_1 on 2023-12-24. Score: 0

conda install -c conda-forge openbabel
from openbabel import pybel as pb
babel_mol = pb.readfile(format="pdb", filename=path_to_pdb).__next__()
babel_mol.addh()
babel_mol.write(format='pdb', filename=path_to_babel_pdbh, overwrite=True)


---

