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