Protein Structure (PDB Module)
Bio.PDB reads Protein Data Bank (PDB/mmCIF) files into an object hierarchy - Structure, Model, Chain, Residue, Atom - and provides tools to walk that hierarchy, compute distances, and analyze structural features. It is the gateway to structural bioinformatics in Python.
Parsing a Structure
from Bio.PDB import PDBParser
parser = PDBParser(QUIET=True)
structure = parser.get_structure("1a2o", "1a2o.pdb")
print(structure)
print(structure.get_level_list("C")) # chains, e.g. ['A', 'B']
Walking the Hierarchy
for model in structure:
for chain in model:
print("chain", chain.id, "residues", len(chain))
for i, residue in enumerate(chain):
if i < 5:
print(" ", residue.id, residue.resname)
else:
break
Residues and Atoms
chain = structure["0"]["A"]
# iterate atoms of a specific residue
res = chain[10] # residue with serial 11 (0-based)
for atom in res:
print(atom.name, atom.element, atom.coord)
# count atoms by element
from collections import Counter
elements = Counter(atom.element for residue in chain for atom in residue)
print(elements)
Distances and Measurements
from Bio.PDB import PDBParser
from Bio.PDB.Residue import Residue
# distance between two atoms
from Bio.PDB.vectors import Vector
a1 = chain[5]["CA"]
a2 = chain[50]["CA"]
print("C-alpha distance:", round(a1 - a2, 2)) # Euclidean distance
Structure Comparison (Superimposition)
from Bio.PDB import Superimposer
# superimpose two structures (requires two parsed structures)
superimposer = Superimposer()
superimposer.set_targets(mobile_atoms, fixed_atoms)
superimposer.apply(mobile_atoms)
print("RMSD:", superimposer.rmsd) # rough alignment quality
Getting PDB Files
# from RCSB (example):
curl -o 1a2o.pdb https://files.rcsb.org/download/1A2O.pdb
You can also fetch structures via the RCSB API or Biopython's Entrez tools for PDB database access.
Summary
Bio.PDB turns PDB files into a Structure/Model/Chain/Residue/Atom hierarchy you can iterate and index. Use it to enumerate chains and residues, inspect atom coordinates, compute distances and RMSD with vectors and Superimposer, and download structures from RCSB. It is the foundation for any Python structural analysis pipeline.