Hello,
I am trying to use Biopython to find the distance between the alpha carbons for a pair of residues in a model:
from Bio.PDB.PDBParser import PDBParser
parser = PDBParser()
structure = parser.get_structure("4HHB", "4HHB.pdb")
# Create a list of all the residues
residues = []
for model in structure.get_list():
for chain in model.get_list():
for residue in chain.get_list():
residues.append(residue)
# Calculate the distance between the alpha carbons for a pair of residues
firstResidue = residues[0]
secondResidue = residues[1]
diff = firstResidue["CA"].get_coord() - secondResidue["CA"].get_coord()
distance = numpy.sqrt(numpy.sum(diff * diff))
However, I get the error, KeyError: 'CA'. I'm new to Biopython and was hoping someone with more experience can help me understand how to correctly reference atoms in the residues.
Thank you.
Hello lisa,
Please use the formatting bar (especially the
code
option) to present your post better. I've done it for you this time.Also, post your complete code here with some background information about the input; best way is to host the file somewhere and provide a link for that here at biostars or provide first few/ relevant lines here.
Thank you!
Hello, thank you for your response. I have updated my question to include the complete code.
Can you please post the exact error? I can’t see anything obviously wrong with your approach so far.
Try Pymol
https://pymolwiki.org/index.php/Distance
Within this link above see examples
https://bioinformatics.stackexchange.com/questions/783/how-can-we-find-the-distance-between-all-residues-in-a-pdb-file
Here some authors determined the distance by biopython