00001
00002 #include "../headers/pocket.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 c_lst_pockets *clusterPockets(s_lst_vvertice *lvvert, s_fparams *params)
00099 {
00100 int i = -1,
00101 j = -1,
00102 curPocketId=1,
00103 vNb[4] = {0,0,0,0};
00104
00105
00106 s_vvertice *vertices = lvvert->vertices,
00107 *vcur = NULL ;
00108
00109
00110
00111
00112
00113
00114 c_lst_pockets *pockets = c_lst_pockets_alloc();
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 for(i=0;i<lvvert->nvert;i++) {
00125 vcur = vertices + i ;
00126 for(j=0;j<4;j++) vNb[j] = vcur->vneigh[j];
00127 curPocketId=updateIds(lvvert,i,vNb,vcur->resid, curPocketId,pockets, params);
00128
00129
00130 }
00131
00132
00133
00134
00135
00136
00137
00138 node_pocket *p = pockets->first ;
00139 while(p) {
00140 p->pocket->size = p->pocket->v_lst->n_vertices ;
00141 p = p->next ;
00142 }
00143
00144 if(pockets->n_pockets > 0) return pockets ;
00145 else {
00146 my_free(pockets) ;
00147 return NULL ;
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 int updateIds(s_lst_vvertice *lvvert, int i, int *vNb, int resid, int curPocket,
00171 c_lst_pockets *pockets, s_fparams *params)
00172 {
00173
00174 int filteredIdx,j,z;
00175 int groupCreatedFlag=0;
00176 int cur_n_apol=0;
00177 int cur_n_pol=0;
00178
00179
00180
00181
00182 s_vvertice *vertices = lvvert->vertices ;
00183 s_vvertice *vert = &(vertices[i]),
00184 *fvert = NULL ;
00185
00186
00187 for(j=0;j<4;j++) {
00188 if(vNb[j] < lvvert->qhullSize && vNb[j] > 0) {
00189 filteredIdx = lvvert->tr[vNb[j]];
00190 if(filteredIdx!=-1 && filteredIdx < lvvert->nvert){
00191 fvert = &(vertices[filteredIdx]) ;
00192
00193 if(dist(vert->x, vert->y, vert->z, fvert->x, fvert->y, fvert->z) <= params->clust_max_dist){
00194
00195 groupCreatedFlag=1;
00196
00197 if(resid == -1 && fvert->resid==-1){
00198 resid=++curPocket;
00199 vert->resid=resid;
00200 fvert->resid=curPocket;
00201
00202 s_pocket *pocket = alloc_pocket();
00203 pocket->v_lst=c_lst_vertices_alloc();
00204
00205 c_lst_vertices_add_last(pocket->v_lst, vert);
00206 c_lst_vertices_add_last(pocket->v_lst, fvert);
00207
00208 if(vert->type==M_APOLAR_AS) cur_n_apol++;
00209 else cur_n_pol++;
00210
00211 if(fvert->type==M_APOLAR_AS)cur_n_apol++;
00212 else cur_n_pol++;
00213
00214 c_lst_pockets_add_last(pockets, pocket,cur_n_apol,cur_n_pol);
00215
00216 }
00217
00218 else if(resid!=-1 && fvert->resid==-1)
00219 {
00220 fvert->resid=resid;
00221 node_pocket *pocket=searchPocket(resid,pockets);
00222 if(pocket) c_lst_vertices_add_last(pocket->pocket->v_lst, fvert);
00223
00224 if(fvert->type==M_APOLAR_AS) pocket->pocket->nAlphaApol+=1;
00225 else pocket->pocket->nAlphaPol+=1;
00226
00227
00228
00229 }
00230 else if(resid==-1 && fvert->resid!=-1) {
00231 vert->resid = fvert->resid;
00232 resid=fvert->resid;
00233 node_pocket *pocket = searchPocket(resid,pockets);
00234 if(pocket) c_lst_vertices_add_last(pocket->pocket->v_lst, vert);
00235 if(vert->type==M_APOLAR_AS) pocket->pocket->nAlphaApol+=1;
00236 else pocket->pocket->nAlphaPol+=1;
00237
00238 }
00239 else if((resid!=-1 && fvert->resid!=-1) && (resid!=fvert->resid)) {
00240 node_pocket *pocket=searchPocket(resid,pockets);
00241
00242 node_pocket *pocket2=searchPocket(fvert->resid,pockets);
00243
00244
00245 mergePockets(pocket,pocket2,pockets);
00246
00247 for(z=0;z<lvvert->nvert;z++){
00248
00249 if(vertices[z].resid==resid) vertices[z].resid=fvert->resid;
00250 }
00251 resid=fvert->resid;
00252
00253 }
00254 }
00255 }
00256 else {
00257
00258 if(filteredIdx >= lvvert->nvert) {
00259 fprintf(stdout, "INDEX ERROR\n") ;
00260 }
00261 }
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 }
00273
00274
00275
00276
00277 if(groupCreatedFlag) return curPocket;
00278
00279
00280
00281
00282 cur_n_apol=0;
00283 cur_n_pol=0;
00284 resid=++curPocket;
00285 vert->resid=resid;
00286 s_pocket *pocket=alloc_pocket();
00287 pocket->v_lst=c_lst_vertices_alloc();
00288 c_lst_vertices_add_last(pocket->v_lst, vert);
00289 if(vert->type==M_APOLAR_AS) cur_n_apol++;
00290 else cur_n_pol++;
00291 c_lst_pockets_add_last(pockets,pocket,cur_n_apol,cur_n_pol);
00292
00293
00294 return curPocket;
00295
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 float set_pocket_mtvolume(s_pocket *pocket, int niter)
00321 {
00322 int i = 0,
00323 nb_in = 0,
00324 nit = 0 ;
00325
00326 float xmin = 0.0, xmax = 0.0,
00327 ymin = 0.0, ymax = 0.0,
00328 zmin = 0.0, zmax = 0.0,
00329 xtmp = 0.0, ytmp = 0.0, ztmp = 0.0,
00330 xr = 0.0, yr = 0.0, zr = 0.0,
00331 vbox = 0.0 ;
00332
00333 c_lst_vertices *vertices = pocket->v_lst ;
00334 node_vertice *cur = vertices->first ;
00335 s_vvertice *vcur = NULL ;
00336
00337
00338 while(cur) {
00339 vcur = cur->vertice ;
00340
00341
00342 if(nit == 0) {
00343 xmin = vcur->x - vcur->ray ; xmax = vcur->x + vcur->ray ;
00344 ymin = vcur->y - vcur->ray ; ymax = vcur->y + vcur->ray ;
00345 zmin = vcur->z - vcur->ray ; zmax = vcur->z + vcur->ray ;
00346 }
00347 else {
00348 if(xmin > (xtmp = vcur->x - vcur->ray)) xmin = xtmp ;
00349 else if(xmax < (xtmp = vcur->x + vcur->ray)) xmax = xtmp ;
00350
00351 if(ymin > (ytmp = vcur->y - vcur->ray)) ymin = ytmp ;
00352 else if(ymax < (ytmp = vcur->y + vcur->ray)) ymax = ytmp ;
00353
00354 if(zmin > (ztmp = vcur->z - vcur->ray)) zmin = ztmp ;
00355 else if(zmax < (ztmp = vcur->z + vcur->ray)) zmax = ztmp ;
00356 }
00357
00358 cur = cur->next ;
00359 nit++ ;
00360 }
00361
00362
00363 vbox = (xmax - xmin)*(ymax - ymin)*(zmax - zmin) ;
00364
00365
00366 for(i = 0 ; i < niter ; i++) {
00367 xr = rand_uniform(xmin, xmax) ;
00368 yr = rand_uniform(ymin, ymax) ;
00369 zr = rand_uniform(zmin, zmax) ;
00370 cur = vertices->first ;
00371
00372 while(cur) {
00373 vcur = cur->vertice ;
00374
00375 xtmp = vcur->x - xr ;
00376 ytmp = vcur->y - yr ;
00377 ztmp = vcur->z - zr ;
00378
00379
00380 if((vcur->ray*vcur->ray) > (xtmp*xtmp + ytmp*ytmp + ztmp*ztmp)) {
00381
00382 nb_in ++ ; break ;
00383 }
00384 cur = cur->next ;
00385 }
00386 }
00387
00388 pocket->pdesc->volume = ((float)nb_in)/((float)niter)*vbox ;
00389
00390
00391 return pocket->pdesc->volume ;
00392 }
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 float set_pocket_volume(s_pocket *pocket, int idiscret)
00412 {
00413 int niter = 0,
00414 nb_in = 0,
00415 nit = 0 ;
00416
00417 float discret = 1.0/(float)idiscret ;
00418
00419 float x = 0.0, y = 0.0, z = 0.0,
00420 xstep = 0.0, ystep = 0.0, zstep = 0.0 ;
00421
00422 float xmin = 0.0, xmax = 0.0,
00423 ymin = 0.0, ymax = 0.0,
00424 zmin = 0.0, zmax = 0.0,
00425 xtmp = 0.0, ytmp = 0.0, ztmp = 0.0,
00426 vbox = 0.0 ;
00427
00428 c_lst_vertices *vertices = pocket->v_lst ;
00429 node_vertice *cur = vertices->first ;
00430 s_vvertice *vcur = NULL ;
00431
00432
00433 while(cur) {
00434 vcur = cur->vertice ;
00435
00436
00437 if(nit == 0) {
00438 xmin = vcur->x - vcur->ray ; xmax = vcur->x + vcur->ray ;
00439 ymin = vcur->y - vcur->ray ; ymax = vcur->y + vcur->ray ;
00440 zmin = vcur->z - vcur->ray ; zmax = vcur->z + vcur->ray ;
00441 }
00442 else {
00443 if(xmin > (xtmp = vcur->x - vcur->ray)) xmin = xtmp ;
00444 else if(xmax < (xtmp = vcur->x + vcur->ray)) xmax = xtmp ;
00445
00446 if(ymin > (ytmp = vcur->y - vcur->ray)) ymin = ytmp ;
00447 else if(ymax < (ytmp = vcur->y + vcur->ray)) ymax = ytmp ;
00448
00449 if(zmin > (ztmp = vcur->z - vcur->ray)) zmin = ztmp ;
00450 else if(zmax < (ztmp = vcur->z + vcur->ray)) zmax = ztmp ;
00451 }
00452
00453 cur = cur->next ;
00454 nit++ ;
00455 }
00456
00457
00458 vbox = (xmax - xmin)*(ymax - ymin)*(zmax - zmin) ;
00459
00460 xstep = discret * (xmax - xmin) ;
00461 ystep = discret * (ymax - ymin) ;
00462 zstep = discret * (zmax - zmin) ;
00463
00464
00465 for(x = xmin ; x < xmax ; x += xstep) {
00466 for(y = ymin ; y < ymax ; y += ystep) {
00467 for(z = zmin ; z < zmax ; z += zstep) {
00468 cur = vertices->first ;
00469 while(cur) {
00470 vcur = cur->vertice ;
00471 xtmp = vcur->x - x ;
00472 ytmp = vcur->y - y ;
00473 ztmp = vcur->z - z ;
00474
00475
00476 if((vcur->ray*vcur->ray) > (xtmp*xtmp + ytmp*ytmp + ztmp*ztmp)) {
00477
00478 nb_in ++ ; break ;
00479 }
00480 cur = cur->next ;
00481 }
00482 niter ++ ;
00483 }
00484 }
00485 }
00486
00487 pocket->pdesc->volume = ((float)nb_in)/((float)niter)*vbox ;
00488
00489
00490 return pocket->pdesc->volume ;
00491 }
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 void set_pockets_bary(c_lst_pockets *pockets)
00508 {
00509 node_pocket *cur = NULL ;
00510 s_pocket *pcur = NULL ;
00511
00512 float xsum, ysum, zsum ;
00513 int n ;
00514
00515 if(pockets && pockets->n_pockets > 0) {
00516 cur = pockets->first ;
00517 while(cur) {
00518 pcur = cur->pocket ;
00519
00520 xsum = 0.0 ; ysum = 0.0 ; zsum = 0.0 ;
00521 n = 0 ;
00522
00523 node_vertice *nvcur = pcur->v_lst->first ;
00524 while(nvcur) {
00525 xsum += nvcur->vertice->x ;
00526 ysum += nvcur->vertice->y ;
00527 zsum += nvcur->vertice->z ;
00528 n ++ ;
00529
00530 nvcur = nvcur->next ;
00531 }
00532
00533 pcur->bary[0] = xsum / (float) n ;
00534 pcur->bary[1] = ysum / (float) n ;
00535 pcur->bary[2] = zsum / (float) n ;
00536
00537 cur = cur->next ;
00538 }
00539 }
00540 }
00541
00542 void set_pocket_contacted_lig_name(s_pocket *pocket, s_pdb *pdb_w_lig)
00543 {
00544 s_atm *curatom = NULL ;
00545 int natoms=pdb_w_lig->nhetatm;
00546 int i;
00547 s_atm ** atoms=pdb_w_lig->lhetatm;
00548
00549 for(i=0;i<natoms;i++){
00550 curatom=atoms[i];
00551 if(pocket) {
00552
00553
00554 if(dist(pocket->bary[0],pocket->bary[1],pocket->bary[2],curatom->x,curatom->y,curatom->z) < M_LIG_IN_POCKET_DIST && !element_in_kept_res(curatom->res_name)) {
00555 strncpy(pocket->pdesc->ligTag,curatom->res_name,7);
00556 pocket->pdesc->ligTag[7]='\0';
00557
00558 return;
00559 }
00560 }
00561
00562 }
00563
00564 strncpy(pocket->pdesc->ligTag,"NULL\0",5);
00565 return ;
00566 }
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 void set_pockets_descriptors(c_lst_pockets *pockets,s_pdb *pdb,s_fparams *params, s_pdb *pdb_w_lig)
00583 {
00584 node_pocket *cur = NULL ;
00585 s_pocket *pcur = NULL ;
00586 int niter=params->nb_mcv_iter;
00587 int natms = 0, i ;
00588
00589 if(pockets && pockets->n_pockets > 0) {
00590 cur = pockets->first ;
00591
00592 while(cur) {
00593 pcur = cur->pocket ;
00594 reset_desc(pcur->pdesc);
00595
00596 s_vvertice **tab_vert = (s_vvertice **)
00597 my_malloc(pcur->v_lst->n_vertices*sizeof(s_vvertice*)) ;
00598 i = 0 ;
00599 node_vertice *nvcur = pcur->v_lst->first ;
00600
00601
00602
00603
00604 while(nvcur) {
00605
00606
00607
00608
00609
00610 tab_vert[i] = nvcur->vertice ;
00611 nvcur = nvcur->next ;
00612 i++ ;
00613 }
00614
00615
00616 s_atm **pocket_atoms = get_pocket_contacted_atms(pcur, &natms) ;
00617
00618
00619 if(pdb_w_lig) set_pocket_contacted_lig_name(pcur,pdb_w_lig);
00620
00621
00622 set_descriptors(pocket_atoms, natms, tab_vert,pcur->v_lst->n_vertices, pcur->pdesc,niter,pdb,params->flag_do_asa_and_volume_calculations) ;
00623
00624 my_free(pocket_atoms) ;
00625 my_free(tab_vert) ;
00626
00627 cur = cur->next ;
00628
00629 }
00630
00631
00632 set_normalized_descriptors(pockets) ;
00633
00634
00635 cur = pockets->first ;
00636 while(cur) {
00637 cur->pocket->score = score_pocket(cur->pocket->pdesc) ;
00638 cur->pocket->pdesc->drug_score = drug_score_pocket(cur->pocket->pdesc);
00639 cur = cur->next ;
00640 }
00641 }
00642 }
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668 void set_normalized_descriptors(c_lst_pockets *pockets)
00669 {
00670
00671 if(!pockets || pockets->n_pockets <= 0) return ;
00672
00673 node_pocket *cur = NULL ;
00674 s_desc *dcur = NULL ;
00675
00676
00677 float flex_M = 0.0, flex_m = 1.0,
00678 nas_apolp_M = 0.0, nas_apolp_m = 1.0,
00679 density_M = 0.0, density_m = 100.0,
00680 mlhd_M = 0.0, mlhd_m = 1000.0,
00681 as_max_dst_M = 0.0, as_max_dst_m = 1000.0 ;
00682
00683 int nas_M = 0, nas_m = 1000,
00684 polarity_M = -1, polarity_m = 10000 ;
00685
00686 cur = pockets->first ;
00687
00688 while(cur) {
00689 dcur = cur->pocket->pdesc ;
00690
00691 if(cur == pockets->first) {
00692 as_max_dst_M = as_max_dst_m = dcur->as_max_dst ;
00693 density_M = density_m = dcur->as_density ;
00694 polarity_M = polarity_m = dcur->polarity_score ;
00695 flex_M = flex_m = dcur->flex ;
00696 nas_apolp_M = nas_apolp_m = dcur->apolar_asphere_prop ;
00697 mlhd_M = mlhd_m = dcur->mean_loc_hyd_dens ;
00698 nas_M = nas_m = dcur->nb_asph ;
00699 }
00700 else {
00701
00702 if(dcur->as_max_dst > as_max_dst_M)
00703 as_max_dst_M = dcur->as_max_dst ;
00704 else if(dcur->as_max_dst < as_max_dst_m)
00705 as_max_dst_m = dcur->as_max_dst ;
00706
00707 if(dcur->as_density > density_M)
00708 density_M = dcur->as_density ;
00709 else if(dcur->as_density < density_m)
00710 density_m = dcur->as_density ;
00711
00712 if(dcur->polarity_score > polarity_M)
00713 polarity_M = dcur->polarity_score ;
00714 else if(dcur->polarity_score < polarity_m)
00715 polarity_m = dcur->polarity_score ;
00716
00717 if(dcur->mean_loc_hyd_dens > mlhd_M)
00718 mlhd_M =dcur->mean_loc_hyd_dens ;
00719 else if(dcur->mean_loc_hyd_dens < mlhd_m)
00720 mlhd_m =dcur->mean_loc_hyd_dens ;
00721
00722 if(dcur->flex > flex_M) flex_M = dcur->flex ;
00723 else if(dcur->flex < flex_m) flex_m = dcur->flex ;
00724
00725 if(dcur->nb_asph > nas_M) nas_M = dcur->nb_asph ;
00726 else if(dcur->nb_asph < nas_m) nas_m = dcur->nb_asph ;
00727
00728 if(dcur->apolar_asphere_prop > nas_apolp_M)
00729 nas_apolp_M = dcur->apolar_asphere_prop ;
00730 else if(dcur->apolar_asphere_prop < nas_apolp_m)
00731 nas_apolp_m = dcur->apolar_asphere_prop;
00732 }
00733
00734 cur = cur->next ;
00735 }
00736
00737
00738 cur = pockets->first ;
00739 if(pockets->n_pockets> 1){
00740 while(cur) {
00741 dcur = cur->pocket->pdesc ;
00742
00743 if(as_max_dst_M - as_max_dst_m!=0.0){
00744 dcur->as_max_dst_norm =
00745 (dcur->as_max_dst - as_max_dst_m) / (as_max_dst_M - as_max_dst_m) ;
00746 }
00747 if(density_M - density_m!=0.0){
00748 dcur->as_density_norm =
00749 (dcur->as_density - density_m) / (density_M - density_m) ;
00750 }
00751 if(polarity_M - polarity_m!=0.0){
00752 dcur->polarity_score_norm =
00753 (float)(dcur->polarity_score - polarity_m) /
00754 (float)(polarity_M - polarity_m) ;
00755 }
00756 if(mlhd_M - mlhd_m!=0.0){
00757 dcur->mean_loc_hyd_dens_norm =
00758 (dcur->mean_loc_hyd_dens - mlhd_m) / (mlhd_M - mlhd_m) ;
00759 }
00760 if(flex_M - flex_m!=0.0) dcur->flex = (dcur->flex - flex_m) / (flex_M - flex_m) ;
00761 if(nas_M - nas_m!=0.0) dcur->nas_norm = (float) (dcur->nb_asph - nas_m) /
00762 (float) (nas_M - nas_m) ;
00763 if(nas_apolp_M - nas_apolp_m!=0.0){
00764 dcur->prop_asapol_norm =
00765 (dcur->apolar_asphere_prop - nas_apolp_m)
00766 / (nas_apolp_M - nas_apolp_m);
00767 }
00768
00769 cur = cur->next ;
00770 }
00771 }
00772 else {
00773 dcur = cur->pocket->pdesc ;
00774 dcur->polarity_score_norm=0.0;
00775 dcur->as_density_norm=0.0;
00776 dcur->as_max_dst_norm=0.0;
00777 dcur->mean_loc_hyd_dens_norm=0.0;
00778 dcur->flex=0.0;
00779 dcur->nas_norm=0.0;
00780 dcur->prop_asapol_norm=0.0;
00781 }
00782 }
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810 node_pocket *c_lst_pockets_add_first(c_lst_pockets *lst, s_pocket *pocket)
00811 {
00812 node_pocket *newn = NULL ;
00813
00814 if(lst) {
00815 newn = node_pocket_alloc(pocket) ;
00816 lst->first->prev = newn ;
00817 newn->next = lst->first ;
00818
00819 lst->first = newn ;
00820 lst->n_pockets += 1 ;
00821 }
00822
00823 return newn ;
00824 }
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841 node_pocket *c_lst_pockets_add_last(c_lst_pockets *lst,s_pocket *pocket,int cur_n_apol, int cur_n_pol)
00842 {
00843 node_pocket *newn = NULL ;
00844
00845 if(lst) {
00846 newn = node_pocket_alloc(pocket) ;
00847 newn->pocket->nAlphaApol = cur_n_apol;
00848 newn->pocket->nAlphaPol = cur_n_pol;
00849 if(lst->last) {
00850 newn->prev = lst->last ;
00851 lst->last->next = newn ;
00852 }
00853 else {
00854 lst->first = newn ;
00855
00856 }
00857 lst->last = newn ;
00858 lst->n_pockets += 1 ;
00859 }
00860
00861 return newn ;
00862 }
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880 void swap_pockets(c_lst_pockets *pockets, node_pocket *p1, node_pocket *p2)
00881 {
00882 node_pocket *p1prev = p1->prev,
00883 *p1next = p1->next,
00884 *p2prev = p2->prev,
00885 *p2next = p2->next ;
00886
00887 if(p1->next == p2) {
00888
00889
00890 if(p1->prev) p1->prev->next = p2 ;
00891 else pockets->first = p2 ;
00892
00893 if(p2->next) p2->next->prev = p1 ;
00894 else pockets->last = p2 ;
00895
00896 p2->next = p1 ;
00897 p2->prev = p1prev ;
00898 p1->prev = p2 ;
00899 p1->next = p2next ;
00900 }
00901 else if(p1->prev == p2) {
00902
00903
00904 if(p1->next) p1->next->prev = p2 ;
00905 else pockets->last = p2 ;
00906
00907 if(p2->prev) p2->prev->next = p1 ;
00908 else pockets->first = p1 ;
00909
00910 p1->next = p2 ;
00911 p1->prev = p2prev ;
00912 p2->prev = p1 ;
00913 p2->next = p1next;
00914 }
00915 else {
00916
00917
00918 if(p1->next) {
00919
00920 p1->next->prev = p2 ;
00921 if(p1->prev) p1->prev->next = p2 ;
00922 else pockets->first = p2 ;
00923 }
00924 else {
00925
00926
00927 pockets->last = p2 ;
00928 if(p1->prev) {
00929 p1->prev->next = p2 ;
00930 }
00931 }
00932
00933
00934 if(p2->next) {
00935
00936 p2->next->prev = p1 ;
00937 if(p2->prev) p2->prev->next = p1 ;
00938 else pockets->first = p1 ;
00939 }
00940 else {
00941
00942 if(p2->prev) {
00943 p2->prev->next = p1 ;
00944 pockets->last = p1 ;
00945 }
00946 }
00947
00948 p1->next = p2next ;
00949 p1->prev = p2prev ;
00950
00951 p2->next = p1next ;
00952 p2->prev = p1prev ;
00953
00954 }
00955 }
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972 node_pocket *searchPocket(int resid, c_lst_pockets *lst)
00973 {
00974 node_pocket *cur = NULL ;
00975
00976 if(lst) {
00977 cur = lst->first ;
00978 while(cur && cur->pocket->v_lst->first->vertice->resid != resid) {
00979 cur = cur->next ;
00980 }
00981 }
00982
00983 return cur;
00984 }
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 void dropPocket(c_lst_pockets *pockets, node_pocket *pocket)
01017 {
01018
01019 if(pocket->prev && pocket->next){
01020 pocket->prev->next = pocket->next;
01021 pocket->next->prev = pocket->prev;
01022 }
01023 else if(pocket->next){
01024 pocket->next->prev = NULL;
01025 pockets->first = pocket->next;
01026 }
01027 else if(pocket->prev){
01028 pocket->prev->next = NULL;
01029 pockets->last = pocket->prev;
01030 }
01031 c_lst_vertices_free(pocket->pocket->v_lst);
01032 pocket->next = NULL ;
01033 pocket->prev = NULL ;
01034 pockets->n_pockets -= 1;
01035 my_free(pocket->pocket->pdesc);
01036 pocket->pocket->pdesc = NULL ;
01037 my_free(pocket->pocket);
01038 pocket->pocket= NULL;
01039
01040 my_free(pocket);
01041
01042 if(pockets->n_pockets == 0) pockets->first = NULL ;
01043 }
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061 void mergePockets(node_pocket *pocket,node_pocket *pocket2,c_lst_pockets *pockets)
01062 {
01063 s_pocket *pock = pocket->pocket,
01064 *pock2 = pocket2->pocket ;
01065
01066 pockets->current=pocket2;
01067 pock->nAlphaApol += pock2->nAlphaApol;
01068 pock->nAlphaPol += pock2->nAlphaPol;
01069 pock->v_lst->n_vertices += pock2->v_lst->n_vertices;
01070 pock->size = pock->v_lst->n_vertices ;
01071
01072 pock->v_lst->last->next = pock2->v_lst->first;
01073 pock->v_lst->last = pock2->v_lst->last;
01074
01075 my_free(pocket2->pocket->v_lst);
01076 pocket2->pocket->v_lst = NULL;
01077 my_free(pocket2->pocket->pdesc);
01078 my_free(pocket2->pocket);
01079 pocket2->pocket=NULL;
01080
01081 if(pocket2->prev && pocket2->next){
01082 pocket2->prev->next = pocket2->next;
01083 pocket2->next->prev = pocket2->prev;
01084 }
01085 else if(pocket2->next){
01086 pockets->first=pocket2->next;
01087 pocket2->next->prev=NULL;
01088 }
01089 else if(pocket2->prev){
01090 pocket2->prev->next=NULL;
01091 pockets->last=pocket2->prev;
01092 }
01093 else if(!pocket2->prev && !pocket2->next) my_free(pocket2);
01094
01095 pockets->n_pockets-=1;
01096
01097
01098
01099 my_free(pocket2);
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112 }
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137 s_pocket* alloc_pocket(void)
01138 {
01139 s_pocket *p = (s_pocket*)my_malloc(sizeof(s_pocket)) ;
01140 p->pdesc = (s_desc*)my_malloc(sizeof(s_desc)) ;
01141 p->v_lst = NULL ;
01142
01143 reset_pocket(p) ;
01144
01145 return p ;
01146 }
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161 c_lst_pockets *c_lst_pockets_alloc(void)
01162 {
01163 c_lst_pockets *lst = (c_lst_pockets *)my_malloc(sizeof(c_lst_pockets)) ;
01164
01165 lst->first = NULL ;
01166 lst->last = NULL ;
01167 lst->current = NULL ;
01168 lst->n_pockets = 0 ;
01169 lst->vertices = NULL ;
01170
01171 return lst ;
01172 }
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188 node_pocket *node_pocket_alloc(s_pocket *pocket)
01189 {
01190 node_pocket *n_pocket = (node_pocket*)my_malloc(sizeof(node_pocket)) ;
01191
01192 n_pocket->next = NULL ;
01193 n_pocket->prev = NULL ;
01194 n_pocket->pocket = pocket ;
01195
01196 return n_pocket ;
01197 }
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214 void c_lst_pocket_free(c_lst_pockets *lst)
01215 {
01216 node_pocket *cur = NULL,
01217 *next = NULL ;
01218
01219 if(lst) {
01220 cur = lst->first ;
01221 while(cur) {
01222 next = cur->next ;
01223 dropPocket(lst, cur) ;
01224 cur = next ;
01225 }
01226
01227 free_vert_lst(lst->vertices) ;
01228
01229 lst->vertices = NULL ;
01230 lst->first = NULL ;
01231 lst->last = NULL ;
01232 lst->current = NULL ;
01233
01234 my_free(lst) ;
01235 }
01236
01237 }
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269 s_atm** get_pocket_contacted_atms(s_pocket *pocket, int *natoms)
01270 {
01271 int actual_size = 10,
01272 nb_atoms = 0,
01273 i = 0 ;
01274
01275 node_vertice *nvcur = NULL ;
01276 s_vvertice *vcur = NULL ;
01277
01278 s_atm **catoms = NULL ;
01279
01280 if(pocket && pocket->v_lst && pocket->v_lst->n_vertices > 0) {
01281
01282 int atm_ids[pocket->v_lst->n_vertices * 4] ;
01283
01284
01285 catoms = (s_atm **)my_malloc(actual_size*sizeof(s_atm*)) ;
01286 nvcur = pocket->v_lst->first ;
01287 while(nvcur) {
01288 vcur = nvcur->vertice ;
01289
01290 for(i = 0 ; i < 4 ; i++) {
01291 if(in_tab(atm_ids, nb_atoms, vcur->neigh[i]->id) == 0) {
01292 if(nb_atoms >= actual_size) {
01293 catoms = (s_atm **)my_realloc(catoms, (actual_size+10)*sizeof(s_atm**)) ;
01294 actual_size += 10 ;
01295 }
01296
01297 atm_ids[nb_atoms] = vcur->neigh[i]->id ;
01298 catoms[nb_atoms] = vcur->neigh[i] ;
01299 nb_atoms ++ ;
01300 }
01301 }
01302 nvcur = nvcur->next ;
01303 }
01304 }
01305
01306 *natoms = nb_atoms ;
01307
01308 return catoms ;
01309 }
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325 int count_pocket_contacted_atms(s_pocket *pocket)
01326 {
01327 if(!pocket || !(pocket->v_lst) || pocket->v_lst->n_vertices <= 0) return -1 ;
01328
01329 int nb_atoms = 0,
01330 i = 0 ;
01331
01332 node_vertice *nvcur = NULL ;
01333 s_vvertice *vcur = NULL ;
01334
01335
01336 int atm_ids[pocket->v_lst->n_vertices * 4] ;
01337
01338
01339 nvcur = pocket->v_lst->first ;
01340 while(nvcur) {
01341 vcur = nvcur->vertice ;
01342
01343 for(i = 0 ; i < 4 ; i++) {
01344 if(in_tab(atm_ids, nb_atoms, vcur->neigh[i]->id) == 0) {
01345 atm_ids[nb_atoms] = vcur->neigh[i]->id ;
01346 nb_atoms ++ ;
01347 }
01348 }
01349 nvcur = nvcur->next ;
01350 }
01351
01352 return nb_atoms ;
01353 }
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369 s_vvertice** get_pocket_pvertices(s_pocket *pocket)
01370 {
01371 s_vvertice **pverts = my_calloc(pocket->size, sizeof(s_vvertice*)) ;
01372 int i = 0 ;
01373 node_vertice *nvcur = pocket->v_lst->first ;
01374 while(nvcur) {
01375 pverts[i] = nvcur->vertice ;
01376 nvcur = nvcur->next ;
01377 i++ ;
01378 }
01379
01380 return pverts ;
01381 }
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398 void reset_pocket(s_pocket *pocket)
01399 {
01400 pocket->rank = -1 ;
01401
01402 pocket->score = 0.0 ;
01403 pocket->ovlp = -2.0 ;
01404 pocket->ovlp2 = -2.0 ;
01405 pocket->vol_corresp = -2.0 ;
01406
01407 pocket->nAlphaPol = 0 ;
01408 pocket->nAlphaApol = 0 ;
01409
01410 reset_desc(pocket->pdesc) ;
01411 }
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428 void print_pockets(FILE *f, c_lst_pockets *pockets)
01429 {
01430 node_pocket *cur = pockets->first ;
01431 if(pockets) {
01432 fprintf(f, "\n## FPOCKET RESULTS ##\n");
01433 cur = pockets->first;
01434 while(cur) {
01435 print_pocket(f, cur->pocket) ;
01436 cur = cur->next ;
01437 }
01438 }
01439 else {
01440 fprintf(f, "\n## NO POCKETS IN THE LIST ##\n");
01441 }
01442 }
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460 void print_pockets_inv(FILE *f, c_lst_pockets *pockets)
01461 {
01462 if(pockets) {
01463 fprintf(f, "\n## POCKET ##\n");
01464 node_pocket *cur = pockets->last ;
01465 while(cur) {
01466 print_pocket(f, cur->pocket) ;
01467 cur = cur->prev ;
01468 }
01469 }
01470 else {
01471 fprintf(f, "\n## NO POCKETS IN THE LIST ##\n");
01472 }
01473 }
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490 void print_pocket(FILE *f, s_pocket *pocket)
01491 {
01492 if(pocket) {
01493 fprintf(f, "\n## POCKET %d ##\n",pocket->v_lst->first->vertice->resid);
01494
01495 if(pocket->ovlp > -1.0) fprintf(f, "\t Correspondance: %f\n", pocket->ovlp) ;
01496 if(pocket->vol_corresp > -1.0) fprintf(f, "\t Volume Correspondance: %f\n", pocket->vol_corresp) ;
01497 fprintf(f, "\t 0 - Pocket Score: %.4f\n", pocket->score) ;
01498 fprintf(f, "\t 1 - Number of Voronoi vertices: %d\n", pocket->pdesc->nb_asph) ;
01499 fprintf(f, "\t 2 - Mean alpha-sphere radius: %f\n", pocket->pdesc->mean_asph_ray) ;
01500 fprintf(f, "\t 3 - Mean alpha-sphere solvent accessibility: %f\n", pocket->pdesc->masph_sacc) ;
01501 fprintf(f, "\t 4 - Flexibility: %f\n", pocket->pdesc->flex) ;
01502 fprintf(f, "\t 5 - Hydrophobicity Score: %f\n", pocket->pdesc->hydrophobicity_score) ;
01503 fprintf(f, "\t 6 - Polarity Score: %d\n", pocket->pdesc->polarity_score) ;
01504 fprintf(f, "\t 7 - Volume Score: %f\n", pocket->pdesc->volume_score) ;
01505 fprintf(f, "\t 8 - Real volume (approximation): %f\n", pocket->pdesc->volume) ;
01506 fprintf(f, "\t 9 - Charge Score: %d\n", pocket->pdesc->charge_score) ;
01507 fprintf(f, "\t 10 - Local hydrophobic density Score: %f\n", pocket->pdesc->mean_loc_hyd_dens) ;
01508 fprintf(f, "\t 11 - Number of apolar alpha sphere: %d\n", pocket->nAlphaApol) ;
01509 fprintf(f, "\t 12 - Amino acid composition:\n") ;
01510 int i ;
01511 fprintf(f, "\t 12 - ") ;
01512 for(i = 0 ; i < M_NB_AA ; i++) fprintf(f, "%3d ", pocket->pdesc->aa_compo[i]) ;
01513 fprintf(f, "\n") ;
01514 }
01515 }
01516