ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/xlogp.c
Revision: 110
Committed: Thu Mar 12 01:43:50 2009 UTC (12 years, 1 month ago) by gilbertke
File size: 15663 byte(s)
Log Message:
further cleanup and localization of atom data
Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4
5 int get_hybrid(int);
6 int check_ring1(int);
7 float xlogp(int natom,int *atomnum,int **iat,int **bo,long int *flags,int *type);
8 // =========================
9 float xlogp(int natom,int *atomnum,int **iat,int **bo,long int *flags,int *type)
10 {
11 int i,j,k,ia;
12 int iz,nh,nx,npi,nc,itype,dbond,nox,ndouble,nf;
13 int npi_c,npi_x;
14 int nhydrophobic, namino_acid, nhbond, n13FX, n13XX;
15 int atype[100];
16 long int pi_mask;
17 float total,result;
18 // char astring[60];
19 float datype[] = {
20 0.000, 0.484, 0.168,-0.181, 0.358, 0.009,-0.344,-0.439, 0.051,-0.138,
21 -0.417,-0.454,-0.378, 0.223,-0.598,-0.396,-0.699,-0.362, 0.395, 0.236,
22 -0.166, 1.726, 0.098,-0.108, 1.637, 1.774, 0.281, 0.142, 0.715, 0.302,
23 -0.064, 0.079, 0.200, 0.869, 0.316, 0.054, 0.347, 0.046,-0.399,-0.029,
24 -0.330, 0.397, 0.068, 0.327,-2.057, 0.218,-0.582,-0.449,-0.774, 0.040,
25 -0.381, 0.443,-0.117,-2.052,-1.716, 0.321,-0.921,-0.704, 0.119, 1.192,
26 0.434, 0.587, 0.668,-0.791,-0.212, 0.016, 0.752, 1.071, 0.964,-1.817,
27 -1.214,-0.778, 0.493, 1.010, 1.187, 1.489,-0.802,-0.256, 1.626, 0.077,
28 0.264, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
29 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 };
30
31 pi_mask = (1L << PI_MASK);
32 for (i=0;i < 100; i++)
33 atype[i] = 0;
34 //
35 // loop through atoms and classify
36 for (i=1; i <= natom; i++)
37 {
38 if (atomnum[i] == 6) // carbon
39 {
40 iz = get_hybrid(i);
41 nh = nx = npi = nc = 0;
42 for (j=0; j < MAXIAT; j++)
43 {
44 if (iat[i][j] != 0)
45 {
46 if (atomnum[iat[i][j]] == 1) nh++;
47 if (flags[iat[i][j]] & pi_mask) npi++;
48 itype = atomnum[iat[i][j]];
49 if (itype == 6) nc++;
50 if (itype == 7 || itype == 8 || itype == 15 || itype == 16) nx++;
51 itype = type[iat[i][j]];
52 if (itype == 11 || itype == 12 || itype == 13 || itype == 14) nx++;
53 }
54 }
55 if (iz == 1) // sp3
56 {
57 if (nh == 3 && nc == 1 && npi == 0)
58 atype[1]++;
59 else if (nh == 3 && nc == 1 && npi > 0)
60 atype[2]++;
61 else if (nh == 3 && nx == 1)
62 atype[3]++;
63 else if (nh == 2 && nc == 2 && npi == 0)
64 atype[4]++;
65 else if (nh == 2 && nc == 2 && npi > 0)
66 atype[5]++;
67 else if (nh == 2 && nc == 1 && nx == 1)
68 atype[6]++;
69 else if (nh == 2 && nx == 2)
70 atype[7]++;
71 else if (nh == 1 && nc == 3 && npi == 0)
72 atype[8]++;
73 else if (nh == 1 && nc == 3 && npi > 0)
74 atype[9]++;
75 else if (nh == 1 && nc == 2 && nx == 1)
76 atype[10]++;
77 else if (nh == 1 && nc == 1 && nx == 2)
78 atype[11]++;
79 else if (nh == 1 && nx == 3)
80 atype[11]++;
81 else if (nh == 0 && nc == 4 && npi == 0)
82 atype[12]++;
83 else if (nh == 0 && nc == 4 && npi > 0)
84 atype[13]++;
85 else if (nh == 0 && nc == 3 && nx == 1)
86 atype[14]++;
87 else if (nh == 0 && nc == 2 && nx == 2)
88 atype[15]++;
89 else if (nh == 0 && nc == 1 && nx == 3)
90 atype[16]++;
91 else if (nh == 0 && nc == 0 && nx == 4)
92 atype[17]++;
93 } else if (iz == 2) // sp2
94 {
95 dbond = 0;
96 // find double bond atom
97 for (j=0; j < 4; j++)
98 {
99 if (iat[i][j] != 0 && bo[i][j] == 2)
100 {
101 dbond = iat[i][j];
102 break;
103 }
104 }
105 if (dbond == 0) goto L_10; // bad atoms
106 if (nh == 2 && nc == 1)
107 {
108 atype[18]++;
109 goto L_10;
110 }
111 // if not a pi atom
112 if (!(flags[i] & pi_mask)) // non pi atoms
113 {
114 if (atomnum[dbond] == 6) // c=c
115 {
116 if (nh == 1 & nc == 2)
117 {
118 atype[19]++;
119 goto L_10;
120 } else if (nh == 1 && nx == 1)
121 {
122 atype[20]++;
123 goto L_10;
124 } else if (nh == 0 && nc == 3)
125 {
126 atype[22]++;
127 goto L_10;
128 } else if (nh == 0 && nx >= 1)
129 {
130 atype[23]++;
131 goto L_10;
132 }
133 }else // c=x
134 {
135 if (nh == 1)
136 {
137 atype[21]++;
138 goto L_10;
139 } else if (nc >= 1)
140 {
141 atype[24]++;
142 goto L_10;
143 } else if (nx == 3)
144 {
145 atype[25]++;
146 goto L_10;
147 }
148 }
149 } else // pi conjugated systems
150 {
151 nh = nc = nx = npi = 0;
152 npi_c = 0;
153 npi_x = 0;
154 for (j = 0; j < 3; j++)
155 {
156 if (atomnum[iat[i][j]] == 1)
157 nh++;
158 if (atomnum[iat[i][j]] == 6)
159 {
160 nc++;
161 if (flags[iat[i][j]] & pi_mask)
162 {
163 npi++;
164 npi_c++;
165 }
166 }
167 if (atomnum[iat[i][j]] >= 6)
168 {
169 nx++;
170 if (flags[iat[i][j]] & pi_mask)
171 {
172 npi++;
173 npi_x++;
174 }
175 }
176 }
177 if (nh == 1 && nc == 2)
178 atype[26]++;
179 else if (nh == 1 && nc ==1 && nx == 1)
180 atype[27]++;
181 else if (nh == 1 && nx == 2)
182 atype[28]++;
183 else if (nc == 3 && npi == 2)
184 atype[29]++;
185 else if (nc == 2 && npi_x == 2 && nx == 1)
186 atype[30]++;
187 else if (nc == 2 && npi_x == 1 && nx == 1 && npi_x == 1)
188 atype[31]++;
189 else if (nc == 1 && nx == 2 && npi_x == 1 && npi_c == 1)
190 atype[32]++;
191 else if (nc == 1 && nx == 2 && npi_x == 2)
192 atype[33]++;
193 else if (npi == 3)
194 atype[34]++;
195 }
196 } else if (iz == 3)
197 {
198 for (j=0; j < 4; j++)
199 {
200 if (iat[i][j] != 0 && bo[i][j] == 3)
201 {
202 if (atomnum[iat[i][j]] == 7)
203 {
204 atype[77]++;
205 goto L_10;
206 }
207 }
208 }
209 if (nh == 1)
210 atype[35]++;
211 else if (nc == 1)
212 atype[36]++;
213 }
214 } else if (atomnum[i] == 1) // hydrogen
215 {
216 atype[37]++;
217 } else if (atomnum[i] == 8) // oxygen
218 {
219 nh = npi = nx = nc = 0;
220 for (j=0; j < 4; j++)
221 {
222 if (atomnum[iat[i][j]] == 1)
223 nh++;
224 if (atomnum[iat[i][j]] == 6)
225 {
226 nc++;
227 if (flags[iat[i][j]] & pi_mask) npi++;
228 }
229 if (atomnum[iat[i][j]] > 6)
230 {
231 nx++;
232 if (flags[iat[i][j]] & pi_mask) npi++;
233 }
234 }
235 if (type[i] == 6)
236 {
237 if (nh == 1 && nc == 1 && npi == 0)
238 atype[38]++;
239 else if (nh == 1 && nc == 1 && npi == 1)
240 atype[39]++;
241 else if (nh == 1 && nx == 1)
242 atype[40]++;
243 else if (nc == 2 && npi < 2)
244 atype[41]++;
245 else if ( (nc == 1 && nx == 1) || nx == 2)
246 atype[42]++;
247 else if (nc == 2 && npi == 2)
248 atype[43]++;
249 } else if (type[i] == 7)
250 {
251 if (nc == 1)
252 atype[44]++;
253 else if (nx == 1)
254 atype[45]++;
255 }
256 } else if (atomnum[i] == 7) // nitrogen
257 {
258 nh = nx = nc = npi = 0;
259 for (j=0; j < MAXIAT; j++)
260 {
261 if (iat[i][j] != 0)
262 {
263 if (atomnum[iat[i][j]] == 1) nh++;
264 if (atomnum[iat[i][j]] == 6) nc++;
265 if (atomnum[iat[i][j]] > 6) nx++;
266 if (flags[iat[i][j]] & pi_mask) npi++;
267 }
268 }
269 if (type[i] == 8)
270 {
271 if (nh == 2 && nc == 1 && npi == 0) atype[46]++;
272 else if (nh == 2 && nc == 1 && npi > 1) atype[47]++;
273 else if (nh == 2 && nx == 1) atype[48]++;
274 else if (nh == 1 && nc == 2) atype[49]++;
275 else if (nh == 1 && nc == 1 && nx == 1) atype[50]++;
276 else if (nh == 1 && nx == 2) atype[50]++;
277 else if (nh == 0 && nc == 3) atype[51]++;
278 else if (nh == 0 && nx >= 1) atype[52]++;
279 } else if (type[i] == 9)
280 {
281 for (j=0; j < 4; j++)
282 {
283 if (iat[i][j] != 0 )
284 {
285 if (bo[i][j] == 2) // imine type
286 {
287 if (atomnum[iat[i][j]] == 6)
288 {
289 if (nx == 0)
290 atype[53]++;
291 else
292 atype[54]++;
293 goto L_10;
294 } else if (atomnum[iat[i][j]] > 6)
295 {
296 if (nc == 1)
297 atype[55]++;
298 else
299 atype[56]++;
300 goto L_10;
301 }
302 }
303 }
304 }
305 for (j=0; j < 4; j++) // amides
306 {
307 if (iat[i][j] != 0 && atomnum[iat[i][j]] == 6)
308 {
309 ia = iat[i][j];
310 for (k=0; k < 4; k++)
311 {
312 if (iat[ia][k] != 0 && bo[ia][k] == 2)
313 {
314 if (atomnum[iat[ia][k]] == 8) // amide
315 {
316 if (nh == 2 && nc == 1) atype[63]++;
317 else if (nh == 1) atype[64]++;
318 else atype[65]++;
319 goto L_10;
320 }
321 }
322 }
323 }
324 }
325 // picked up amides and imines - everything else must be aromatic
326 if (nh == 1 && nc == 2) atype[58]++;
327 else if (nh == 1 && nx >= 1) atype[59]++;
328 else if (nc == 3) atype[61]++;
329 goto L_10;
330 }
331 } else if (atomnum[i] == 16) // sulfur
332 {
333 nh = 0;
334 nox = 0;
335 ndouble = 0;
336 for (j=0; j < MAXIAT; j++)
337 {
338 if (iat[i][j] != 0)
339 {
340 if (atomnum[iat[i][j]] == 1) nh++;
341 if (atomnum[iat[i][j]] == 8) nox++;
342 if (bo[i][j] == 2) ndouble++;
343 }
344 }
345 if (nox == 2)
346 {
347 atype[71]++;
348 goto L_10;
349 } else if (nox == 1)
350 {
351 atype[70]++;
352 goto L_10;
353 }
354 if (nox == 0 && ndouble == 1)
355 {
356 atype[69]++;
357 goto L_10;
358 }
359 if (nh == 1)
360 {
361 atype[66]++;
362 goto L_10;
363 } else
364 {
365 if (check_ring1(i))
366 {
367 if ((flags[iat[i][0]] & pi_mask) && (flags[iat[i][1]] & pi_mask))
368 {
369 atype[68]++;
370 goto L_10;
371 }
372 } else
373 {
374 atype[67]++;
375 goto L_10;
376 }
377 }
378 } else if (atomnum[i] == 15) // phosphorus
379 {
380 atype[76]++;
381 } else if (atomnum[i] == 11) // fluorine
382 {
383 atype[72]++;
384 } else if (atomnum[i] == 17) // chlorine
385 {
386 atype[73]++;
387 } else if (atomnum[i] == 35) // bromine
388 {
389 atype[74]++;
390 } else if (atomnum[i] == 53) // iodine
391 {
392 atype[75]++;
393 } else
394 {
395 // sprintf(astring,"Atom %d type %d not supported\0",i,atom[i].type);
396 // message_alert(astring,"Error in LogP");
397 }
398 L_10:
399 continue;
400 }
401 // done assigning types = compute logP
402 total = 0.0;
403 for (i=0; i < 100; i++)
404 total += atype[i]*datype[i];
405
406 // now do correction factors
407 nhydrophobic = namino_acid = nhbond = n13FX = n13XX = 0;
408
409 nhydrophobic = atype[1] + atype[2] + atype[4] + atype[5] + atype[8] + atype[9] + atype[12] + atype[13] + atype[18] +
410 atype[19] + atype[22];
411
412 // 1,3 halogens
413 for (i=1; i <= natom; i++)
414 {
415 nf = 0;
416 nx = 0;
417 if (atomnum[i] == 6)
418 {
419 for (j=0; j < MAXIAT; j++)
420 {
421 if (atomnum[iat[i][j]] == 9)
422 nf++;
423 if (atomnum[iat[i][j]] == 17)
424 nx++;
425 if (atomnum[iat[i][j]] == 35)
426 nx++;
427 if (atomnum[iat[i][j]] == 53)
428 nx++;
429 }
430 if ((nf >= 1 && nx >= 1) || nf >= 2)
431 n13FX++;
432 if (nx >=2 && nf == 0)
433 n13XX++;
434 }
435 }
436 // amino acids
437 // hydrogen bonds
438
439
440 result = total + nhydrophobic*0.19F + n13FX*0.08 + n13XX*(-0.26F);
441 return result;
442 }
443 // ==================