Python Script That Can Find Distance Between One Atom Of A Pdb File To All Other Atoms In Another Pdb File
2
1
Entering edit mode
13.5 years ago
Mukesh Goel ▴ 10

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 • 13k views
ADD COMMENT
2
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
1
Entering edit mode

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

ADD REPLY
5
Entering edit mode
13.5 years ago

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 COMMENT
4
Entering edit mode
13.5 years ago
brentp 24k

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 COMMENT

Login before adding your answer.

Traffic: 2547 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6