forked from lmorency/NRGsuite
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Geometry.py
executable file
·286 lines (210 loc) · 8.84 KB
/
Geometry.py
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
'''
NRGsuite: PyMOL molecular tools interface
Copyright (C) 2011 Gaudreault, F., Morency, LP. & Najmanovich, R.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from __future__ import print_function
# coding: utf-8
'''
@title: Geometry.py
@summary: Module that define some tools used by FlexAID.
@contain: distance, angle, dihedralAngle
@organization: Najmanovich Research Group
@creation date: oct. 13, 2010
'''
import math
'''******************************************************************************
SUBROUTINE middle: Calculates the center of geometry between 2 points
******************************************************************************'''
def middle(pointA, pointB):
return [ ( pointA[0] + pointB[0] ) / 2.0 ,
( pointA[1] + pointB[1] ) / 2.0 ,
( pointA[2] + pointB[2] ) / 2.0
]
'''******************************************************************************
SUBROUTINE distance: Calculates the cartesian distance between two point in
3 dimensions.
******************************************************************************'''
def distance(pointA, pointB):
d = 0.0
for i in range(0, 3):
d += (pointA[i]-pointB[i])**2
d = math.sqrt(d)
return d
'''******************************************************************************
SUBROUTINE distance: Calculates the cartesian squared distance between two point in
3 dimensions.
******************************************************************************'''
def sqrdistance(pointA, pointB):
d = 0.0
for i in range(0, 3):
d += (pointA[i] - pointB[i])**2
return d
'''*******************************************************************************
SUBROUTINE angle: Calculates the valence angle between three consecutives atoms.
*******************************************************************************'''
def angle(pointA, pointB, pointC):
cosa = 0.0
absu = 0.0
absv = 0.0
for i in range(0, 3):
cosa += (pointA[i]-pointB[i])*(pointC[i]-pointB[i])
absu += (pointA[i]-pointB[i])*(pointA[i]-pointB[i])
absv += (pointC[i]-pointB[i])*(pointC[i]-pointB[i])
absv += 1e-10;
absu += 1e-10;
cosa = cosa / math.sqrt(absu*absv)
cosa = math.acos(cosa)*(180.0/math.pi)
return cosa
'''*******************************************************************************
SUBROUTINE dihedralAngle: Calculates the torsional angle between 4 consecutives atoms
*******************************************************************************'''
def dihedralAngle(pointA, pointB, pointC, pointD):
# Init the arrays of 3 floats
t = [0.0, 0.0, 0.0]
u = [0.0, 0.0, 0.0]
w = [0.0, 0.0, 0.0]
m = [0.0, 0.0, 0.0]
n = [0.0, 0.0, 0.0]
v = [0.0, 0.0, 0.0]
# Init the float values
absm = 0.0
absn = 0.0
absv = 0.0
absu = 0.0
costheta = 0.0
theta = 0.0
q = 0.0
for i in range(0, 3):
t[i] = pointA[i]-pointB[i]
u[i] = pointC[i]-pointB[i]
w[i] = pointD[i]-pointB[i]
m[0] = (t[1]*u[2]) - (t[2]*u[1])
m[1] = (t[2]*u[0]) - (t[0]*u[2])
m[2] = (t[0]*u[1]) - (t[1]*u[0])
n[0] = (w[1]*u[2]) - (w[2]*u[1])
n[1] = (w[2]*u[0]) - (w[0]*u[2])
n[2] = (w[0]*u[1]) - (w[1]*u[0])
absm = math.sqrt((m[0]*m[0])+(m[1]*m[1])+(m[2]*m[2]))
absn = math.sqrt((n[0]*n[0])+(n[1]*n[1])+(n[2]*n[2]))
costheta = ((m[0]*n[0]) + (m[1]*n[1]) + (m[2]*n[2]))/(absm*absn)
theta = math.acos(costheta)
v[0] = (m[1]*n[2]) - (m[2]*n[1])
v[1] = (m[2]*n[0]) - (m[0]*n[2])
v[2] = (m[0]*n[1]) - (m[1]*n[0])
absv = math.sqrt((v[0]*v[0])+(v[1]*v[1])+(v[2]*v[2]))
absu = math.sqrt((u[0]*u[0])+(u[1]*u[1])+(u[2]*u[2]))
absv += 1e-10;
absu += 1e-10;
q = ((v[0]*u[0]) + (v[1]*u[1]) + (v[2]*u[2]))/(absv*absu)
theta = q*theta*(180.0/math.pi)
return theta
'''
@summary: SUBROUTINE buildcc: builds the cartesianlen( coordinates of the tot atoms
present in array list according to the reconstruction data.
@return: PDBCoord for each atom of the ligand (dictionary)
'''
def buildcc(ListAtom,RecAtom,DisAngDih,Ori):
tot = len(ListAtom)
PDBCoord = {}
# init the list (x, y, z)
x = [0.0, 0.0, 0.0, 0.0]
y = [0.0, 0.0, 0.0, 0.0]
z = [0.0, 0.0, 0.0, 0.0]
for an in range(0, tot):
NoAtom = ListAtom[an] #Number of the atom treated
for i in range(1, 4):
#print('No Atom: ' + str(NoAtom) + ' -> ' + str(self.RecAtom[NoAtom][i-1]))
j = RecAtom[NoAtom][i - 1]
#print('j: ' + str(j))
if(j != 0):
x[i] = float(PDBCoord[j][0])
y[i] = float(PDBCoord[j][1])
z[i] = float(PDBCoord[j][2])
elif(i == 1):
x[i] = 1.0 + float(Ori[0])
y[i] = 0.0 + float(Ori[1])
z[i] = 0.0 + float(Ori[2])
elif(i == 3):
x[i] = 0.0 + float(Ori[0])
y[i] = 1.0 + float(Ori[1])
z[i] = 0.0 + float(Ori[2])
else:
x[i] = 0.0 + float(Ori[0])
y[i] = 0.0 + float(Ori[1])
z[i] = 0.0 + float(Ori[2])
# END of FOR(i)
a = y[1] * (z[2] - z[3]) + y[2] * (z[3] - z[1]) + y[3] * (z[1] - z[2])
b = z[1] * (x[2] - x[3]) + z[2] * (x[3] - x[1]) + z[3] * (x[1] - x[2])
c = x[1] * (y[2] - y[3]) + x[2] * (y[3] - y[1]) + x[3] * (y[1] - y[2])
op = math.sqrt((a * a) + (b * b) + (c * c))
cx = float(a) / op
cy = float(b) / op
cz = float(c) / op
#print('cx= ' + str(cx) + ' cy= ' + str(cy) + ' cz= ' + str(cz))
a = x[2] - x[1]
b = y[2] - y[1]
c = z[2] - z[1]
d = float(1.0) / (math.sqrt((a * a) + (b * b) + (c * c)))
#print('d : ' + str(d))
op = float(DisAngDih[NoAtom][0]) * d
xn = a * op
yn = b * op
zn = c * op
#print('d= ' + str(d) + ' op= ' + str(op) + ' xn= ' + str(xn) + ' yn= ' + str(yn) + ' zn= ' + str(zn))
a = cx * cx
b = cy * cy
c = cz * cz
#print('ang= ' + str(self.DisAngDih[NoAtom][1]))
angPI = float(DisAngDih[NoAtom][1]) * math.pi / 180.0
ct = math.cos(angPI)
st = -1.0 * (math.sin(angPI))
op = 1.0 - ct
# print('ct= ' + str(ct) + ' st= ' + str(st) + ' op= ' + str(op))
xk = (cx * cz * op - cy * st) * zn + ((1.0 - a) * ct + a) * xn + (cx * cy * op + cz * st) * yn
yk = (cy * cx * op - cz * st) * xn + ((1.0 - b) * ct + b) * yn + (cy * cz * op + cx * st) * zn
zk = (cz * cy * op - cx * st) * yn + ((1.0 - c) * ct + c) * zn + (cz * cx * op + cy * st) * xn
#print('xk=' + str(xk) + ' yk=' + str(yk) + ' zk=' + str(zk))
#print('dih= ' + str(self.DisAngDih[NoAtom][2]))
dihPI = float(DisAngDih[NoAtom][2]) * math.pi / 180.0
ct = math.cos(dihPI)
st = math.sin(dihPI)
op = 1.0 - ct
cx = (x[2] - x[1]) * d
cy = (y[2] - y[1]) * d
cz = (z[2] - z[1]) * d
a = cx * cx
b = cy * cy
c = cz * cz
#print('a= ' + str(a) + ' b= ' + str(b) + ' c= ' + str(c))
x[0] = (((cx * cz * op) - (cy * st)) * zk) + ((((1.0 - a) * ct) + a) * xk) + (((cx * cy * op) + (cz * st)) * yk) + x[1]
y[0] = (((cy * cx * op) - (cz * st)) * xk) + ((((1.0 - b) * ct) + b) * yk) + (((cy * cz * op) + (cx * st)) * zk) + y[1]
z[0] = (((cz * cy * op) - (cx * st)) * yk) + ((((1.0 - c) * ct) + c) * zk) + (((cz * cx * op) + (cy * st)) * xk) + z[1]
#print('NO Atom: ' + str(NoAtom) + ' X: ' + str(x[0]) + ' Y: ' + str(y[0]) + ' Z: ' + str(z[0]))
#3 floating numbers
PDBCoord[NoAtom] = [x[0], y[0], z[0]]
#END of FOR(an)
return PDBCoord
'''
@summary: SUBROUTINE rmsd: calculates RMSD between predicted and reference
'''
def rmsd(dictCoord, dictCoordRef):
tot = 0
sum = 0.0
try:
for index in dictCoord.keys():
sum += sqrdistance( dictCoord[index], dictCoordRef[index] )
tot += 1
sum /= float(tot)
return ( math.sqrt(sum) )
except:
return 'N/A'