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

Line File contents
1 #define EXTERN extern
2 #include "pcwin.h"
3 #include "pcmod.h"
4 #include "utility.h"
5
6 int is_cyclo3(int, int *);
7 int is_cyclo4(int, int *);
8 int is_cyclo5(int, int *);
9 int is_cyclo6(int, int *);
10 int icompare(int, int *,int *);
11 int find_rsize(int,int);
12 int aromatic_5(int,int *);
13 int aromatic_6(int *);
14 void get_rsize(int,int,int,int *);
15 void search_rings(int);
16
17 struct t_ringdata {
18 int nring3, nring4, nring5, nring6;
19 int tot3, tot4, tot5, tot6;
20 int **iring3,**iring4,**iring5,**iring6;
21 } ringdata;
22
23 void search_rings(int mode)
24 {
25 int i,j,ij,k,unique,ifive,isix;
26 int array[7],array1[6],array2[6];
27 long int mask3, mask4, mask5, mask6, aromatic_mask;
28
29 if (mode == -1)
30 {
31 if (ringdata.nring3 > 0)
32 free_imatrix(ringdata.iring3, 0,ringdata.nring3, 0,4);
33 if (ringdata.nring4 > 0)
34 free_imatrix(ringdata.iring4, 0,ringdata.nring4, 0,5);
35 if (ringdata.nring5 > 0)
36 free_imatrix(ringdata.iring5, 0,ringdata.nring5, 0,6);
37 if (ringdata.nring6 > 0)
38 free_imatrix(ringdata.iring6, 0,ringdata.nring6, 0,7);
39 return;
40 }
41
42 mask3 = (1L << RING3);
43 mask4 = (1L << RING4);
44 mask5 = (1L << RING5);
45 mask6 = (1L << RING6);
46 aromatic_mask = (1L << AROMATIC_MASK);
47
48 for (i=1; i <= natom; i++)
49 {
50 atom[i].flags &= ~aromatic_mask;
51 }
52
53 for (i=1; i <= natom; i++)
54 {
55 if (atom[i].atomnum > 1)
56 {
57 if ( !(atom[i].flags & mask3)) // cyclopropane
58 {
59 if (is_cyclo3(i, array))
60 atom[i].flags |= mask3;
61 }
62 if ( !(atom[i].flags & mask4)) // cyclobutane
63 {
64 if (is_cyclo4(i, array))
65 atom[i].flags |= mask4;
66 }
67 if ( !(atom[i].flags & mask5)) // cyclopentane
68 {
69 if (is_cyclo5(i,array))
70 {
71 for (j=0; j < 5; j++)
72 atom[array[j]].flags |= mask5;
73 }
74 }
75 if ( !(atom[i].flags & mask6)) // cyclohexane
76 {
77 if (is_cyclo6(i,array))
78 {
79 for (j=0; j < 6; j++)
80 atom[array[j]].flags |= mask6;
81 }
82 }
83 }
84 }
85 // count rings and allocate memory
86 ringdata.nring3 = 0;
87 ringdata.nring4 = 0;
88 ringdata.nring5 = 0;
89 ringdata.nring6 = 0;
90 for (i=1; i <= natom; i++)
91 {
92 if (atom[i].flags & mask3)
93 ringdata.nring3++;
94 if (atom[i].flags & mask4)
95 ringdata.nring4++;
96 if (atom[i].flags & mask5)
97 ringdata.nring5++;
98 if (atom[i].flags & mask6)
99 ringdata.nring6++;
100 }
101 // ringdata.nring6 /= 2;
102
103 if (ringdata.nring3 > 0)
104 ringdata.iring3 = imatrix(0,ringdata.nring3, 0,4);
105 if (ringdata.nring4 > 0)
106 ringdata.iring4 = imatrix(0,ringdata.nring4, 0,5);
107 if (ringdata.nring5 > 0)
108 ringdata.iring5 = imatrix(0,ringdata.nring5, 0,6);
109 if (ringdata.nring6 > 0)
110 ringdata.iring6 = imatrix(0,ringdata.nring6, 0,7);
111
112 for (i=0; i < ringdata.nring5; i++)
113 {
114 for (j=0; j < 5; j++)
115 ringdata.iring5[i][j] = 0;
116 ringdata.iring5[i][5] = FALSE;
117 }
118 for (i=0; i < ringdata.nring6; i++)
119 {
120 for (j=0; j < 6; j++)
121 ringdata.iring6[i][j] = 0;
122 ringdata.iring6[i][6] = FALSE;
123 }
124
125 // find rings
126 ringdata.tot3 = 0;
127 ringdata.tot4 = 0;
128 ringdata.tot5 = 0;
129 ringdata.tot6 = 0;
130
131 for (i=1; i <= natom; i++)
132 {
133 if (atom[i].flags & mask3)
134 {
135 is_cyclo3(i,array);
136 unique = TRUE;
137 for (j=0; j < 3 ;j++)
138 array1[j] = array[j];
139 for(j=0; j < ringdata.tot3; j++)
140 {
141 for (k=0; k < 3; k++)
142 array2[k] = ringdata.iring3[j][k];
143 if ( icompare(3,array1,array2))
144 unique = FALSE;
145 }
146 if (unique == TRUE)
147 {
148 ringdata.iring3[ringdata.tot3][0] = array[0];
149 ringdata.iring3[ringdata.tot3][1] = array[1];
150 ringdata.iring3[ringdata.tot3][2] = array[2];
151 ringdata.tot3++;
152 }
153 }
154 if (atom[i].flags & mask4)
155 {
156 is_cyclo4(i,array);
157 unique = TRUE;
158 for (j=0; j < 4 ;j++)
159 array1[j] = array[j];
160 for(j=0; j < ringdata.tot4; j++)
161 {
162 for (k=0; k < 4; k++)
163 array2[k] = ringdata.iring4[j][k];
164 if ( icompare(4,array1,array2))
165 unique = FALSE;
166 }
167 if (unique == TRUE)
168 {
169 ringdata.iring4[ringdata.tot4][0] = array[0];
170 ringdata.iring4[ringdata.tot4][1] = array[1];
171 ringdata.iring4[ringdata.tot4][2] = array[2];
172 ringdata.iring4[ringdata.tot4][3] = array[3];
173 ringdata.tot4++;
174 }
175 }
176 if (atom[i].flags & mask5)
177 {
178 is_cyclo5(i,array);
179 unique = TRUE;
180 for (j=0; j < 5 ;j++)
181 array1[j] = array[j];
182 for(j=0; j < ringdata.tot5; j++)
183 {
184 for (k=0; k < 5; k++)
185 array2[k] = ringdata.iring5[j][k];
186 if ( icompare(5,array1,array2))
187 unique = FALSE;
188 }
189 if (unique == TRUE)
190 {
191 ringdata.iring5[ringdata.tot5][0] = array[0];
192 ringdata.iring5[ringdata.tot5][1] = array[1];
193 ringdata.iring5[ringdata.tot5][2] = array[2];
194 ringdata.iring5[ringdata.tot5][3] = array[3];
195 ringdata.iring5[ringdata.tot5][4] = array[4];
196 ringdata.tot5++;
197 }
198 }
199 if (atom[i].flags & mask6)
200 {
201 is_cyclo6(i,array);
202 unique = TRUE;
203 for (j=0; j < 6 ;j++)
204 array1[j] = array[j];
205 for(j=0; j < ringdata.tot6; j++)
206 {
207 for (k=0; k < 6; k++)
208 array2[k] = ringdata.iring6[j][k];
209 if ( icompare(6,array1,array2))
210 unique = FALSE;
211 }
212 if (unique == TRUE)
213 {
214 ringdata.iring6[ringdata.tot6][0] = array[0];
215 ringdata.iring6[ringdata.tot6][1] = array[1];
216 ringdata.iring6[ringdata.tot6][2] = array[2];
217 ringdata.iring6[ringdata.tot6][3] = array[3];
218 ringdata.iring6[ringdata.tot6][4] = array[4];
219 ringdata.iring6[ringdata.tot6][5] = array[5];
220 ringdata.tot6++;
221 }
222 }
223 }
224 // now do ring map for fused rings
225 for (i=1; i <= natom; i++)
226 {
227 if ( !(atom[i].flags & aromatic_mask) )
228 {
229 ifive = find_rsize(5,i);
230 isix = find_rsize(6,i);
231 if ( isix > 1) // 6-6 fused ring
232 {
233 continue;
234 } else if (isix == 1 && ifive == 1) // 6-5 fused ring system
235 {
236 for (ij=0; ij < ringdata.tot6; ij++)
237 {
238 get_rsize(i,6,ij,array);
239 isix = aromatic_6(array);
240 if (isix == TRUE)
241 {
242 for(j=0; j < 6; j++)
243 {
244 atom[array[j]].flags |= aromatic_mask;
245 }
246 ringdata.iring6[ij][6] = TRUE;
247 }else
248 ringdata.iring6[ij][6] = FALSE;
249 }
250 for (ij=0; ij < ringdata.tot5; ij++)
251 {
252 get_rsize(i,5,ij,array);
253 isix = aromatic_5(ij,array);
254 if (isix == TRUE)
255 {
256 for(j=0; j < 5; j++)
257 {
258 atom[array[j]].flags |= aromatic_mask;
259 }
260 ringdata.iring5[ij][5] = TRUE;
261 }else
262 ringdata.iring5[ij][5] = FALSE;
263 }
264 } else if (ifive > 1) // 5-5 fused ring
265 {
266 continue;
267 }
268 }
269 }
270 // now do rest of rings - six rings first
271 for (i=0; i < ringdata.tot6; i++)
272 {
273 for(j=0; j < 6; j++)
274 array[j] = ringdata.iring6[i][j];
275 isix = aromatic_6(array);
276 if (isix == TRUE)
277 {
278 for(j=0; j < 6; j++)
279 atom[ringdata.iring6[i][j]].flags |= aromatic_mask;
280 ringdata.iring6[i][6] = TRUE;
281 }else
282 ringdata.iring6[i][6] = FALSE;
283 }
284 for (i=0; i < ringdata.tot5; i++)
285 {
286 for(j=0; j < 5; j++)
287 array[j] = ringdata.iring5[i][j];
288 ifive = aromatic_5(i,array);
289 if (ifive == TRUE)
290 {
291 for(j=0; j < 5; j++)
292 atom[ringdata.iring5[i][j]].flags |= aromatic_mask;
293 ringdata.iring5[i][5] = TRUE;
294 }else
295 ringdata.iring5[i][5] = FALSE;
296 }
297 }