-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNaTorsion.hpp
More file actions
351 lines (338 loc) · 17.2 KB
/
NaTorsion.hpp
File metadata and controls
351 lines (338 loc) · 17.2 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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/* calculate backbone torsion angles (omega, psi, phi, kappa, alpha) */
#ifndef NaTorsion_HPP
#define NaTorsion_HPP 1
#include <cstring>
#include "PDBParser.hpp"
#include "GeometryTools.hpp"
using namespace std;
/* calculate pucker (C1'C2'C3'C4'), pseudo torsion (eta, theta, eta', theta')
* backbone torsion (alpha, beta, gamma, delta , epsilon, zeta) and
* sidechain torsion (chi) from backbone.pdb */
void NaTorsion(ChainUnit& chain, vector<vector<float> >&NaTorMat,
vector<vector<float> >&NaLenMat, vector<vector<float> >&NaAngMat,
const bool show_tor, const bool show_len, const bool show_ang)
{
int L=chain.residues.size();
// default torsion angles: omega=phi=psi=360
vector<float> tmp_tor(19,-360.);
vector<float> tmp_len(36,-1.);
vector<float> tmp_ang(21,-360.);
if (show_tor) NaTorMat.assign(L,tmp_tor);
if (show_len) NaLenMat.assign(L,tmp_len);
if (show_ang) NaAngMat.assign(L,tmp_ang);
// coordinates of previous residue
vector<float> prev_P(3,0); bool has_prev_P=false;
vector<float> prev_O5(3,0); bool has_prev_O5=false;
vector<float> prev_C5(3,0); bool has_prev_C5=false;
vector<float> prev_C4(3,0); bool has_prev_C4=false;
vector<float> prev_C3(3,0); bool has_prev_C3=false;
vector<float> prev_C2(3,0); bool has_prev_C2=false;
vector<float> prev_C1(3,0); bool has_prev_C1=false;
vector<float> prev_O4(3,0); bool has_prev_O4=false;
vector<float> prev_O3(3,0); bool has_prev_O3=false;
// coordinates of current residue
vector<float> P(3,0.); bool has_P=false;
vector<float> O5(3,0.); bool has_O5=false;
vector<float> C5(3,0.); bool has_C5=false;
vector<float> C4(3,0.); bool has_C4=false;
vector<float> C3(3,0.); bool has_C3=false;
vector<float> C2(3,0.); bool has_C2=false;
vector<float> C1(3,0.); bool has_C1=false;
vector<float> O4(3,0.); bool has_O4=false;
vector<float> O3(3,0.); bool has_O3=false;
vector<float> O2(3,0.); bool has_O2=false;
vector<float> Nx(3,0.); bool has_Nx=false;
vector<float> Cx(3,0.); bool has_Cx=false;
// coordinates of next residue
vector<float> next_P(3,0); bool has_next_P=false;
vector<float> next_O5(3,0); bool has_next_O5=false;
vector<float> next_C4(3,0); bool has_next_C4=false;
vector<float> next_C1(3,0); bool has_next_C1=false;
char base=' ';
int r,a; // residue index, atom index
for (r=0;r<L;r++)
{
// whether the required atom exists
has_prev_P=false;
has_prev_O5=false;
has_prev_C5=false;
has_prev_C4=false;
has_prev_C3=false;
has_prev_C2=false;
has_prev_C1=false;
has_prev_O4=false;
has_prev_O3=false;
has_P=false;
has_O5=false;
has_C5=false;
has_C4=false;
has_C3=false;
has_C2=false;
has_C1=false;
has_O4=false;
has_O3=false;
has_O2=false;
has_Nx=false;
has_Cx=false;
has_next_P=false;
has_next_O5=false;
has_next_C4=false;
has_next_C1=false;
base=tolower(chain.residues[r].resn[2]);
if (r>0) // find previous residue atoms
{
for (a=0;a<chain.residues[r-1].atoms.size();a++)
{
if (chain.residues[r-1].atoms[a].name==" P ")
{
has_prev_P=true;
prev_P=chain.residues[r-1].atoms[a].xyz;
}
else if (chain.residues[r-1].atoms[a].name==" O5'")
{
has_prev_O5=true;
prev_O5=chain.residues[r-1].atoms[a].xyz;
}
else if (chain.residues[r-1].atoms[a].name==" C5'")
{
has_prev_C5=true;
prev_C5=chain.residues[r-1].atoms[a].xyz;
}
else if (chain.residues[r-1].atoms[a].name==" C4'")
{
has_prev_C4=true;
prev_C4=chain.residues[r-1].atoms[a].xyz;
}
else if (chain.residues[r-1].atoms[a].name==" C3'")
{
has_prev_C3=true;
prev_C3=chain.residues[r-1].atoms[a].xyz;
}
else if (chain.residues[r-1].atoms[a].name==" C2'")
{
has_prev_C2=true;
prev_C2=chain.residues[r-1].atoms[a].xyz;
}
else if (chain.residues[r-1].atoms[a].name==" C1'")
{
has_prev_C1=true;
prev_C1=chain.residues[r-1].atoms[a].xyz;
}
else if (chain.residues[r-1].atoms[a].name==" O4'")
{
has_prev_O4=true;
prev_O4=chain.residues[r-1].atoms[a].xyz;
}
else if (chain.residues[r-1].atoms[a].name==" O3'")
{
has_prev_O3=true;
prev_O3=chain.residues[r-1].atoms[a].xyz;
}
}
}
// find current residue atoms
for (a=0;a<chain.residues[r].atoms.size();a++)
{
if (chain.residues[r].atoms[a].name==" P ")
{
has_P=true;
P=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" O5'")
{
has_O5=true;
O5=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" C5'")
{
has_C5=true;
C5=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" C4'")
{
has_C4=true;
C4=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" C3'")
{
has_C3=true;
C3=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" C2'")
{
has_C2=true;
C2=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" C1'")
{
has_C1=true;
C1=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" O4'")
{
has_O4=true;
O4=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" O3'")
{
has_O3=true;
O3=chain.residues[r].atoms[a].xyz;
}
else if (chain.residues[r].atoms[a].name==" O2'")
{
has_O2=true;
O2=chain.residues[r].atoms[a].xyz;
}
else if((chain.residues[r].atoms[a].name==" N9 " &&
(base=='a' || base=='g')) ||
(chain.residues[r].atoms[a].name==" N1 " &&
(base=='c' || base=='t' || base=='u')))
{
has_Nx=true;
Nx=chain.residues[r].atoms[a].xyz;
}
else if((chain.residues[r].atoms[a].name==" C4 " &&
(base=='a' || base=='g')) ||
(chain.residues[r].atoms[a].name==" C2 " &&
(base=='c' || base=='t' || base=='u')))
{
has_Cx=true;
Cx=chain.residues[r].atoms[a].xyz;
}
}
if (r+1<L) // find next residue atoms
{
for (a=0;a<chain.residues[r+1].atoms.size();a++)
{
if (chain.residues[r+1].atoms[a].name==" P ")
{
has_next_P=true;
next_P=chain.residues[r+1].atoms[a].xyz;
}
else if (chain.residues[r+1].atoms[a].name==" O5'")
{
has_next_O5=true;
next_O5=chain.residues[r+1].atoms[a].xyz;
}
else if (chain.residues[r+1].atoms[a].name==" C4'")
{
has_next_C4=true;
next_C4=chain.residues[r+1].atoms[a].xyz;
}
else if (chain.residues[r+1].atoms[a].name==" C1'")
{
has_next_C1=true;
next_C1=chain.residues[r+1].atoms[a].xyz;
}
}
}
if (show_tor)
{
if (has_C4 && has_O4 && has_C1 && has_C2) NaTorMat[r][0]=rad2deg(Points2Dihedral(C4,O4,C1,C2)); // v0
if (has_O4 && has_C1 && has_C2 && has_C3) NaTorMat[r][1]=rad2deg(Points2Dihedral(O4,C1,C2,C3)); // v1
if (has_C1 && has_C2 && has_C3 && has_C4) NaTorMat[r][2]=rad2deg(Points2Dihedral(C1,C2,C3,C4)); // v2 pucker
if (has_C2 && has_C3 && has_C4 && has_O4) NaTorMat[r][3]=rad2deg(Points2Dihedral(C2,C3,C4,O4)); // v3
if (has_C3 && has_C4 && has_O4 && has_C1) NaTorMat[r][4]=rad2deg(Points2Dihedral(C3,C4,O4,C1)); // v4
if (has_C5 && has_C4 && has_C3 && has_C2) NaTorMat[r][5]=rad2deg(Points2Dihedral(C5,C4,C3,C2)); // v5
if (has_C4 && has_C3 && has_C2 && has_O2) NaTorMat[r][6]=rad2deg(Points2Dihedral(C4,C3,C2,O2)); // v6
if (has_prev_C4 && has_P && has_C4 && has_next_P) NaTorMat[r][7]=rad2deg(Points2Dihedral(prev_C4,P,C4,next_P)); // eta
if (has_P && has_C4 && has_next_P && has_next_C4) NaTorMat[r][8]=rad2deg(Points2Dihedral(P,C4,next_P,next_C4)); // theta
if (has_prev_C1 && has_P && has_C1 && has_next_P) NaTorMat[r][9]=rad2deg(Points2Dihedral(prev_C1,P,C1,next_P)); // eta'
if (has_P && has_C1 && has_next_P && has_next_C1) NaTorMat[r][10]=rad2deg(Points2Dihedral(P,C1,next_P,next_C1)); // theta'
if (has_prev_O3 && has_P && has_O5 && has_C5) NaTorMat[r][11]=rad2deg(Points2Dihedral(prev_O3,P,O5,C5)); // alpha
if (has_P && has_O5 && has_C5 && has_C4) NaTorMat[r][12]=rad2deg(Points2Dihedral(P,O5,C5,C4)); // beta
if (has_O5 && has_C5 && has_C4 && has_C3) NaTorMat[r][13]=rad2deg(Points2Dihedral(O5,C5,C4,C3)); // gamma
if (has_C5 && has_C4 && has_C3 && has_O3) NaTorMat[r][14]=rad2deg(Points2Dihedral(C5,C4,C3,O3)); // delta
if (has_C4 && has_C3 && has_O3 && has_next_P) NaTorMat[r][15]=rad2deg(Points2Dihedral(C4,C3,O3,next_P)); // epsilon
if (has_C3 && has_O3 && has_next_P && has_next_O5)NaTorMat[r][16]=rad2deg(Points2Dihedral(C3,O3,next_P,next_O5));// zeta
if (has_C1 && has_C4 && has_P && has_next_P) NaTorMat[r][17]=rad2deg(Points2Dihedral(C1,C4,P,next_P)); // i1
if (has_O4 && has_C1 && has_Nx && has_Cx) NaTorMat[r][18]=rad2deg(Points2Dihedral(O4,C1,Nx,Cx)); // chi
}
if (show_len)
{
if (has_prev_P && has_P) NaLenMat[r][0] =Points2Distance(prev_P,P); // P[-1]-P
if (has_prev_O5 && has_O5) NaLenMat[r][1] =Points2Distance(prev_O5,O5); // O5'[-1]-O5'
if (has_prev_C5 && has_C5) NaLenMat[r][2] =Points2Distance(prev_C5,C5); // C5'[-1]-C5'
if (has_prev_C4 && has_C4) NaLenMat[r][3] =Points2Distance(prev_C4,C4); // C4'[-1]-C4'
if (has_prev_C3 && has_C3) NaLenMat[r][4] =Points2Distance(prev_C3,C3); // C3'[-1]-C3'
if (has_prev_O3 && has_O3) NaLenMat[r][5] =Points2Distance(prev_O3,O3); // O3'[-1]-O3'
if (has_prev_C2 && has_C2) NaLenMat[r][6] =Points2Distance(prev_C2,C2); // C2'[-1]-C2'
if (has_prev_C1 && has_C1) NaLenMat[r][7] =Points2Distance(prev_C1,C1); // C1'[-1]-C1'
if (has_prev_O4 && has_O4) NaLenMat[r][8] =Points2Distance(prev_O4,O4); // O4'[-1]-O4'
if (has_P && has_C4) NaLenMat[r][9] =Points2Distance(P,C4); // P-C4'
if (has_C4 && has_next_P) NaLenMat[r][10]=Points2Distance(C4,next_P); // C4'-P[+1]
if (has_P && has_C1) NaLenMat[r][11]=Points2Distance(P,C1); // P-C1'
if (has_C1 && has_next_P) NaLenMat[r][12]=Points2Distance(C1,next_P); // C1'-P[+1]
if (has_prev_O3 && has_O5) NaLenMat[r][13]=Points2Distance(prev_O3,O5); // O3'[-1]-O5'
if (has_P && has_C5) NaLenMat[r][14]=Points2Distance(P,C5); // P-C5'
if (has_C5 && has_C3) NaLenMat[r][15]=Points2Distance(C5,C3); // C5'-C3'
if (has_C4 && has_O3) NaLenMat[r][16]=Points2Distance(C4,O3); // C4'-O3'
if (has_C3 && has_next_P) NaLenMat[r][17]=Points2Distance(C3,next_P); // C3'-P[+1]
if (has_C4 && has_C2) NaLenMat[r][18]=Points2Distance(C4,C2); // C4'-C2'
if (has_O4 && has_C3) NaLenMat[r][19]=Points2Distance(O4,C3); // O4'-C3'
if (has_C4 && has_C1) NaLenMat[r][20]=Points2Distance(C4,C1); // C4'-C1'
if (has_C3 && has_C1) NaLenMat[r][21]=Points2Distance(C3,C1); // C3'-C1'
if (has_O4 && has_Nx) NaLenMat[r][22]=Points2Distance(O4,Nx); // O4'-N
if (has_prev_O3 && has_P) NaLenMat[r][23]=Points2Distance(prev_O3,P); // O3'[-1]-P
if (has_P && has_O5) NaLenMat[r][24]=Points2Distance(P,O5); // P-O5'
if (has_O5 && has_C5) NaLenMat[r][25]=Points2Distance(O5,C5); // O5'-C5'
if (has_C5 && has_C4) NaLenMat[r][26]=Points2Distance(C5,C4); // C5'-C4'
if (has_C4 && has_C3) NaLenMat[r][27]=Points2Distance(C4,C3); // C4'-C3'
if (has_C3 && has_O3) NaLenMat[r][28]=Points2Distance(C3,O3); // C3'-O3'
if (has_C3 && has_C2) NaLenMat[r][29]=Points2Distance(C3,C2); // C3'-C2'
if (has_C2 && has_C1) NaLenMat[r][30]=Points2Distance(C2,C1); // C2'-C1'
if (has_C4 && has_O4) NaLenMat[r][31]=Points2Distance(C4,O4); // C4'-O4'
if (has_O4 && has_C1) NaLenMat[r][32]=Points2Distance(O4,C1); // O4'-O1'
if (has_C2 && has_O2) NaLenMat[r][33]=Points2Distance(C2,O2); // C2'-O2'
if (has_C1 && has_Nx) NaLenMat[r][34]=Points2Distance(C1,Nx); // C1'-Nx
if (has_Nx && has_Cx) NaLenMat[r][35]=Points2Distance(Nx,Cx); // N-C
}
if (show_ang)
{
if (has_prev_C4 && has_P && has_C4) NaAngMat[r][0] =rad2deg(Points2Angle(prev_C4,P,C4)); // C4'[-1]-P-C4'
if (has_P && has_C4 && has_next_P) NaAngMat[r][1] =rad2deg(Points2Angle(P,C4,next_P)); // P-C4'-P[+1]
if (has_prev_C1 && has_P && has_C1) NaAngMat[r][2] =rad2deg(Points2Angle(prev_C1,P,C1)); // C1'[-1]-P-C1'
if (has_P && has_C1 && has_next_P) NaAngMat[r][3] =rad2deg(Points2Angle(P,C1,next_P)); // P-C1'-P[+1]
if (has_P && has_C4 && has_C1) NaAngMat[r][4] =rad2deg(Points2Angle(P,C4,C1)); // P-C4'-C1'
if (has_prev_O3 && has_P && has_O5) NaAngMat[r][5] =rad2deg(Points2Angle(prev_O3,P,O5)); // O3'[-1]-P-O5'
if (has_P && has_O5 && has_C5) NaAngMat[r][6] =rad2deg(Points2Angle(P,O5,C5)); // P-O5'-C5'
if (has_O5 && has_C5 && has_C4) NaAngMat[r][7] =rad2deg(Points2Angle(O5,C5,C4)); // O5'-C5'-C4'
if (has_C5 && has_C4 && has_C3) NaAngMat[r][8] =rad2deg(Points2Angle(C5,C4,C3)); // C5'-C4'-C3'
if (has_C4 && has_C3 && has_O3) NaAngMat[r][9] =rad2deg(Points2Angle(C4,C3,O3)); // C4'-C3'-O3'
if (has_C3 && has_O3 && has_next_P) NaAngMat[r][10]=rad2deg(Points2Angle(C3,O3,next_P)); // C3'-O3'-P[+1]
if (has_C4 && has_C3 && has_C2) NaAngMat[r][11]=rad2deg(Points2Angle(C4,C3,C2)); // C4'-C3'-C2'
if (has_O3 && has_C3 && has_C2) NaAngMat[r][12]=rad2deg(Points2Angle(O3,C3,C2)); // O3'-C3'-C2'
if (has_C3 && has_C2 && has_C1) NaAngMat[r][13]=rad2deg(Points2Angle(C3,C2,C1)); // C3'-C2'-C1'
if (has_C3 && has_C4 && has_O4) NaAngMat[r][14]=rad2deg(Points2Angle(C3,C4,O4)); // C3'-C4'-O4'
if (has_C5 && has_C4 && has_O4) NaAngMat[r][15]=rad2deg(Points2Angle(C5,C4,O4)); // C5'-C4'-O4'
if (has_C4 && has_O4 && has_C1) NaAngMat[r][16]=rad2deg(Points2Angle(C4,O4,C1)); // C4'-O4'-C1'
if (has_O4 && has_C1 && has_C2) NaAngMat[r][17]=rad2deg(Points2Angle(O4,C1,C2)); // O4'-C1'-C2'
if (has_O2 && has_C2 && has_C3) NaAngMat[r][18]=rad2deg(Points2Angle(O2,C2,C3)); // O2'-C2'-C3'
if (has_O4 && has_C1 && has_Nx) NaAngMat[r][19]=rad2deg(Points2Angle(O4,C1,Nx)); // O4'-C1'-Nx
if (has_C1 && has_Nx && has_Cx) NaAngMat[r][20]=rad2deg(Points2Angle(C1,Nx,Cx)); // C1'-Nx-Cx
}
}
tmp_tor.clear();
tmp_len.clear();
tmp_ang.clear();
prev_C4.clear();
prev_C1.clear();
prev_O3.clear();
P.clear();
O5.clear();
C5.clear();
C4.clear();
C3.clear();
C2.clear();
C1.clear();
O4.clear();
O3.clear();
Nx.clear();
Cx.clear();
next_P.clear();
next_O5.clear();
next_C4.clear();
next_C1.clear();
return;
}
#endif