ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/branches/sync4pymol12/src/mengine/src/mark.c
Revision: 99
Committed: Mon Jan 19 04:31:29 2009 UTC (10 years, 7 months ago) by wdelano
File size: 22888 byte(s)
Log Message:
synchronized with trunk, less openmp lib/include
Line User Rev File contents
1 tjod 3 #define EXTERN extern
2    
3     #include "pcwin.h"
4     #include "pcmod.h"
5     #include "utility.h"
6     #include "pot.h"
7     #include "field.h"
8    
9     void make_bond(int,int,int);
10     void deletebond(int,int);
11     void get_hbond(void);
12     int is_piatom(int);
13     void message_alert(char *, char *);
14     void marker(double, double, double, int);
15     void bbchk(void);
16     int ibond(int,int);
17    
18     EXTERN struct t_piatomk {
19     int npiatom;
20     int kat[MAXPIATOM], qp[MAXPIATOM];
21     float q[MAXPIATOM], ion[MAXPIATOM], emz[MAXPIATOM], zor[MAXPIATOM], zz[MAXPIATOM];
22     float w1[MAXPIATOM], w2[MAXPIATOM], w3[MAXPIATOM];
23     } piatomk;
24    
25     // ==================================================
26     int is_piatom(int ia)
27     {
28     int i, it;
29    
30     if (field.type == MMX )
31     {
32     it = atom[ia].mmx_type;
33     for (i=0; i < piatomk.npiatom; i++)
34     {
35     if (it == piatomk.kat[i])
36     return TRUE;
37     }
38     } else if (field.type == MM3)
39     {
40     it = atom[ia].mm3_type;
41     for (i=0; i < piatomk.npiatom; i++)
42     {
43     if (it == piatomk.kat[i])
44     return TRUE;
45     }
46     } else
47     {
48     it = atom[ia].mmx_type;
49    
50     if( it == 2 || it == 3 || it == 4 || it == 6 || it == 7 || it == 9 || it == 10 || it == 42 ||
51     it == 37 || it == 41 || it == 46 || it == 47 || it == 48 || it == 29 ||
52     it == 30 || it == 15 || it == 38 || it == 66 || it == 57 )
53     return TRUE;
54     }
55     return FALSE;
56     }
57     // ============================================
58     void bbchk()
59     {
60     int back, i, i1, i2, i3,
61     iat2k, ibib, ibond1, ii, ijj, ip1, ip2, ip3, iatk,
62     ip4, ipf1, ipf1n, ipf4, ipf4n, it, j, jii, jjldx, k, k1,
63     k2, kdx, kk, kt, l, ldx, lev, maxlev, mnlev,
64     mnp1, mnp2, mxnode, nb, node, path[200][2];
65     int found;
66     long int mask;
67     int *iara, **iarb;
68    
69    
70     /* iara flag =1(aromatic atom) =0(non-aromatic atom)
71     * iarb flag =1(aromatic bond) =2(biphenyl-like bond)
72     * =3(butadiene-like bond) =0(other)
73     * call this subroutine from ce1(link) by making statement #316
74     * the call statement.
75     * use iarb flags in kbond and komega where appropriate
76     * one can potentially use this subr. to set logary flags
77     * for use in model
78     * */
79    
80     iara = ivector(0,natom+1);
81     iarb = imatrix(0,3,0,natom+1);
82    
83     mask = 1L << PI_MASK;
84     for( i = 1; i <= natom; i++ )
85     {
86     atom[i].flags &= ~mask;
87     }
88     for( i = 0; i <= natom; i++ )
89     {
90     iara[i] = 0;
91     for( j = 0; j < 3; j++ )
92     {
93     iarb[j][i] = 0;
94     }
95     }
96    
97     nb = 0;
98     for( i = 1; i <= natom; i++ )
99     {
100     it = atom[i].mmx_type;
101     if (is_piatom(i) )
102     {
103     for( j = 0; j < MAXIAT; j++ )
104     {
105     if( atom[i].iat[j] && i < atom[i].iat[j] )
106     {
107     i1 = i;
108     i2 = atom[i].iat[j];
109     i3 = atom[i].bo[j];
110     it = atom[i1].mmx_type;
111     kt = atom[i2].mmx_type;
112     /* NOW CHECK FOR AROMATIC RINGS INVOLVING ATOMS I1 AND I2 */
113     path[0][0] = i1;
114     path[1][0] = i2;
115     maxlev = 20;
116     mnlev = 2;
117     /* changed from maxiat to 3 */
118     mxnode = 3;
119     mnp1 = mxnode + 1;
120     mnp2 = mxnode + 2;
121     for( lev = 0; lev < 6; lev++ )
122     {
123     path[lev][1] = 0;
124     }
125     for( lev = 2; lev < 6; lev++ )
126     {
127     path[lev][0] = 0;
128     }
129     lev = 2;
130     while( True )
131     {
132     if( lev <= maxlev )
133     {
134     kdx = path[lev][0];
135     node = path[lev][1] + 1;
136     while( node <= mxnode )
137     {
138     ldx = atom[kdx].iat[node];
139     if( ldx > 0 )
140     {
141     jjldx = 0;
142     /* changed maxiat to 3 */
143     for( ijj = 0; ijj < 3; ijj++ )
144     {
145     if( atom[ldx].iat[ijj] && atom[ldx].bo[ijj] )
146     jjldx += 1;
147     }
148     if( jjldx == 1 )
149     ldx = 0;
150     }
151     it = 0;
152     if( ldx )
153     it = atom[ldx].mmx_type;
154     if( it == 2 || it == 37 || it == 40 || it == 41 )
155     {
156     ldx = ldx;
157     }
158     else
159     {
160     ldx = 0;
161     }
162     if( !ldx )
163     {
164     node += 1;
165     }
166     else
167     {
168     back = lev - 1;
169     while( back > 0 && ldx != path[back][0] )
170     {
171     back -= 1;
172     }
173     if( !back )
174     {
175     path[lev][1] = node;
176     lev += 1;
177     path[lev][0] = ldx;
178     node = mnp2;
179     }
180     else if( back != 1 )
181     {
182     node += 1;
183     /* IF(LEV.GE.5) THEN */
184     }
185     else if( lev == 6 )
186     {
187     /* AROMATIC RING FOUND */
188     goto L_70;
189     }
190     else
191     {
192     node += 1;
193     }
194     }
195     }
196     if( node == mnp1 )
197     {
198     /* IF(LEV.EQ.MNLEV) GOTO 100 ! ACYCLIC OR NON-AROM. SYSTEM */
199     if( lev == mnlev )
200     goto L_181;
201     path[lev][0] = 0;
202     path[lev][1] = 0;
203     lev -= 1;
204     }
205     }
206     else
207     {
208     path[lev][0] = 0;
209     path[lev][1] = 0;
210     lev -= 1;
211     }
212     }
213    
214     /*c AROMATIC RING FOUND */
215     L_70:
216     ;
217     for( k = 0; k <= lev; k++ )
218     {
219     k1 = path[k][0];
220     k2 = path[k + 1][0];
221     iara[k1] = 1;
222     iara[k2] = 1;
223     iarb[0][nb] = k1;
224     iarb[1][nb] = k2;
225     iarb[2][nb] = 1;
226     nb += 1;
227     if( atom[k1].mmx_type != 40 )
228     atom[k1].flags |= mask;
229     if( atom[k2].mmx_type != 40 )
230     atom[k2].flags |= mask;
231     }
232     k1 = path[0][0];
233     k2 = path[lev][0];
234     iarb[0][nb] = k1;
235     iarb[1][nb] = k2;
236     iarb[2][nb] = 1;
237     nb += 1;
238     }
239     L_181:
240     ;
241     }
242     }
243     }
244    
245     for( i = 1; i <= natom; i++ )
246     {
247     it = atom[i].mmx_type;
248     if (is_piatom(i) )
249     {
250     for( j = 0; j < MAXIAT; j++ )
251     {
252     if( (atom[i].iat[j] && atom[i].bo[j] != 9) &&
253     i < atom[i].iat[j] )
254     {
255     /* search iarb array to see if this bond has been found before */
256     for( k = 0; k < nb; k++ )
257     {
258     if( iarb[0][k] == i && iarb[1][k] == atom[i].iat[j] )
259     goto L_182;
260     }
261     i1 = i;
262     i2 = atom[i].iat[j];
263     i3 = atom[i].bo[j];
264     it = atom[i1].mmx_type;
265     kt = atom[i2].mmx_type;
266     if( it == 2 && kt == 2 && i3 == 1 )
267     {
268    
269     /* HAVE NOW IDENTIFIED A TYPE 2-TYPE 2 SINGLE BOND NOT IN AN
270     * AROMATIC RING */
271     if( iara[i1] == 1 && iara[i2] == 1 )
272     {
273     /* BIPENYL-LIKE BOND (2-2 SINGLE BOND BETWEEN 2 AROM RINGS) */
274     iarb[2][k] = 2;
275     }
276     else
277     {
278     iarb[2][k] = 3;
279     }
280     }
281     }
282     L_182:
283     ;
284     }
285     }
286     }
287     /* CHECK FOR BUTADIENE LIKE PI ATOM SEQUENCES * */
288     for( i = 1; i <= natom; i++ )
289     {
290     for( j = 0; j < MAXIAT; j++ )
291     {
292     if( atom[i].iat[j] && atom[i].bo[j] != 9 )
293     {
294     i1 = i;
295     i2 = atom[i].iat[j];
296     i3 = atom[i].bo[j];
297     ip2 = atom[i1].mmx_type;
298     ip3 = atom[i2].mmx_type;
299     ipf1 = 0;
300     ipf4 = 0;
301     ipf1n = 0;
302     ipf4n = 0;
303     if( i3 == 1 )
304     {
305     /* includes sulfur */
306     if( is_piatom(i1) && is_piatom(i2) )
307     {
308     for( k = 0; k < MAXIAT; k++ )
309     {
310     if( atom[i1].iat[k] )
311     {
312     ip1 = atom[atom[i1].iat[k]].mmx_type;
313     if( ip1 )
314     {
315     if( atom[i1].iat[k] != i2 )
316     {
317     iatk = atom[i1].iat[k];
318     if( ibond(iatk,i1) )
319     {
320     /* sulfur */
321     if(is_piatom(iatk) && (ibond( iatk, i1 ) > 1) )
322     goto L_184;
323     }
324     }
325     }
326     }
327     }
328     goto L_183;
329     L_184:
330     ipf1 = 1;
331     ipf1n = atom[i1].iat[k];
332     L_183:
333     for( kk = 0; kk < MAXIAT; kk++ )
334     {
335     iat2k = atom[i2].iat[kk];
336     if( iat2k && atom[i2].bo[kk] != 9 )
337     {
338     ip4 = atom[iat2k].mmx_type;
339     if( ip4 )
340     {
341     if( iat2k != i1 )
342     {
343     ibond1 = ibond( iat2k, i2 );
344     ibib = ibond1;
345     if( is_piatom(iat2k) && (ibib > 1) )
346     goto L_186;
347     }
348     }
349     }
350     }
351     goto L_185;
352     L_186:
353     ipf4 = 1;
354     ipf4n = atom[i2].iat[kk];
355     }
356     L_185:
357     if( (ipf1 == 1 && ipf4 == 1) && i3 == 1 )
358     {
359     atom[ipf1n].flags |= mask;
360     atom[i1].flags |= mask;
361     atom[i2].flags |= mask;
362     atom[ipf4n].flags |= mask;
363     }
364     }
365     }
366     }
367     }
368    
369     /* Check for conjugated c+, c. c- */
370     for( i = 1; i <= natom; i++ )
371     {
372     if( atom[i].mmx_type == 29 || atom[i].mmx_type == 30 || atom[i].mmx_type == 48 )
373     {
374     for( k = 0; k < MAXIAT; k++ )
375     {
376     j = atom[i].iat[k];
377     if( j != 0 && atom[i].bo[k] != 9 )
378     {
379     ip4 = atom[j].mmx_type;
380     /* sulfur */
381     if( is_piatom(j) )
382     {
383     for( ii = 0; ii < MAXIAT; ii++ )
384     {
385     jii = atom[j].iat[ii];
386     if( jii && atom[j].bo[ii] != 9 )
387     {
388     if( jii != i )
389     {
390     ip4 = atom[jii].mmx_type;
391     if( is_piatom(jii) )
392     {
393     atom[i].flags |= mask;
394     atom[j].flags |= mask;
395     }
396     }
397     }
398     }
399     }
400     }
401     }
402     }
403     }
404    
405    
406     /* CHECK FOR 1ST ATOM SUBSTITUENTS ON PI FLAGGED CONJUGATED ATOMS * */
407     L_187:
408     found = FALSE;
409     for( l = 1; l <= natom; l++ )
410     {
411     if( atom[l].flags & mask )
412     {
413     for( k = 0; k < MAXIAT; k++ )
414     {
415     if( atom[l].iat[k] && atom[l].bo[k] <= 3 )
416     {
417     ip1 = atom[atom[l].iat[k]].mmx_type;
418     if( ip1 == 0 )
419     break;
420     /* sulfur */
421     if( is_piatom(atom[l].iat[k]) && ip1 != 40 && !(atom[atom[l].iat[k]].flags & mask) )
422     {
423     atom[atom[l].iat[k]].flags |= mask;
424     found = TRUE;
425     }
426     }
427     }
428     }
429    
430     }
431     if (found == TRUE) goto L_187;
432     //
433     // unmark allenes
434     for (i=1; i <= natom; i++)
435     {
436     if (atom[i].mmx_type == 4)
437     {
438     if (atom[i].iat[0] != 0 && atom[i].iat[1] != 0)
439     {
440     if (atom[i].bo[0] == 2 && atom[i].bo[1] == 2)
441     {
442     atom[i].flags &= ~mask;
443     atom[atom[i].iat[0]].flags &= ~mask;
444     atom[atom[i].iat[1]].flags &= ~mask;
445     }
446     }
447     }
448     }
449    
450     free_imatrix(iarb, 0,3, 0, natom+1);
451     free_ivector(iara, 0, natom+1);
452     return;
453     }
454     /* ===================================== */
455     int ibond(int i1,int j1)
456     {
457     int i, ib, ibond_v, ii, j;
458    
459    
460     if( (!i1 || !j1) || i1 == j1 )
461     {
462     ibond_v = 0;
463     }
464     else
465     {
466    
467     i = i1;
468     j = j1;
469     if( i > j )
470     {
471     ii = i;
472     i = j;
473     j = ii;
474     }
475     for( ib = 0; ib < MAXIAT; ib++ )
476     {
477     if( atom[i].iat[ib] == j )
478     goto L_1;
479     }
480     ibond_v = 0;
481     goto L_2;
482     L_1:
483     ibond_v = atom[i].bo[ib];
484     }
485     L_2:
486     return( ibond_v );
487     }
488     /* ============================================= */
489     int checkbond(int i, int j)
490     {
491     int loop;
492     for (loop = 0; loop < MAXIAT; loop++)
493     {
494     if (atom[i].iat[loop] == j)
495     return loop;
496     }
497     return (-1);
498     }