# Script distance check.py

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<source lang="python">

1. !/usr/bin/python

import sys import os import re import numpy import math

input=sys.argv[1]#contact.out in_pdb=sys.argv[2]#pdb file with actual coordinates

residues=[] CN_dist=[]#[pos1, pos2, cn, state] state~TP or FP coordinates={}

1. calculates euklidean distance between two atoms

def calc_dist(co1, co2):#dictionary with xyz

p1=numpy.array((co1["x"],co1["y"],co1["z"]))
p2=numpy.array((co2["x"],co2["y"],co2["z"]))
dist=numpy.linalg.norm(p1-p2)
return dist
1. checks distance between any atom of two residues

def any_atom(atom1_list, atom2_list):

for a1 in atom1_list:
for a2 in atom2_list:
dist=calc_dist(a1,a2)
if(dist<5.0):
return "TP"
return "FP"
1. checks TP oor FP for all residue pairs

def all_dist(res):

for i in res:#for every residue pair
if(i[5]>1 ):
#print(i)
#print(coordinates.has_key(i[0]))
atoms1=coordinates[i[0]]#of all atoms of residue 1 (list of dictionarys)
atoms2=coordinates[i[2]]#of all atoms of residue 2 (list of dictionarys)
state=any_atom(atoms1, atoms2)
CN_dist.append([i[0],i[1],i[2],i[3],i[5],state])

file=open(in_pdb, 'r')
for line in lines:
if(re.match("^ATOM",line)):
info=line.split()
if(info[2]=="N"):#every new residue starts with N
res_co=[{"x":float(info[6]),"y":float(info[7]),"z":float(info[8])}] #list of coordinates of all atoms
else:
res_co.append({"x":float(info[6]),"y":float(info[7]),"z":float(info[8])})
#print(info)
coordinates[int(info[5])]=res_co #key:aa position
file.close()
1. info[position1, residue1, position2, residue2, MI, CN]

file=open(input, 'r')
for line in lines:
text=line.lstrip().rstrip('\n')
info=text.split()
info[0]=int(info[0])
info[2]=int(info[2])
info[4]=float(info[4])
info[5]=float(info[5])
residues.append(info)
file.close()
1. writes CN_dist into file

def make_output(a):

file_name="corelations_%s"%(input)
file=open(file_name, 'w')
for i in a:
file.write("%i %s %i %s %f %s\n"%(i[0],i[1],i[2],i[3],i[4],i[5]))
file.close()

if __name__ == '__main__':