ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/rings.c
Revision: 110
Committed: Thu Mar 12 01:43:50 2009 UTC (12 years, 2 months ago) by gilbertke
File size: 28147 byte(s)
Log Message:
further cleanup and localization of atom data
Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4 #include "rings.h"
5 #include "utility.h"
6
7 int have_ring3(void);
8 int have_ring4(void);
9 int have_ring5(void);
10 int have_ring6(void);
11 int isbond(int, int);
12 int is_ring31(int);
13 int is_ring41(int);
14 int is_ring42(int,int);
15 int is_ring43(int, int, int);
16 int is_ring44(int *);
17 int is_ring51(int);
18 int is_ring52(int, int);
19 int is_ring53(int, int, int);
20 int is_ring54(int, int, int, int);
21 int is_ring55(int *);
22 int is_ring61(int);
23 int is_ring62(int, int);
24 int is_ring63(int,int,int);
25 int is_ring66(int *);
26 int is_cyclo5(int, int *);
27 void ksort(int, int *);
28 void message_alert(char *, char *);
29 int is_cyclo6(int, int *);
30 int find_rsize(int, int);
31 void get_rsize(int,int,int,int *);
32 int aromatic_5(int *array,long int *flags,int *atomnum,int **,int **);
33 int aromatic_6(int *,long int *flags,int *atomnum,int **,int **);
34 void get_rings(int natom,long int *flags,int *atomnum,int **iat,int **bo);
35 void allocate_rings(int niatom);
36 int check_ring1(int);
37
38 // ===========================
39 void allocate_rings(int niatom)
40 {
41 rings.nring3 = 0;
42 rings.nring4 = 0;
43 rings.nring5 = 0;
44 rings.nring6 = 0;
45 rings.r13 = imatrix(0,(niatom+10)/3, 0,3);
46 rings.r14 = imatrix(0,(niatom+10)/4, 0,4);
47 rings.r15 = imatrix(0,(niatom+10)/5, 0,5);
48 rings.r16 = imatrix(0,(niatom+10)/2, 0,6);
49 }
50 // ======================
51 int have_ring3()
52 {
53 if (rings.nring3 > 0)
54 return TRUE;
55 else
56 return FALSE;
57 }
58 int have_ring4()
59 {
60 if (rings.nring4 > 0)
61 return TRUE;
62 else
63 return FALSE;
64 }
65 int have_ring5()
66 {
67 if (rings.nring5 > 0)
68 return TRUE;
69 else
70 return FALSE;
71 }
72 int have_ring6()
73 {
74 if (rings.nring6 > 0)
75 return TRUE;
76 else
77 return FALSE;
78 }
79 /* --------------------------------------------------------- */
80 // iatom is atom number to search on
81 // isize = ring size
82 // num = number of ring if more than one ring containing atom iatom
83 // array = array of ring atoms
84 //
85 void get_rsize(int iatom, int isize, int num, int *array)
86 {
87 int i, j, k, icount;
88 icount = -1;
89
90 if (isize == 3)
91 {
92 for (i=0; i < rings.nring3; i++)
93 {
94 for (j=0; j < 3; j++)
95 {
96 if (iatom == rings.r13[i][j])
97 icount++;
98 if (icount == num)
99 {
100 for (k=0; k < isize; k++)
101 array[k] = rings.r13[i][k];
102 return;
103 }
104 }
105 }
106 } else if (isize == 4)
107 {
108 for (i=0; i < rings.nring4; i++)
109 {
110 for (j=0; j < 4; j++)
111 {
112 if (iatom == rings.r14[i][j])
113 icount++;
114 if (icount == num)
115 {
116 for (k=0; k < isize; k++)
117 array[k] = rings.r14[i][k];
118 return;
119 }
120 }
121 }
122 } else if (isize == 5)
123 {
124 for (i=0; i < rings.nring5; i++)
125 {
126 for (j=0; j < 5; j++)
127 {
128 if (iatom == rings.r15[i][j])
129 icount++;
130 if (icount == num)
131 {
132 for (k=0; k < isize; k++)
133 array[k] = rings.r15[i][k];
134 return;
135 }
136 }
137 }
138 } else if (isize == 6)
139 {
140 for (i=0; i < rings.nring6; i++)
141 {
142 for (j=0; j < 6; j++)
143 {
144 if (iatom == rings.r16[i][j])
145 icount++;
146 if (icount == num)
147 {
148 for (k=0; k < isize; k++)
149 array[k] = rings.r16[i][k];
150 return;
151 }
152 }
153 }
154 }
155 }
156 /* --------------------------------------------------------- */
157 int find_rsize(int isize,int iatom)
158 {
159 int i, j, icount;
160
161 icount = 0;
162 if (isize == 3)
163 {
164 for (i=0; i < rings.nring3; i++)
165 {
166 for(j=0; j < 3; j++)
167 {
168 if (rings.r13[i][j] == iatom)
169 icount++;
170 }
171 }
172 return(icount);
173 }else if (isize == 4)
174 {
175 for (i=0; i < rings.nring4; i++)
176 {
177 for(j=0; j < 4; j++)
178 {
179 if (rings.r14[i][j] == iatom)
180 icount++;
181 }
182 }
183 return(icount);
184 }else if (isize == 5)
185 {
186 for (i=0; i < rings.nring5; i++)
187 {
188 for(j=0; j < 5; j++)
189 {
190 if (rings.r15[i][j] == iatom)
191 icount++;
192 }
193 }
194 return(icount);
195 }else if (isize == 6)
196 {
197 for (i=0; i < rings.nring6; i++)
198 {
199 for(j=0; j < 6; j++)
200 {
201 if (rings.r16[i][j] == iatom)
202 icount++;
203 }
204 }
205 return(icount);
206 }
207 return(icount);
208 }
209 // =======================
210 int is_ring31(int ia)
211 {
212 int i,j;
213
214 for (i=0; i < rings.nring3; i++)
215 {
216 for (j=0; j < 3; j++)
217 {
218 if (ia == rings.r13[i][j])
219 {
220 return(TRUE);
221 }
222 }
223 }
224 return FALSE;
225 }
226 /* ============================ */
227 int is_ring41(int ia)
228 {
229 int i,j, found;
230
231 found = FALSE;
232 for (i=0; i < rings.nring4; i++)
233 {
234 for (j=0; j < 4; j++)
235 {
236 if (ia == rings.r14[i][j])
237 {
238 found = TRUE;
239 return (found);
240 }
241 }
242 }
243 return (found);
244 }
245 /* -------------------------------------------------------- */
246 int is_ring42(int ia, int ib)
247 {
248 int i,j, k, itmp, jtmp;
249 if (ia < ib )
250 {
251 itmp = ia;
252 jtmp = ib;
253 }else
254 {
255 itmp = ib;
256 jtmp = ia;
257 }
258 for (i=0; i < rings.nring4; i++)
259 {
260 for (j = 0; j < 3; j++)
261 {
262 if ( itmp == rings.r14[i][j])
263 {
264 for (k=j+1; k < 4; k++)
265 {
266 if (jtmp == rings.r14[i][k])
267 return(TRUE);
268 }
269 }
270 }
271 }
272 return(FALSE);
273 }
274 /* -------------------------------------------------------- */
275 int is_ring43(int ia, int ib, int ic)
276 {
277 int i, found;
278 int array[5];
279
280 found = FALSE;
281 array[0] = ia;
282 array[1] = ib;
283 array[2] = ic;
284 ksort(3,array);
285 for (i=0; i < rings.nring4; i++)
286 {
287 if ( array[0] == rings.r14[i][0] && rings.r14[i][1] == array[1] && rings.r14[i][2] == array[2])
288 {
289 found = TRUE;
290 return(found);
291 }
292 if ( rings.r14[i][0] == array[0] && rings.r14[i][1] == array[1] && rings.r14[i][3] == array[2])
293 {
294 found = TRUE;
295 return(found);
296 }
297 if ( rings.r14[i][0] == array[0] && rings.r14[i][2] == array[1] && rings.r14[i][3] == array[2])
298 {
299 found = TRUE;
300 return(found);
301 }
302 if ( rings.r14[i][1] == array[0] && rings.r14[i][2] == array[1] && rings.r14[i][3] == array[2])
303 {
304 found = TRUE;
305 return(found);
306 }
307 }
308 return(found);
309 }
310 /* -------------------------------------------------------- */
311 int is_ring44(int *array)
312 {
313 int i;
314 for (i=0; i < rings.nring4; i++)
315 {
316 if (array[0] == rings.r14[i][0] && array[1] == rings.r14[i][1] &&
317 array[2] == rings.r14[i][2] && array[3] == rings.r14[i][3])
318 return(TRUE);
319 }
320 return FALSE;
321 }
322 /* -------------------------------------------------------- */
323 int is_ring51(int ia)
324 {
325 int i,j;
326
327 for(i=0; i < rings.nring5; i++)
328 {
329 for (j=0; j < 5; j++)
330 {
331 if (rings.r15[i][j] == ia)
332 {
333 return(TRUE);
334 }
335 }
336 }
337 return(FALSE);
338 }
339 // ======================================
340 int is_cyclo5(int ia, int *array)
341 {
342 int i,j;
343
344 for(i=0; i < rings.nring5; i++)
345 {
346 for (j=0; j < 5; j++)
347 {
348 if (rings.r15[i][j] == ia)
349 {
350 array[0] = rings.r15[i][0];
351 array[1] = rings.r15[i][1];
352 array[2] = rings.r15[i][2];
353 array[3] = rings.r15[i][3];
354 array[4] = rings.r15[i][4];
355 return(TRUE);
356 }
357 }
358 }
359 return(FALSE);
360 }
361 /* -------------------------------------------------------- */
362 int is_ring52(int ia, int ib)
363 {
364 int i, j,k, itmp, jtmp;
365 if (ia < ib)
366 {
367 itmp = ia;
368 jtmp = ib;
369 }else
370 {
371 itmp = ib;
372 jtmp = ia;
373 }
374 for (i=0; i < rings.nring5; i++)
375 {
376 for (j=0; j < 4; j++)
377 {
378 if (itmp == rings.r15[i][j])
379 {
380 for (k=j+1; k < 5; k++)
381 {
382 if (jtmp == rings.r15[i][k])
383 return(TRUE);
384 }
385 }
386 }
387 }
388 return(FALSE);
389 }
390 /* -------------------------------------------------------- */
391 int is_ring53(int ia, int ib, int ic)
392 {
393 int i, j,k,l;
394 int array[5];
395
396 array[0] = ia;
397 array[1] = ib;
398 array[2] = ic;
399 ksort(3,array);
400 for (i=0; i < rings.nring5; i++)
401 {
402 for (j=0; j < 3; j++)
403 {
404 if (array[0] == rings.r15[i][j])
405 {
406 for (k=j+1; k < 4; k++)
407 {
408 if (array[1] == rings.r15[i][k])
409 {
410 for (l=j+1; l < 5; l++)
411 {
412 if (array[2] == rings.r15[i][l])
413 return(TRUE);
414 }
415 }
416 }
417 }
418 }
419 }
420 return(FALSE);
421 }
422 /* -------------------------------------------------------- */
423 int is_ring54(int ia, int ib, int ic, int id)
424 {
425 int i;
426 int array[5];
427 array[0] = ia;
428 array[1] = ib;
429 array[2] = ic;
430 array[3] = id;
431 ksort(4,array);
432 for (i=0; i < rings.nring5; i++)
433 {
434 if (array[0] == rings.r15[i][0])
435 {
436 if (array[1] == rings.r15[i][1])
437 {
438 if (array[2] == rings.r15[i][2])
439 {
440 if (array[3] == rings.r15[i][3])
441 return(TRUE);
442 else if (array[3] == rings.r15[i][4])
443 return(TRUE);
444 else
445 return(FALSE);
446 } else if (array[2] == rings.r15[i][3] && array[3] == rings.r15[i][4])
447 return(TRUE);
448 } else if (array[1] == rings.r15[i][2] &&
449 array[2] == rings.r15[i][3] && array[3] == rings.r15[i][4])
450 return(TRUE);
451
452 } else if (array[0] == rings.r15[i][1] && array[1] == rings.r15[i][2] &&
453 array[2] == rings.r15[i][3] && array[3] == rings.r15[i][4])
454 return(TRUE);
455 }
456 return (FALSE);
457 }
458 /* -------------------------------------------------------- */
459 int is_ring55(int *array)
460 {
461 int i;
462 for(i=0; i < rings.nring5; i++)
463 {
464 if ( array[0] == rings.r15[i][0] && array[1] == rings.r15[i][1] && array[2] == rings.r15[i][2] &&
465 array[3] == rings.r15[i][3] && array[4] == rings.r15[i][4])
466 return(TRUE);
467 }
468 return (FALSE);
469 }
470 /* -------------------------------------------------------- */
471 int is_ring61(int ia)
472 {
473 int i, j;
474 for(i=0; i < rings.nring6; i++)
475 {
476 for(j=0; j < 6; j++)
477 {
478 if (ia == rings.r16[i][j])
479 return (TRUE);
480 }
481 }
482 return (FALSE);
483 }
484 /* -------------------------------------------------------- */
485 int is_ring62(int ia, int ib)
486 {
487 int i, j,k, itmp, jtmp;
488 if (ia < ib)
489 {
490 itmp = ia;
491 jtmp = ib;
492 }else
493 {
494 itmp = ib;
495 jtmp = ia;
496 }
497 for (i=0; i < rings.nring6; i++)
498 {
499 for (j=0; j < 5; j++)
500 {
501 if (itmp == rings.r16[i][j])
502 {
503 for (k=j+1; k < 6; k++)
504 {
505 if (jtmp == rings.r16[i][k])
506 return(TRUE);
507 }
508 }
509 }
510 }
511 return(FALSE);
512 }
513 /* -------------------------------------------------------- */
514 int is_ring63(int ia, int ib, int ic)
515 {
516 int i, j, k, l;
517 int array[5];
518
519 array[0] = ia;
520 array[1] = ib;
521 array[2] = ic;
522 ksort(3,array);
523 for (i=0; i < rings.nring6; i++)
524 {
525 for (j=0; j < 4; j++)
526 {
527 if (array[0] == rings.r16[i][j])
528 {
529 for (k=j+1; k < 5; k++)
530 {
531 if (array[1] == rings.r16[i][k])
532 {
533 for (l=k+1; l < 6; l++)
534 {
535 if (array[2] == rings.r16[i][l])
536 return(TRUE);
537 }
538 }
539 }
540 }
541 }
542 }
543 return(FALSE);
544 }
545 /* -------------------------------------------------------- */
546 int is_ring66(int *array)
547 {
548 int i;
549 for(i=0; i < rings.nring6; i++)
550 {
551 if ( array[0] == rings.r16[i][0] && array[1] == rings.r16[i][1] && array[2] == rings.r16[i][2] &&
552 array[3] == rings.r16[i][3] && array[4] == rings.r16[i][4] && array[5] == rings.r16[i][5])
553 return(TRUE);
554 }
555 return (FALSE);
556 }
557 /* -------------------------------------------------------- */
558 void get_rings(int natom,long int *flags,int *atomnum,int **iat,int **bo)
559 {
560 int i,j, add_ring, k, l, m, n,ij,isix;
561 int jatm,katm,latm,matm,xatm;
562 int array[6];
563 long int aromatic_mask;
564
565 rings.nring3 = 0;
566 rings.nring4 = 0;
567 rings.nring5 = 0;
568 rings.nring6 = 0;
569 aromatic_mask = (1L << AROMATIC_MASK);
570
571 // get three membered rings
572 for (i=1; i <= natom; i++)
573 {
574 for (j=0; j < MAXIAT; j++)
575 {
576 if (iat[i][j] != 0)
577 {
578 jatm = iat[i][j];
579 for (k=0; k < MAXIAT; k++)
580 {
581 if (iat[jatm][k] != 0 && iat[jatm][k] != i)
582 {
583 if (isbond(i,iat[jatm][k]))
584 {
585 array[0] = i;
586 array[1] = jatm;
587 array[2] = iat[jatm][k];
588 ksort(3,array);
589 add_ring = TRUE;
590 for (j = 0; j < rings.nring3; j++)
591 {
592 if (array[0] == rings.r13[j][0] && array[1] == rings.r13[j][1]
593 && array[2] == rings.r13[j][2])
594 {
595 add_ring = FALSE;
596 break;
597 }
598 }
599 if (add_ring == TRUE)
600 {
601 rings.r13[rings.nring3][0] = array[0];
602 rings.r13[rings.nring3][1] = array[1];
603 rings.r13[rings.nring3][2] = array[2];
604 rings.nring3++;
605 if (rings.nring3 >= MAXATOM/3)
606 message_alert("Error. Too many 3 membered rings!","ERROR");
607 }
608 }
609 }
610 }
611 }
612 }
613 }
614 // get four membered rings
615 for(i=1; i <= natom; i++)
616 {
617 for(j=0; j < MAXIAT; j++)
618 {
619 if (iat[i][j] != 0)
620 {
621 jatm = iat[i][j];
622 for (k=0; k < MAXIAT; k++)
623 {
624 if (iat[jatm][k] != 0 && iat[jatm][k] != i)
625 {
626 katm = iat[jatm][k];
627 if (!(isbond(katm,i)))
628 {
629 for(l=0; l < MAXIAT; l++)
630 {
631 if (iat[katm][l] != 0 && iat[katm][l] != jatm)
632 {
633 if (isbond(i,iat[katm][l]) )
634 {
635 array[0] = i;
636 array[1] = jatm;
637 array[2] = katm;
638 array[3] = iat[katm][l];
639 ksort(4, array);
640 if ( is_ring44(array) == FALSE )
641 {
642 rings.r14[rings.nring4][0] = array[0];
643 rings.r14[rings.nring4][1] = array[1];
644 rings.r14[rings.nring4][2] = array[2];
645 rings.r14[rings.nring4][3] = array[3];
646 rings.nring4++;
647 if (rings.nring4 >= MAXATOM/4)
648 message_alert("Error. Too many 4 membered rings!","ERROR");
649 }
650 }
651 }
652 }
653 }
654 }
655 }
656 }
657 }
658 }
659 // get five membered rings i-jatm-katm-latm-
660 for(i=1; i <= natom; i++)
661 {
662 for(j=0; j < MAXIAT; j++)
663 {
664 if (iat[i][j] != 0)
665 {
666 jatm = iat[i][j];
667 for (k=0; k < MAXIAT; k++)
668 {
669 if (iat[jatm][k] != 0 && iat[jatm][k] != i)
670 {
671 katm = iat[jatm][k];
672 if (!(isbond(katm,i)))
673 {
674 for(l=0; l < MAXIAT; l++)
675 {
676 if (iat[katm][l] != 0 && iat[katm][l] != jatm)
677 {
678 latm = iat[katm][l];
679 for (m=0; m < MAXIAT; m++)
680 {
681 if (iat[latm][m] != 0 && iat[latm][m] != katm && iat[latm][m] != jatm)
682 {
683 if (isbond(i,iat[latm][m]))
684 {
685 array[0] = i;
686 array[1] = jatm;
687 array[2] = katm;
688 array[3] = latm;
689 array[4] = iat[latm][m];
690 ksort(5,array);
691 if (is_ring55(array) == FALSE)
692 {
693 rings.r15[rings.nring5][0] = array[0];
694 rings.r15[rings.nring5][1] = array[1];
695 rings.r15[rings.nring5][2] = array[2];
696 rings.r15[rings.nring5][3] = array[3];
697 rings.r15[rings.nring5][4] = array[4];
698 rings.nring5++;
699 if (rings.nring5 >= MAXATOM/5)
700 message_alert("Error. Too many 5 membered rings!","ERROR");
701 isix = aromatic_5(array,flags,atomnum,iat,bo);
702 if (isix == TRUE)
703 {
704 for (ij = 0; ij < 5; ij++)
705 flags[array[ij]] |= aromatic_mask;
706 }
707 }
708 }
709 }
710 }
711 }
712 }
713 }
714 }
715 }
716 }
717 }
718 }
719 // get six membered rings
720 for(i=1; i <= natom; i++)
721 {
722 for(j=0; j < MAXIAT; j++)
723 {
724 if (iat[i][j] != 0)
725 {
726 jatm = iat[i][j];
727 for (k=0; k < MAXIAT; k++)
728 {
729 if (iat[jatm][k] != 0 && iat[jatm][k] != i)
730 {
731 katm = iat[jatm][k];
732 if (!(isbond(katm,i)))
733 {
734 for(l=0; l < MAXIAT; l++)
735 {
736 if (iat[katm][l] != 0 && iat[katm][l] != jatm)
737 {
738 latm = iat[katm][l];
739 for (m=0; m < MAXIAT; m++)
740 {
741 if (iat[latm][m] != 0 && iat[latm][m] != katm && iat[latm][m] != jatm)
742 {
743 xatm = iat[latm][m];
744 for (n = 0; n < MAXIAT; n++)
745 {
746 if (iat[xatm][n] != 0 && iat[xatm][n] != latm && iat[xatm][n] != katm)
747 if (isbond(i,iat[xatm][n]))
748 {
749 array[0] = i;
750 array[1] = jatm;
751 array[2] = katm;
752 array[3] = latm;
753 array[4] = xatm;
754 array[5] = iat[xatm][n];
755 ksort(6,array);
756 if (is_ring66(array) == FALSE)
757 {
758 rings.r16[rings.nring6][0] = array[0];
759 rings.r16[rings.nring6][1] = array[1];
760 rings.r16[rings.nring6][2] = array[2];
761 rings.r16[rings.nring6][3] = array[3];
762 rings.r16[rings.nring6][4] = array[4];
763 rings.r16[rings.nring6][5] = array[5];
764 rings.nring6++;
765 if (rings.nring6 >= MAXATOM/6)
766 message_alert("Error. Too many 6 membered rings!","ERROR");
767 isix = aromatic_6(array,flags,atomnum,iat,bo);
768 if (isix == TRUE)
769 {
770 for (ij = 0; ij < 6; ij++)
771 flags[array[ij]] |= aromatic_mask;
772 }
773 }
774 }
775 }
776 }
777 }
778 }
779 }
780 }
781 }
782 }
783 }
784 }
785 }
786 }
787 /* =================================================== */
788 void ksort(int num, int array[])
789 {
790 int i,temp;
791 int found;
792
793 L_1:
794 found = FALSE;
795 for (i=0; i < num-1; i++)
796 {
797 if (array[i+1] < array[i])
798 {
799 temp = array[i];
800 array[i] = array[i+1];
801 array[i+1] = temp;
802 found = TRUE;
803 }
804 }
805 if (found == TRUE)
806 goto L_1;
807 }
808 /* --------------------------------------------------------- */
809 int aromatic_5(int *array,long int *flags,int *atomnum,int **iat,int **bo)
810 {
811 int i,j,k, jatm, katm;
812 int nodbl, npi;
813 int ia, ib, ic;
814 int db[10];
815 int ihetero;
816 long int aromatic_mask, mask6;
817
818 aromatic_mask = (1 << AROMATIC_MASK);
819 mask6 = (1L << RING6);
820
821 npi = 0;
822 ihetero = 0;
823 for (i=0; i < 4; i++)
824 {
825 jatm = array[i];
826 for (j=i+1;j < 5; j++)
827 {
828 katm = array[j];
829 if (isbond(jatm,katm))
830 {
831 for (k=0; k < MAXIAT; k++)
832 {
833 if (iat[jatm][k] == katm)
834 {
835 if (bo[jatm][k] == 2)
836 {
837 db[npi] = i+j;
838 npi++;
839 }else if ( (flags[jatm] & aromatic_mask && flags[jatm] & mask6 )
840 && (flags[katm] & aromatic_mask && flags[katm] & mask6 ))
841 {
842 db[npi] = i+j;
843 npi++;
844 }
845 }
846 }
847 }
848 }
849 }
850 for (i=0; i < 5; i++)
851 {
852 jatm = array[i];
853 if (atomnum[jatm] != 6)
854 {
855 nodbl = FALSE;
856 for(j=0; j < MAXIAT; j++)
857 {
858 if (iat[jatm][j] != 0)
859 {
860 if (bo[jatm][j] > 1 && bo[jatm][j] != 9)
861 nodbl = TRUE;
862 }
863 }
864 if (nodbl == FALSE)
865 ihetero = jatm;
866 }
867 }
868 if (npi >= 2 && ihetero != 0) // got an aromatic ring with heteroatom
869 return TRUE;
870
871 if (npi == 0) // no double bonds in ring
872 return FALSE;
873
874 if (npi == 1 && ihetero == 0)
875 return FALSE;
876
877 if (npi == 1)
878 {
879 if (db[0] == 1)
880 {
881 ia = array[2];
882 ib = array[3];
883 ic = array[4];
884 } else if (db[0] == 3)
885 {
886 ia = array[0];
887 ib = array[3];
888 ic = array[4];
889 } else if (db[0] == 4)
890 {
891 ia = array[1];
892 ib = array[2];
893 ic = array[3];
894 } else if (db[0] == 5)
895 {
896 ia = array[0];
897 ib = array[1];
898 ic = array[4];
899 } else if (db[0] == 7)
900 {
901 ia = array[0];
902 ib = array[1];
903 ic = array[2];
904 }
905 if (ia == ihetero)
906 {
907 for(i=0; i < rings.nring6; i++)
908 {
909 for (j=0; j < 6; j++)
910 {
911 if (rings.r16[i][j] == ib)
912 {
913 if (flags[ib] & aromatic_mask)
914 return TRUE;
915 }
916 if (rings.r16[i][j] == ic)
917 {
918 if (flags[ic] & aromatic_mask)
919 return TRUE;
920 }
921 }
922 }
923 } else if (ib == ihetero)
924 {
925 for(i=0; i < rings.nring6; i++)
926 {
927 for (j=0; j < 6; j++)
928 {
929 if (rings.r16[i][j] == ia)
930 {
931 if (flags[ia] & aromatic_mask)
932 return TRUE;
933 }
934 if (rings.r16[i][j] == ic)
935 {
936 if (flags[ic] & aromatic_mask)
937 return TRUE;
938 }
939 }
940 }
941 } else if (ic == ihetero)
942 {
943 for(i=0; i < rings.nring6; i++)
944 {
945 for (j=0; j < 6; j++)
946 {
947 if (rings.r16[i][j] == ib)
948 {
949 if (flags[ib] & aromatic_mask)
950 return TRUE;
951 }
952 if (rings.r16[i][j] == ia)
953 {
954 if (flags[ia] & aromatic_mask)
955 return TRUE;
956 }
957 }
958 }
959 }
960 }
961 return FALSE;
962 }
963 /* --------------------------------------------------------- */
964 int aromatic_6(int *array,long int *flags,int *atomnum,int **iat,int **bo)
965 {
966 int i,j,k, ia,ib, idbl,kdbl;
967 int num, inarray[10];
968 long int aromatic_mask, mask6;
969
970 aromatic_mask = (1 << AROMATIC_MASK);
971 mask6 = (1L << RING6);
972 num = 0;
973 for (i=0; i < 10; i++)
974 inarray[i] = FALSE;
975
976 for (i=0; i < 5; i++)
977 {
978 ia = array[i];
979 for (j=i+1; j < 6; j++)
980 {
981 for (k=0; k < MAXIAT; k++)
982 {
983 if (iat[ia][k] == array[j])
984 {
985 if (bo[ia][k] == 2)
986 {
987 num++;
988 inarray[i] = TRUE;
989 inarray[j] = TRUE;
990 }
991 }
992 }
993 }
994 }
995 if (num == 3)
996 return TRUE;
997
998 if (num >= 1)
999 {
1000 for(i=0; i < 5; i++)
1001 {
1002 if (inarray[i] == FALSE)
1003 {
1004 ia = array[i];
1005 for(j=i+1;j < 6; j++)
1006 {
1007 if (inarray[j] == FALSE)
1008 {
1009 ib = array[j];
1010 if ( (flags[ia] & aromatic_mask) && (flags[ib] & aromatic_mask))
1011 {
1012 num++;
1013 if (num == 3)
1014 return TRUE;
1015 } else if (isbond(ia,ib))
1016 {
1017 idbl = FALSE;
1018 kdbl = FALSE;
1019 for(k=0; k < MAXIAT; k++)
1020 {
1021 if (iat[ia][k] !=0 && bo[ia][k] == 2)
1022 {
1023 if (atomnum[iat[ia][k]] == 6 || atomnum[iat[ia][k]] == 7)
1024 {
1025 if (flags[iat[ia][k]] & mask6)
1026 idbl = TRUE;
1027 }
1028 }
1029 if (iat[ib][k] !=0 && bo[ib][k] == 2)
1030 {
1031 if (atomnum[iat[ib][k]] == 6 || atomnum[iat[ib][k]] == 7)
1032 {
1033 if (flags[iat[ib][k]] & mask6)
1034 kdbl = TRUE;
1035 }
1036 }
1037 }
1038 if (idbl == TRUE && kdbl == TRUE)
1039 {
1040 num++;
1041 if (num == 3)
1042 return TRUE;
1043 }
1044 }
1045 inarray[i] = TRUE;
1046 inarray[j] = TRUE;
1047 }
1048 }
1049 }
1050 }
1051 }
1052 return FALSE;
1053 }
1054 // ==================================
1055 int check_ring1(int ia)
1056 {
1057 if (is_ring61(ia)) return TRUE;
1058 if (is_ring51(ia)) return TRUE;
1059 if (is_ring31(ia)) return TRUE;
1060 if (is_ring41(ia)) return TRUE;
1061 return FALSE;
1062 }