ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/smi23d/src/mengine/mark.c
Revision: 3
Committed: Mon Jun 9 21:38:26 2008 UTC (11 years, 4 months ago) by tjod
File size: 22943 byte(s)
Log Message:
test

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