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