# How can I calculate the distances between two specific residues of a protein from a PDB file?

Suppose, we have a protein (16PK).

We are considering a 5-residue segment/window.

If we assume ASN10 to be the ith residue, how can I calculate the following distances in Python?

1. from [i+2] to [i-2]
2. from [i+1] to [i-2]
3. from [i+2] to [i-1]

Next major question is, what would be the distances like if my segment/window is 7 or 9 residues long? Your $$[i,j,k]$$ coordinates in the PDB file are coordinates. You can readily compute Euclidean distances between any pair of coordinates as described in the wiki page:

$$d(p,q)=\sqrt{(p_1-q_1)^2 + (p_2-q_2)^2 + (p_3-q_3)^2}.$$

This resource suggests one such approach (code reproduced below in case that site stops existing):

import Bio.PDB
import numpy

def calc_residue_dist(residue_one, residue_two) :
"""Returns the C-alpha distance between two residues"""
diff_vector  = residue_one["CA"].coord - residue_two["CA"].coord
return numpy.sqrt(numpy.sum(diff_vector * diff_vector))