Skip to content

Instantly share code, notes, and snippets.

@JoaoRodrigues
Last active August 29, 2015 13:56
Show Gist options
  • Save JoaoRodrigues/9095892 to your computer and use it in GitHub Desktop.
Save JoaoRodrigues/9095892 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Example to align two equivalent protein structures.
"""
from Bio.PDB import PDBParser, Superimposer
parser = PDBParser(QUIET=1)
protA = parser.get_structure('protA', 'pdb_xyzA.pdb')
protB = parser.get_structure('protB', 'pdb_xyzB.pdb')
equivalent_atoms = []
for resA in protA.get_residues():
for chain in protB.get_chains():
if resA.id in chain:
# Align only CA-atoms
if 'CA' in resA:
ca_pair = (resA['CA'], chain[resA.id]['CA'])
equivalent_atoms.append(ca_pair)
super_imposer = Superimposer()
ref_atoms, mobi_atoms = zip(*equivalent_atoms)
super_imposer.set_atoms(ref_atoms, mobi_atoms)
print "RMS = {0:.2f}".format(super_imposer.rms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment