Reputation: 33
I am trying to run a code using BioPython that will allow me to iterate through the atoms of multiple proteins and remove all hydrogen atoms from them. To identify which atoms correspond to hydrogen I wrote the following code:
atom = residues[0].get_atoms()
atoms = list(atom)
atoms
[<Atom N>,
<Atom CA>,
<Atom C>,
<Atom O>,
<Atom CB>,
<Atom OG1>,
<Atom CG2>,
<Atom H1>,
<Atom H2>,
<Atom H3>,
<Atom HA>,
<Atom HB>,
<Atom HG1>,
<Atom HG21>,
<Atom HG22>,
<Atom HG23>]
How can I make it so that BioPython will return the name of the actual element of these atoms, such as "Carbon" or "Hydrogen"?
Note, I tried to use the following functions from the Bio.PDB.Atom
module:
"get_name()",
"get_id"
"get_full_id"
They did not return the desired element name.
Upvotes: 0
Views: 313
Reputation: 3571
Atom's element is stored in:
atom.element
It's a string with periodic table element abbreviation: C and H rather than Carbon and Hydrogen.
Upvotes: 2
Reputation: 48600
You may need to translate the elements yourself. You can use the periodictable
package.
Note that biopython
uses upper-case e.g. FE
for element names and periodictable
uses title-case e.g. Fe
.
I created two methods below: one that takes a symbol i.e. symbol_to_english
, and another that takes the atom i.e. atom_to_english
and passes its name to symbol_to_english
.
import periodictable as pt
from Bio.PDB.Atom import Atom
def symbol_to_english(symbol: str) -> str:
"""This function converts a symbol to its English name.
Args:
symbol (str): The symbol of the element.
Returns:
str: The English name of the element.
"""
try:
return pt.elements.isotope(symbol.title()).name.title()
except Exception as exc:
raise ValueError(f"Could not convert symbol {symbol} to English.") from exc
def atom_to_english(atom: Atom) -> str:
"""This function converts an atom's element to its English name.
Args:
atom (Atom): The atom to convert.
Returns:
str: The English name of the atom's element.
"""
return symbol_to_english(atom.element)
if __name__ == "__main__":
atoms = [Atom("FE", (1, 2, 3), 1.0, 1.0, "", "FE", 1, "FE")]
names = [atom_to_english(atom) for atom in atoms]
print(names) # ['Iron']
Upvotes: 0