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