00001
00002 #include "../headers/cluster.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 void pck_final_clust(c_lst_pockets *pockets, s_fparams *params,s_pdb *pdb,s_pdb *pdb_w_lig)
00071 {
00072 node_pocket *pcur = NULL,
00073 *pnext = NULL ,
00074 *curMobilePocket = NULL ;
00075
00076 node_vertice *vcur = NULL ;
00077 node_vertice *curMobileVertice = NULL ;
00078
00079 s_vvertice *vvcur = NULL,
00080 *mvvcur = NULL ;
00081 float vcurx,
00082 vcury,
00083 vcurz ;
00084 float curdist;
00085 float curasphdens,dens1,dens2;
00086 float **dmat;
00087 size_t i,j;
00088 dmat=(float **)malloc(sizeof(float *)*pockets->n_pockets);
00089 for(i=0;i<pockets->n_pockets;i++) {
00090 dmat[i]=(float *) malloc(sizeof(float)*pockets->n_pockets);
00091 for(j=0;j<pockets->n_pockets;j++) dmat[i][j]=0.0;
00092 }
00093
00094
00095
00096 int nflag ;
00097
00098 if(!pockets) {
00099 fprintf(stderr, "! Incorrect argument during Multiple Linkage Clustering.\n") ;
00100 return ;
00101 }
00102
00103
00104 set_pockets_descriptors(pockets,pdb,params,pdb_w_lig);
00105 pcur = pockets->first ;
00106
00107 i=0;
00108 size_t n_slist=0;
00109 while(pcur) {
00110 j=i+1;
00111
00112 curMobilePocket = pcur->next ;
00113 while(curMobilePocket) {
00114 curdist=0.0;
00115
00116 nflag = 0 ;
00117
00118 vcur = pcur->pocket->v_lst->first ;
00119 while(vcur){
00120
00121 curMobileVertice = curMobilePocket->pocket->v_lst->first ;
00122 vvcur = vcur->vertice ;
00123 vcurx = vvcur->x ;
00124 vcury = vvcur->y ;
00125 vcurz = vvcur->z ;
00126
00127
00128 while(curMobileVertice){
00129 mvvcur = curMobileVertice->vertice ;
00130 if(dist(vcurx, vcury, vcurz, mvvcur->x, mvvcur->y, mvvcur->z)<params->sl_clust_max_dist) curdist-=1.0;
00131 curMobileVertice = curMobileVertice->next;
00132 }
00133 vcur = vcur->next ;
00134 }
00135
00136 pnext = curMobilePocket->next ;
00137
00138
00139
00140
00141
00142 dens1=pcur->pocket->pdesc->as_density;
00143 dens1=((isnan(dens1)) ? 0.0 : dens1);
00144
00145 dens2=curMobilePocket->pocket->pdesc->as_density;
00146 dens2=((isnan(dens2)) ? 0.0 : dens2);
00147 curasphdens=0.01*(dens1-dens2)*(dens1-dens2);
00148 curasphdens+=(exp(0.1*dens1)+exp(0.1*dens2))/2.0-1.0;
00149
00150 dmat[i][j]=curdist;
00151 dmat[j][i]=curdist;
00152 curMobilePocket = pnext ;
00153 n_slist++;
00154 j++;
00155 }
00156 pcur = pcur->next ;
00157 i++;
00158 }
00159
00160
00161
00162
00163 n_slist=((pockets->n_pockets*pockets->n_pockets)-pockets->n_pockets)/2;
00164 s_sorted_pocket_list *slist=NULL;
00165 slist=(s_sorted_pocket_list *)my_malloc(sizeof(s_sorted_pocket_list)*n_slist);
00166
00167 for(i=0;i<n_slist;i++) slist[i].dist=0.0;
00168
00169 s_sorted_pocket_list *el=my_malloc(sizeof(s_sorted_pocket_list));
00170
00171
00172
00173 int c=0;
00174 for(i=0;i<pockets->n_pockets-1;i++){
00175
00176 for(j=i+1;j<pockets->n_pockets;j++){
00177
00178 el->dist=dmat[i][j];
00179 memcpy(&(slist[c].dist),&(dmat[i][j]),sizeof(float));
00180
00181 slist[c].pid1=i;
00182 slist[c].pid2=j;
00183
00184
00185 c++;
00186 }
00187
00188 }
00189
00190
00191 qsort((void *)slist,n_slist,sizeof(s_sorted_pocket_list),comp_pocket);
00192
00193
00194
00195 i=0;
00196
00197
00198 node_pocket **pock_list=my_malloc(sizeof(node_pocket *)*pockets->n_pockets);
00199 pcur=pockets->first;
00200 i=0;
00201
00202 while(pcur) {
00203 pock_list[i]=pcur;
00204 pcur=pcur->next;
00205 i++;
00206 }
00207
00208 int idx1,idx2;
00209 node_pocket *p1,*p2;
00210 i=0;
00211 size_t init_n_pockets=pockets->n_pockets;
00212
00213 while((slist[i].dist<=-params->sl_clust_min_nneigh) && (i<n_slist)){
00214
00215
00216 idx1=slist[i].pid1;
00217 idx2=slist[i].pid2;
00218
00219
00220
00221 if(pock_list[idx1]!=pock_list[idx2]){
00222 p1=*(pock_list+idx1);
00223 p2=*(pock_list+idx2);
00224 dens1=((isnan(p1->pocket->pdesc->as_density)) ? 0.0 : p1->pocket->pdesc->as_density)/p1->pocket->pdesc->nb_asph;
00225 dens2=((isnan(p2->pocket->pdesc->as_density)) ? 0.0 : p2->pocket->pdesc->as_density)/p2->pocket->pdesc->nb_asph;
00226
00227 if(dens1 < 0.1 && dens2 < 0.1){
00228 for(j=0;j<init_n_pockets;j++){
00229 if(pock_list[j]==p2){
00230 pock_list[j]=p1;
00231
00232 }
00233 }
00234
00235 mergePockets(p1,p2,pockets);
00236 pock_list[idx2]=p1;
00237 }
00238 }
00239 i++;
00240 }
00241
00242
00243
00244
00245
00246
00247 for(i=0;i<pockets->n_pockets;i++) free(dmat[i]);
00248 free(dmat);
00249
00250 }
00251
00252
00253
00254
00255 int comp_pocket(const void *el1, const void *el2)
00256 {
00257
00258 s_sorted_pocket_list *ia = (s_sorted_pocket_list *)el1;
00259 s_sorted_pocket_list *ib = (s_sorted_pocket_list *)el2;
00260
00261
00262 if (ia->dist < ib->dist) return -1;
00263 if (ia->dist == ib->dist) return 0;
00264 if (ia->dist > ib->dist) return 1;
00265 return 0;
00266 }
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 void pck_ml_clust(c_lst_pockets *pockets, s_fparams *params)
00291 {
00292 node_pocket *pcur = NULL,
00293 *pnext = NULL ,
00294 *curMobilePocket = NULL ;
00295
00296 node_vertice *vcur = NULL ;
00297 node_vertice *curMobileVertice = NULL ;
00298
00299 s_vvertice *vvcur = NULL,
00300 *mvvcur = NULL ;
00301 float vcurx,
00302 vcury,
00303 vcurz ;
00304
00305
00306
00307 int nflag ;
00308
00309 if(!pockets) {
00310 fprintf(stderr, "! Incorrect argument during Single Linkage Clustering.\n") ;
00311 return ;
00312 }
00313
00314
00315 pcur = pockets->first ;
00316 while(pcur) {
00317
00318 curMobilePocket = pcur->next ;
00319 while(curMobilePocket) {
00320 nflag = 0 ;
00321
00322 vcur = pcur->pocket->v_lst->first ;
00323 while(vcur && nflag <= params->sl_clust_min_nneigh){
00324
00325 curMobileVertice = curMobilePocket->pocket->v_lst->first ;
00326 vvcur = vcur->vertice ;
00327 vcurx = vvcur->x ;
00328 vcury = vvcur->y ;
00329 vcurz = vvcur->z ;
00330
00331
00332 while(curMobileVertice && nflag <= params->sl_clust_min_nneigh){
00333 mvvcur = curMobileVertice->vertice ;
00334 if(dist(vcurx, vcury, vcurz, mvvcur->x, mvvcur->y, mvvcur->z)
00335 < params->sl_clust_max_dist) {
00336
00337 nflag++;
00338 }
00339 curMobileVertice = curMobileVertice->next;
00340 }
00341 vcur = vcur->next ;
00342 }
00343
00344 pnext = curMobilePocket->next ;
00345
00346 if(nflag >= params->sl_clust_min_nneigh) {
00347
00348 mergePockets(pcur,curMobilePocket,pockets);
00349 }
00350 curMobilePocket = pnext ;
00351 }
00352
00353 pcur = pcur->next ;
00354 }
00355 }
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 void pck_ml_clust_test(c_lst_pockets *pockets, s_fparams *params)
00377 {
00378 node_pocket *pcur = NULL,
00379 *pnext = NULL ,
00380 *curMobilePocket = NULL ;
00381
00382 node_vertice *vcur = NULL ;
00383 node_vertice *curMobileVertice = NULL ;
00384
00385 s_vvertice *vvcur = NULL,
00386 *mvvcur = NULL ;
00387 float vcurx,
00388 vcury,
00389 vcurz ;
00390
00391
00392
00393 int nflag,
00394 restart = 0;
00395
00396 if(!pockets) {
00397 fprintf(stderr, "! Incorrect argument during Single Linkage Clustering.\n") ;
00398 return ;
00399 }
00400 printf("ML starting\n") ;
00401
00402 pcur = pockets->first ;
00403 while(pcur) {
00404
00405 curMobilePocket = pcur->next ;
00406 while(curMobilePocket) {
00407 nflag = 0 ;
00408
00409 vcur = pcur->pocket->v_lst->first ;
00410 while(vcur && nflag <= params->sl_clust_min_nneigh){
00411
00412 curMobileVertice = curMobilePocket->pocket->v_lst->first ;
00413 vvcur = vcur->vertice ;
00414 vcurx = vvcur->x ;
00415 vcury = vvcur->y ;
00416 vcurz = vvcur->z ;
00417
00418
00419 while(curMobileVertice && nflag <= params->sl_clust_min_nneigh){
00420 mvvcur = curMobileVertice->vertice ;
00421 if(dist(vcurx, vcury, vcurz, mvvcur->x, mvvcur->y, mvvcur->z)
00422 < params->sl_clust_max_dist) {
00423
00424 nflag++;
00425 break ;
00426
00427
00428 }
00429 curMobileVertice = curMobileVertice->next;
00430 }
00431 vcur = vcur->next ;
00432 }
00433
00434 pnext = curMobilePocket->next ;
00435
00436 if(nflag >= params->sl_clust_min_nneigh) {
00437
00438 mergePockets(pcur,curMobilePocket,pockets);
00439 restart = 1 ; printf("Merging\n") ;
00440 break ;
00441 }
00442 curMobilePocket = pnext ;
00443 }
00444
00445
00446 if(restart == 1) {
00447 restart = 0 ;
00448 pcur = pockets->first ;
00449 }
00450 else pcur = pcur->next ;
00451 }
00452 printf("ML ending\n") ;
00453 }
00454
00455