ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/type_mmx.c
Revision: 75
Committed: Mon Dec 15 18:03:29 2008 UTC (12 years, 11 months ago) by gilbertke
File size: 140533 byte(s)
Log Message:
fixes in typeing to pass MMFF validation suite
Line File contents
1 #define EXTERN extern
2 #include "pcwin.h"
3 #include "pcmod.h"
4 #include "field.h"
5 #include "utility.h"
6
7 void set_atomtype(int,int,int,int,int,int);
8 void set_atomtypes(int);
9 int is_cyclo3(int, int *);
10 int is_cyclo4(int, int *);
11 int is_cyclo5(int, int *);
12 int is_cyclo6(int, int *);
13 int isbond(int,int);
14 int aromatic_5(int,int *);
15 int aromatic_6(int *);
16 void search_rings(int);
17 int find_rsize(int,int);
18 void get_rsize(int,int,int, int *);
19 int icompare(int, int *, int *);
20 void type_amber(void);
21 void adjust_mmfftypes();
22 void bbchk(void);
23 void deletebond(int,int);
24 void pireset(void);
25
26 EXTERN struct t_ringdata {
27 int nring3, nring4, nring5, nring6;
28 int tot3, tot4, tot5, tot6;
29 int **iring3,**iring4,**iring5,**iring6;
30 } ringdata;
31
32
33 void type_mmx()
34 {
35 int i, j, ij, jji, jjk, jjbo, jj_bo, iatype,nh;
36 int k, l, jatm, katm, latm, jbo,kbo,lbo, m, ismetal;
37 int nnit,nnh,nc,no,nox,nitatom;
38 int ktype,jtype, jjik;
39 int adjn, nplus, adjn1, noxide, icurr;
40 int mmxtype,mm3type,mmfftype, ia, ib, ia1, ib1;
41 int ndouble, ntriple;
42 int icycl3, icycl4, icycl5, icycl6;
43 int full_ring, non_pi;
44 int array[7];
45 int nit[6];
46 int have_pi;
47 long int aromatic_mask, mask6, type_mask,pi_mask;
48
49 // save flags array
50 have_pi = FALSE;
51 pi_mask = (1L << PI_MASK);
52 for (i=1; i <= natom; i++)
53 {
54 if (atom[i].flags & pi_mask)
55 {
56 have_pi = TRUE;
57 break;
58 }
59 }
60
61 aromatic_mask = (1 << AROMATIC_MASK);
62 mask6 = (1L << RING6);
63 type_mask = (1L << NO_RETYPE);
64 if (have_pi == FALSE) // if we already have pi no need to mark
65 bbchk();
66 search_rings(0);
67
68 for (i=1; i <= natom; i++)
69 {
70 mmxtype = atom[i].mmx_type;
71 mm3type = atom[i].mm3_type;
72 mmfftype = atom[i].mmff_type;
73 if (atom[i].atomnum != 0 && !(atom[i].flags & type_mask) )
74 {
75 if (mmxtype == 100 || mmxtype == 101 || mmxtype == 102 || mmxtype == 103 ) // user defined type
76 {
77 goto L_20;
78 }
79 if (atom[i].atomnum == 1) // hydrogens
80 {
81 if (atom[i].mmx_type == 60) // dummy atoms
82 {
83 atom[i].flags |= (1L << DUMMY); // mark dummy atom
84 mmxtype = 60;
85 mm3type = 200;
86 mmfftype = 5;
87 goto L_10;
88 }
89 if (atom[i].mmx_type == 45) // TS H
90 {
91 mmxtype = 45;
92 mm3type = 0;
93 mmfftype = 0;
94 goto L_10;
95 }
96 if (atom[i].mmx_type == 36) // Deuterium
97 {
98 mmxtype = 36;
99 mm3type = 36;
100 mmfftype = 5;
101 goto L_10;
102 }
103 jji = 0;
104 for (j=0; j < MAXIAT; j++)
105 {
106 if (atom[i].iat[j] != 0 && (atom[i].bo[j] == 1 || atom[i].bo[j] == 9))
107 jji++;
108 }
109 if (jji == 2 ) // hydrogen bonded to two atoms or bonded to one and coordinated to another
110 {
111 mmxtype = 70;
112 goto L_10;
113 }
114 if (atom[atom[i].iat[0]].atomnum == 6) // carbon
115 {
116 mmxtype = 5;
117 mm3type = 5;
118 mmfftype = 5;
119 jatm = atom[i].iat[0];
120 for (j=0; j < 3; j++) // Acetylene
121 {
122 if (atom[jatm].bo[j] == 3)
123 {
124 mm3type = 124;
125 goto L_10;
126 }
127 }
128 goto L_10;
129 } else if (atom[atom[i].iat[0]].atomnum == 7) // nitrogen
130 {
131 jji = 0;
132 jatm = atom[i].iat[0];
133 iatype = atom[jatm].mmx_type;
134 noxide = FALSE;
135 ismetal = FALSE;
136 mmxtype = 23;
137 mm3type = 23;
138 mmfftype = 23;
139 for (j=0; j < MAXIAT; j++)
140 {
141 if (atom[jatm].iat[j] != 0 && atom[atom[jatm].iat[j]].mmx_type != 20 )
142 {
143 jji += atom[jatm].bo[j];
144 if (atom[atom[jatm].iat[j]].mmx_type >= 300)
145 ismetal = TRUE;
146 if (atom[atom[jatm].iat[j]].atomnum == 8)
147 {
148 katm = atom[jatm].iat[j];
149 jjk = 0;
150 for (k=0; k < MAXIAT; k++)
151 {
152 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 9)
153 jjk++;
154 }
155 if (jjk == 1)
156 noxide = TRUE;
157 }
158 }
159 }
160 if (jji == 4) // N+
161 {
162 mmxtype = 24;
163 mm3type = 48;
164 if (ismetal == TRUE)
165 {
166 mmxtype = 23;
167 mm3type = 23;
168 }
169 mmfftype = 36;
170 if (noxide == TRUE)
171 mmfftype = 23;
172 goto L_10;
173 }
174 if (atom[jatm].flags & aromatic_mask)
175 {
176 mmxtype = 23;
177 mm3type = 23;
178 mmfftype = 23;
179 if (is_cyclo5(jatm,array) )
180 {
181 jjk = 0;
182 for (j=0; j < 5; j++)
183 {
184 if (atom[array[j]].atomnum == 7)
185 jjk++;
186 }
187 if (jjk == 2)
188 {
189 jj_bo = 0;
190 for (j=0; j < 5; j++)
191 {
192 if (atom[array[j]].atomnum == 7 && array[j] != jatm)
193 {
194 katm = array[j];
195 for(k=0; k < MAXIAT; k++)
196 {
197 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 9 && atom[atom[katm].iat[k]].mmx_type != 20)
198 jj_bo += atom[katm].bo[k];
199 }
200 if (jj_bo == 4)
201 {
202 mmfftype = 36;
203 goto L_10;
204 }
205 }
206 }
207 }
208 }
209 goto L_10;
210 }
211 if (atom[atom[i].iat[0]].mmff_type == 56 || atom[atom[i].iat[0]].mmff_type == 55)
212 {
213 mmfftype = 36;
214 goto L_10;
215 }
216 if (atom[atom[i].iat[0]].mmff_type == 62)
217 {
218 mmfftype = 23;
219 goto L_10;
220 }
221 for (j=0; j < MAXIAT; j++)
222 {
223 if (atom[jatm].iat[j] != 0 && atom[atom[jatm].iat[j]].mmx_type != 20)
224 {
225 if (atom[jatm].bo[j] == 2 && (atom[atom[jatm].iat[j]].atomnum == 6 || atom[atom[jatm].iat[j]].atomnum == 7)) // imine
226 {
227 mmxtype = 23;
228 mm3type = 23;
229 mmfftype = 27;
230 goto L_10;
231 }
232 if (atom[jatm].bo[j] == 2 && atom[atom[jatm].iat[j]].atomnum == 16 ) // imine
233 {
234 mmxtype = 23;
235 mm3type = 23;
236 mmfftype = 28;
237 goto L_10;
238 }
239 if (atom[atom[jatm].iat[j]].atomnum == 16 && atom[atom[jatm].iat[j]].mmff_type == 18) // thioamide
240 {
241 mmxtype = 23;
242 mm3type = 23;
243 mmfftype = 28;
244 goto L_10;
245 }
246 if (atom[atom[jatm].iat[j]].atomnum == 6 || atom[atom[jatm].iat[j]].atomnum == 7) // amide and enamine
247 {
248 katm = atom[jatm].iat[j];
249 for (k=0; k < MAXIAT; k++)
250 {
251 if (atom[katm].iat[k] != 0 && atom[katm].iat[k] != jatm)
252 {
253 if (atom[katm].bo[k] == 3 && atom[atom[katm].iat[k]].atomnum == 7)
254 {
255 mmxtype = 23;
256 mm3type = 23;
257 if (atom[jatm].mmff_type != 8)
258 mmfftype = 28;
259 else
260 mmfftype = 23;
261 goto L_10;
262 }
263 if (atom[katm].bo[k] == 2)
264 {
265 if (atom[atom[katm].iat[k]].atomnum == 8 || atom[atom[katm].iat[k]].atomnum == 16) // amide
266 {
267 mmxtype = 23;
268 mm3type = 28;
269 mmfftype = 28;
270 goto L_10;
271 } else if (atom[atom[katm].iat[k]].atomnum == 6)
272 {
273 mmxtype = 23;
274 mm3type = 28;
275 if (atom[jatm].mmff_type != 8)
276 mmfftype = 28;
277 else
278 mmfftype = 23;
279 goto L_10;
280 } else if ( atom[atom[katm].iat[k]].atomnum == 7) // HN-c=n and HN-c=n+
281 {
282 mmfftype = 28;
283 jjk = 0;
284 noxide = FALSE;
285 latm = atom[katm].iat[k];
286 for (l=0; l < MAXIAT; l++)
287 {
288 if (atom[latm].iat[l] != 0)
289 {
290 jjk += atom[latm].bo[l];
291 if (atom[atom[latm].iat[l]].atomnum == 8)
292 noxide = TRUE;
293 }
294 }
295 if (jjk == 4 && noxide == FALSE && atom[jatm].mmff_type != 40)
296 mmfftype = 36;
297 goto L_10;
298 }
299 }
300 }
301 }
302 }
303 }
304 }
305 mmxtype = 23; // amine
306 mm3type = 23;
307 mmfftype = 23;
308 goto L_10;
309 } else if (atom[atom[i].iat[0]].atomnum == 8) // oxygen
310 {
311 mmxtype = 21;
312 mm3type = 21;
313 mmfftype = 21;
314 jatm = atom[i].iat[0];
315 if (atom[jatm].iat[0] != i)
316 katm = atom[jatm].iat[0];
317 else
318 katm = atom[jatm].iat[1];
319 jji = 0;
320 for (j=0; j < MAXIAT; j++)
321 {
322 if (atom[jatm].iat[j] != 0 && atom[atom[jatm].iat[j]].atomnum == 1)
323 jji++;
324 }
325 if (atom[katm].atomnum == 1 && jji == 2) // water
326 {
327 mmxtype = 21;
328 mm3type = 21;
329 mmfftype = 31;
330 goto L_10;
331 } else if (atom[katm].atomnum == 1 && jji == 3) // h3o+
332 {
333 mmxtype = 24;
334 mm3type = 21;
335 mmfftype = 50;
336 goto L_10;
337 }
338 if (atom[katm].atomnum == 15) // h-o-p
339 {
340 mmxtype = 24;
341 mm3type = 24;
342 mmfftype = 24;
343 goto L_10;
344 }
345 if (atom[katm].atomnum == 16) // h-o-s
346 {
347 mmxtype = 24;
348 mm3type = 24;
349 mmfftype = 33;
350 goto L_10;
351 }
352 jji = 0;
353 for (j=0; j < MAXIAT; j++)
354 {
355 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] != 9 && atom[atom[jatm].iat[j]].mmx_type != 20)
356 jji++;
357 }
358 if (jji == 3 || jji == 4) // O+
359 {
360 mmxtype = 24;
361 mm3type = 21;
362 mmfftype = 50;
363 goto L_10;
364 }
365 for (j=0; j < MAXIAT; j++)
366 {
367 if (atom[atom[katm].iat[j]].atomnum == 8 && atom[katm].iat[j] != jatm)
368 {
369 if (atom[katm].bo[j] == 2) // carboxyl
370 {
371 mmxtype = 24;
372 mm3type = 24;
373 mmfftype = 24;
374 goto L_10;
375 }
376 }
377 if (atom[katm].atomnum == 6 && (atom[atom[katm].iat[j]].atomnum == 6 || atom[atom[katm].iat[j]].atomnum == 7)
378 && atom[katm].iat[j] != jatm) // enol
379 {
380 if (atom[katm].bo[j] == 2)
381 {
382 mmxtype = 28;
383 mm3type = 73;
384 mmfftype = 29;
385 goto L_10;
386 }
387 }
388 }
389 if (jji == 2) // OH
390 {
391 mmxtype = 21;
392 mm3type = 21;
393 mmfftype = 21;
394 for (j=0; j < MAXIAT; j++) // H-O=C
395 {
396 if (atom[jatm].iat[j] == katm && atom[jatm].bo[j] == 2)
397 {
398 mmxtype = 24;
399 mmfftype = 52;
400 goto L_10;
401 }
402 }
403 goto L_10;
404 }
405 goto L_10;
406 } else if (atom[atom[i].iat[0]].atomnum == 5) // boron
407 {
408 mmxtype = 23;
409 mm3type = 5;
410 mmfftype = 71;
411 goto L_10;
412 } else if (atom[atom[i].iat[0]].atomnum == 9 || atom[atom[i].iat[0]].atomnum == 17 ||
413 atom[atom[i].iat[0]].atomnum == 35 || atom[atom[i].iat[0]].atomnum == 53) // halogens
414 {
415 mmxtype = 21;
416 mm3type = 5;
417 mmfftype = 71;
418 goto L_10;
419 } else if (atom[atom[i].iat[0]].atomnum == 16) // sulfur
420 {
421 mmxtype = 21;
422 mm3type = 5;
423 mmfftype = 71;
424 goto L_10;
425 } else if (atom[atom[i].iat[0]].atomnum == 15) // phosphorous
426 {
427 mmxtype = 23;
428 mm3type = 5;
429 mmfftype = 71;
430 goto L_10;
431 } else // bridging hydrogens
432 {
433 jji = 0;
434 mm3type = 5;
435 for (j=0; j < MAXIAT; j++)
436 if (atom[i].iat[j] != 0)
437 jji++;
438 if (jji == 2)
439 mmxtype = 70;
440 else
441 {
442 mmxtype = 5;
443 mm3type = 5;
444 mmfftype = 5;
445 }
446 goto L_10;
447 }
448 } else if (atom[i].atomnum == 5) // boron
449 {
450 if (atom[i].mmx_type == 27) // four coordinate boron
451 {
452 mmxtype = 27;
453 mm3type = 27;
454 mmfftype = 0;
455 goto L_10;
456 }
457 if (atom[i].mmx_type == 43) // Transition state boron
458 {
459 mmxtype = 43;
460 mm3type = 0;
461 mmfftype = 0;
462 goto L_10;
463 }
464 jji = 0;
465 for (j=0; j < MAXIAT; j++)
466 {
467 if (atom[i].iat[j] != 0)
468 jji++;
469 }
470 if (jji == 4)
471 {
472 mmxtype = 27;
473 mm3type = 27;
474 mmfftype = 0;
475 } else
476 {
477 mmxtype = 26;
478 mm3type = 26;
479 mmfftype = 0;
480 }
481 goto L_10;
482 // =========================== Carbon ===============================
483 } else if (atom[i].atomnum == 6) // carbon
484 {
485 ndouble = 0;
486 ntriple = 0;
487 jji = 0;
488 icycl3 = find_rsize(3,i);
489 icycl4 = find_rsize(4,i);
490 icycl5 = find_rsize(5,i);
491 icycl6 = find_rsize(6,i);
492
493 for (j=0; j < MAXIAT; j++)
494 {
495 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
496 {
497 jji++;
498 if (atom[i].bo[j] == 3)
499 ntriple++;
500 if (atom[i].bo[j] == 2)
501 ndouble++;
502 }
503 }
504 // check here for types that can not be done by rules but must be set by user
505 // and thus should not be changed
506 if (mmxtype == 29) // C radical
507 {
508 mmxtype = 29;
509 mm3type = 29;
510 mmfftype = 0;
511 goto L_10;
512 } else if (mmxtype == 30) // C cation
513 {
514 mmxtype = 30;
515 mm3type = 30;
516 mmfftype = 0;
517 goto L_10;
518 } else if (mmxtype == 48) // C anion
519 {
520 mmxtype = 48;
521 mm3type = 0;
522 mmfftype = 0;
523 goto L_10;
524 } else if (mmxtype == 40) // aromatic carbon
525 {
526 mmxtype = 40;
527 mm3type = 50;
528 mmfftype = 37;
529 goto L_10;
530 } else if (mmxtype == 49 || mmxtype == 50 || mmxtype == 51 || mmxtype == 52) // TS atoms
531 {
532 mm3type = 0;
533 mmfftype = 0;
534 goto L_10;
535 }
536 // check rings
537 if (icycl5 >= 1 && icycl6 >= 1 && atom[i].flags & aromatic_mask) // CB and CN
538 {
539 get_rsize(i,5,0,array);
540 for (j=0; j < 5; j++)
541 {
542 if ( !(atom[array[j]].flags & aromatic_mask))
543 goto L_NOTPURINE;
544 }
545 nnh = 0;
546 nnit = 0;
547 for (j=0; j < 5; j++)
548 {
549 if (atom[array[j]].atomnum == 7)
550 {
551 nnit++;
552 for (k=0; k < 4; k++)
553 {
554 if (atom[atom[array[j]].iat[k]].atomnum == 1)
555 nnh++;
556 }
557 }
558 }
559 if (nnit == 2 && nnh == 2)
560 {
561 mmxtype = 2;
562 mm3type = 2;
563 mmfftype = 78;
564 goto L_10;
565 }
566 //
567 nnh = 0;
568 nnit = 0;
569 for (j=0; j < MAXIAT; j++)
570 {
571 if (atom[atom[i].iat[j]].atomnum == 7)
572 {
573 nnit++;
574 for (k=0; k < MAXIAT; k++)
575 {
576 if (atom[atom[atom[i].iat[j]].iat[k]].atomnum == 1)
577 {
578 nnh++;
579 }
580 }
581 }
582 }
583 }
584 L_NOTPURINE:
585 if (icycl5 >= 1 && atom[i].flags & aromatic_mask)
586 {
587 mmxtype = 2;
588 mm3type = 2;
589 for (ij=0; ij < icycl5; ij++)
590 {
591 // do mmff types
592 get_rsize(i,5,ij,array);
593 if (aromatic_5(ij,array))
594 {
595 icurr = -1;
596 nplus = FALSE;
597 for (j=0; j < 5; j++)
598 {
599 if (array[j] == i)
600 icurr = j;
601 if (atom[array[j]].atomnum == 7)
602 {
603 jjk = 0;
604 jj_bo = 0;
605 for (k=0; k < MAXIAT; k++)
606 {
607 if (atom[array[j]].iat[k] != 0 && atom[array[j]].bo[k] != 9 && atom[atom[array[j]].iat[k]].mmx_type != 20)
608 {
609 jjk++;
610 jj_bo += atom[array[j]].bo[k];
611 }
612 }
613 if (jjk == 2 && jj_bo == 2) // divalent N anion
614 {
615 mmfftype = 78;
616 goto L_10;
617 }
618 if (jj_bo == 4)
619 nplus = TRUE;
620 }
621 }
622
623 // check alpha
624 ia = (icurr+4)%5;
625 ib = (icurr+6)%5;
626 if (atom[array[ia]].atomnum == 7 && atom[array[ib]].atomnum == 7) // n=c-n
627 {
628 jatm = array[ia];
629 katm = array[ib];
630 jbo = 0;
631 kbo = 0;
632 for (j=0; j < MAXIAT; j++)
633 {
634 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] != 9 && atom[atom[jatm].iat[j]].mmx_type != 20)
635 jbo += atom[jatm].bo[j];
636 if (atom[katm].iat[j] != 0 && atom[katm].bo[j] != 9 && atom[atom[katm].iat[j]].mmx_type != 20)
637 kbo += atom[katm].bo[j];
638 }
639 if ( jbo == 4 && kbo == 3)
640 {
641 adjn = FALSE;
642 for (j=0; j < MAXIAT; j++)
643 {
644 if (atom[katm].iat[j] != 0 && atom[katm].bo[j] == 2)
645 adjn = TRUE;
646 }
647 if (adjn == FALSE)
648 {
649 mmfftype = 80;
650 goto L_10;
651 }
652 }else if (jbo == 3 && kbo == 4)
653 {
654 adjn = FALSE;
655 for (j=0; j < MAXIAT; j++)
656 {
657 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] == 2)
658 adjn = TRUE;
659 }
660 if (adjn == FALSE)
661 {
662 mmfftype = 80;
663 goto L_10;
664 }
665 }
666 }
667 if (nplus == TRUE) // found N+ in ring
668 {
669 noxide = FALSE;
670 jjk = 0;
671 for (j=0; j < 5; j++)
672 {
673 if (atom[array[j]].atomnum == 7)
674 {
675 nit[jjk] = j;
676 jjk++;
677 }
678 }
679 if (jjk >= 2)
680 {
681 jatm = array[nit[0]];
682 katm = array[nit[1]];
683 jbo = 0;
684 kbo = 0;
685 adjn = FALSE;
686 adjn1 = FALSE;
687 for (k=0; k < MAXIAT; k++)
688 {
689 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] != 9 && atom[atom[jatm].iat[k]].mmx_type != 20)
690 jbo += atom[jatm].bo[k];
691 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 9 && atom[atom[katm].iat[k]].mmx_type != 20)
692 kbo += atom[katm].bo[k];
693 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] == 2)
694 adjn = TRUE;
695 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] == 2)
696 adjn1 = TRUE;
697 }
698 if ( (jbo == 4 && kbo == 3 && adjn1 == FALSE) ||
699 (jbo == 3 && kbo == 4 && adjn == FALSE) )
700 {
701 noxide = FALSE;
702 if (jbo == 4)
703 ia1 = jatm;
704 else
705 ia1 = katm;
706 for (k=0; k < MAXIAT; k++)
707 {
708 if (atom[ia1].iat[k] != 0 && atom[atom[ia1].iat[k]].atomnum == 8)
709 {
710 jjk = 0;
711 ib1 = atom[ia1].iat[k];
712 for (l=0; l < MAXIAT; l++)
713 {
714 if (atom[ib1].iat[l] != 0 && atom[ib1].bo[l] != 9)
715 jjk++;
716 }
717 if (jjk == 1)
718 noxide = TRUE;
719 }
720 }
721 if (noxide == FALSE)
722 {
723 mmfftype = 78;
724 goto L_10;
725 }
726 }
727 }
728 }
729
730 if (atom[array[ia]].atomnum != 6 && atom[array[ib]].atomnum != 6) // x=c-x
731 {
732 jatm = array[ia];
733 katm = array[ib];
734 jbo = 0;
735 kbo = 0;
736 for (j=0; j < MAXIAT; j++)
737 {
738 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] != 9 && atom[atom[jatm].iat[j]].mmx_type != 20)
739 jbo += atom[jatm].bo[j];
740 if (atom[katm].iat[j] != 0 && atom[katm].bo[j] != 9 && atom[atom[katm].iat[j]].mmx_type != 20)
741 kbo += atom[katm].bo[j];
742 }
743 if ( (jbo == 4 && kbo == 2) || (jbo == 2 && kbo == 4))
744 {
745 for (j=0; j < MAXIAT; j++)
746 {
747 if (atom[i].iat[j] != 0 && atom[i].iat[j] != jatm && atom[i].iat[j] != katm)
748 {
749 if (atom[atom[i].iat[j]].atomnum == 7)
750 {
751 mmfftype = 80;
752 goto L_10;
753 }
754 }
755 }
756 }
757 }
758 if (atom[array[ia]].atomnum == 7) // alpha n
759 {
760 jatm = array[ia];
761 adjn = FALSE;
762 for (j=0; j < MAXIAT; j++)
763 {
764 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] ==2)
765 adjn = TRUE;
766 }
767 if (adjn == FALSE)
768 {
769 mmfftype = 63;
770 goto L_10;
771 }
772 }
773 if (atom[array[ib]].atomnum == 7) // alpha n
774 {
775 jatm = array[ib];
776 adjn = FALSE;
777 for (j=0; j < MAXIAT; j++)
778 {
779 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] == 2)
780 adjn = TRUE;
781 }
782 if (adjn == FALSE)
783 {
784 mmfftype = 63;
785 goto L_10;
786 }
787 }
788 if (atom[array[ia]].atomnum == 8 || atom[array[ib]].atomnum == 8 || // alpha o or s
789 atom[array[ia]].atomnum == 16 || atom[array[ib]].atomnum == 16 )
790 {
791 mmfftype = 63;
792 goto L_10;
793 }
794 // check beta
795 ia = (icurr+3)%5;
796 ib = (icurr+7)%5;
797 if (atom[array[ia]].atomnum == 7) // c=x-n
798 {
799 jatm = array[ia];
800 adjn = FALSE;
801 for (j=0; j < MAXIAT; j++)
802 {
803 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] == 2)
804 adjn = TRUE;
805 }
806 if (adjn == FALSE)
807 {
808 mmfftype = 64;
809 goto L_10;
810 }
811 }
812 if (atom[array[ib]].atomnum == 7) // c=x-n
813 {
814 jatm = array[ib];
815 adjn = FALSE;
816 for (j=0; j < MAXIAT; j++)
817 {
818 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] == 2)
819 adjn = TRUE;
820 }
821 if (adjn == FALSE)
822 {
823 mmfftype = 64;
824 goto L_10;
825 }
826 }
827 if (atom[array[ia]].atomnum == 8 || atom[array[ib]].atomnum == 8 || // beta o or s
828 atom[array[ia]].atomnum == 16 || atom[array[ib]].atomnum == 16 )
829 {
830 mmfftype = 64;
831 goto L_10;
832 }
833 }
834 }
835 }
836 if (icycl6 >= 1 && atom[i].flags & aromatic_mask)
837 {
838 mmxtype = 2;
839 mm3type = 2;
840 mmfftype = 37;
841 for (k = 0; k < icycl6; k++)
842 {
843 get_rsize(i,6,k,array);
844 {
845 full_ring = TRUE;
846 non_pi = FALSE;
847 for (j=0; j < 6; j++) // check all ring atoms are pi
848 {
849 if ( !(atom[array[j]].flags & aromatic_mask) )
850 non_pi = TRUE;
851 }
852 if (non_pi == TRUE)
853 full_ring = FALSE;
854 }
855 if (full_ring == TRUE)
856 break;
857 }
858 if (full_ring == FALSE) mmfftype = 2;
859 goto L_10;
860 }
861 if (icycl3 >= 1 )
862 {
863 mmxtype = 22;
864 mm3type = 22; // type 38 for cyclopropene, type 67 for cyclopropanone
865 if (ndouble >= 1)
866 {
867 for (j=0; j < MAXIAT; j++)
868 {
869 if (atom[i].iat[j] != 0)
870 {
871 if (atom[i].bo[j] == 2 && atom[atom[i].iat[j]].atomnum == 8)
872 {
873 mmxtype = 3;
874 mm3type = 67;
875 goto L_10;
876 }
877 }
878 }
879 mm3type = 38;
880 }
881 mmfftype = 22;
882 goto L_10;
883 }
884 // start of check on bondorders
885 if (ntriple == 1)
886 {
887 mmxtype = 4;
888 mm3type = 4;
889 mmfftype = 4;
890 if (jji == 1 && atom[atom[i].iat[0]].atomnum == 7)
891 {
892 mmfftype = 60; // isonitrile carbon
893 }
894 if ( (atom[atom[i].iat[0]].mmx_type >= 300) &&
895 atom[atom[i].iat[1]].mmx_type == 46)
896 {
897 mmxtype = 63;
898 goto L_10;
899 }
900 if ( (atom[atom[i].iat[1]].mmx_type >= 300) &&
901 atom[atom[i].iat[0]].mmx_type == 46)
902 {
903 mmxtype = 63;
904 goto L_10;
905 }
906 for (j=0; j < MAXIAT; j++)
907 {
908 if ( (atom[atom[i].iat[j]].mmx_type >= 300) && atom[i].bo[j] == 3)
909 {
910 mmxtype = 62;
911 goto L_10;
912 }
913 }
914 goto L_10;
915 }
916 if (ndouble == 2) // allenes and ketenes
917 {
918 mmxtype = 4;
919 mm3type = 68;
920 mmfftype = 4;
921 for (j=0; j < MAXIAT; j++) // metal carbene
922 {
923 if ( atom[atom[i].iat[j]].mmx_type >= 300)
924 mmxtype = 61;
925 }
926 goto L_10;
927 }
928 if (ndouble == 1)
929 {
930 for (j=0; j < MAXIAT; j++)
931 {
932 if (atom[i].iat[j] != 0)
933 {
934 if (atom[i].bo[j] == 2)
935 {
936 jatm = atom[i].iat[j];
937 break;
938 }
939 }
940 }
941 if (atom[jatm].atomnum == 15) // c=p
942 {
943 mmxtype = 2;
944 mm3type = 2;
945 mmfftype = 3;
946 goto L_10;
947 }
948 if (atom[jatm].atomnum == 16) // c=s
949 {
950 mmxtype = 2;
951 mm3type = 2;
952 mmfftype = 3;
953 for (k=0; k < MAXIAT; k++)
954 {
955 if (atom[i].iat[k] != 0 && atom[i].bo[k] != 9)
956 {
957 if (atom[atom[i].iat[k]].atomnum == 16 && atom[i].iat[k] != jatm)
958 {
959 katm = atom[i].iat[k];
960 jjk = 0;
961 for (l=0; l < MAXIAT; l++)
962 {
963 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9)
964 jjk++;
965 }
966 if (jjk == 1) // thiocarboxylate
967 {
968 mmfftype = 41;
969 goto L_10;
970 }
971 }
972 }
973 }
974 goto L_10;
975 }
976 if (atom[jatm].atomnum == 8) // C=O
977 {
978 mmxtype = 3;
979 mm3type = 3;
980 mmfftype = 3;
981 if (is_cyclo3(i,array)) // cyclopropanone
982 mm3type = 67;
983 else if (is_cyclo4(i,array)) // cyclobutanone
984 mm3type = 58;
985 else // carboxylate
986 {
987 for(k=0; k < MAXIAT; k++)
988 {
989 if (atom[i].iat[k] != 0)
990 {
991 if (atom[atom[i].iat[k]].atomnum == 8 && atom[i].iat[k] != jatm)
992 {
993 katm = atom[i].iat[k];
994 jjk = 0;
995 for (l=0; l < MAXIAT; l++)
996 {
997 if (atom[katm].iat[l] != 0 && atom[atom[katm].iat[l]].mmx_type != 20)
998 jjk++;
999 }
1000 if (jjk == 1)
1001 {
1002 mmfftype = 41;
1003 break;
1004 }
1005 }
1006 }
1007 }
1008 }
1009 goto L_10;
1010 } else if (atom[jatm].atomnum == 7) // C=N
1011 {
1012 mmxtype = 2;
1013 mm3type = 2;
1014 mmfftype = 3;
1015 if (jji == 3)
1016 {
1017 if (atom[i].iat[0] == jatm)
1018 {
1019 katm = atom[i].iat[1];
1020 latm = atom[i].iat[2];
1021 } else if (atom[i].iat[1] == jatm)
1022 {
1023 katm = atom[i].iat[0];
1024 latm = atom[i].iat[2];
1025 } else if (atom[i].iat[2] == jatm)
1026 {
1027 katm = atom[i].iat[0];
1028 latm = atom[i].iat[1];
1029 }
1030 if (atom[jatm].atomnum == 7 && atom[katm].atomnum == 7 && atom[latm].atomnum == 7)
1031 {
1032 jbo = 0;
1033 kbo = 0;
1034 lbo = 0;
1035 adjn = FALSE;
1036 for (j=0; j < MAXIAT; j++)
1037 {
1038 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] != 9 && atom[atom[jatm].iat[j]].mmx_type != 20)
1039 jbo += atom[jatm].bo[j];
1040 if (atom[katm].iat[j] != 0 && atom[katm].bo[j] != 9 && atom[atom[katm].iat[j]].mmx_type != 20)
1041 {
1042 kbo += atom[katm].bo[j];
1043 if (atom[katm].bo[j] == 2)
1044 adjn = TRUE;
1045 }
1046 if (atom[latm].iat[j] != 0 && atom[latm].bo[j] != 9)
1047 {
1048 lbo += atom[latm].bo[j];
1049 if (atom[latm].bo[j] == 2)
1050 adjn = TRUE;
1051 }
1052 }
1053 if (jbo == 4 && kbo == 3 && lbo == 3 && adjn == FALSE)
1054 {
1055 mmfftype = 57;
1056 goto L_10;
1057 }
1058 }
1059 if (atom[jatm].atomnum == 7 && atom[katm].atomnum == 7)
1060 {
1061 jbo = 0;
1062 kbo = 0;
1063 adjn = FALSE;
1064 for (j=0; j < MAXIAT; j++)
1065 {
1066 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] != 9 && atom[atom[jatm].iat[j]].mmx_type != 20)
1067 jbo += atom[jatm].bo[j];
1068 if (atom[katm].iat[j] != 0 && atom[katm].bo[j] != 9 && atom[atom[katm].iat[j]].mmx_type != 20)
1069 {
1070 kbo += atom[katm].bo[j];
1071 if (atom[katm].bo[j] == 2)
1072 adjn = TRUE;
1073 }
1074 }
1075 if (jbo == 4 && kbo == 3 && adjn == FALSE)
1076 {
1077 mmfftype = 57;
1078 goto L_10;
1079 }
1080 }
1081 if (atom[jatm].atomnum == 7 && atom[latm].atomnum == 7)
1082 {
1083 jbo = 0;
1084 lbo = 0;
1085 adjn = FALSE;
1086 for (j=0; j < MAXIAT; j++)
1087 {
1088 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] != 9 && atom[atom[jatm].iat[j]].mmx_type != 20)
1089 jbo += atom[jatm].bo[j];
1090 if (atom[latm].iat[j] != 0 && atom[latm].bo[j] != 9 && atom[atom[latm].iat[j]].mmx_type != 20)
1091 {
1092 lbo += atom[latm].bo[j];
1093 if (atom[latm].bo[j] == 2)
1094 adjn = TRUE;
1095 }
1096 }
1097 if (jbo == 4 && lbo == 3 && adjn == FALSE)
1098 {
1099 mmfftype = 57;
1100 goto L_10;
1101 }
1102 }
1103 }
1104 goto L_10;
1105 } else if (atom[jatm].atomnum == 6) // C=C
1106 {
1107 mmxtype = 2;
1108 mm3type = 2;
1109 mmfftype = 2;
1110 if (is_cyclo3(i,array)) // cyclopropene
1111 {
1112 mm3type = 38;
1113 goto L_10;
1114 }
1115 if (is_cyclo4(i,array)) // cyclobutene
1116 {
1117 mmxtype = 57;
1118 mm3type = 57;
1119 mmfftype = 30;
1120 goto L_10;
1121 }
1122
1123 goto L_10;
1124 } else // default for cases not dealt with yet
1125 {
1126 mmxtype = 2;
1127 mm3type = 2;
1128 mmfftype = 2;
1129 goto L_10;
1130 }
1131 goto L_10;
1132 }
1133 // get here with only single bonds to carbon
1134 mmxtype = 1;
1135 mm3type = 1;
1136 mmfftype = 1;
1137 if (is_cyclo3(i,array))
1138 {
1139 mmxtype = 22;
1140 mm3type = 22;
1141 mmfftype = 22;
1142 goto L_10;
1143 } else if (is_cyclo4(i,array))
1144 {
1145 mmxtype = 56;
1146 mm3type = 56;
1147 mmfftype = 20;
1148 goto L_10;
1149 }
1150 goto L_10;
1151 } else if (atom[i].atomnum == 7) // nitrogen
1152 {
1153 jji = 0;
1154 nc = 0;
1155 nh = 0;
1156 jjbo = 0;
1157 ndouble = 0;
1158 ntriple = 0;
1159 nplus = FALSE;
1160 noxide = FALSE;
1161 for (j=0; j < MAXIAT; j++)
1162 {
1163 if (atom[i].iat[j] != 0 && atom[atom[i].iat[j]].mmx_type != 20 && atom[atom[i].iat[j]].mmx_type < 300)
1164 jji++;
1165 if (atom[atom[i].iat[j]].atomnum == 1)
1166 nh++;
1167 if (atom[atom[i].iat[j]].atomnum == 6)
1168 nc++;
1169 }
1170 icycl5 = find_rsize(5,i);
1171 icycl6 = find_rsize(6,i);
1172 //
1173 if (icycl5 >= 1 && atom[i].flags & aromatic_mask)
1174 {
1175 for (j=0; j < MAXIAT; j++)
1176 {
1177 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9 && atom[atom[i].iat[j]].mmx_type != 20 )
1178 {
1179 jji++;
1180 jjbo += atom[i].bo[j];
1181 if (atom[atom[i].iat[j]].atomnum == 8)
1182 {
1183 katm = atom[i].iat[j];
1184 jjk = 0;
1185 for (k=0; k < MAXIAT; k++)
1186 {
1187 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 9)
1188 jjk++;
1189 }
1190 if (jjk == 1)
1191 noxide = TRUE;
1192 }
1193 }
1194 }
1195 get_rsize(i,5,0,array);
1196 for(j=0; j < 5; j++)
1197 {
1198 if (atom[array[j]].atomnum == 7)
1199 {
1200 jjk = 0;
1201 jj_bo = 0;
1202 for (k=0; k < MAXIAT; k++)
1203 {
1204 if (atom[array[j]].iat[k] != 0 && atom[array[j]].bo[k] != 9)
1205 {
1206 jjk++;
1207 jj_bo += atom[array[j]].bo[k];
1208 }
1209 }
1210 if (jji == 2 && jj_bo == 2) // found divalent anion
1211 {
1212 mmfftype = 76;
1213 goto L_10;
1214 }
1215 }
1216 }
1217 if (jji == 2 && jjbo == 2) // divalent anion
1218 {
1219 // mmxtype = 77;
1220 mmfftype = 76;
1221 goto L_10;
1222 }
1223 if (jjbo == 4 && noxide == TRUE)
1224 {
1225 mmxtype = 41;
1226 mm3type = 39;
1227 mmfftype = 82;
1228 goto L_10;
1229 }
1230 if (jjbo == 4)
1231 {
1232 mmxtype = 41;
1233 mm3type = 39;
1234 mmfftype = 81;
1235 goto L_10;
1236 }
1237 // assume only one ring need to fix this
1238 get_rsize(i,5,0,array);
1239 ndouble = 0;
1240 for (j=0; j < MAXIAT; j++)
1241 {
1242 if (atom[i].iat[j] != 0 && atom[i].bo[j] == 2)
1243 ndouble++;
1244 }
1245 if (ndouble == 1) // check for alpha or beta N,O,S
1246 {
1247 mmxtype = 37;
1248 mm3type = 37;
1249 icurr = -1;
1250 for (j=0; j < 5; j++)
1251 {
1252 if (array[j] == i)
1253 icurr = j;
1254 }
1255 if (icurr == 0)
1256 {
1257 ia = array[1];
1258 ib = array[4];
1259 } else if (icurr == 4)
1260 {
1261 ia = array[0];
1262 ib = array[3];
1263 } else
1264 {
1265 ia = array[icurr-1];
1266 ib = array[icurr+1];
1267 }
1268
1269 if (atom[ia].atomnum == 7) // alpha
1270 {
1271 adjn = FALSE;
1272 for (k=0; k < MAXIAT; k++)
1273 {
1274 if (atom[ia].iat[k] != 0 && atom[ia].bo[k] == 2)
1275 adjn = TRUE;
1276 }
1277 if (adjn == FALSE)
1278 {
1279 mmfftype = 65;
1280 goto L_10;
1281 }
1282 }
1283 if (atom[ib].atomnum == 7)
1284 {
1285 adjn = FALSE;
1286 for (k=0; k < MAXIAT; k++)
1287 {
1288 if (atom[ib].iat[k] != 0 && atom[ib].bo[k] == 2)
1289 adjn = TRUE;
1290 }
1291 if (adjn == FALSE)
1292 {
1293 mmfftype = 65;
1294 goto L_10;
1295 }
1296 }
1297 if (atom[ia].atomnum == 8 || atom[ia].atomnum == 16)
1298 {
1299 mmfftype = 65;
1300 goto L_10;
1301 }
1302 if (atom[ib].atomnum == 8 || atom[ib].atomnum == 16)
1303 {
1304 mmfftype = 65;
1305 goto L_10;
1306 }
1307 // now check beta
1308 if (icurr == 0)
1309 {
1310 ia = array[2]; ib = array[3];
1311 } else if (icurr == 1)
1312 {
1313 ia = array[3]; ib = array[4];
1314 } else if (icurr == 2)
1315 {
1316 ia = array[4]; ib = array[0];
1317 } else if (icurr == 3)
1318 {
1319 ia = array[0]; ib = array[1];
1320 } else if (icurr == 4)
1321 {
1322 ia = array[1]; ib = array[2];
1323 }
1324 if (atom[ia].atomnum == 7)
1325 {
1326 jjk = 0;
1327 jj_bo = 0;
1328 for (k=0; k < MAXIAT; k++)
1329 {
1330 if (atom[ia].iat[k] != 0 && atom[ia].bo[k] != 9)
1331 {
1332 jjk++;
1333 jj_bo += atom[ia].bo[k];
1334 }
1335 }
1336 if (jjk == 3 && jj_bo == 3)
1337 {
1338 mmfftype = 66;
1339 goto L_10;
1340 }
1341 }
1342 if (atom[ib].atomnum == 7)
1343 {
1344 jjk = 0;
1345 jj_bo = 0;
1346 for (k=0; k < MAXIAT; k++)
1347 {
1348 if (atom[ib].iat[k] != 0 && atom[ib].bo[k] != 9)
1349 {
1350 jjk++;
1351 jj_bo += atom[ib].bo[k];
1352 }
1353 }
1354 if (jjk == 3 && jj_bo == 3)
1355 {
1356 mmfftype = 66;
1357 goto L_10;
1358 }
1359 }
1360 if (atom[ia].atomnum == 8 || atom[ia].atomnum == 16)
1361 {
1362 mmfftype = 66;
1363 goto L_10;
1364 }
1365 if (atom[ib].atomnum == 8 || atom[ib].atomnum == 16)
1366 {
1367 mmfftype = 66;
1368 goto L_10;
1369 }
1370 }
1371 // single bonds only
1372 icurr = -1;
1373 nplus = FALSE;
1374 for (j=0; j < 5; j++)
1375 {
1376 if (array[j] == i)
1377 icurr = j;
1378 if (atom[array[j]].atomnum == 7)
1379 nplus = TRUE;
1380 }
1381 if (nplus == TRUE)
1382 {
1383 if (icurr == 0)
1384 {
1385 ia = array[2]; ib = array[3];
1386 } else if (icurr == 1)
1387 {
1388 ia = array[3]; ib = array[4];
1389 } else if (icurr == 2)
1390 {
1391 ia = array[4]; ib = array[0];
1392 } else if (icurr == 3)
1393 {
1394 ia = array[0]; ib = array[1];
1395 } else if (icurr == 4)
1396 {
1397 ia = array[1]; ib = array[2];
1398 }
1399 if (atom[ia].atomnum == 7)
1400 {
1401 jj_bo = 0;
1402 noxide = FALSE;
1403 for (k=0; k < MAXIAT; k++)
1404 {
1405 if (atom[ia].iat[k] != 0 && atom[ia].bo[k] != 9)
1406 jj_bo += atom[ia].bo[k];
1407 if (atom[atom[ia].iat[k]].atomnum == 8)
1408 {
1409 jjk = 0;
1410 katm = atom[ia].iat[k];
1411 for (l=0; l < MAXIAT; l++)
1412 {
1413 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9)
1414 jjk++;
1415 }
1416 if (jjk == 1)
1417 noxide = TRUE;
1418 }
1419 }
1420 if (jj_bo == 4 && noxide == FALSE)
1421 {
1422 mmfftype = 81; // histidine ??
1423 goto L_10;
1424 }
1425 }
1426 if (atom[ib].atomnum == 7)
1427 {
1428 jj_bo = 0;
1429 noxide = FALSE;
1430 for (k=0; k < MAXIAT; k++)
1431 {
1432 if (atom[ib].iat[k] != 0 && atom[ib].bo[k] != 9)
1433 jj_bo += atom[ib].bo[k];
1434 if (atom[atom[ib].iat[k]].atomnum == 8)
1435 {
1436 jjk = 0;
1437 katm = atom[ib].iat[k];
1438 for (l=0; l < MAXIAT; l++)
1439 {
1440 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9)
1441 jjk++;
1442 }
1443 if (jjk == 1)
1444 noxide = TRUE;
1445 }
1446 }
1447 if (jj_bo == 4 && noxide == FALSE)
1448 {
1449 mmfftype = 81; // histidine ??
1450 goto L_10;
1451 }
1452 }
1453 }
1454 // need test for pyrol here
1455 ndouble = 0;
1456 for (j=0; j < MAXIAT; j++)
1457 {
1458 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
1459 {
1460 katm = atom[i].iat[j];
1461 for (k=0; k < MAXIAT; k++)
1462 {
1463 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] == 2)
1464 ndouble++;
1465 }
1466 }
1467 }
1468 if (ndouble >= 1)
1469 {
1470 mmxtype = 9;
1471 mm3type = 9;
1472 }
1473 // failed tests use general type
1474 mmfftype = 39;
1475 goto L_10;
1476 }
1477 if (icycl6 >= 1 && atom[i].flags & aromatic_mask)
1478 {
1479 mmxtype = 37;
1480 mm3type = 37;
1481 mmfftype = 38;
1482 nnit = 0;
1483 get_rsize(i,6,0,array);
1484 for (j=0; j < 6; j++)
1485 {
1486 if (atom[array[j]].atomnum == 7)
1487 nnit++;
1488 }
1489 jji = 0;
1490 jjbo = 0;
1491 for (j=0; j < MAXIAT; j++)
1492 {
1493 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9 && atom[atom[i].iat[j]].mmx_type != 20 &&
1494 atom[atom[i].iat[j]].mmx_type < 300 )
1495 {
1496 jji++;
1497 jjbo += atom[i].bo[j];
1498 if (atom[atom[i].iat[j]].atomnum == 8)
1499 {
1500 katm = atom[i].iat[j];
1501 jjk =0;
1502 for (k=0; k < MAXIAT; k++)
1503 {
1504 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 9 && atom[atom[katm].iat[k]].mmx_type != 20)
1505 jjk++;
1506 }
1507 if (jjk == 1)
1508 noxide = TRUE;
1509 }
1510 }
1511 }
1512 if (jjbo == 4 && noxide == TRUE)
1513 {
1514 mmxtype = 41;
1515 mm3type = 143;
1516 mmfftype = 69;
1517 } else if (jjbo == 4)
1518 {
1519 mmxtype = 41;
1520 mm3type = 111;
1521 mmfftype = 58;
1522 }
1523 goto L_10;
1524 }
1525 // non cyclic systems
1526 jji = 0;
1527 jjbo = 0;
1528 ndouble = 0;
1529 ntriple = 0;
1530 for (j=0; j < MAXIAT; j++)
1531 {
1532 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9 && atom[atom[i].iat[j]].mmx_type != 20 && atom[atom[i].iat[j]].mmx_type < 300)
1533 {
1534 jji++;
1535 jjbo += atom[i].bo[j];
1536 if (atom[i].bo[j] == 2)
1537 ndouble++;
1538 if (atom[i].bo[j] == 3)
1539 ntriple++;
1540 }
1541 }
1542 if (ntriple == 1) // nitriles and isonitriles
1543 {
1544 mmxtype = 10;
1545 mm3type = 10;
1546 if (jji == 1)
1547 mmfftype = 42;
1548 else if (jji == 2)
1549 {
1550 mmfftype = 61;
1551 mmxtype = 68;
1552 // nitrile oxides
1553 if (atom[atom[i].iat[0]].atomnum == 8 || atom[atom[i].iat[1]].atomnum == 8)
1554 mmxtype = 41;
1555 }
1556 for (j=0; j < MAXIAT; j++)
1557 {
1558 if (atom[atom[i].iat[j]].mmx_type >= 300)
1559 mmxtype = 65;
1560 }
1561 goto L_10;
1562 }
1563 // two double bonds to N - azides
1564 if (ndouble == 2 && jji == 2)
1565 {
1566 mmxtype = 37;
1567 mm3type = 46;
1568 mmfftype = 53;
1569 goto L_10;
1570 } else if (ndouble == 2 && jji == 3) // nitrate
1571 {
1572 mmxtype = 41;
1573 mm3type = 45;
1574 mmfftype = 45;
1575 goto L_10;
1576 }
1577 // single double bond to N
1578 if (ndouble == 1)
1579 {
1580 mmxtype = 37;
1581 mm3type = 37;
1582 mmfftype = 9;
1583 if (jji == 3 && jjbo == 4) //=N+
1584 {
1585 mmxtype = 41;
1586 mm3type = 39;
1587 // goto L_10;
1588 }
1589 for (j=0; j < MAXIAT; j++)
1590 {
1591 if (atom[i].iat[j] != 0 && atom[i].bo[j] == 2)
1592 {
1593 jatm = atom[i].iat[j];
1594 break;
1595 }
1596 }
1597 if (jji == 1 && atom[jatm].atomnum == 7) // N=N=X azido and diazo
1598 {
1599 mmfftype = 47;
1600 goto L_10;
1601 }
1602 if (atom[jatm].atomnum == 8) // N=O
1603 {
1604 if (jjbo == 4) // nitro
1605 {
1606 mmxtype = 41;
1607 mm3type = 46;
1608 mmfftype = 45;
1609 goto L_10;
1610 } else if (jjbo == 3) // nitroso
1611 {
1612 mmxtype = 37;
1613 mm3type = 0;
1614 mmfftype = 46;
1615 goto L_10;
1616 }
1617 }else if (atom[jatm].atomnum == 16) // N=S=O
1618 {
1619 for (k=0; k < MAXIAT; k++)
1620 {
1621 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] != 9 && atom[jatm].iat[k] != i)
1622 {
1623 if (atom[atom[jatm].iat[k]].atomnum == 8 && atom[jatm].bo[k] == 2)
1624 {
1625 mmfftype = 48;
1626 goto L_10;
1627 }
1628 }
1629 }
1630 } else if (atom[jatm].atomnum == 7) // N=N
1631 {
1632 mmfftype = 9;
1633 if (jjbo == 4)
1634 {
1635 for (k=0; k < MAXIAT; k++)
1636 {
1637 if (atom[i].iat[k] != 0 && atom[i].iat[k] != jatm)
1638 {
1639 if (atom[atom[i].iat[k]].atomnum == 8) // n=n-o azoxy
1640 {
1641 mmxtype = 37;
1642 mm3type = 37;
1643 mmfftype = 67;
1644 goto L_10;
1645 }
1646 }
1647 }
1648 }
1649 goto L_10;
1650 } else if (atom[jatm].atomnum == 6) // N=C
1651 {
1652 jjk = 0;
1653 for (k=0; k < MAXIAT; k++)
1654 {
1655 if (atom[jatm].iat[k] != 0)
1656 jjk++;
1657 }
1658 if (jjk == 3)
1659 {
1660 if (atom[jatm].iat[0] == i)
1661 {
1662 katm = atom[jatm].iat[1];
1663 latm = atom[jatm].iat[2];
1664 } else if (atom[jatm].iat[1] == i)
1665 {
1666 katm = atom[jatm].iat[0];
1667 latm = atom[jatm].iat[2];
1668 } else if (atom[jatm].iat[2] == i)
1669 {
1670 katm = atom[jatm].iat[0];
1671 latm = atom[jatm].iat[1];
1672 }
1673 jbo = 0;
1674 kbo = 0;
1675 lbo = 0;
1676 adjn = FALSE;
1677 if (atom[katm].atomnum == 7 && atom[latm].atomnum == 7)
1678 {
1679 for (k=0; k < MAXIAT; k++)
1680 {
1681 if (atom[i].iat[k] != 0 && atom[i].bo[k] != 0 && atom[atom[i].iat[k]].mmx_type != 20)
1682 jbo += atom[i].bo[k];
1683 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 0 && atom[atom[katm].iat[k]].mmx_type != 20)
1684 {
1685 kbo += atom[katm].bo[k];
1686 if (atom[katm].bo[k] == 2)
1687 adjn = TRUE;
1688 }
1689 if (atom[latm].iat[k] != 0 && atom[latm].bo[k] != 0 && atom[atom[latm].iat[k]].mmx_type != 20)
1690 {
1691 lbo += atom[latm].bo[k];
1692 if (atom[latm].bo[k] == 2)
1693 adjn = TRUE;
1694 }
1695 }
1696 if (jbo == 4 && kbo == 3 && lbo == 3 && adjn == FALSE)
1697 {
1698 mmfftype = 56;
1699 goto L_10;
1700 }
1701 }
1702 if (atom[katm].atomnum == 7)
1703 {
1704 jbo = 0;
1705 kbo = 0;
1706 adjn = FALSE;
1707 for (k=0; k < MAXIAT; k++)
1708 {
1709 if (atom[i].iat[k] != 0 && atom[i].bo[k] != 0 && atom[atom[i].iat[k]].mmx_type != 20)
1710 jbo += atom[i].bo[k];
1711 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 0 && atom[atom[katm].iat[k]].mmx_type != 20)
1712 {
1713 kbo += atom[katm].bo[k];
1714 if (atom[katm].bo[k] == 2)
1715 adjn = TRUE;
1716 }
1717 }
1718 if (jbo == 4 && kbo == 3 && adjn == FALSE)
1719 {
1720 mmfftype = 55;
1721 goto L_10;
1722 }
1723 }
1724 if (atom[latm].atomnum == 7)
1725 {
1726 jbo = 0;
1727 lbo = 0;
1728 adjn = FALSE;
1729 for (k=0; k < MAXIAT; k++)
1730 {
1731 if (atom[i].iat[k] != 0 && atom[i].bo[k] != 0)
1732 jbo += atom[i].bo[k];
1733 if (atom[latm].iat[k] != 0 && atom[latm].bo[k] != 0)
1734 {
1735 lbo += atom[latm].bo[k];
1736 if (atom[latm].bo[k] == 2)
1737 adjn = TRUE;
1738 }
1739 }
1740 if (jbo == 4 && lbo == 3 && adjn == FALSE)
1741 {
1742 mmfftype = 55;
1743 goto L_10;
1744 }
1745 }
1746 }
1747 if (jjbo == 4) // c=n+
1748 {
1749 mmxtype = 41;
1750 for (j=0; j < MAXIAT; j++)
1751 {
1752 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
1753 {
1754 if (atom[atom[i].iat[j]].atomnum == 8) // c=n+-o
1755 {
1756 katm = atom[i].iat[j];
1757 jjk = 0;
1758 for (k=0; k < MAXIAT; k++)
1759 {
1760 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 9)
1761 jjk++;
1762 }
1763 if (jjk == 1)
1764 mmfftype = 67;
1765 else if (jjk == 2)
1766 mmfftype = 54;
1767 goto L_10;
1768 }
1769 }
1770 }
1771 mmfftype = 54;
1772 goto L_10;
1773 }
1774 mmxtype = 37;
1775 mm3type = 37;
1776 mmfftype = 9;
1777 goto L_10;
1778 } // got here with not assignment check other side for mmff
1779 for (j=0; j < MAXIAT; j++)
1780 {
1781 if (atom[i].iat[j] != 0 && atom[i].iat[j] != jatm && atom[i].bo[j] != 9)
1782 {
1783 katm = atom[i].iat[j];
1784 if (atom[katm].atomnum == 16)
1785 {
1786 for (k=0; k < MAXIAT; k++)
1787 {
1788 if (atom[katm].iat[k] != 0 && atom[katm].iat[k] != i && atom[katm].bo[k] == 2)
1789 {
1790 if (atom[atom[katm].iat[k]].atomnum == 8)
1791 {
1792 mmfftype = 43;
1793 goto L_10;
1794 }
1795 }
1796 }
1797 }
1798 }
1799 }
1800 goto L_10;
1801 }
1802 // goto here with only single bonds to nitrogen
1803 mmxtype = 8;
1804 mm3type = 8;
1805 mmfftype = 8;
1806 if (jji == 2) // divalent anionic N
1807 {
1808 for (j=0; j < MAXIAT; j++)
1809 {
1810 if (atom[atom[i].iat[j]].mmx_type > 300) // attached metal
1811 {
1812 for (k=0; k < MAXIAT; k++)
1813 {
1814 if (atom[i].iat[k] != 0 && atom[i].iat[k] != atom[i].iat[j])
1815 {
1816 jatm = atom[i].iat[k];
1817 for (l=0; l < MAXIAT; l++)
1818 {
1819 if (atom[jatm].iat[l] != 0)
1820 {
1821 if (atom[jatm].bo[l] >= 2)
1822 {
1823 mmxtype = 9;
1824 goto L_10;
1825 }
1826 }
1827 }
1828 }
1829 }
1830 }
1831 }
1832 // mmxtype = 77;
1833 mmfftype = 62;
1834 goto L_10;
1835 }
1836 if (jji == 4 && jjbo == 4)
1837 {
1838 mmxtype = 41;
1839 mm3type = 39;
1840 mmfftype = 34;
1841 for (j=0; j < MAXIAT; j++)
1842 {
1843 if (atom[i].iat[j] != 0 && (atom[atom[i].iat[j]].mmx_type >= 300))
1844 {
1845 mmxtype = 8;
1846 mm3type = 8;
1847 }
1848 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
1849 {
1850 if (atom[atom[i].iat[j]].atomnum == 8)
1851 mmfftype = 68;
1852 }
1853 }
1854 goto L_10;
1855 }
1856 ndouble = 0;
1857 for (j=0; j < MAXIAT; j++)
1858 {
1859 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
1860 {
1861 katm = atom[i].iat[j];
1862 for (k=0; k < MAXIAT; k++)
1863 {
1864 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] == 2)
1865 ndouble++;
1866 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] == 3)
1867 ndouble++;
1868 }
1869 }
1870 }
1871 if (ndouble >= 1)
1872 {
1873 mmxtype = 9;
1874 mm3type = 9;
1875 mmfftype = 8;
1876 for (j=0; j < MAXIAT; j++)
1877 {
1878 if (atom[i].iat[j] != 0 && atom[atom[i].iat[j]].atomnum == 6)
1879 {
1880 jatm = atom[i].iat[j];
1881 jjk = 0;
1882 for (k=0; k < MAXIAT; k++)
1883 {
1884 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] != 9 && atom[atom[jatm].iat[k]].mmx_type != 20)
1885 jjk++;
1886 }
1887 if (jjk == 3)
1888 {
1889 if (atom[jatm].iat[0] == i)
1890 {
1891 if (atom[jatm].bo[1] == 2)
1892 {
1893 katm = atom[jatm].iat[1];
1894 latm = atom[jatm].iat[2];
1895 }else
1896 {
1897 latm = atom[jatm].iat[1];
1898 katm = atom[jatm].iat[2];
1899 }
1900 } else if (atom[jatm].iat[1] == i)
1901 {
1902 if (atom[jatm].bo[0] == 2)
1903 {
1904 katm = atom[jatm].iat[0];
1905 latm = atom[jatm].iat[2];
1906 }else
1907 {
1908 latm = atom[jatm].iat[0];
1909 katm = atom[jatm].iat[2];
1910 }
1911 }else if (atom[jatm].iat[2] == i)
1912 {
1913 if (atom[jatm].bo[0] == 2)
1914 {
1915 katm = atom[jatm].iat[0];
1916 latm = atom[jatm].iat[1];
1917 }else
1918 {
1919 latm = atom[jatm].iat[0];
1920 katm = atom[jatm].iat[1];
1921 }
1922 }
1923 if (atom[katm].atomnum == 7 && atom[latm].atomnum == 7)
1924 {
1925 jbo = 0;
1926 kbo = 0;
1927 adjn = FALSE;
1928 for(k=0; k < MAXIAT; k++)
1929 {
1930 if (atom[katm].iat[k] != 0 && atom[katm].bo[k] != 9 && atom[atom[katm].iat[k]].mmx_type != 20)
1931 jbo += atom[katm].bo[k];
1932 if (atom[latm].iat[k] != 0 && atom[latm].bo[k] != 9 && atom[atom[latm].iat[k]].mmx_type != 20)
1933 {
1934 kbo += atom[latm].bo[k];
1935 if (atom[latm].bo[k] == 2)
1936 adjn = TRUE;
1937 }
1938 }
1939 if ( jbo == 4 && kbo == 3 && adjn == FALSE)
1940 {
1941 mmfftype =56;
1942 goto L_10;
1943 }
1944 }
1945 if (atom[katm].atomnum == 7) // N-C=N+
1946 {
1947 jj_bo = 0;
1948 noxide = FALSE;
1949 for (l=0; l < MAXIAT; l++)
1950 {
1951 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9 && atom[atom[katm].iat[l]].mmx_type != 20)
1952 jj_bo += atom[katm].bo[l];
1953 if (atom[atom[katm].iat[l]].atomnum == 8)
1954 {
1955 jjk = 0;
1956 latm = atom[katm].iat[l];
1957 for (m=0; m < MAXIAT; m++)
1958 {
1959 if (atom[latm].iat[m] != 0 && atom[latm].bo[m] != 9)
1960 jjk++;
1961 }
1962 if (jjk == 1)
1963 noxide = TRUE;
1964 }
1965 }
1966 if (jj_bo == 4 && !(atom[katm].flags & aromatic_mask && atom[katm].flags & mask6) && noxide == FALSE) // N-C=N+
1967 {
1968 mmfftype = 55;
1969 goto L_10;
1970 }
1971 }
1972 }
1973 }
1974 if (atom[i].iat[j] != 0 && atom[atom[i].iat[j]].atomnum == 7) // n-n=n
1975 {
1976 jatm = atom[i].iat[j];
1977 for (k=0; k < MAXIAT; k++)
1978 {
1979 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != i)
1980 {
1981 if (atom[jatm].bo[k] == 2 && atom[atom[jatm].iat[k]].atomnum == 7)
1982 {
1983 jbo = 0;
1984 kbo = 0;
1985 katm = atom[jatm].iat[k];
1986 for (l=0; l < MAXIAT; l++)
1987 {
1988 if (atom[jatm].iat[l] != 0 && atom[jatm].bo[l] != 9)
1989 jbo += atom[jatm].bo[l];
1990 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9)
1991 kbo += atom[katm].bo[l];
1992 }
1993 if (jbo == 3 && kbo == 3)
1994 {
1995 mmfftype = 10;
1996 goto L_10;
1997 }
1998 }
1999 }
2000 }
2001 }
2002
2003 }
2004 for(j=0; j < MAXIAT; j++)
2005 {
2006 if (atom[i].iat[j] != 0)
2007 {
2008 jatm = atom[i].iat[j];
2009 if (atom[jatm].atomnum == 16) // sulfonamide - need to check this further
2010 {
2011 jjk = 0;
2012 for (k=0; k < MAXIAT; k++)
2013 {
2014 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] != 9)
2015 {
2016 if (atom[atom[jatm].iat[k]].atomnum == 8 && atom[jatm].bo[k] == 2)
2017 jjk++;
2018 }
2019 }
2020 if (jjk >= 2)
2021 {
2022 mmxtype = 9;
2023 mm3type = 155;
2024 mmfftype = 43;
2025 goto L_10;
2026 }
2027 }
2028 if (atom[jatm].atomnum == 5) // boron
2029 {
2030 mmxtype = 9;
2031 mm3type = 9;
2032 mmfftype = 9;
2033 goto L_10;
2034 }
2035 }
2036 }
2037 for(j=0; j < MAXIAT; j++)
2038 {
2039 if (atom[i].iat[j] != 0)
2040 {
2041 jatm = atom[i].iat[j];
2042 for (k=0; k < MAXIAT; k++)
2043 {
2044 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] == 2)
2045 {
2046 if (atom[jatm].atomnum == 6 && atom[atom[jatm].iat[k]].atomnum == 8) // amide
2047 {
2048 mmxtype = 9;
2049 mm3type = 9;
2050 mmfftype = 10;
2051 goto L_10;
2052 }
2053 if (atom[jatm].atomnum == 6 && atom[atom[jatm].iat[k]].atomnum == 16) // thioamide
2054 {
2055 mmxtype = 9;
2056 mm3type = 9;
2057 mmfftype = 10;
2058 goto L_10;
2059 }
2060 }
2061 }
2062 }
2063 }
2064 if (jji == 3 && ndouble >= 1 ) // eneamine
2065 {
2066 for (j=0; j < MAXIAT; j++)
2067 {
2068 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
2069 {
2070 if (atom[atom[i].iat[j]].atomnum == 6)
2071 {
2072 jatm = atom[i].iat[j];
2073 for (k=0; k < MAXIAT; k++)
2074 {
2075 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] == 2)
2076 {
2077 mmxtype = 9;
2078 mmfftype = 40;
2079 goto L_10;
2080 }
2081 }
2082 }
2083 }
2084 }
2085 }
2086
2087 for(j=0; j < MAXIAT; j++)
2088 {
2089 if (atom[i].iat[j] != 0)
2090 {
2091 jatm = atom[i].iat[j];
2092 for (k=0; k < MAXIAT; k++)
2093 {
2094 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] == 2)
2095 {
2096 if (atom[jatm].atomnum == 15) // n-p=x
2097 {
2098 jjk = 0;
2099 for (l=0; l < MAXIAT; l++)
2100 {
2101 if (atom[jatm].iat[l] != 0 && atom[jatm].bo[l] != 9)
2102 jjk++;
2103 }
2104 if (jjk > 3)
2105 {
2106 mmxtype = 8;
2107 mm3type = 8;
2108 mmfftype = 8;
2109 goto L_10;
2110 }
2111 }
2112 }
2113 }
2114 }
2115 }
2116
2117 }
2118 // end of ndouble test
2119 for (j=0; j < MAXIAT; j++)
2120 {
2121 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
2122 {
2123 if (atom[atom[i].iat[j]].atomnum == 6) // carbon
2124 {
2125 for (k=0; k < MAXIAT; k++)
2126 {
2127 if (atom[atom[i].iat[j]].iat[k] != 0 && atom[atom[i].iat[j]].iat[k] != i)
2128 {
2129 if (atom[atom[i].iat[j]].bo[k] == 3 && atom[atom[atom[i].iat[j]].iat[k]].atomnum == 7)
2130 {
2131 mmfftype = 43;
2132 goto L_10;
2133 }
2134 }
2135 }
2136 } else if (atom[atom[i].iat[j]].atomnum == 7) // nitrogen - n-n bond - n-n-c=o
2137 {
2138 jatm = atom[i].iat[j];
2139 for (k=0; k < MAXIAT; k++)
2140 {
2141 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != i)
2142 {
2143 katm = atom[jatm].iat[k];
2144 if (atom[katm].atomnum == 6)
2145 {
2146 for (l=0; l < MAXIAT; l++)
2147 {
2148 if (atom[katm].iat[l] != 0 && atom[katm].iat[l] != jatm)
2149 {
2150 if (atom[atom[katm].iat[l]].atomnum == 8 && atom[katm].bo[l] == 2)
2151 {
2152 mmxtype = 9;
2153 goto L_10;
2154 }
2155 }
2156 }
2157 }
2158 }
2159 }
2160 }
2161 }
2162 }
2163 if (is_cyclo5(i,array) && atom[i].flags & aromatic_mask) // heterocycle
2164 {
2165 for (j=1; j < 5; j++)
2166 {
2167 if (atom[array[j]].atomnum != 6)
2168 {
2169 mmxtype = 8;
2170 mm3type = 8;
2171 mmfftype = 79;
2172 goto L_10;
2173 }
2174 }
2175 }
2176 for (j=0; j < MAXIAT; j++) // guanadinium
2177 {
2178 if (atom[i].iat[j] != 0 && atom[atom[i].iat[j]].atomnum == 6)
2179 {
2180 jatm = atom[i].iat[j];
2181 jjk = 0;
2182 for (k=0; k < MAXIAT; k++)
2183 {
2184 if (atom[jatm].iat[k] != 0)
2185 jjk++;
2186 }
2187 if (jjk == 3 && (atom[atom[jatm].iat[0]].atomnum == 7 &&
2188 atom[atom[jatm].iat[1]].atomnum == 7 && atom[atom[jatm].iat[2]].atomnum == 7) )
2189 {
2190 mmfftype = 56;
2191 goto L_10;
2192 }
2193 }
2194 }
2195 // mmxtypes that should not be changed - set by user
2196 if (atom[i].mmx_type == 41) // N+
2197 {
2198 mmxtype = 41;
2199 mm3type = 39;
2200 mmfftype = atom[i].mmff_type;
2201 if (mmfftype == 0 && (mmfftype != 34 || mmfftype != 54 || mmfftype != 55 || mmfftype != 56
2202 || mmfftype != 58 || mmfftype != 69 || mmfftype != 80 || mmfftype != 81) )
2203 mmfftype = 34;
2204 goto L_10;
2205 } else if (atom[i].mmx_type == 55) // TS Nitrogen
2206 {
2207 mmxtype = 55;
2208 mm3type = 0;
2209 mmfftype = 0;
2210 goto L_10;
2211 }
2212 goto L_10;
2213 } else if (atom[i].atomnum == 8) // oxygen
2214 {
2215 /* ======================== Oxygen ==================================== */
2216 if (atom[i].mmx_type == 53) // TS Oxygen
2217 {
2218 mmxtype = 53;
2219 mm3type = 0;
2220 mmfftype = 0;
2221 goto L_10;
2222 }
2223 jjbo = 0;
2224 for (j=0; j < MAXIAT; j++)
2225 {
2226 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9 && atom[atom[i].iat[j]].mmx_type != 20
2227 && (atom[atom[i].iat[j]].mmx_type < 300))
2228 jjbo += atom[i].bo[j];
2229 }
2230 if (jjbo == 3) // o+
2231 {
2232 mmxtype = 46;
2233 mmfftype = 49;
2234 mm3type = 0;
2235 for (j=0; j < MAXIAT; j++)
2236 {
2237 if (atom[i].iat[j] != 0 && atom[i].bo[j] == 2)
2238 {
2239 mmfftype = 51;
2240 goto L_10;
2241 }
2242 }
2243 goto L_10;
2244 }
2245 mmxtype = atom[i].mmx_type;
2246 if (mmxtype == 66)
2247 {
2248 mm3type = 47;
2249 mmfftype = 32;
2250 }
2251 if (mmxtype == 6 || mmxtype == 7 || mmxtype == 66)
2252 {
2253 for (j=0; j < MAXIAT; j++)
2254 {
2255 if (atom[i].bo[j] == 2) // x=0
2256 {
2257 mmxtype = 7;
2258 mm3type = 7;
2259 mmfftype = 7;
2260 jatm = atom[i].iat[j];
2261 if (atom[jatm].atomnum == 15) // p=o
2262 {
2263 for (k=0; k < MAXIAT; k++)
2264 {
2265 jjk = 0;
2266 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != i && atom[atom[jatm].iat[k]].atomnum == 8)
2267 {
2268 katm = atom[jatm].iat[k];
2269 for (l=0; l < MAXIAT; l++)
2270 {
2271 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9 && atom[atom[katm].iat[l]].mmx_type != 20)
2272 jjk++;
2273 }
2274 if (jjk == 1 && atom[katm].mmx_type == 42)
2275 {
2276 mmxtype = 66;
2277 mm3type = 47;
2278 }
2279 }
2280 }
2281 mmfftype = 32;
2282 goto L_10;
2283 }
2284 if (atom[jatm].atomnum == 16) // s=o
2285 {
2286 for (k=0; k < MAXIAT; k++)
2287 {
2288 jjk = 0;
2289 jj_bo = 0;
2290 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != i && atom[atom[jatm].iat[k]].atomnum == 8)
2291 {
2292 katm = atom[jatm].iat[k];
2293 for (l=0; l < MAXIAT; l++)
2294 {
2295 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9 && atom[atom[katm].iat[l]].mmx_type != 20)
2296 {
2297 jjk++;
2298 jj_bo += atom[katm].bo[l];
2299 }
2300 }
2301 if (jjk == 1 && jj_bo == 1 && atom[katm].mmx_type == 42)
2302 {
2303 mmxtype = 66;
2304 mm3type = 47;
2305 mmfftype = 32;
2306 goto L_10;
2307 }
2308 }
2309 }
2310 }
2311 if (atom[jatm].atomnum == 6) // c=o
2312 {
2313 mmfftype = 7;
2314 for (k=0; k < MAXIAT; k++)
2315 {
2316 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != i && atom[jatm].bo[k] != 9)
2317 {
2318 if (atom[atom[jatm].iat[k]].atomnum == 8)
2319 {
2320 katm = atom[jatm].iat[k];
2321 jjk = 0;
2322 for (l=0; l < MAXIAT; l++)
2323 {
2324 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9 && atom[atom[katm].iat[l]].mmx_type != 20)
2325 jjk++;
2326 }
2327 if (jjk == 1) // carboxylate
2328 {
2329 mmxtype = 66;
2330 mm3type = 47;
2331 mmfftype = 32;
2332 goto L_10;
2333 }
2334 if (jjk == 2) // ester and acids
2335 {
2336 if ( atom[atom[katm].iat[0]].atomnum != 1 && atom[atom[katm].iat[1]].atomnum != 1) // ester
2337 {
2338 mm3type = 78;
2339 goto L_10;
2340 } else if ( atom[atom[katm].iat[0]].atomnum == 1 || atom[atom[katm].iat[1]].atomnum == 1) // acid
2341 {
2342 mm3type = 77;
2343 goto L_10;
2344 }
2345 }
2346 }
2347 }
2348 }
2349 for (k=0; k < MAXIAT; k++)
2350 {
2351 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != i && atom[jatm].bo[k] != 9)
2352 {
2353 if (atom[atom[jatm].iat[k]].atomnum == 7) // amide
2354 {
2355 mm3type = 7; // should be 79 but database only has 58-79
2356 goto L_10;
2357 }
2358 }
2359 }
2360 for (k=0; k < MAXIAT; k++)
2361 {
2362 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != i && atom[jatm].bo[k] != 9)
2363 {
2364 if (atom[atom[jatm].iat[k]].atomnum == 6) // vinyl ketone
2365 {
2366 katm = atom[jatm].iat[k];
2367 for (l=0; l < MAXIAT; l++)
2368 {
2369 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] == 2)
2370 {
2371 mm3type = 81;
2372 goto L_10;
2373 }
2374 }
2375 }
2376 }
2377 }
2378 }
2379
2380 for (k=0; k < MAXIAT; k++)
2381 {
2382 if (atom[atom[jatm].iat[k]].atomnum == 8 && atom[jatm].iat[k] != i && atom[jatm].bo[k] == 1)
2383 {
2384 jji = 0;
2385 latm = atom[jatm].iat[k];
2386 for (l=0; l < MAXIAT; l++)
2387 {
2388 if (atom[latm].iat[l] != 0 && atom[latm].bo[l] != 9 && atom[atom[latm].iat[l]].mmx_type != 20)
2389 jji++;
2390 }
2391 if (jji == 1)
2392 {
2393 mmxtype = 66;
2394 mm3type = 47;
2395 mmfftype = 32;
2396 goto L_10;
2397 }
2398 } else if (atom[atom[jatm].iat[k]].atomnum == 8 && atom[jatm].iat[k] != i && atom[jatm].bo[k] == 2)
2399 {
2400 mmfftype = 32;
2401 goto L_10;
2402 } else if (atom[atom[jatm].iat[k]].atomnum == 16 && atom[jatm].iat[k] != i && atom[jatm].bo[k] == 2)
2403 {
2404 jjk = 0;
2405 latm = atom[jatm].iat[k];
2406 for (l=0; l < MAXIAT; l++)
2407 {
2408 if (atom[latm].iat[l] != 0 && atom[latm].bo[l] != 9 && atom[atom[latm].iat[l]].mmx_type != 20)
2409 jjk++;
2410 }
2411 if (jjk == 1)
2412 {
2413 mmxtype = 66;
2414 mm3type = 47;
2415 }
2416 mmfftype = 32;
2417 goto L_10;
2418 } else if (atom[atom[jatm].iat[k]].atomnum == 7 && atom[jatm].iat[k] != i && atom[jatm].bo[k] == 2)
2419 {
2420 mmfftype = 32;
2421 goto L_10;
2422 }
2423 }
2424 goto L_10;
2425 } else if (atom[i].bo[j] == 3)
2426 {
2427 mmxtype = 46;
2428 mmfftype = 53;
2429 goto L_10;
2430 }
2431 } // got here with only single bonds - don't reset 66
2432 jji = 0;
2433 nh = 0;
2434 for (j=0; j < MAXIAT; j++)
2435 {
2436 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9 && atom[atom[i].iat[j]].mmx_type != 20 &&
2437 atom[atom[i].iat[j]].mmx_type < 300)
2438 jji++;
2439 if (atom[atom[i].iat[j]].atomnum == 1)
2440 nh++;
2441 }
2442 if (jji == 1) // only one bond
2443 {
2444 if (atom[atom[i].iat[0]].atomnum == 6)
2445 {
2446 jatm = atom[i].iat[0];
2447 for (j=0; j < MAXIAT; j++)
2448 {
2449 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] == 2)
2450 {
2451
2452 if (atom[atom[jatm].iat[j]].atomnum == 6) // c=c
2453 {
2454 mmfftype = 35;
2455 goto L_10;
2456 }
2457 }
2458 }
2459 }
2460 if (atom[atom[i].iat[0]].atomnum == 7) // n-o
2461 {
2462 mmxtype = 66;
2463 mm3type = 69;
2464 mmfftype = 32;
2465 goto L_10;
2466 }
2467 if (atom[atom[i].iat[0]].atomnum == 15 || atom[atom[i].iat[0]].atomnum == 16) // p-o
2468 {
2469 mmxtype = 66;
2470 mm3type = 7;
2471 mmfftype = 32;
2472 goto L_10;
2473 }
2474
2475 }
2476 // test for epoxides
2477 if (is_cyclo3(i,array))
2478 {
2479 mm3type = 49;
2480 mmfftype = 6;
2481 goto L_10;
2482 }
2483 if (is_cyclo5(i,array))
2484 {
2485 if (atom[i].flags & aromatic_mask)
2486 {
2487 mmfftype = 59;
2488 mm3type = 41;
2489 goto L_10;
2490 }
2491 }
2492 if (jji == 2)
2493 {
2494 if (nh == 2) // mmff water
2495 {
2496 mmfftype = 70;
2497 goto L_10;
2498 } else if (nh == 1) // ROH and RCOOH
2499 {
2500 mm3type = 6;
2501 mmfftype = 6;
2502 jatm = atom[i].iat[0];
2503 for (j=0; j < MAXIAT; j++)
2504 {
2505 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] == 2)
2506 {
2507 if (atom[atom[jatm].iat[j]].atomnum == 8)
2508 {
2509 mm3type = 75;
2510 break;
2511 }
2512 }
2513 }
2514 goto L_10;
2515 } else
2516 {
2517 mmfftype = 6;
2518 goto L_10;
2519 }
2520 jatm = atom[i].iat[0];
2521 jtype = 0;
2522 katm = atom[i].iat[1];
2523 ktype = 0;
2524 for (j=0; j < MAXIAT; j++)
2525 {
2526 if (atom[jatm].iat[j] != 0 && atom[jatm].bo[j] == 2)
2527 {
2528 if (atom[atom[jatm].iat[j]].atomnum == 8)
2529 {
2530 jtype = 3;
2531 break;
2532 } else if (atom[atom[jatm].iat[j]].atomnum == 6)
2533 {
2534 jtype = 2;
2535 break;
2536 }
2537 }
2538 }
2539 for (j=0; j < MAXIAT; j++)
2540 {
2541 if (atom[katm].iat[j] != 0 && atom[katm].bo[j] == 2)
2542 {
2543 if (atom[atom[katm].iat[j]].atomnum == 8)
2544 {
2545 ktype = 3;
2546 break;
2547 }else if (atom[atom[katm].iat[j]].atomnum == 6)
2548 {
2549 ktype = 2;
2550 break;
2551 }
2552 }
2553 }
2554 if (jtype == 3 && ktype == 3) // anhydrides
2555 mm3type = 148;
2556 else if (jtype == 3 || ktype == 3) // carboxyl & ester
2557 mm3type = 75;
2558 else if (jtype == 2 && ktype == 2) // furan type ??
2559 mm3type = 41;
2560 else if (jtype == 2 || ktype == 2) // vinyl type ??
2561 mm3type = 41;
2562 else
2563 mm3type = 6;
2564 goto L_10;
2565 }
2566 if (mmxtype != 66)
2567 {
2568 mmxtype = 6;
2569 mm3type = 6;
2570 mmfftype = 6;
2571 }
2572 goto L_10;
2573 } else if (mmxtype == 42)
2574 {
2575 mmfftype = 32;
2576 for (j=0; j < MAXIAT; j++)
2577 {
2578 if (atom[atom[i].iat[j]].atomnum == 16 || atom[atom[i].iat[j]].atomnum == 15)
2579 {
2580 mmxtype = 66;
2581 mm3type = 47;
2582 mmfftype = 32;
2583 goto L_10;
2584 }
2585 if (atom[atom[i].iat[j]].atomnum == 7)
2586 {
2587 mmxtype = 42;
2588 mm3type = 69;
2589 jj_bo = 0;
2590 for (k=0; k < MAXIAT; k++)
2591 {
2592 if (atom[atom[i].iat[j]].iat[k] != 0 && atom[atom[i].iat[j]].bo[k] != 9)
2593 jj_bo += atom[atom[i].iat[j]].bo[k];
2594 }
2595 if (jj_bo >= 4)
2596 {
2597 mmxtype = 66;
2598 mm3type = 69;
2599 mmfftype = 32;
2600 } else
2601 mmfftype = 35;
2602 goto L_10;
2603 }
2604 if (atom[atom[i].iat[j]].atomnum == 6 )
2605 {
2606 jatm = atom[i].iat[j];
2607 mmfftype = 35;
2608 for (k=0; k < MAXIAT; k++)
2609 {
2610 if (atom[jatm].iat[k] != i && atom[atom[jatm].iat[k]].atomnum == 8 && atom[jatm].bo[k] == 2)
2611 {
2612 mmxtype = 66;
2613 mm3type = 47;
2614 mmfftype = 32;
2615 goto L_10;
2616 }
2617 }
2618 }
2619 }
2620 goto L_10;
2621 } else
2622 goto L_10;
2623 } else if (atom[i].atomnum == 13) // aluminum
2624 {
2625 mmxtype = 44;
2626 mm3type = 0;
2627 jji = 0;
2628 for (j=0; j < MAXIAT; j++)
2629 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
2630 jji++;
2631 if (jji == 4)
2632 mmxtype = 58;
2633 goto L_10;
2634 } else if (atom[i].atomnum == 15) // phosphorus
2635 {
2636 mmxtype = 25;
2637 mm3type = 25;
2638 mmfftype = 25;
2639 jji = 0;
2640 for (j=0; j < MAXIAT; j++)
2641 {
2642 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
2643 jji++;
2644 if (atom[atom[i].iat[j]].atomnum == 6 && atom[i].bo[j] == 2)
2645 {
2646 mmxtype = 67;
2647 mmfftype = 75;
2648 goto L_10;
2649 }
2650 if (atom[atom[i].iat[j]].atomnum == 8 && atom[i].bo[j] == 2)
2651 mm3type = 153;
2652 }
2653 if (jji >= 5)
2654 {
2655 mmxtype = 47;
2656 mm3type = 60;
2657 }else if (jji == 3)
2658 {
2659 mmxtype = 25;
2660 mmfftype = 26;
2661 }
2662 goto L_10;
2663 } else if (atom[i].atomnum == 16) // sulfur
2664 {
2665 mmxtype = 15;
2666 mm3type = 15;
2667 mmfftype = 15;
2668 jji = 0;
2669 ndouble = 0;
2670 for (j=0; j < MAXIAT; j++)
2671 {
2672 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9 && atom[atom[i].iat[j]].mmx_type != 20 &&
2673 (atom[atom[i].iat[j]].mmx_type < 300))
2674 {
2675 jji++;
2676 if (atom[i].bo[j] == 2)
2677 ndouble++;
2678 }
2679 }
2680 if (jji == 1 && ndouble == 1)
2681 {
2682 if (atom[atom[i].iat[0]].atomnum == 16) // s=s-
2683 {
2684 mmfftype = 72;
2685 goto L_10;
2686 }
2687 if (atom[atom[i].iat[0]].atomnum == 6) // s=c
2688 {
2689 mmxtype = 38;
2690 mm3type = 74;
2691 if (atom[i].bo[0] == 2)
2692 {
2693 mmfftype = 16;
2694 jatm = atom[i].iat[0];
2695 for (k=0; k < MAXIAT; k++)
2696 {
2697 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] != 9)
2698 {
2699 if (atom[atom[jatm].iat[k]].atomnum == 16 && atom[jatm].iat[k] != i)
2700 {
2701 katm = atom[jatm].iat[k];
2702 jj_bo = 0;
2703 for (l=0; l < MAXIAT; l++)
2704 {
2705 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9)
2706 jj_bo++;
2707 }
2708 if (jj_bo == 1) // s=c-s i-jatm-katm
2709 {
2710 mmfftype = 72;
2711 goto L_10;
2712 }
2713 }
2714 }
2715 }
2716 goto L_10;
2717 }else if (atom[i].bo[0] == 1)
2718 {
2719 mmfftype = 72;
2720 goto L_10;
2721 }
2722 goto L_10;
2723 }
2724 if (atom[atom[i].iat[0]].atomnum == 15 ) // s=p
2725 {
2726 mmxtype = 38;
2727 mm3type = 74;
2728 mmfftype = 72;
2729 goto L_10;
2730 }
2731 }
2732 if (jji == 2)
2733 {
2734 mmxtype = 15;
2735 mm3type = 15;
2736 mmfftype = 15;
2737 if (is_cyclo5(i,array)) // thiophene
2738 {
2739 if (atom[i].flags & aromatic_mask)
2740 {
2741 mmfftype = 44;
2742 mm3type = 42;
2743 goto L_10;
2744 }
2745 }
2746 if (ndouble == 2)
2747 mmfftype = 74;
2748 goto L_10;
2749 }
2750 if (jji == 3)
2751 {
2752 mmxtype = 17;
2753 mm3type = 17;
2754 mmfftype = 17;
2755 if (ndouble == 2)
2756 mmfftype = 73;
2757 if (ndouble == 3)
2758 mmfftype = 18;
2759 goto L_10;
2760 }
2761 if (jji == 4)
2762 {
2763 mmxtype = 18;
2764 mm3type = 18;
2765 for (j=0; j < MAXIAT; j++)
2766 {
2767 if (atom[atom[i].iat[j]].atomnum == 7 ) // sulfamide
2768 mm3type = 154;
2769 }
2770 mmfftype = 18;
2771 goto L_10;
2772 }
2773 goto L_10;
2774 } else if (atom[i].atomnum == 17) // chlorine
2775 {
2776 mm3type = 12;
2777 mmxtype = 12;
2778 mmfftype = 12;
2779 jji = 0;
2780 for (j=0; j < MAXIAT; j++)
2781 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
2782 jji++;
2783 if (jji == 2)
2784 mmxtype = 74; // bridging chlorine
2785 else if (jji == 4) // perchlorate
2786 mmfftype = 77;
2787 goto L_10;
2788 } else if (atom[i].atomnum == 34) // selenium
2789 {
2790 mm3type = 34;
2791 mmxtype = 34;
2792 for (j=0; j < MAXIAT; j++)
2793 {
2794 if (atom[i].bo[j] == 2)
2795 mmxtype = 39;
2796 }
2797 goto L_10;
2798 } else if (atom[i].atomnum == 9) // Florine
2799 {
2800 mmxtype = 11;
2801 mm3type = 11;
2802 mmfftype = 11;
2803 goto L_10;
2804 } else if (atom[i].atomnum == 35) // Bromine
2805 {
2806 mmxtype = 13;
2807 mm3type = 13;
2808 mmfftype = 13;
2809 goto L_10;
2810 } else if (atom[i].atomnum == 53) // Iodine
2811 {
2812 if (atom[i].mmx_type == 54) // Sn2 I
2813 {
2814 mmxtype = 54;
2815 mm3type = 0;
2816 mmfftype = 0;
2817 goto L_10;
2818 }
2819 mmxtype = 14;
2820 mm3type = 14;
2821 mmfftype = 14;
2822 goto L_10;
2823 } else if (atom[i].atomnum == 14 ) // Silicon
2824 {
2825 mmxtype = 19;
2826 mm3type = 19;
2827 mmfftype = 19;
2828 goto L_10;
2829 } else if (atom[i].atomnum == 50 ) // Tin
2830 {
2831 mmxtype = 32;
2832 mm3type = 32;
2833 mmfftype = 0;
2834 goto L_10;
2835 } else if (mmxtype >= 300) // metal atom - try to assign MMFF type
2836 {
2837 mm3type = mmxtype;
2838 if (mmfftype == 0)
2839 mmfftype = mmxtype;
2840 }
2841 L_10:
2842 set_atomtype(i,mmxtype,mm3type,mmfftype,0,0);
2843 L_20:
2844 continue; // do nothing
2845 }
2846 }
2847 // finished normal now type amber
2848 search_rings(-1);
2849 if (have_pi == FALSE)
2850 pireset();
2851 set_atomtypes(field.type);
2852 }
2853 /* --------------------------------------------------------- */
2854 int is_cyclo3(int ia, int *array)
2855 {
2856 int i,k;
2857 int jatm;
2858
2859 for(i = 0; i < MAXIAT; i++)
2860 {
2861 if (atom[ia].iat[i] != 0 && atom[ia].bo[i] != 9 && atom[atom[ia].iat[i]].atomnum != 1)
2862 {
2863 jatm = atom[ia].iat[i];
2864 for(k=0; k < MAXIAT; k++)
2865 {
2866 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != ia && atom[jatm].bo[k] != 9 && atom[atom[jatm].iat[k]].atomnum != 1)
2867 {
2868 if (isbond(ia,atom[jatm].iat[k]))
2869 {
2870 array[0] = ia;
2871 array[1] = jatm;
2872 array[2] = atom[jatm].iat[k];
2873 return TRUE;
2874 }
2875 }
2876 }
2877 }
2878 }
2879 return FALSE;
2880 }
2881 /* --------------------------------------------------------- */
2882 int is_cyclo4(int ia, int *array)
2883 {
2884 int i,k,l;
2885 int jatm,katm;
2886
2887 for(i = 0; i < MAXIAT; i++)
2888 {
2889 if (atom[ia].iat[i] != 0 && atom[ia].bo[i] != 9)
2890 {
2891 jatm = atom[ia].iat[i];
2892 for(k=0; k < MAXIAT; k++)
2893 {
2894 if (atom[jatm].iat[k] != 0 && atom[jatm].iat[k] != ia && atom[jatm].bo[k] != 9)
2895 {
2896 katm = atom[jatm].iat[k];
2897 for (l=0; l < MAXIAT; l++)
2898 {
2899 if (atom[katm].iat[l] != 0 && atom[katm].iat[l] != jatm && atom[katm].bo[l] != 9)
2900 {
2901 if (isbond(ia,atom[katm].iat[l]))
2902 {
2903 array[0] = ia;
2904 array[1] = jatm;
2905 array[2] = katm;
2906 array[3] = atom[katm].iat[l];
2907 return TRUE;
2908 }
2909 }
2910 }
2911 }
2912 }
2913 }
2914 }
2915 return FALSE;
2916 }
2917 /* --------------------------------------------------------- */
2918 int is_cyclo5(int ia, int *array)
2919 {
2920 int i,j,k,l;
2921 int jatm,katm,latm;
2922
2923 for (i=0; i < 6; i++)
2924 array[i] = 0;
2925
2926 for(i=0; i < MAXIAT; i++)
2927 {
2928 if (atom[ia].iat[i] != 0)
2929 {
2930 jatm = atom[ia].iat[i];
2931 for(j=0; j < MAXIAT; j++)
2932 {
2933 if (atom[jatm].iat[j] != 0 && atom[jatm].iat[j] != ia && atom[jatm].bo[j] != 9)
2934 {
2935 katm = atom[jatm].iat[j];
2936 if ( !isbond(ia,katm)) // three membered ring
2937 {
2938 for(k=0; k < MAXIAT; k++)
2939 {
2940 if (atom[katm].iat[k] != 0 && atom[katm].iat[k] != jatm && atom[katm].iat[k] != ia && atom[katm].bo[k] != 9)
2941 {
2942 latm = atom[katm].iat[k];
2943 if ( !isbond(ia,latm)) // four membered ring
2944 {
2945 for (l=0; l < MAXIAT; l++)
2946 {
2947 if (atom[latm].iat[l] != 0 && atom[latm].iat[l] != katm && atom[latm].iat[l] != jatm &&
2948 atom[latm].iat[l] != ia && atom[latm].bo[l] != 9)
2949 {
2950 if (isbond(ia,atom[latm].iat[l]))
2951 {
2952 array[0] = ia;
2953 array[1] = jatm;
2954 array[2] = katm;
2955 array[3] = latm;
2956 array[4] = atom[latm].iat[l];
2957 return TRUE;
2958 }
2959 }
2960 }
2961 }
2962 }
2963 }
2964 }
2965 }
2966 }
2967 }
2968 }
2969 return FALSE;
2970 }
2971 /* --------------------------------------------------------- */
2972 int is_cyclo6(int ia, int *array)
2973 {
2974 int i,j,k,l,m;
2975 int jatm,katm,latm,matm,xatm;
2976
2977 for (i=0; i < 6; i++)
2978 array[i] = 0;
2979
2980 for(i=0; i < MAXIAT; i++)
2981 {
2982 if (atom[ia].iat[i] != 0)
2983 {
2984 jatm = atom[ia].iat[i];
2985 for(j=0; j < MAXIAT; j++)
2986 {
2987 if (atom[jatm].iat[j] != 0 && atom[jatm].iat[j] != ia && atom[jatm].bo[j] != 9)
2988 {
2989 katm = atom[jatm].iat[j];
2990 for(k=0; k < MAXIAT; k++)
2991 {
2992 if (atom[katm].iat[k] != 0 && atom[katm].iat[k] != jatm && atom[katm].iat[k] != ia && atom[katm].bo[k] != 9)
2993 {
2994 latm = atom[katm].iat[k];
2995 if (!isbond(ia,latm)) // bail out for four memebered rings
2996 {
2997 for (l=0; l < MAXIAT; l++)
2998 {
2999 if (atom[latm].iat[l] != 0 && atom[latm].iat[l] != katm && atom[latm].iat[l] != jatm &&
3000 atom[latm].iat[l] != ia && atom[latm].bo[l] != 9)
3001 {
3002 matm = atom[latm].iat[l];
3003 if (!(isbond(ia,matm))) // bail out for five membered ring
3004 {
3005 for (m=0; m < MAXIAT; m++)
3006 {
3007 xatm = atom[matm].iat[m];
3008 if (xatm != 0 && xatm != matm && xatm != latm && xatm != katm && xatm != jatm && xatm != ia)
3009 {
3010 if (isbond(ia,xatm))
3011 {
3012 array[0] = ia;
3013 array[1] = jatm;
3014 array[2] = katm;
3015 array[3] = latm;
3016 array[4] = matm;
3017 array[5] = xatm;
3018 return TRUE;
3019 }
3020 }
3021 }
3022 }
3023 }
3024 }
3025 }
3026 }
3027 }
3028 }
3029 }
3030 }
3031 }
3032 return FALSE;
3033 }
3034 /* --------------------------------------------------------- */
3035 int find_rsize(int isize,int iatom)
3036 {
3037 int i, j, icount;
3038
3039 icount = 0;
3040 if (isize == 3)
3041 {
3042 for (i=0; i < ringdata.tot3; i++)
3043 {
3044 for(j=0; j < 3; j++)
3045 {
3046 if (ringdata.iring3[i][j] == iatom)
3047 icount++;
3048 }
3049 }
3050 return(icount);
3051 }else if (isize == 4)
3052 {
3053 for (i=0; i < ringdata.tot4; i++)
3054 {
3055 for(j=0; j < 4; j++)
3056 {
3057 if (ringdata.iring4[i][j] == iatom)
3058 icount++;
3059 }
3060 }
3061 return(icount);
3062 }else if (isize == 5)
3063 {
3064 for (i=0; i < ringdata.tot5; i++)
3065 {
3066 for(j=0; j < 5; j++)
3067 {
3068 if (ringdata.iring5[i][j] == iatom)
3069 icount++;
3070 }
3071 }
3072 return(icount);
3073 }else if (isize == 6)
3074 {
3075 for (i=0; i < ringdata.tot6; i++)
3076 {
3077 for(j=0; j < 6; j++)
3078 {
3079 if (ringdata.iring6[i][j] == iatom)
3080 icount++;
3081 }
3082 }
3083 return(icount);
3084 }
3085 return(icount);
3086 }
3087 /* --------------------------------------------------------- */
3088 // iatom is atom number to search on
3089 // isize = ring size
3090 // num = number of ring if more than one ring containing atom iatom
3091 // array = array of ring atoms
3092 //
3093 void get_rsize(int iatom, int isize, int num, int *array)
3094 {
3095 int i, j, k, icount;
3096 icount = -1;
3097
3098 if (isize == 3)
3099 {
3100 for (i=0; i < ringdata.tot3; i++)
3101 {
3102 for (j=0; j < 3; j++)
3103 {
3104 if (iatom == ringdata.iring3[i][j])
3105 icount++;
3106 if (icount == num)
3107 {
3108 for (k=0; k < isize; k++)
3109 array[k] = ringdata.iring3[i][k];
3110 return;
3111 }
3112 }
3113 }
3114 } else if (isize == 4)
3115 {
3116 for (i=0; i < ringdata.tot4; i++)
3117 {
3118 for (j=0; j < 4; j++)
3119 {
3120 if (iatom == ringdata.iring3[i][j])
3121 icount++;
3122 if (icount == num)
3123 {
3124 for (k=0; k < isize; k++)
3125 array[k] = ringdata.iring4[i][k];
3126 return;
3127 }
3128 }
3129 }
3130 } else if (isize == 5)
3131 {
3132 for (i=0; i < ringdata.tot5; i++)
3133 {
3134 for (j=0; j < 5; j++)
3135 {
3136 if (iatom == ringdata.iring5[i][j])
3137 icount++;
3138 if (icount == num)
3139 {
3140 for (k=0; k < isize; k++)
3141 array[k] = ringdata.iring5[i][k];
3142 return;
3143 }
3144 }
3145 }
3146 } else if (isize == 6)
3147 {
3148 for (i=0; i < ringdata.tot6; i++)
3149 {
3150 for (j=0; j < 6; j++)
3151 {
3152 if (iatom == ringdata.iring6[i][j])
3153 icount++;
3154 if (icount == num)
3155 {
3156 for (k=0; k < isize; k++)
3157 array[k] = ringdata.iring6[i][k];
3158 return;
3159 }
3160 }
3161 }
3162 }
3163 }
3164 /* --------------------------------------------------------- */
3165 int aromatic_5(int ringindex, int *array)
3166 {
3167 int i,j,k, jatm, katm;
3168 int nodbl, npi;
3169 int ia, ib, ic;
3170 int db[10];
3171 int ihetero;
3172 long int aromatic_mask, mask6;
3173
3174 aromatic_mask = (1 << AROMATIC_MASK);
3175 mask6 = (1L << RING6);
3176
3177 npi = 0;
3178 ihetero = 0;
3179 for (i=0; i < 4; i++)
3180 {
3181 jatm = array[i];
3182 for (j=i+1;j < 5; j++)
3183 {
3184 katm = array[j];
3185 if (isbond(jatm,katm))
3186 {
3187 for (k=0; k < MAXIAT; k++)
3188 {
3189 if (atom[jatm].iat[k] == katm)
3190 {
3191 if (atom[jatm].bo[k] == 2)
3192 {
3193 db[npi] = i+j;
3194 npi++;
3195 }else if ( (atom[jatm].flags & aromatic_mask && atom[jatm].flags & mask6 )
3196 && (atom[katm].flags & aromatic_mask && atom[katm].flags & mask6 ))
3197 {
3198 db[npi] = i+j;
3199 npi++;
3200 }
3201 }
3202 }
3203 }
3204 }
3205 }
3206 for (i=0; i < 5; i++)
3207 {
3208 jatm = array[i];
3209 if (atom[jatm].atomnum != 6)
3210 {
3211 nodbl = FALSE;
3212 for(j=0; j < MAXIAT; j++)
3213 {
3214 if (atom[jatm].iat[j] != 0)
3215 {
3216 if (atom[jatm].bo[j] > 1 && atom[jatm].bo[j] != 9)
3217 nodbl = TRUE;
3218 }
3219 }
3220 if (nodbl == FALSE)
3221 ihetero = jatm;
3222 }
3223 }
3224 if (npi >= 2 && ihetero != 0) // got an aromatic ring with heteroatom
3225 return TRUE;
3226
3227 if (npi == 0) // no double bonds in ring
3228 return FALSE;
3229
3230 if (npi == 1 && ihetero == 0)
3231 return FALSE;
3232
3233 if (npi == 1)
3234 {
3235 if (db[0] == 1)
3236 {
3237 ia = array[2];
3238 ib = array[3];
3239 ic = array[4];
3240 } else if (db[0] == 3)
3241 {
3242 ia = array[0];
3243 ib = array[3];
3244 ic = array[4];
3245 } else if (db[0] == 4)
3246 {
3247 ia = array[1];
3248 ib = array[2];
3249 ic = array[3];
3250 } else if (db[0] == 5)
3251 {
3252 ia = array[0];
3253 ib = array[1];
3254 ic = array[4];
3255 } else if (db[0] == 7)
3256 {
3257 ia = array[0];
3258 ib = array[1];
3259 ic = array[2];
3260 }
3261 if (ia == ihetero)
3262 {
3263 for(i=0; i < ringdata.nring6; i++)
3264 {
3265 for (j=0; j < 6; j++)
3266 {
3267 if (ringdata.iring6[i][j] == ib)
3268 {
3269 if (atom[ib].flags & aromatic_mask)
3270 return TRUE;
3271 }
3272 if (ringdata.iring6[i][j] == ic)
3273 {
3274 if (atom[ic].flags & aromatic_mask)
3275 return TRUE;
3276 }
3277 }
3278 }
3279 } else if (ib == ihetero)
3280 {
3281 for(i=0; i < ringdata.nring6; i++)
3282 {
3283 for (j=0; j < 6; j++)
3284 {
3285 if (ringdata.iring6[i][j] == ia)
3286 {
3287 if (atom[ia].flags & aromatic_mask)
3288 return TRUE;
3289 }
3290 if (ringdata.iring6[i][j] == ic)
3291 {
3292 if (atom[ic].flags & aromatic_mask)
3293 return TRUE;
3294 }
3295 }
3296 }
3297 } else if (ic == ihetero)
3298 {
3299 for(i=0; i < ringdata.nring6; i++)
3300 {
3301 for (j=0; j < 6; j++)
3302 {
3303 if (ringdata.iring6[i][j] == ib)
3304 {
3305 if (atom[ib].flags & aromatic_mask)
3306 return TRUE;
3307 }
3308 if (ringdata.iring6[i][j] == ia)
3309 {
3310 if (atom[ia].flags & aromatic_mask)
3311 return TRUE;
3312 }
3313 }
3314 }
3315 }
3316 }
3317 return FALSE;
3318 }
3319 /* --------------------------------------------------------- */
3320 int aromatic_6(int *array)
3321 {
3322 int i,j,k, ia,ib, idbl,kdbl;
3323 int num, inarray[10];
3324 long int aromatic_mask, mask6;
3325
3326 aromatic_mask = (1 << AROMATIC_MASK);
3327 mask6 = (1L << RING6);
3328 num = 0;
3329 for (i=0; i < 10; i++)
3330 inarray[i] = FALSE;
3331
3332 for (i=0; i < 5; i++)
3333 {
3334 ia = array[i];
3335 for (j=i+1; j < 6; j++)
3336 {
3337 for (k=0; k < MAXIAT; k++)
3338 {
3339 if (atom[ia].iat[k] == array[j])
3340 {
3341 if (atom[ia].bo[k] == 2)
3342 {
3343 num++;
3344 inarray[i] = TRUE;
3345 inarray[j] = TRUE;
3346 }
3347 }
3348 }
3349 }
3350 }
3351 if (num == 3)
3352 return TRUE;
3353
3354 if (num >= 1)
3355 {
3356 for(i=0; i < 5; i++)
3357 {
3358 if (inarray[i] == FALSE)
3359 {
3360 ia = array[i];
3361 for(j=i+1;j < 6; j++)
3362 {
3363 if (inarray[j] == FALSE)
3364 {
3365 ib = array[j];
3366 if ( (atom[ia].flags & aromatic_mask) && (atom[ib].flags & aromatic_mask))
3367 {
3368 num++;
3369 if (num == 3)
3370 return TRUE;
3371 } else if (isbond(ia,ib))
3372 {
3373 idbl = FALSE;
3374 kdbl = FALSE;
3375 for(k=0; k < MAXIAT; k++)
3376 {
3377 if (atom[ia].iat[k] !=0 && atom[ia].bo[k] == 2)
3378 {
3379 if (atom[atom[ia].iat[k]].atomnum == 6 || atom[atom[ia].iat[k]].atomnum == 7)
3380 {
3381 if (atom[atom[ia].iat[k]].flags & mask6)
3382 idbl = TRUE;
3383 }
3384 }
3385 if (atom[ib].iat[k] !=0 && atom[ib].bo[k] == 2)
3386 {
3387 if (atom[atom[ib].iat[k]].atomnum == 6 || atom[atom[ib].iat[k]].atomnum == 7)
3388 {
3389 if (atom[atom[ib].iat[k]].flags & mask6)
3390 kdbl = TRUE;
3391 }
3392 }
3393 }
3394 if (idbl == TRUE && kdbl == TRUE)
3395 {
3396 num++;
3397 if (num == 3)
3398 return TRUE;
3399 }
3400 }
3401 inarray[i] = TRUE;
3402 inarray[j] = TRUE;
3403 }
3404 }
3405 }
3406 }
3407 }
3408 return FALSE;
3409 }
3410 /* ================================================== */
3411 // look for ionic types input with bonds and adjust to make ionic
3412 //
3413 void adjust_mmfftypes()
3414 {
3415 int i,j, iatt;
3416
3417 for (i=1; i <= natom; i++)
3418 {
3419 if (atom[i].mmff_type == 89 ) // F-
3420 {
3421 for (j=0; j < MAXIAT; j++)
3422 {
3423 if (atom[i].iat[j] != 0)
3424 deletebond(i,atom[i].iat[j]);
3425 }
3426 } else if (atom[i].mmff_type == 90 ) // CL-
3427 {
3428 for (j=0; j < MAXIAT; j++)
3429 {
3430 if (atom[i].iat[j] != 0)
3431 deletebond(i,atom[i].iat[j]);
3432 }
3433 } else if (atom[i].mmff_type == 91 ) // Br-
3434 {
3435 for (j=0; j < MAXIAT; j++)
3436 {
3437 if (atom[i].iat[j] != 0)
3438 deletebond(i,atom[i].iat[j]);
3439 }
3440 } else if (atom[i].mmff_type == 92 ) // Li+
3441 {
3442 for (j=0; j < MAXIAT; j++)
3443 {
3444 if (atom[i].iat[j] != 0)
3445 {
3446 iatt = atom[i].iat[j];
3447 deletebond(i,iatt);
3448 if (atom[iatt].atomnum == 8)
3449 set_atomtype(iatt,42,0,92,0,0);
3450 }
3451 }
3452 } else if (atom[i].mmff_type == 93 ) // Na+
3453 {
3454 for (j=0; j < MAXIAT; j++)
3455 {
3456 if (atom[i].iat[j] != 0)
3457 {
3458 iatt = atom[i].iat[j];
3459 deletebond(i,iatt);
3460 if (atom[iatt].atomnum == 8)
3461 set_atomtype(iatt,42,0,93,0,0);
3462 }
3463 }
3464 } else if (atom[i].mmff_type == 94 ) // K+
3465 {
3466 for (j=0; j < MAXIAT; j++)
3467 {
3468 if (atom[i].iat[j] != 0)
3469 {
3470 iatt = atom[i].iat[j];
3471 deletebond(i,iatt);
3472 if (atom[iatt].atomnum == 8)
3473 set_atomtype(iatt,42,0,94,0,0);
3474 }
3475 }
3476 } else if (atom[i].mmff_type == 95 ) // Zn+2
3477 {
3478 for (j=0; j < MAXIAT; j++)
3479 {
3480 if (atom[i].iat[j] != 0)
3481 {
3482 iatt = atom[i].iat[j];
3483 deletebond(i,iatt);
3484 if (atom[iatt].atomnum == 8)
3485 set_atomtype(iatt,42,0,95,0,0);
3486 }
3487 }
3488 } else if (atom[i].mmff_type == 96 ) // Ca+2
3489 {
3490 for (j=0; j < MAXIAT; j++)
3491 {
3492 if (atom[i].iat[j] != 0)
3493 {
3494 iatt = atom[i].iat[j];
3495 deletebond(i,iatt);
3496 if (atom[iatt].atomnum == 8)
3497 set_atomtype(iatt,42,0,96,0,0);
3498 }
3499 }
3500 }
3501 }
3502 }