Answers.Body: <p>Your <span class="math-container">$[i,j,k]$</span> coordinates in the PDB file are coordinates. You can readily compute <a href="http://%20Euclidean%20distance%20-%20Wikipediahttps://en.wikipedia.org%20%E2%80%BA%20wiki%20%E2%80%BA%20Euclidean_distance" rel="nofollow noreferrer">Euclidean distances</a> between any pair of coordinates as described in the wiki page:</p>
  <p><span class="math-container">$d(p,q)=\sqrt{(p_1-q_1)^2 + (p_2-q_2)^2 + (p_3-q_3)^2}.
  $</span></p>
  <p><a href="https://warwick.ac.uk/fac/sci/moac/people/students/peter_cock/python/protein_contact_map/" rel="nofollow noreferrer">This resource</a> suggests one such approach (code reproduced below in case that site stops existing):</p>
  <pre class="lang-py prettyprint-override"><code>import Bio.PDB
  import numpy
  
  def calc_residue_dist(residue_one, residue_two) :
      &quot;&quot;&quot;Returns the C-alpha distance between two residues&quot;&quot;&quot;
      diff_vector  = residue_one[&quot;CA&quot;].coord - residue_two[&quot;CA&quot;].coord
      return numpy.sqrt(numpy.sum(diff_vector * diff_vector))
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-29T00:02:56.630Z
Answers.LastActivityDate: 2021-08-29T00:02:56.630Z
Answers.UserDisplayName: Maximilian Press
Body: <p>Suppose, we have a protein (<code>16PK</code>).</p>
  <p>We are considering a 5-residue segment/window.</p>
  <p>If we assume <code>ASN10</code> to be the <code>i</code>th residue, how can I calculate the following distances in <strong>Python</strong>?</p>
  <ol>
  <li>from [i+2] to [i-2]</li>
  <li>from [i+1] to [i-2]</li>
  <li>from [i+2] to [i-1]</li>
  </ol>
  <p>Next major question is, what would be the distances like if my segment/window is 7 or 9 residues long?</p>
  <img src="https://i.sstatic.net/ft9jZ.png" width="450">
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-06T11:28:07.503Z
Comments.Text: See this question for recommendations on a number of tools to calculate such distances: https://bioinformatics.stackexchange.com/questions/783/how-can-we-find-the-distance-between-all-residues-in-a-pdb-file
Comments.UserDisplayName: jgreener
Tags: <python><proteins><pdb>
Title: How can I calculate the distances between two specific residues of a protein from a PDB file?
ThreadText: # How can I calculate the distances between two specific residues of a protein from a PDB file?
  
  (Asked by: username_0 on 2021-08-28)
  
  Suppose, we have a protein (`16PK`).
  
  We are considering a 5-residue segment/window.
  
  If we assume `ASN10` to be the `i`th 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?
  
  ![](https://i.sstatic.net/ft9jZ.png)
  
  **Tags:** python, proteins, pdb
  
  > **Comments:**
  > **username_1**: See this question for recommendations on a number of tools to calculate such distances: https://bioinformatics.stackexchange.com/questions/783/how-can-we-find-the-distance-between-all-residues-in-a-pdb-file  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-08-29. Score: 2 | Accepted answer
  
  Your $[i,j,k]$ coordinates in the PDB file are coordinates. You can readily compute [Euclidean distances](http://%20Euclidean%20distance%20-%20Wikipediahttps://en.wikipedia.org%20%E2%80%BA%20wiki%20%E2%80%BA%20Euclidean_distance) 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](https://warwick.ac.uk/fac/sci/moac/people/students/peter_cock/python/protein_contact_map/) suggests one such approach (code reproduced below in case that site stops existing):
  
  ```py
  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))
  
  ```
  
  
  ---
  
  