ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/ktorsion.c
Revision: 90
Committed: Fri Jan 16 21:55:34 2009 UTC (12 years, 10 months ago) by gilbertke
File size: 16686 byte(s)
Log Message:
code cleanup
Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4 #include "pcmod.h"
5 #include "torsions.h"
6 #include "rings.h"
7 #include "field.h"
8 #include "atom_k.h"
9
10 int isbond(int,int);
11 int is_delocalbond(int,int);
12 void numeral(int,char *,int);
13 void angle(int,int,int,float *);
14 void four(char *,char *,char *,char *, char *);
15 int is_ring42(int,int);
16 int is_ring54(int, int, int, int);
17 void message_alert(char *, char *);
18
19 EXTERN struct t_allene {
20 int nallene, ntor[10];
21 } allene;
22
23
24 EXTERN struct t_torkn1 {
25 int use_tor4, use_tor5;
26 int ntor, ntor4, ntor5, ntordel, torindex[MAXTORDEL];
27 char kv[MAXTORCONST][13], kv4[MAXTOR4CONST][13], kv5[MAXTOR5CONST][13];
28 char kvdel[MAXTORDEL][13];
29 float tv1[MAXTORCONST], tv2[MAXTORCONST], tv3[MAXTORCONST];
30 float tv4[MAXTORCONST], tv5[MAXTORCONST], tv6[MAXTORCONST];
31 int phase1[MAXTORCONST], phase2[MAXTORCONST], phase3[MAXTORCONST];
32 int phase4[MAXTORCONST], phase5[MAXTORCONST], phase6[MAXTORCONST];
33 float tv41[MAXTOR4CONST], tv42[MAXTOR4CONST], tv43[MAXTOR4CONST];
34 int phase41[MAXTOR4CONST], phase42[MAXTOR4CONST], phase43[MAXTOR4CONST];
35 float tv51[MAXTOR5CONST], tv52[MAXTOR5CONST], tv53[MAXTOR5CONST];
36 int phase51[MAXTOR5CONST], phase52[MAXTOR5CONST], phase53[MAXTOR5CONST];
37 float tvdel1[MAXTORDEL], tvdel2[MAXTORDEL], tvdel3[MAXTORDEL];
38 int phasedel1[MAXTORDEL], phasedel2[MAXTORDEL], phasedel3[MAXTORDEL];
39 } torkn1;
40
41 EXTERN struct t_torknp {
42 int npitor;
43 char kp[MAXPITORCONST][13];
44 int ph1[MAXPITORCONST], ph2[MAXPITORCONST], ph3[MAXPITORCONST];
45 float tv1[MAXPITORCONST], tv2[MAXPITORCONST], tv3[MAXPITORCONST];
46 } torknp;
47
48 EXTERN int Missing_constants;
49
50 void ktorsion()
51 {
52 int i, j, ierr, itor, ii, ki, k;
53 int ia, ib, ic, id;
54 int ita, itb, itc, itd;
55 int cl_a, cl_b, cl_c, cl_d;
56 int use_ring4, use_ring5;
57 long int mask;
58 char izero[4];
59 char pa[4],pb[4],pc[4],pd[4],pt[13], kv1[13];
60 char k1[13], k2[13], k3[13], k4[13], k5[13], k6[13], k7[13], k8[13], k9[13], k10[13],
61 k11[13], k12[13], k13[13], k14[13], k15[13];
62 float v1, v2, v3, rangle;
63
64 mask = (1L << 0);
65 itor = 0;
66 use_ring4 = FALSE;
67 if (rings.nring4 > 0 && torkn1.ntor4 > 0)
68 use_ring4 = TRUE;
69
70 use_ring5 = FALSE;
71 if (rings.nring5 > 0 && torkn1.ntor5 > 0)
72 use_ring5 = TRUE;
73
74 for (i=0; i < torsions.ntor; i++)
75 {
76 ia = torsions.i14[i][0];
77 ib = torsions.i14[i][1];
78 ic = torsions.i14[i][2];
79 id = torsions.i14[i][3];
80
81 ita = atom[ia].type;
82 itb = atom[ib].type;
83 itc = atom[ic].type;
84 itd = atom[id].type;
85
86 cl_a = atom[ia].tclass;
87 cl_b = atom[ib].tclass;
88 cl_c = atom[ic].tclass;
89 cl_d = atom[id].tclass;
90
91 if (field.type == MMX)
92 {
93 if (ita == 40)
94 ita = 2;
95 if (itb == 40)
96 itb = 2;
97 if (itc == 40)
98 itc = 2;
99 if (itd == 40)
100 itd = 2;
101
102 if (ita == 56 && itb == 56 && itc == 56 && itd == 56)
103 {
104 ita = 1; itb = 1; itc = 1; itd = 1;
105 }
106 }
107 numeral(ita,pa,3);
108 numeral(itb,pb,3);
109 numeral(itc,pc,3);
110 numeral(itd,pd,3);
111
112 if (itb < itc )
113 four(pa,pb, pc, pd, pt);
114 else if (itb > itc)
115 four(pd,pc, pb, pa, pt);
116 else if (ita < itd)
117 four(pa,pb, pc, pd, pt);
118 else
119 four(pd,pc, pb, pa, pt);
120 strcpy(izero," 0");
121
122 if (field.type == MMFF94)
123 {
124
125 numeral(atom_k.tclass1[ita],pa,3);
126 numeral(atom_k.tclass[itb],pb,3);
127 numeral(atom_k.tclass[itc],pc,3);
128 numeral(atom_k.tclass1[itd],pd,3);
129
130
131 if (atom_k.tclass[itb] < atom_k.tclass[itc] )
132 {
133 four(pa, pb, pc, izero,k2);
134 four(izero ,pb, pc, pd,k3);
135 } else if (atom_k.tclass[itb] > atom_k.tclass[itc])
136 {
137 four(izero,pc, pb, pa, k2);
138 four(pd,pc, pb, izero, k3);
139 } else if (atom_k.tclass1[ita] < atom_k.tclass1[itd])
140 {
141 four(pa,pb, pc, izero, k2);
142 four(izero,pb, pc, pd, k3);
143 } else
144 {
145 four(izero,pc, pb, pa, k2);
146 four(pd,pc, pb, izero, k3);
147 }
148 } else
149 {
150 four( izero, pc, pb, pa, k1 );
151 four( pd, pc, pb, izero, k2 );
152 four( izero, pb, pc, pd, k3 );
153 }
154
155 numeral(ita,pa,3);
156 numeral(itb,pb,3);
157 numeral(itc,pc,3);
158 numeral(itd,pd,3);
159
160 four( pa, pb, pc, izero, k4 );
161 four( izero, pc, pb, izero, k5 );
162 four( izero, pb, pc, izero, k6 );
163 four( pd, pc, izero, izero, k7 );
164 four( izero, izero, pc,pd, k8 );
165
166 four( izero, izero, pb, pa, k9 );
167 four( pa, pb, izero, izero, k10 );
168 four( izero, izero, pc, izero, k11 );
169 four( izero, pc, izero, izero, k12 );
170 four( izero, izero, pb, izero, k13 );
171 four( izero, pb, izero, izero, k14 );
172
173 numeral(cl_a,pa,3);
174 numeral(cl_b,pb,3);
175 numeral(cl_c,pc,3);
176 numeral(cl_d,pd,3);
177 if (itb < itc )
178 four(pa,pb, pc, pd, k15);
179 else if (itb > itc)
180 four(pd,pc, pb, pa, k15);
181 else if (ita < itd)
182 four(pa,pb, pc, pd, k15);
183 else
184 four(pd,pc, pb, pa, k15);
185
186 ierr = FALSE;
187 // check for four membered rings
188 if ( isbond(ia,id) )
189 {
190 for(j=0; j < torkn1.ntor4; j++)
191 {
192 strcpy(kv1,torkn1.kv4[j]);
193 if (strcmp(pt,kv1) == 0 || strcmp(k1,kv1) == 0 || strcmp(k2,kv1) == 0 || strcmp(k3,kv1) == 0 ||
194 strcmp(k4,kv1) == 0 || strcmp(k5,kv1) == 0 || strcmp(k6,kv1) == 0 || strcmp(k7,kv1) == 0 ||
195 strcmp(k8,kv1) == 0 || strcmp(k9,kv1) == 0 || strcmp(k10,kv1) == 0 || strcmp(k11,kv1) == 0 ||
196 strcmp(k12,kv1) == 0 || strcmp(k13,kv1) == 0 || strcmp(k14,kv1) == 0 )
197 {
198 torsions.v1[i] = torkn1.tv41[j];
199 torsions.ph1[i] = torkn1.phase41[j];
200 torsions.v2[i] = torkn1.tv42[j];
201 torsions.ph2[i] = torkn1.phase42[j];
202 torsions.v3[i] = torkn1.tv43[j];
203 torsions.ph3[i] = torkn1.phase43[j];
204 ierr = TRUE;
205 goto L_10;
206 }
207 }
208 }
209 // delocalized torsions
210 if ( is_delocalbond(ib,ic) )
211 {
212 for(j=0; j < torkn1.ntordel; j++)
213 {
214 strcpy(kv1,torkn1.kvdel[j]);
215 if (strcmp(pt,kv1) == 0 || strcmp(k1,kv1) == 0 || strcmp(k2,kv1) == 0 || strcmp(k3,kv1) == 0 ||
216 strcmp(k4,kv1) == 0 || strcmp(k5,kv1) == 0 || strcmp(k6,kv1) == 0 || strcmp(k7,kv1) == 0 ||
217 strcmp(k8,kv1) == 0 || strcmp(k9,kv1) == 0 || strcmp(k10,kv1) == 0 || strcmp(k11,kv1) == 0 ||
218 strcmp(k12,kv1) == 0 || strcmp(k13,kv1) == 0 || strcmp(k14,kv1) == 0 )
219 {
220 torsions.v1[i] = torkn1.tvdel1[j];
221 torsions.ph1[i] = torkn1.phasedel1[j];
222 torsions.v2[i] = torkn1.tvdel2[j];
223 torsions.ph2[i] = torkn1.phasedel2[j];
224 torsions.v3[i] = torkn1.tvdel3[j];
225 torsions.ph3[i] = torkn1.phasedel3[j];
226 ierr = TRUE;
227 goto L_10;
228 }
229 }
230 }
231 // check for five membered rings
232 if (is_ring54(ia,ib,ic,id) )
233 {
234 for(j=0; j < torkn1.ntor5; j++)
235 {
236 strcpy(kv1,torkn1.kv5[j]);
237 if (strcmp(pt,kv1) == 0 || strcmp(k1,kv1) == 0 || strcmp(k2,kv1) == 0 || strcmp(k3,kv1) == 0 ||
238 strcmp(k4,kv1) == 0 || strcmp(k5,kv1) == 0 || strcmp(k6,kv1) == 0 || strcmp(k7,kv1) == 0 ||
239 strcmp(k8,kv1) == 0 || strcmp(k9,kv1) == 0 || strcmp(k10,kv1) == 0 || strcmp(k11,kv1) == 0 ||
240 strcmp(k12,kv1) == 0 || strcmp(k13,kv1) == 0 || strcmp(k14,kv1) == 0 )
241 {
242 torsions.v1[i] = torkn1.tv51[j];
243 torsions.ph1[i] = torkn1.phase51[j];
244 torsions.v2[i] = torkn1.tv52[j];
245 torsions.ph2[i] = torkn1.phase52[j];
246 torsions.v3[i] = torkn1.tv53[j];
247 torsions.ph3[i] = torkn1.phase53[j];
248 ierr = TRUE;
249 goto L_10;
250 }
251 }
252 }
253 // check regular parameters
254 if (field.type == MMFF94)
255 {
256 for(j=0; j < torkn1.ntor; j++) // specific constants
257 {
258 strcpy(kv1,torkn1.kv[j]);
259 if (strcmp(pt,kv1) == 0)
260 {
261 torsions.v1[i] = torkn1.tv1[j];
262 torsions.ph1[i] = torkn1.phase1[j];
263 torsions.v2[i] = torkn1.tv2[j];
264 torsions.ph2[i] = torkn1.phase2[j];
265 torsions.v3[i] = torkn1.tv3[j];
266 torsions.ph3[i] = torkn1.phase3[j];
267 torsions.v4[i] = torkn1.tv4[j];
268 torsions.ph4[i] = torkn1.phase4[j];
269 torsions.v5[i] = torkn1.tv5[j];
270 torsions.ph5[i] = torkn1.phase5[j];
271 torsions.v6[i] = torkn1.tv6[j];
272 torsions.ph6[i] = torkn1.phase6[j];
273 goto L_10;
274 }
275 }
276 for(j=0; j < torkn1.ntor; j++) // class 2
277 {
278 strcpy(kv1,torkn1.kv[j]);
279 if (strcmp(k2,kv1) == 0 || strcmp(k3,kv1) == 0 )
280 {
281 torsions.v1[i] = torkn1.tv1[j];
282 torsions.ph1[i] = torkn1.phase1[j];
283 torsions.v2[i] = torkn1.tv2[j];
284 torsions.ph2[i] = torkn1.phase2[j];
285 torsions.v3[i] = torkn1.tv3[j];
286 torsions.ph3[i] = torkn1.phase3[j];
287 torsions.v4[i] = torkn1.tv4[j];
288 torsions.ph4[i] = torkn1.phase4[j];
289 torsions.v5[i] = torkn1.tv5[j];
290 torsions.ph5[i] = torkn1.phase5[j];
291 torsions.v6[i] = torkn1.tv6[j];
292 torsions.ph6[i] = torkn1.phase6[j];
293 goto L_10;
294 }
295 }
296 for(j=0; j < torkn1.ntor; j++) // wild cards
297 {
298 strcpy(kv1,torkn1.kv[j]);
299 if (strcmp(k5,kv1) == 0 || strcmp(k6,kv1) == 0 || strcmp(k7,kv1) == 0 || strcmp(k8,kv1) == 0 )
300 {
301 torsions.v1[i] = torkn1.tv1[j];
302 torsions.ph1[i] = torkn1.phase1[j];
303 torsions.v2[i] = torkn1.tv2[j];
304 torsions.ph2[i] = torkn1.phase2[j];
305 torsions.v3[i] = torkn1.tv3[j];
306 torsions.ph3[i] = torkn1.phase3[j];
307 torsions.v4[i] = torkn1.tv4[j];
308 torsions.ph4[i] = torkn1.phase4[j];
309 torsions.v5[i] = torkn1.tv5[j];
310 torsions.ph5[i] = torkn1.phase5[j];
311 torsions.v6[i] = torkn1.tv6[j];
312 torsions.ph6[i] = torkn1.phase6[j];
313 goto L_10;
314 }
315 }
316 }
317 // check regular specific parameters
318 for(j=0; j < torkn1.ntor; j++)
319 {
320 strcpy(kv1,torkn1.kv[j]);
321 if (strcmp(pt,kv1) == 0)
322 {
323 torsions.v1[i] = torkn1.tv1[j];
324 torsions.ph1[i] = torkn1.phase1[j];
325 torsions.v2[i] = torkn1.tv2[j];
326 torsions.ph2[i] = torkn1.phase2[j];
327 torsions.v3[i] = torkn1.tv3[j];
328 torsions.ph3[i] = torkn1.phase3[j];
329 torsions.v4[i] = torkn1.tv4[j];
330 torsions.ph4[i] = torkn1.phase4[j];
331 torsions.v5[i] = torkn1.tv5[j];
332 torsions.ph5[i] = torkn1.phase5[j];
333 torsions.v6[i] = torkn1.tv6[j];
334 torsions.ph6[i] = torkn1.phase6[j];
335 // check for pi torsions = mm3 does not define pitorsion parameter so we need to pick it up here
336 if (itb == 2 && itc == 2 && field.type == MMX)
337 {
338 for (k=0; k < MAXIAT; k++)
339 {
340 if (atom[ib].iat[k] == ic)
341 {
342 if (atom[ib].bo[k] == 1 && is_delocalbond(ib,ic) )
343 {
344 torsions.v1[i] = 0.5;
345 torsions.v2[i] = 1.0;
346 torsions.v3[i] = 0.0;
347 ierr = TRUE;
348 goto L_10;
349 break;
350 }
351 }
352 }
353 }
354 goto L_10;
355 break;
356 }
357 }
358 // check regular generalized parameters
359 for(j=0; j < torkn1.ntor; j++)
360 {
361 strcpy(kv1,torkn1.kv[j]);
362 if (strcmp(pt,kv1) == 0 || strcmp(k1,kv1) == 0 || strcmp(k2,kv1) == 0 || strcmp(k3,kv1) == 0 ||
363 strcmp(k4,kv1) == 0 || strcmp(k5,kv1) == 0 || strcmp(k6,kv1) == 0 || strcmp(k7,kv1) == 0 ||
364 strcmp(k8,kv1) == 0 || strcmp(k9,kv1) == 0 || strcmp(k10,kv1) == 0 || strcmp(k11,kv1) == 0 ||
365 strcmp(k12,kv1) == 0 || strcmp(k13,kv1) == 0 || strcmp(k14,kv1) == 0 || strcmp(k15,kv1) == 0)
366 {
367 torsions.v1[i] = torkn1.tv1[j];
368 torsions.ph1[i] = torkn1.phase1[j];
369 torsions.v2[i] = torkn1.tv2[j];
370 torsions.ph2[i] = torkn1.phase2[j];
371 torsions.v3[i] = torkn1.tv3[j];
372 torsions.ph3[i] = torkn1.phase3[j];
373 torsions.v4[i] = torkn1.tv4[j];
374 torsions.ph4[i] = torkn1.phase4[j];
375 torsions.v5[i] = torkn1.tv5[j];
376 torsions.ph5[i] = torkn1.phase5[j];
377 torsions.v6[i] = torkn1.tv6[j];
378 torsions.ph6[i] = torkn1.phase6[j];
379 // check for pi torsions = mm3 does not define pitorsion parameter so we need to pick it up here
380 if (itb == 2 && itc == 2 && field.type == MMX)
381 {
382 for (k=0; k < MAXIAT; k++)
383 {
384 if (atom[ib].iat[k] == ic)
385 {
386 if (atom[ib].bo[k] == 1 && is_delocalbond(ib,ic) )
387 {
388 torsions.v1[i] = 0.5;
389 torsions.v2[i] = 1.0;
390 torsions.v3[i] = 0.0;
391 ierr = TRUE;
392 goto L_10;
393 break;
394 }
395 }
396 }
397 }
398 goto L_10;
399 break;
400 }
401 }
402 // missing parameters
403 if (ierr == FALSE)
404 {
405 // Missing_constants = TRUE;
406 fprintf(pcmlogfile,"Torsion constants missing: angle: %d %d %d %d types: %d %d %d %d\n",ia,ib,ic,id,
407 ita, itb, itc, itd);
408 }
409 L_10:
410 continue;
411 }
412
413 if (allene.nallene > 0)
414 {
415 for (i = 0; i < allene.nallene; i++)
416 {
417 torsions.v1[allene.ntor[i]] = 0;
418 torsions.v2[allene.ntor[i]] = -11.5;
419 torsions.v3[allene.ntor[i]] = 0;
420 }
421 }
422 }
423 /* -------------------------------------------- */
424 void four(char *pa, char *pb, char *pc, char *pd, char *pt)
425 {
426 strcpy(pt,pa);
427 strcat(pt,pb);
428 strcat(pt,pc);
429 strcat(pt,pd);
430 }