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