Question: Python Script That Can Find Distance Between One Atom Of A Pdb File To All Other Atoms In Another Pdb File
1
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 • 8.2k views
written 8.7 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
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 - c2)**2
y_dist = (c1 - c2)**2
z_dist = (c1 - c2)**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
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), a)
model_b = Bio.PDB.PDBParser().get_structure(op.splitext(b), b)

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
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.8646665,"math_prob":0.67555726,"size":2765,"snap":"2019-51-2020-05","text_gpt3_token_len":773,"char_repetition_ratio":0.09634191,"word_repetition_ratio":0.03757829,"special_character_ratio":0.27197108,"punctuation_ratio":0.114583336,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9798183,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-18T23:43:20Z\",\"WARC-Record-ID\":\"<urn:uuid:783586bb-91d9-4a58-b232-5b2b8f5fc6a7>\",\"Content-Length\":\"35039\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9843f28d-1a07-4f35-9cbc-a028e989a0de>\",\"WARC-Concurrent-To\":\"<urn:uuid:b8431bb8-2f08-4426-9aee-40044969edaa>\",\"WARC-IP-Address\":\"69.164.220.180\",\"WARC-Target-URI\":\"https://www.biostars.org/p/8587/\",\"WARC-Payload-Digest\":\"sha1:L5II2X43D2SOXUGRHIXBPJ5Z6UFIKVJO\",\"WARC-Block-Digest\":\"sha1:3LD2QPJKRNSTHWTVASQN6LT477MBNAQK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250593994.14_warc_CC-MAIN-20200118221909-20200119005909-00251.warc.gz\"}"}