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