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

Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4 #include "pcmod.h"
5
6 #include "angles.h"
7 #include "torsions.h"
8 #include "rings.h"
9
10
11 int isbond(int, int);
12 int isangle(int,int);
13 int is_ring31(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 void ksort(int, int *);
28 void message_alert(char *, char *);
29 int is_cyclo6(int, int *);
30
31 int is_ring31(int ia)
32 {
33 int i,j;
34
35 for (i=0; i < rings.nring3; i++)
36 {
37 for (j=0; j < 3; j++)
38 {
39 if (ia == rings.r13[i][j])
40 {
41 return(TRUE);
42 }
43 }
44 }
45 return FALSE;
46 }
47 /* ============================ */
48 int is_ring41(int ia)
49 {
50 int i,j, found;
51
52 found = FALSE;
53 for (i=0; i < rings.nring4; i++)
54 {
55 for (j=0; j < 4; j++)
56 {
57 if (ia == rings.r14[i][j])
58 {
59 found = TRUE;
60 return (found);
61 }
62 }
63 }
64 return (found);
65 }
66 /* -------------------------------------------------------- */
67 int is_ring42(int ia, int ib)
68 {
69 int i,j, k, itmp, jtmp;
70 if (ia < ib )
71 {
72 itmp = ia;
73 jtmp = ib;
74 }else
75 {
76 itmp = ib;
77 jtmp = ia;
78 }
79 for (i=0; i < rings.nring4; i++)
80 {
81 for (j = 0; j < 3; j++)
82 {
83 if ( itmp == rings.r14[i][j])
84 {
85 for (k=j+1; k < 4; k++)
86 {
87 if (jtmp == rings.r14[i][k])
88 return(TRUE);
89 }
90 }
91 }
92 }
93 return(FALSE);
94 }
95 /* -------------------------------------------------------- */
96 int is_ring43(int ia, int ib, int ic)
97 {
98 int i, found;
99 int array[5];
100
101 found = FALSE;
102 array[0] = ia;
103 array[1] = ib;
104 array[2] = ic;
105 ksort(3,array);
106 for (i=0; i < rings.nring4; i++)
107 {
108 if ( array[0] == rings.r14[i][0] && rings.r14[i][1] == array[1] && rings.r14[i][2] == array[2])
109 {
110 found = TRUE;
111 return(found);
112 }
113 if ( rings.r14[i][0] == array[0] && rings.r14[i][1] == array[1] && rings.r14[i][3] == array[2])
114 {
115 found = TRUE;
116 return(found);
117 }
118 if ( rings.r14[i][0] == array[0] && rings.r14[i][2] == array[1] && rings.r14[i][3] == array[2])
119 {
120 found = TRUE;
121 return(found);
122 }
123 if ( rings.r14[i][1] == array[0] && rings.r14[i][2] == array[1] && rings.r14[i][3] == array[2])
124 {
125 found = TRUE;
126 return(found);
127 }
128 }
129 return(found);
130 }
131 /* -------------------------------------------------------- */
132 int is_ring44(int *array)
133 {
134 int i;
135 for (i=0; i < rings.nring4; i++)
136 {
137 if (array[0] == rings.r14[i][0] && array[1] == rings.r14[i][1] &&
138 array[2] == rings.r14[i][2] && array[3] == rings.r14[i][3])
139 return(TRUE);
140 }
141 return FALSE;
142 }
143 /* -------------------------------------------------------- */
144 int is_ring51(int ia)
145 {
146 int i,j;
147
148 for(i=0; i < rings.nring5; i++)
149 {
150 for (j=0; j < 5; j++)
151 {
152 if (rings.r15[i][j] == ia)
153 {
154 return(TRUE);
155 }
156 }
157 }
158 return(FALSE);
159 }
160 /* -------------------------------------------------------- */
161 int is_ring52(int ia, int ib)
162 {
163 int i, j,k, itmp, jtmp;
164 if (ia < ib)
165 {
166 itmp = ia;
167 jtmp = ib;
168 }else
169 {
170 itmp = ib;
171 jtmp = ia;
172 }
173 for (i=0; i < rings.nring5; i++)
174 {
175 for (j=0; j < 4; j++)
176 {
177 if (itmp == rings.r15[i][j])
178 {
179 for (k=j+1; k < 5; k++)
180 {
181 if (jtmp == rings.r15[i][k])
182 return(TRUE);
183 }
184 }
185 }
186 }
187 return(FALSE);
188 }
189 /* -------------------------------------------------------- */
190 int is_ring53(int ia, int ib, int ic)
191 {
192 int i, j,k,l;
193 int array[5];
194
195 array[0] = ia;
196 array[1] = ib;
197 array[2] = ic;
198 ksort(3,array);
199 for (i=0; i < rings.nring5; i++)
200 {
201 for (j=0; j < 3; j++)
202 {
203 if (array[0] == rings.r15[i][j])
204 {
205 for (k=j+1; k < 4; k++)
206 {
207 if (array[1] == rings.r15[i][k])
208 {
209 for (l=j+1; l < 5; l++)
210 {
211 if (array[2] == rings.r15[i][l])
212 return(TRUE);
213 }
214 }
215 }
216 }
217 }
218 }
219 return(FALSE);
220 }
221 /* -------------------------------------------------------- */
222 int is_ring54(int ia, int ib, int ic, int id)
223 {
224 int i;
225 int array[5];
226 array[0] = ia;
227 array[1] = ib;
228 array[2] = ic;
229 array[3] = id;
230 ksort(4,array);
231 for (i=0; i < rings.nring5; i++)
232 {
233 if (array[0] == rings.r15[i][0])
234 {
235 if (array[1] == rings.r15[i][1])
236 {
237 if (array[2] == rings.r15[i][2])
238 {
239 if (array[3] == rings.r15[i][3])
240 return(TRUE);
241 else if (array[3] == rings.r15[i][4])
242 return(TRUE);
243 else
244 return(FALSE);
245 } else if (array[2] == rings.r15[i][3] && array[3] == rings.r15[i][4])
246 return(TRUE);
247 } else if (array[1] == rings.r15[i][2] &&
248 array[2] == rings.r15[i][3] && array[3] == rings.r15[i][4])
249 return(TRUE);
250
251 } else if (array[0] == rings.r15[i][1] && array[1] == rings.r15[i][2] &&
252 array[2] == rings.r15[i][3] && array[3] == rings.r15[i][4])
253 return(TRUE);
254 }
255 return (FALSE);
256 }
257 /* -------------------------------------------------------- */
258 int is_ring55(int *array)
259 {
260 int i;
261 for(i=0; i < rings.nring5; i++)
262 {
263 if ( array[0] == rings.r15[i][0] && array[1] == rings.r15[i][1] && array[2] == rings.r15[i][2] &&
264 array[3] == rings.r15[i][3] && array[4] == rings.r15[i][4])
265 return(TRUE);
266 }
267 return (FALSE);
268 }
269 /* -------------------------------------------------------- */
270 int is_ring61(int ia)
271 {
272 int i, j;
273 for(i=0; i < rings.nring6; i++)
274 {
275 for(j=0; j < 6; j++)
276 {
277 if (ia == rings.r16[i][j])
278 return (TRUE);
279 }
280 }
281 return (FALSE);
282 }
283 /* -------------------------------------------------------- */
284 int is_ring62(int ia, int ib)
285 {
286 int i, j,k, itmp, jtmp;
287 if (ia < ib)
288 {
289 itmp = ia;
290 jtmp = ib;
291 }else
292 {
293 itmp = ib;
294 jtmp = ia;
295 }
296 for (i=0; i < rings.nring6; i++)
297 {
298 for (j=0; j < 5; j++)
299 {
300 if (itmp == rings.r16[i][j])
301 {
302 for (k=j+1; k < 6; k++)
303 {
304 if (jtmp == rings.r16[i][k])
305 return(TRUE);
306 }
307 }
308 }
309 }
310 return(FALSE);
311 }
312 /* -------------------------------------------------------- */
313 int is_ring63(int ia, int ib, int ic)
314 {
315 int i, j, k, l;
316 int array[5];
317
318 array[0] = ia;
319 array[1] = ib;
320 array[2] = ic;
321 ksort(3,array);
322 for (i=0; i < rings.nring6; i++)
323 {
324 for (j=0; j < 4; j++)
325 {
326 if (array[0] == rings.r16[i][j])
327 {
328 for (k=j+1; k < 5; k++)
329 {
330 if (array[1] == rings.r16[i][k])
331 {
332 for (l=k+1; l < 6; l++)
333 {
334 if (array[2] == rings.r16[i][l])
335 return(TRUE);
336 }
337 }
338 }
339 }
340 }
341 }
342 return(FALSE);
343 }
344 /* -------------------------------------------------------- */
345 int is_ring66(int *array)
346 {
347 int i;
348 for(i=0; i < rings.nring6; i++)
349 {
350 if ( array[0] == rings.r16[i][0] && array[1] == rings.r16[i][1] && array[2] == rings.r16[i][2] &&
351 array[3] == rings.r16[i][3] && array[4] == rings.r16[i][4] && array[5] == rings.r16[i][5])
352 return(TRUE);
353 }
354 return (FALSE);
355 }
356 /* -------------------------------------------------------- */
357
358 void get_rings()
359 {
360 int i,j, add_ring, k, l;
361 int jatm,katm;
362 int array[6];
363
364 rings.nring3 = 0;
365 rings.nring4 = 0;
366 rings.nring5 = 0;
367 rings.nring6 = 0;
368
369 // get three membered rings
370 for (i=0; i < angles.nang; i++)
371 {
372 if (isbond(angles.i13[i][0], angles.i13[i][2]))
373 {
374 array[0] = angles.i13[i][0];
375 array[1] = angles.i13[i][1];
376 array[2] = angles.i13[i][2];
377 ksort(3, array);
378 add_ring = TRUE;
379 for (j = 0; j < rings.nring3; j++)
380 {
381 if (array[0] == rings.r13[j][0] && array[1] == rings.r13[j][1]
382 && array[2] == rings.r13[j][2])
383 {
384 add_ring = FALSE;
385 break;
386 }
387 }
388 if (add_ring == TRUE)
389 {
390 rings.r13[rings.nring3][0] = array[0];
391 rings.r13[rings.nring3][1] = array[1];
392 rings.r13[rings.nring3][2] = array[2];
393 rings.nring3++;
394 }
395 }
396 }
397 // get four membered rings
398 for(i=1; i <= natom; i++)
399 {
400 for(j=0; j < MAXIAT; j++)
401 {
402 if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9)
403 {
404 jatm = atom[i].iat[j];
405 for (k=0; k < MAXIAT; k++)
406 {
407 if (atom[jatm].iat[k] != 0 && atom[jatm].bo[k] != 9 && atom[jatm].iat[k] != i)
408 {
409 katm = atom[jatm].iat[k];
410 if (!(isbond(katm,i)))
411 {
412 for(l=0; l < MAXIAT; l++)
413 {
414 if (atom[katm].iat[l] != 0 && atom[katm].bo[l] != 9 && atom[katm].iat[l] != jatm)
415 {
416 if (isbond(i,atom[katm].iat[l]) )
417 {
418 array[0] = i;
419 array[1] = jatm;
420 array[2] = katm;
421 array[3] = atom[katm].iat[l];
422 ksort(4, array);
423 if ( is_ring44(array) == FALSE )
424 {
425 rings.r14[rings.nring4][0] = array[0];
426 rings.r14[rings.nring4][1] = array[1];
427 rings.r14[rings.nring4][2] = array[2];
428 rings.r14[rings.nring4][3] = array[3];
429 rings.nring4++;
430 }
431 }
432 }
433 }
434 }
435 }
436 }
437 }
438 }
439 }
440 // get five membered rings
441 for(i=0; i < torsions.ntor; i++)
442 {
443 if (!isbond(torsions.i14[i][0],torsions.i14[i][3]))
444 {
445 for (j=0; j < MAXIAT; j++)
446 {
447 jatm = atom[torsions.i14[i][0]].iat[j];
448 if ( jatm != torsions.i14[i][1] && jatm != torsions.i14[i][2] && jatm != torsions.i14[i][3] )
449 {
450 if (isbond(jatm,torsions.i14[i][3]))
451 {
452 array[0] = jatm;
453 array[1] = torsions.i14[i][0];
454 array[2] = torsions.i14[i][1];
455 array[3] = torsions.i14[i][2];
456 array[4] = torsions.i14[i][3];
457 ksort(5,array);
458 if ( is_ring55(array) == FALSE )
459 {
460 rings.r15[rings.nring5][0] = array[0];
461 rings.r15[rings.nring5][1] = array[1];
462 rings.r15[rings.nring5][2] = array[2];
463 rings.r15[rings.nring5][3] = array[3];
464 rings.r15[rings.nring5][4] = array[4];
465 rings.nring5++;
466 if (rings.nring5 >= natom)
467 message_alert("Error. Too many 5 membered rings!","ERROR");
468
469 }
470 }
471 }
472 }
473 }
474 }
475 // get six membered rings
476 for(i=0; i <= natom; i++)
477 {
478 if (atom[i].type != 5 && atom[i].type != 20)
479 {
480 if (is_cyclo6(i, array))
481 {
482 ksort(6,array);
483 if (is_ring66(array) == FALSE)
484 {
485 rings.r16[rings.nring6][0] = array[0];
486 rings.r16[rings.nring6][1] = array[1];
487 rings.r16[rings.nring6][2] = array[2];
488 rings.r16[rings.nring6][3] = array[3];
489 rings.r16[rings.nring6][4] = array[4];
490 rings.r16[rings.nring6][5] = array[5];
491 rings.nring6++;
492 if (rings.nring6 >= natom)
493 message_alert("Error. Too many 6 membered rings!","ERROR");
494 }
495 }
496 }
497 }
498
499 /* if (rings.nring3 != 0)
500 printf("Number of three membered rings: %d\n",rings.nring3);
501 if (rings.nring4 != 0)
502 printf("Number of four membered rings: %d\n",rings.nring4);
503 if (rings.nring5 != 0)
504 printf("Number of five membered rings: %d\n",rings.nring5);
505 if (rings.nring6 != 0)
506 printf("Number of six membered rings: %d\n",rings.nring6); */
507
508 }
509 /* =================================================== */
510 void ksort(int num, int array[])
511 {
512 int i,temp;
513 int found;
514
515 L_1:
516 found = FALSE;
517 for (i=0; i < num-1; i++)
518 {
519 if (array[i+1] < array[i])
520 {
521 temp = array[i];
522 array[i] = array[i+1];
523 array[i+1] = temp;
524 found = TRUE;
525 }
526 }
527 if (found == TRUE)
528 goto L_1;
529 }