Question: Python Script That Can Find Distance Between One Atom Of A Pdb File To All Other Atoms In Another Pdb File
gravatar for Mukesh Goel
7.8 years ago by
Mukesh Goel10
Mukesh Goel10 wrote:

Hi..Actually I want a script in python that can find distance between one atom of a pdb file to all other atoms in another pdb file.Otherwise I can put all the atoms in one file and find the distance between N of first residue to all N of second protein.if anyone can also guide me how to do this then also I will be highly thankful.

pdb python • 6.9k views
ADD COMMENTlink written 7.8 years ago by Mukesh Goel10

What you're asking does not make much sense. The pdb coordinates in 2 different files can be completely different (even if it's the same protein) - you would need to align your structures first in order to make any reasonable comparison.

ADD REPLYlink written 7.8 years ago by Michael Schubert6.9k

Naive question but, if you know (or verify), that the two structures are similar can't you just normalize your distance by the observed distance between a same given set of atoms (in a same plane) in the two files? I'm not used to these kind of computation so sorry if this seems stupid. =)

ADD REPLYlink written 7.8 years ago by Philippe1.9k

If I understand you correctly, this approach would not account for different orientation.

ADD REPLYlink written 7.8 years ago by Michael Schubert6.9k
gravatar for Simon Cockell
7.8 years ago by
Simon Cockell7.3k
Simon Cockell7.3k wrote:

The distance between two atoms can be expressed as:

d = sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)

So your Python script needs a method that implements this for 2 sets of coordinates passed to it. eg:

import math
def distance(c1, c2):
    x_dist = (c1[0] - c2[0])**2
    y_dist = (c1[1] - c2[1])**2
    z_dist = (c1[2] - c2[2])**2
    return math.sqrt(x_dist + y_dist + z_dist)

The rest of what you want to do is just plumbing, and should be simple.

EDIT - All this said, I endorse Michael's comment above, you need to be sure the coordinates of your 2 files are actually comparable before you do any of this.

ADD COMMENTlink written 7.8 years ago by Simon Cockell7.3k
gravatar for brentp
7.8 years ago by
Salt Lake City, UT
brentp22k wrote:

Assuming you've addressed all the issues @Michael Schubert mentions, I think you can use bio-python to do this. Something like this to find the distance from atom 111 in the B file to all atoms in the A file:

import Bio.PDB
import os.path as op
a = '1XI4.pdb'
b = '1XI4.pdb'

ATOM = 111

model_a = Bio.PDB.PDBParser().get_structure(op.splitext(a)[0], a)[0]
model_b = Bio.PDB.PDBParser().get_structure(op.splitext(b)[0], b)[0]

b_residues = list(model_b.get_residues())

print "a-index a-name distance"
for i, r in enumerate(model_a.get_residues()):
    dist = abs(r['CA'] - b_residues[ATOM]['CA'])
    print i, r.get_resname(), dist
ADD COMMENTlink written 7.8 years ago by brentp22k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 781 users visited in the last hour