-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStructureTools.py
More file actions
169 lines (134 loc) · 5.82 KB
/
Copy pathStructureTools.py
File metadata and controls
169 lines (134 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import os
import string
import math
import numpy
from path import path
from itertools import islice
def distancePoints((x1,y1,z1),(x2,y2,z2)):
"""
Computes the distance between the two sets of coordinates
input: 2 tuples with the corresponding coordinates
output: distance
"""
x = (x1-x2)
y = (y1-y2)
z = (z1-z2)
return math.sqrt(x*x+y*y+z*z)
def centerMassOfResidue(dPDB):
"""
Calculates the center of mass of each residue contained in dPDB
Input : dPDB a dictionary
Output : dPDB with XCM, YCM and ZCM the coordinates of the center of mass of each residue
"""
reslist = dPDB["position"]
for res in reslist :
x = y = z = 0.0
# looping over the current residue atoms
for atom in dPDB[res]["atome"] :
x += dPDB[res][atom]["x"]
y += dPDB[res][atom]["y"]
z += dPDB[res][atom]["z"]
#Calculation of the center of mass of the current residue
Xcm = float(x)/len(dPDB[res]["atome"])
Ycm = float(y)/len(dPDB[res]["atome"])
Zcm = float(z)/len(dPDB[res]["atome"])
dPDB[res]["XCM"] = Xcm
dPDB[res]["YCM"] = Ycm
dPDB[res]["ZCM"] = Zcm
def computeDist_dico(d_res1, d_res2, mode) :
"""
Compute the distance between to residues
Input : d_res1, d_res2 are dictionary corresponding to residue 1 and residue 2 respectively, mode atom or center
Output : the distance between d-res1 and d_res2
"""
#Compute the distance between atoms of a couple of residues
if mode == "atom" :
minval = 1000000
for atom1 in d_res1["atome"] :
coord1 = [d_res1[atom1]["x"], d_res1[atom1]["y"], d_res1[atom1]["z"]]
for atom2 in d_res2["atome"] :
coord2 = [d_res2[atom2]["x"], d_res2[atom2]["y"], d_res2[atom2]["z"]]
dist = distancePoints((coord1[0], coord1[1], coord1[2]),(coord2[0],coord2[1], coord2[2]))
if minval > dist :
minval = dist
#Computes the distance between the CM of the 2 given residues
elif mode == "center" :
dPDBtmp = {}
dPDBtmp["position"] = ["res1", "res2"]
dPDBtmp["res1"] = d_res1
dPDBtmp["res2"] = d_res2
centerMassOfResidue(dPDBtmp)
minval = distancePoints((dPDBtmp["res1"]["XCM"],dPDBtmp["res1"]["YCM"],dPDBtmp["res1"]["ZCM"]),(dPDBtmp["res2"]["XCM"],dPDBtmp["res2"]["YCM"],dPDBtmp["res2"]["ZCM"]))
return minval
def scorelist(listFiles, listScores, filename):
"""
Create in a file a ranking of the scores from best (minimum value) to worst (maximum value) with the correspond file number in front
Input: the list of the files and the list of the scores, as well as the name wished for the file
Output: the ranking in a file
"""
dir_path = os.path.dirname(os.path.realpath(__file__))
pathname=dir_path+"/scoring_Cornell"
try:
if not os.path.exists(pathname):
os.makedirs(pathname)
except:
print "ERROR : You don't seem to have the rights to write in this directory"
sys.exit()
filepath = os.path.join(pathname, filename)
fileid = open(filepath, 'w+')
xarray= numpy.array(listFiles)
yarray= numpy.array(listScores)
data= numpy.array([xarray,yarray])
data= data.T
data= data[data[:, 1].argsort()]
numpy.savetxt(fileid,data,fmt=['%d','%d'])
fileid.close()
return data[0][0]
def writePDB(dPDBrec, dPDBlig, prediction) :
"""
Write the PDB file of the predicted complex
Input: dictionnaries of the receptor and solution ligand, as well as the name of the PDB file
"""
pred = open(prediction, "w")
for chain in dPDBrec["nchaine"]:
for res in dPDBrec[chain]["position"] :
for atom in dPDBrec[chain][res]["atome"] :
pred.write("ATOM %5d %-4s%3s %s%4s %8.3f%8.3f%8.3f 1.00 1.00 X X \n"%(dPDBrec[chain][res][atom]["ID"], atom, dPDBrec[chain][res]["residu"],chain, res,dPDBrec[chain][res][atom]["x"], dPDBrec[chain][res][atom]["y"],dPDBrec[chain][res][atom]["z"] ))
for chain in dPDBlig["nchaine"]:
for res in dPDBlig[chain]["position"] :
for atom in dPDBlig[chain][res]["atome"] :
pred.write("ATOM %5d %-4s%3s %s%4s %8.3f%8.3f%8.3f 1.00 1.00 X X\n"%(dPDBlig[chain][res][atom]["ID"], atom, dPDBlig[chain][res]["residu"],chain, res,dPDBlig[chain][res][atom]["x"], dPDBlig[chain][res][atom]["y"],dPDBlig[chain][res][atom]["z"] ))
pred.close()
def writeInterfacePDB(dPDBcompl, prediction) :
"""
Add the Bfactor in the PDB file of the predicted complex
Input: dictionnary containing the Bfactor as well as the name of the new file
"""
pred = open(prediction, "w")
for chain in dPDBcompl["nchaine"]:
for res in dPDBcompl[chain]["position"] :
for atom in dPDBcompl[chain][res]["atome"] :
pred.write("ATOM %5d %-4s%3s %s%4s %8.3f%8.3f%8.3f 1.00 %d X X\n"%(dPDBcompl[chain][res][atom]["ID"], atom, dPDBcompl[chain][res]["residu"],chain, res,dPDBcompl[chain][res][atom]["x"], dPDBcompl[chain][res][atom]["y"],dPDBcompl[chain][res][atom]["z"], dPDBcompl[chain][res]["bfactor"] ))
pred.close()
def extract100Bests(indir):
"""
Extract the 100 bests scores following the first scoring method to apply the second scoring method to them
Input: the directory containing the ranking of the scores
Output: a list containing the number of the best files, a list containing the name of the best files, a list containing the best scores
"""
infile = open("scoring_Cornell/Scoring1.txt")
head = list(islice(infile, 100))
listBestHits=[]
listBestFiles=[]
listBestScores=[]
for i in head:
num, score = i.split(" ")
num=str(num)
number=int(num)
score=score.strip('\n')
score=int(score)
listBestHits.append(indir+"/1BRS_A_1BRS_B_allatom_"+num+"_DP.pdb")
listBestScores.append(score)
listBestFiles.append(number)
infile.close()
return listBestHits, listBestScores, listBestFiles