Question: Python Script That Can Find Distance Between One Atom Of A Pdb File To All Other Atoms In Another Pdb File
1
9.5 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 • 9.1k views
written 9.5 years ago by Mukesh Goel10
2

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.

1

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. =)

1

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

5
9.5 years ago by
Simon Cockell7.3k
Newcastle
Simon Cockell7.3k wrote:

The distance between two atoms can be expressed as:

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.

4
9.5 years ago by
brentp23k
Salt Lake City, UT
brentp23k 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
``````