ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/branches/sync4pymol12/src/mengine/src/kangle.c
Revision: 99
Committed: Mon Jan 19 04:31:29 2009 UTC (10 years, 6 months ago) by wdelano
File size: 22429 byte(s)
Log Message:
synchronized with trunk, less openmp lib/include
Line File contents
1 #define EXTERN extern
2 #include "pcwin.h"
3 #include "pcmod.h"
4
5 #include "angles.h"
6 #include "rings.h"
7 #include "field.h"
8 #include "bonds_ff.h"
9 #include "atom_k.h"
10
11 int is_ring43(int, int, int);
12 int is_ring53(int, int, int);
13 int is_ring63(int, int, int);
14 int is_delocalbond(int, int);
15 int isbond(int,int);
16 int find_bond(int,int);
17 long ipack(int ,int ,int ,int);
18 long kang(int,int,int);
19 void numeral(int,char *,int);
20 float get_general_angle(int);
21
22
23 EXTERN struct t_angk1 {
24 int use_ang3, use_ang4, use_ang5;
25 int nang, nang3, nang4, nang5;
26 int ndel, ndel3, ndel4;
27 char ktype[MAXANGCONST][10],ktype3[MAXANG3CONST][10],ktype4[MAXANG4CONST][10],ktype5[MAXANG5CONST][10];
28 char kdel[MAXANGDEL][10],kdel3[MAXANG3DEL][10],kdel4[MAXANG4DEL][10];
29 float con[MAXANGCONST], ang[MAXANGCONST][3];
30 float con3[MAXANG3CONST], ang3[MAXANG3CONST][3];
31 float con4[MAXANG4CONST], ang4[MAXANG4CONST][3];
32 float con5[MAXANG5CONST], ang5[MAXANG5CONST][3];
33 float condel[MAXANGDEL], angdel[MAXANGDEL][3];
34 float condel3[MAXANG3DEL], angdel3[MAXANG3DEL][3];
35 float condel4[MAXANG4DEL], angdel4[MAXANG4DEL][3];
36 } angk1;
37
38 EXTERN int Missing_constants;
39
40 void kangle()
41 {
42 int i, j, k, izero, ierr, nh, nRc, nligand, jji;
43 int ia, ib, ic, ie;
44 int iaa, ibb, icc;
45 int cl_a, cl_b, cl_c;
46 int nbo1, nb1, nb2;
47 char pa[4],pb[4],pc[4],pt[10], pt1[10], pt2[10],pt3[10], pt4[10], pt5[10], pt6[10], pt7[10];
48 char zero[4];
49 float bkan, at;
50
51 if( angles.nang != 0 )
52 {
53 for( i = 0; i < angles.nang; i++ )
54 {
55 ia = angles.i13[i][0];
56 ib = angles.i13[i][1];
57 ic = angles.i13[i][2];
58 iaa = atom[ia].type;
59 ibb = atom[ib].type;
60 icc = atom[ic].type;
61 cl_a = atom[ia].tclass;
62 cl_b = atom[ib].tclass;
63 cl_c = atom[ic].tclass;
64
65 /* get bond index each bond for MMFF94 */
66 nb1 = find_bond(ia,ib);
67 nb2 = find_bond(ib,ic);
68
69 /* special metal cases */
70 if( iaa >= 300)
71 cl_a = 300;
72
73 if( ibb >= 300)
74 cl_b = 300;
75
76 if( icc >= 300)
77 cl_c = 300;
78
79 /* special MMX cases */
80 if ( field.type == MMX)
81 {
82 if( iaa == 40 )
83 iaa = 2;
84
85 if( ibb == 40 )
86 ibb = 2;
87
88 if( icc == 40 )
89 icc = 2;
90
91 }
92 numeral(iaa,pa,3);
93 numeral(ibb,pb,3);
94 numeral(icc,pc,3);
95 if( iaa <= icc )
96 {
97 strcpy(pt,pa);
98 strcat(pt,pb);
99 strcat(pt,pc);
100 }
101 if( iaa > icc )
102 {
103 strcpy(pt,pc);
104 strcat(pt,pb);
105 strcat(pt,pa);
106 }
107 izero = 0;
108 strcpy(zero," 0");
109 strcpy(pt1,pa); strcat(pt1,pb); strcat(pt1,zero);
110 strcpy(pt2,pc); strcat(pt2,pb); strcat(pt2,zero);
111 strcpy(pt3,zero); strcat(pt3,pb); strcat(pt3,pc);
112 strcpy(pt4,zero); strcat(pt4,pb); strcat(pt4,pa);
113 strcpy(pt5,zero); strcat(pt5,pb); strcat(pt5,zero);
114
115 numeral(cl_a,pa,3);
116 numeral(cl_b,pb,3);
117 numeral(cl_c,pc,3);
118 if (cl_a < cl_c)
119 {
120 strcpy(pt6,pa); strcat(pt6,pb); strcat(pt6,pc);
121 }else
122 {
123 strcpy(pt6,pc); strcat(pt6,pb); strcat(pt6,pa);
124 }
125
126 if (field.type == MMFF94)
127 {
128 cl_a = atom_k.tclass1[atom[ia].type];
129 cl_b = atom_k.tclass1[atom[ib].type];
130 cl_c = atom_k.tclass1[atom[ic].type];
131 numeral(cl_a,pa,3);
132 numeral(cl_b,pb,3);
133 numeral(cl_c,pc,3);
134 if (cl_a < cl_c)
135 {
136 strcpy(pt7,pa); strcat(pt7,pb); strcat(pt7,pc);
137 }else
138 {
139 strcpy(pt7,pc); strcat(pt7,pb); strcat(pt7,pa);
140 }
141 }
142 angles.acon[i] = 0.0;
143 angles.anat[i] = 0.0;
144 angles.angtype[i] = HARMONIC;
145
146 ierr = FALSE;
147 /* check TS constants */
148 /* check delocalized angles in MMFF94 cyclopropanes */
149 if (field.type == MMFF94 && angk1.ndel3 > 0)
150 {
151 if (isbond(ia,ic) )
152 {
153 nbo1 = bonds_ff.index[nb1] + bonds_ff.index[nb2];
154 if (nbo1 == 1 || nbo1 == 2)
155 {
156 for(j=0; j < angk1.ndel3; j++)
157 {
158 if (strcmp(angk1.kdel3[j],pt) == 0)
159 {
160 angles.acon[i] = angk1.condel3[j];
161 angles.anat[i] = angk1.angdel3[j][0];
162 if (nbo1 == 1)
163 angles.index[i] = 5;
164 else if (nbo1 == 2)
165 angles.index[i] = 6;
166 ierr = TRUE;
167 break;
168 }
169 }
170 }
171
172 if (ierr == TRUE)
173 goto L_10;
174 }
175 }
176 /* check three membered rings */
177 if ( (rings.nring3 > 0) && (angk1.nang3 > 0) )
178 {
179 if (isbond(ia,ic))
180 {
181 /* search three membered ring parameters */
182 for (j = 0; j < angk1.nang3; j++)
183 {
184 if ( (strcmp(angk1.ktype3[j],pt) == 0) || (strcmp(angk1.ktype3[j],pt1) == 0) ||
185 (strcmp(angk1.ktype3[j],pt2) == 0) || (strcmp(angk1.ktype3[j],pt3) == 0) ||
186 (strcmp(angk1.ktype3[j],pt4) == 0) || (strcmp(angk1.ktype3[j],pt5) == 0))
187 {
188 if ( angk1.ang3[j][1] == 0.0 && angk1.ang3[j][2] == 0)
189 {
190 angles.acon[i] = angk1.con3[j];
191 angles.anat[i] = angk1.ang3[j][0];
192 angles.index[i] = 3;
193 ierr = TRUE;
194 break;
195 } else
196 {
197 nh = 0;
198 for (k=0; k < MAXIAT; k++)
199 {
200 ie = atom[ib].iat[k];
201 if ( (atom[ie].type == 5 || atom[ie].type == 36) && (ie != ia) && (ie != ic))
202 nh++;
203 }
204 angles.acon[i] = angk1.con3[j];
205 angles.anat[i] = angk1.ang3[j][nh];
206 angles.index[i] = 3;
207 ierr = TRUE;
208 break;
209 }
210 }
211 }
212 if (ierr == TRUE)
213 goto L_10;
214 else
215 {
216 Missing_constants = TRUE;
217 }
218 }
219 }
220 /* check delocalized angles in MMFF94 cyclobutanes */
221 if (field.type == MMFF94 && angk1.ndel4 > 0)
222 {
223 nRc = is_ring43(ia, ib, ic);
224 if (nRc == TRUE)
225 {
226 nbo1 = bonds_ff.index[nb1] + bonds_ff.index[nb2];
227 if (nbo1 == 1 || nbo1 == 2)
228 {
229 for(j=0; j < angk1.ndel4; j++)
230 {
231 if (strcmp(angk1.kdel4[j],pt) == 0)
232 {
233 angles.acon[i] = angk1.condel4[j];
234 angles.anat[i] = angk1.angdel4[j][0];
235 if (nbo1 == 1)
236 angles.index[i] = 7;
237 else if (nbo1 == 2)
238 angles.index[i] = 8;
239 ierr = TRUE;
240 break;
241 }
242 }
243 }
244 if (ierr == TRUE)
245 goto L_10;
246 }
247 }
248 /* check four memebered rings */
249 if ( (rings.nring4 > 0) && (angk1.nang4 > 0) )
250 {
251 nRc = is_ring43(ia, ib, ic);
252 if (nRc == TRUE)
253 {
254 /* search four membered ring parameters */
255 for (j = 0; j < angk1.nang4; j++)
256 {
257 if ( (strcmp(angk1.ktype4[j],pt) == 0) || (strcmp(angk1.ktype4[j],pt1) == 0) ||
258 (strcmp(angk1.ktype4[j],pt2) == 0) || (strcmp(angk1.ktype4[j],pt3) == 0) ||
259 (strcmp(angk1.ktype4[j],pt4) == 0) || (strcmp(angk1.ktype4[j],pt5) == 0))
260 {
261 if ( angk1.ang4[j][1] == 0.0 && angk1.ang4[j][2] == 0)
262 {
263 angles.acon[i] = angk1.con4[j];
264 angles.anat[i] = angk1.ang4[j][0];
265 angles.index[i] = 4;
266 ierr = TRUE;
267 break;
268 } else
269 {
270 nh = 0;
271 for (k=0; k < MAXIAT; k++)
272 {
273 ie = atom[ib].iat[k];
274 if ( (atom[ie].type == 5 || atom[ie].type == 36) && (ie != ia) && (ie != ic))
275 nh++;
276 }
277 angles.acon[i] = angk1.con4[j];
278 angles.anat[i] = angk1.ang4[j][nh];
279 angles.index[i] = 4;
280 ierr = TRUE;
281 break;
282 }
283 }
284 }
285 if (ierr == TRUE)
286 goto L_10;
287 else
288 {
289 Missing_constants = TRUE;
290 }
291 }
292 }
293 /* check five membered rings */
294 if ( (rings.nring5 > 0) && (angk1.nang5 > 0) )
295 {
296 nRc = is_ring53(ia,ib, ic);
297 if (nRc == TRUE)
298 {
299 /* search five memebered ring parameters */
300 for (j = 0; j < angk1.nang5; j++)
301 {
302 if ( (strcmp(angk1.ktype5[j],pt) == 0) || (strcmp(angk1.ktype5[j],pt1) == 0) ||
303 (strcmp(angk1.ktype5[j],pt2) == 0) || (strcmp(angk1.ktype5[j],pt3) == 0) ||
304 (strcmp(angk1.ktype5[j],pt4) == 0) || (strcmp(angk1.ktype5[j],pt5) == 0) )
305 {
306 if ( angk1.ang5[j][1] == 0.0 && angk1.ang5[j][2] == 0)
307 {
308 angles.acon[i] = angk1.con5[j];
309 angles.anat[i] = angk1.ang5[j][0];
310 angles.index[i] = 0;
311 ierr = TRUE;
312 break;
313 } else
314 {
315 nh = 0;
316 for (k=0; k < MAXIAT; k++)
317 {
318 ie = atom[ib].iat[k];
319 if ( (atom[ie].type == 5 || atom[ie].type == 36) && (ie != ia) && (ie != ic))
320 nh++;
321 }
322 angles.acon[i] = angk1.con5[j];
323 angles.anat[i] = angk1.ang5[j][nh];
324 angles.index[i] = 0;
325 ierr = TRUE;
326 break;
327 }
328 }
329 }
330 if (ierr == TRUE)
331 goto L_10;
332 // don't fail on missing 5 ring parameters
333 }
334 }
335 /* check delocalized angles in MMFF94 */
336 if (field.type == MMFF94 && angk1.ndel > 0)
337 {
338 if ( bonds_ff.index[nb1] == 1 || bonds_ff.index[nb2] == 1 )
339 {
340 nbo1 = bonds_ff.index[nb1] + bonds_ff.index[nb2];
341 for(j=0; j < angk1.ndel; j++)
342 {
343 if (strcmp(angk1.kdel[j],pt) == 0)
344 {
345 angles.acon[i] = angk1.condel[j];
346 angles.anat[i] = angk1.angdel[j][0];
347 if (nbo1 == 1)
348 angles.index[i] = 1;
349 else if (nbo1 == 2)
350 angles.index[i] = 2;
351 ierr = TRUE;
352 break;
353 }
354 }
355 if (ierr == TRUE)
356 goto L_10;
357 }
358 }
359 /* check regular parameters for specific angles*/
360 for (j = 0; j < angk1.nang; j++)
361 {
362 if ( (strcmp(angk1.ktype[j],pt) == 0) )
363 {
364 if ( angk1.ang[j][1] == 0.0 && angk1.ang[j][2] == 0)
365 {
366 angles.acon[i] = angk1.con[j];
367 angles.anat[i] = angk1.ang[j][0];
368 angles.index[i] = 0;
369 ierr = TRUE;
370 break;
371 } else
372 {
373 nh = 0;
374 for (k=0; k < MAXIAT; k++)
375 {
376 ie = atom[ib].iat[k];
377 if ( (atom[ie].atomnum == 1) && (ie != ia) && (ie != ic))
378 nh++;
379 }
380 angles.acon[i] = angk1.con[j];
381 angles.anat[i] = angk1.ang[j][nh];
382 angles.index[i] = 0;
383 ierr = TRUE;
384 break;
385 }
386 }
387 }
388 if (ierr == TRUE)
389 goto L_10;
390 // did not find any specific look for generalized
391 for (j = 0; j < angk1.nang; j++)
392 {
393 if ( (strcmp(angk1.ktype[j],pt) == 0) || (strcmp(angk1.ktype[j],pt1) == 0) ||
394 (strcmp(angk1.ktype[j],pt2) == 0) || (strcmp(angk1.ktype[j],pt3) == 0) ||
395 (strcmp(angk1.ktype[j],pt4) == 0) || (strcmp(angk1.ktype[j],pt5) == 0) ||
396 (strcmp(angk1.ktype[j],pt6) == 0))
397 {
398 if ( angk1.ang[j][1] == 0.0 && angk1.ang[j][2] == 0)
399 {
400 angles.acon[i] = angk1.con[j];
401 angles.anat[i] = angk1.ang[j][0];
402 angles.index[i] = 0;
403 ierr = TRUE;
404 break;
405 } else
406 {
407 nh = 0;
408 for (k=0; k < MAXIAT; k++)
409 {
410 ie = atom[ib].iat[k];
411 if ( (atom[ie].atomnum == 1) && (ie != ia) && (ie != ic))
412 nh++;
413 }
414 angles.acon[i] = angk1.con[j];
415 angles.anat[i] = angk1.ang[j][nh];
416 angles.index[i] = 0;
417 ierr = TRUE;
418 break;
419 }
420 }
421 }
422 if (ierr == TRUE)
423 goto L_10;
424 /* check MMFF for class1 parameters */
425 if (field.type == MMFF94)
426 {
427 for (j = 0; j < angk1.nang; j++)
428 {
429 if ( (strcmp(angk1.ktype[j],pt7) == 0) )
430 {
431 if ( angk1.ang[j][1] == 0.0 && angk1.ang[j][2] == 0)
432 {
433 angles.acon[i] = angk1.con[j];
434 angles.anat[i] = angk1.ang[j][0];
435 angles.index[i] = 0;
436 ierr = TRUE;
437 break;
438 } else
439 {
440 nh = 0;
441 for (k=0; k < MAXIAT; k++)
442 {
443 ie = atom[ib].iat[k];
444 if ( (atom[ie].atomnum == 1) && (ie != ia) && (ie != ic))
445 nh++;
446 }
447 angles.acon[i] = angk1.con[j];
448 angles.anat[i] = angk1.ang[j][nh];
449 angles.index[i] = 0;
450 ierr = TRUE;
451 break;
452 }
453 }
454 }
455 if (ierr == TRUE)
456 goto L_10;
457 }
458 if (ierr != TRUE)
459 {
460 bkan = get_general_angle(ibb);
461 angles.acon[i] = 0.80;
462 angles.anat[i] = bkan;
463 angles.index[i] = 0;
464 // ==== done with angle lookup =============
465 L_10:
466 if (field.type == MMX && ierr != TRUE)
467 {
468 if (ibb >= 300)
469 {
470 nligand = 0;
471 jji = 0;
472 for ( k=0; k < MAXIAT; k++)
473 {
474 if (atom[ib].iat[k] != 0 && atom[ib].bo[k] != 9)
475 jji++;
476 if (atom[ib].bo[k] == 9)
477 nligand++;
478 }
479 if (jji == 2 && nligand == 0)
480 {
481 angles.acon[i] = .1;
482 angles.anat[i] = 180.;
483 }
484 if ((jji == 3 && nligand == 0) || (jji == 2 && nligand == 1) )
485 {
486 angles.acon[i] = .1;
487 angles.anat[i] = 120.;
488 }
489 if ((jji == 4 && nligand == 0) || (jji == 3 && nligand == 1) || (jji == 2 && nligand == 2))
490 {
491 if (jji == 4 && (atom[ib].type >= 300 && (atom[ib].flags & (1L << SATMET_MASK) &&
492 atom[ib].flags & (1L << GT18e_MASK) && atom[ib].flags & (1L << SQPLAN_MASK) &&
493 !(atom[ib].flags & (1L << LOWSPIN_MASK)))) )
494 {
495 angles.acon[i] = .0001;
496 angles.anat[i] = 90.;
497 } else
498 {
499 angles.acon[i] = .1;
500 angles.anat[i] = 109.5;
501 }
502 }
503
504 }
505 }
506 }
507 }
508 }
509 }
510 // ===================================
511 // generalized angles for MMFF with no hydrogen minimization
512 float get_general_angle(int ia)
513 {
514 float angs[80] = {
515 109.0, 120.0, 120.0, 180.0, 0.000, 109.0, 0.000, 109.0, 120.0, 118.0,
516 0.000, 0.000, 0.000, 0.000, 109.0, 109.0, 120.0, 109.0, 109.0, 90.00,
517 0.000, 60.00, 0.000, 0.000, 109.0, 109.0, 0.000, 0.000, 0.000, 90.00,
518 0.000, 0.000, 0.000, 109.0, 0.000, 0.000, 120.0, 120.0, 120.0, 120.0,
519 120.0, 180.0, 120.0, 120.0, 120.0, 120.0, 0.000, 0.000, 109.0, 0.000,
520 109.0, 0.000, 180.0, 120.0, 120.0, 120.0, 120.0, 120.0, 120.0, 180.0,
521 180.0, 120.0, 120.0, 120.0, 120.0, 120.0, 120.0, 109.0, 120.0, 109.0,
522 0.000, 109.0, 109.0, 120.0, 120.0, 109.0, 0.000, 109.0, 109.0, 109.0 };
523
524 if (ia < 80)
525 return (angs[ia-1]);
526 else
527 return 109.0;
528 }
529 /* --------------------------------- */
530 long kang(int i,int j,int k)
531 {
532 long int kang_v;
533 static long i10000 = 10000;
534 static long i100 = 100;
535
536 kang_v = i10000*i + i100*j + k;
537 return( kang_v );
538 }
539
540 /* -------------------- */
541 long ipack(int i,int j,int k,int l)
542 {
543 long int ipack_v;
544 static long itbig = 200000000;
545 static long itmid = 2000000;
546 static long ithou = 1000;
547
548 ipack_v = itbig*i + itmid*j + ithou*k + l;
549 return( ipack_v );
550 }