-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotorsion.c
388 lines (356 loc) · 9.98 KB
/
dotorsion.c
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
* v 2 add ring awarness
* 3 rings have no torsions
* 4,5,... ? rings have increased torsions
*
* 3/5/03
*/
/* preammp.c
*
* prepare ammp files using UFF type potentials
* dictionary entries for bonds
*
* nbond (general and special)
* as res.atom res.atom order
* or bond res.atom res.atom r k for specials
*
*
**rules for geometry
**
**1) every pair of bonds with one common atom determine an angle
**2) every set of three bonds where 1 and 3 share half of 2
** i.e. a-b, b-c, c-d
** defines a torsion.
**3) special chiral centers are hand coded for each residue
**4) Planar torsions are hand coded for unified atom models, but
** in general occur when three bonds exist with a common c_2 or o_2
** atom.
**5) inversion hybrids are generally ignored, but are defined for a
** a_n atom when n bonds exist with a as a common atom.
*
*/
#define ANSI 1
/* misc includes - ANSI and some are just to be safe */
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#ifdef ANSI
#include <stdlib.h>
#endif
#include "uff.h"
/* uff.h defines NAME_LENGTH == length of an atom id
* (Name_length+1 space reserved for \0)
* and SIG_DIGIT == size of number or identifier in special
* structure (SIG_DIGIT+1 space reserved for \0)
*/
/* copyright 1993 robert w. harrison
* this notice may not be removed
* the author(s) and his sponsoring institution (TJU)
* reserve all commercial rights including the right
* to modify this notice. This code may be
* freely distributed for non-commercial scientific
* use.
*/
/* atom kinds are defined globally */
#define MAX_ATOM 300
extern ATOMDATA kinds[MAX_ATOM];
extern int inkinds;
/* maximum number of atoms is a residue */
#define MAX_RES 300
extern float x[MAX_RES], y[MAX_RES], z[MAX_RES];
extern float a[MAX_RES],b[MAX_RES],q[MAX_RES];
extern float mass[MAX_RES];
extern int serial[MAX_RES],defined[MAX_RES];
extern int mykind[MAX_RES];
extern char name[MAX_RES][20];
extern int inres;
/* space for special stuff */
#define MAX_SP 300
/* the array for the bonds */
extern int bondlist[1000][2],inbondlist; /* more than enough */
extern float rijlist[1000],orderlist[1000];
extern int torsionlist[1000][4],intorsionlist;
static int ringlist[1000];
static int anglelist[1000][3],inanglelist;
/* this anglelist is different from the extern one in that it is the
* list of all the angles that are generated from bonds */
do_torsion(dict, ntorsion, output )
FILE *dict,*output;
int ntorsion; /* the number of special angles can be zero */
{ /* start of routine */
int i,j,k,l,m;
int right, left ;
int i1,i2,i3,i4, match_label();
char line[256],token[7][80];
int bondedr[1000],inbondedr;
int bondedl[1000],inbondedl;
int n;
float offset,kijkl;
/* initialize and build the ring lists */
init_ringlist();
init_anglelist();
three_four_five_ringlist();
intorsionlist = 0;
/* do the special angles if any */
for( l=0; l< ntorsion; l++)
{
if( fgets(line,256,dict) == NULL)
{ /* premature end of file is a fatal error */
fprintf(stderr," FATAL error, end of file in a dictionary ");
exit(0);
}
/* now parse out the first term */
i = 0;
while((line[i] == ' ' || line[i] == '\t') && line[i] != '\0' ) i++;
j = 0;
while( (line[i] != ' ' && line[i] != ',') && (line[i] != '\0'
&& line[i] != '\n')) token[0][j++] = line[i++];
token[0][j] = '\0';
while((line[i] == ' ' || line[i] == '\t') && line[i] != '\0' ) i++;
j = 0;
while( (line[i] != ' ' && line[i] != ',') && (line[i] != '\0'
&& line[i] != '\n')) token[1][j++] = line[i++];
token[1][j] = '\0';
while((line[i] == ' ' || line[i] == '\t') && line[i] != '\0' ) i++;
j = 0;
while( (line[i] != ' ' && line[i] != ',') && (line[i] != '\0'
&& line[i] != '\n')) token[2][j++] = line[i++];
token[2][j] = '\0';
while((line[i] == ' ' || line[i] == '\t') && line[i] != '\0' ) i++;
j = 0;
while( (line[i] != ' ' && line[i] != ',') && (line[i] != '\0'
&& line[i] != '\n')) token[3][j++] = line[i++];
token[3][j] = '\0';
while((line[i] == ' ' || line[i] == '\t') && line[i] != '\0' ) i++;
j = 0;
while( (line[i] != ' ' && line[i] != ',') && (line[i] != '\0'
&& line[i] != '\n')) token[4][j++] = line[i++];
token[4][j] = '\0';
while((line[i] == ' ' || line[i] == '\t') && line[i] != '\0' ) i++;
j = 0;
while( (line[i] != ' ' && line[i] != ',') && (line[i] != '\0'
&& line[i] != '\n')) token[5][j++] = line[i++];
token[5][j] = '\0';
j = 0;
while( (line[i] != ' ' && line[i] != ',') && (line[i] != '\0'
&& line[i] != '\n')) token[6][j++] = line[i++];
token[6][j] = '\0';
i1 = match_label( &token[0][0]);
i2 = match_label( &token[1][0]);
i3 = match_label( &token[2][0]);
i4 = match_label( &token[3][0]);
torsionlist[intorsionlist][0] = i1;
torsionlist[intorsionlist][1] = i2;
torsionlist[intorsionlist][2] = i3;
torsionlist[intorsionlist][3] = i4;
intorsionlist += 1;
fprintf( output,"torsion %d %d %d %d %s %s %s ;\n",
serial[i1],serial[i2],serial[i3],serial[i4],&token[4][0],&token[5][0],
&token[6][0]);
}/* end of special torsion loop */
for( i=0; i< inbondlist; i++)
{ /* for each bond */
inbondedl = 0;
for( k=0; k< inbondlist; k++)
{ if( k != i)
{
if( bondlist[k][0] == bondlist[i][1])
{ bondedl[inbondedl] = bondlist[k][1];
inbondedl += 1;}
if( bondlist[k][1] == bondlist[i][1])
{ bondedl[inbondedl] = bondlist[k][0];
inbondedl += 1;}
}
}
inbondedr = 0;
for( k=0; k< inbondlist; k++)
{ if( k != i)
{
if( bondlist[k][0] == bondlist[i][0])
{ bondedr[inbondedr] = bondlist[k][1];
inbondedr += 1;}
if( bondlist[k][1] == bondlist[i][0])
{ bondedr[inbondedr] = bondlist[k][0];
inbondedr += 1;}
}
}
/* skip if terminal or theta == 180 */
/*if( inbondedr > 0 && inbondedl > 0
&& (kinds[mykind[right]].theta <179. && kinds[mykind[left]].theta< 179.))
*/
if( inbondedr > 0 && inbondedl > 0 )
{ /* only do torsions when there are some */
/* sp2 atoms do not possess kinds.V > 0 */
/* sp1 atoms have 180 as theta */
right = bondlist[i][0];
left = bondlist[i][1]; /* note right and left are arb. */
if( kinds[mykind[right]].V > 0. &&
kinds[mykind[left]].V > 0.)
{ /* sp3 sp3 */
n = 3; offset = 0.;
kijkl = sqrt(kinds[mykind[left]].V*kinds[mykind[right]].V);
if( ringlist[i] == 3) kijkl *= 6.;
if( ringlist[i] == 4) kijkl *= 3.;
if( ringlist[i] == 5) kijkl *= 1.5;
} else
if( (kinds[mykind[right]].V > 0. &&
kinds[mykind[left]].V < 0.) ||
( kinds[mykind[right]].V < 0. &&
kinds[mykind[left]].V > 0.) )
{ /* sp3 sp2 */
/* n is complicated
*
* sp3 sp3 sp2 x n=3 ,180.
* sp2 sp3 sp2 x n = 6 ,180.
*/
n = 3; offset = 180.;
for( l=0; l< inbondedr ;l++)
for( k=0; k< inbondedl ;k++)
{
i1 = bondedr[l];
i4 = bondedl[k];
if((kinds[mykind[right]].V > 0. && kinds[mykind[i1]].V < 0. )
|| (kinds[mykind[left]].V> 0. &&kinds[mykind[i4]].V < 0.))
n = 6; offset = 180.;
}
kijkl = 1.;
kijkl = sqrt(kinds[mykind[left]].U*kinds[mykind[right]].U);
kijkl = 5.*kijkl*(1.+ 4.18*log( orderlist[i]));
} else
if( kinds[mykind[right]].V < 0. &&
kinds[mykind[left]].V < 0.)
{ /* sp2 sp2 */
n = 2; offset = 180.;
kijkl = sqrt(kinds[mykind[left]].U*kinds[mykind[right]].U);
kijkl = 5.*kijkl*(1.+ 4.18*log( orderlist[i]));
}
if( kinds[mykind[left]].theta > 170. ) kijkl = 0.;
if( kinds[mykind[right]].theta > 170. ) kijkl = 0.;
kijkl = kijkl/inbondedr/inbondedl;
i2 = right;
i3 = left;
for( l=0; l< inbondedr ;l++)
for( k=0; k< inbondedl ;k++)
{
i1 = bondedr[l];
i4 = bondedl[k];
fprintf( output," torsion %d %d %d %d %f %d %f ;\n",
serial[i1],serial[i2],serial[i3],serial[i4],
kijkl,n,offset);
}
} /* end of inbondedr > 0 if */
}/* end of bond loop */
} /* end of do_torsion */
int init_ringlist()
{
int i;
for( i=0; i< inbondlist; i++)
ringlist[i] = 0;
}
int init_anglelist()
{
int i,j;
inanglelist = 0;
for( i=0; i< inbondlist; i++)
{
int i1,i2,j1,j2,j3;
i1 = bondlist[i][0];
i2 = bondlist[i][1];
for( j=0; j< inbondlist; j++)
{ if( j == i) continue;
j1 = bondlist[j][0];
j2 = bondlist[j][1];
if( j1 == i1)
{
anglelist[inanglelist][0] = j2;
anglelist[inanglelist][1] = i1;
anglelist[inanglelist++][2] = i2;
}
if( j2 == i1)
{
anglelist[inanglelist][0] = j1;
anglelist[inanglelist][1] = i1;
anglelist[inanglelist++][2] = i2;
}
if( j1 == i2)
{
anglelist[inanglelist][0] = j2;
anglelist[inanglelist][1] = i2;
anglelist[inanglelist++][2] = i1;
}
if( j2 == i2)
{
anglelist[inanglelist][0] = j1;
anglelist[inanglelist][1] = i2;
anglelist[inanglelist++][2] = i1;
}
}/* j */
}/* i */
}
int three_four_five_ringlist( )
{
int i,j,k,l, i1,i2,j1,j2;
int rightbond[100],leftbond[100];
int inright,inleft;
for( i=0; i< inbondlist; i++)
{
/* build the right/left bond list */
inright = 0;
inleft = 0;
i1 = bondlist[i][0];
i2 = bondlist[i][1];
for( j=0; j< inbondlist; j++)
{
if( j == i) continue;
j1 = bondlist[j][0];
j2 = bondlist[j][1];
if( j1 == i1) rightbond[inright++] = j2;
if( j2 == i1) rightbond[inright++] = j1;
if( j1 == i2) leftbond[inleft++] = j2;
if( j2 == i2) leftbond[inleft++] = j1;
}/* j */
/* no rings if no bonds */
if( inleft == 0 || inright == 0) continue;
/* now to check for a threebond there is an identical atom in right and left */
for( k=0; k< inright; k++)
for( l = 0; l < inleft; l++)
{ if( rightbond[k] == leftbond[l] )
{ ringlist[i] = 3; break; }
}/* k,l */
if( ringlist[i] > 0 ) continue; /* cant be 3 and 4 and ... */
for( k=0; k< inright; k++)
for( l = 0; l < inleft; l++)
{
int m;
for(m=0; m < inbondlist; m++)
{
if( m == i) continue;
j1 = bondlist[m][0];
j2 = bondlist[m][1];
if( (rightbond[k] == j1 && leftbond[l] == j2) ||
(rightbond[k] == j2 && leftbond[l] == j1) )
{
ringlist[i] = 4; break;
}
}/* m */
if( ringlist[i] == 4) break;
}/* k,l */
if( ringlist[i] > 0 ) continue; /* cant be 3 and 4 and ... */
for( k=0; k< inright; k++)
for( l = 0; l < inleft; l++)
{
int m;
for(m=0; m < inanglelist; m++)
{
j1 = anglelist[m][0];
j2 = anglelist[m][2];
if( (rightbond[k] == j1 && leftbond[l] == j2) ||
(rightbond[k] == j2 && leftbond[l] == j1) )
{
ringlist[i] = 5; break;
}
}/* m */
}/* k,l */
}/* i */
}