00001 #include "../headers/mdpocket.h"
00002
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 void mdpocket_detect(s_mdparams *par)
00090 {
00091 int i;
00092 FILE *fout[6] ;
00093 FILE *timef;
00094 c_lst_pockets *pockets=NULL;
00095 s_mdgrid *freqgrid=NULL;
00096 s_mdgrid *refgrid=NULL;
00097 s_mdgrid *densgrid=NULL;
00098 s_pdb *cpdb=NULL;
00099 par->fpar->flag_do_asa_and_volume_calculations=0;
00100 FILE *cf;
00101 char cf_name[350] = "" ;
00102 char pdb_code[350] = "" ;
00103 if(par) {
00104
00105
00106 fout[1] = fopen(par->f_freqdx,"w") ;
00107 fout[2] = fopen(par->f_densdx,"w") ;
00108 fout[3] = fopen(par->f_freqiso,"w") ;
00109 fout[4] = fopen(par->f_densiso,"w") ;
00110 fout[5] = fopen(par->f_appdb,"w");
00111 timef=fopen("time.txt","w");
00112 if(fout[1] && fout[2] && fout[3] && fout[4] && fout[5]) {
00113
00114 clock_t b, e ;
00115
00116
00117 for(i = 0 ; i < par->nfiles ; i++) {
00118 b = clock() ;
00119 fprintf(stdout, "<mdpocket>s %d/%d - %s:",
00120 i+1, par->nfiles, par->fsnapshot[i]) ;
00121 cpdb=open_pdb_file(par->fsnapshot[i]);
00122
00123
00124 pockets=mdprocess_pdb(cpdb, par,fout[0],i+1);
00125 if(pockets){
00126 if(i==0) {
00127 freqgrid=init_md_grid(pockets);
00128 densgrid=init_md_grid(pockets);
00129 refgrid=init_md_grid(pockets);
00130 }
00131 else {
00132 reset_grid(refgrid);
00133 }
00134 calculate_md_dens_grid(densgrid,pockets,par);
00135 update_md_grid(freqgrid,refgrid,pockets,par);
00136 }
00137 free_pdb_atoms(cpdb);
00138 if(i == par->nfiles - 1) fprintf(stdout,"\n");
00139 else fprintf(stdout,"\r");
00140 fflush(stdout);
00141 c_lst_pocket_free(pockets);
00142
00143
00144 e = clock() ;
00145
00146 fprintf(timef,"%f\n",((double)e - b) / CLOCKS_PER_SEC);
00147 fflush(timef);
00148
00149
00150 }
00151 freqgrid->n_snapshots=par->nfiles;
00152 densgrid->n_snapshots=par->nfiles;
00153
00154 normalize_grid(freqgrid,par->nfiles);
00155 normalize_grid(densgrid,par->nfiles);
00156 cpdb=open_pdb_file(par->fsnapshot[0]);
00157 rpdb_read(cpdb, NULL, M_DONT_KEEP_LIG) ;
00158 project_grid_on_atoms(densgrid,cpdb);
00159 write_first_bfactor_density(fout[5],cpdb);
00160 free_pdb_atoms(cpdb);
00161 if(par->bfact_on_all){
00162 for(i = 0 ; i < par->nfiles ; i++) {
00163 strcpy(pdb_code, par->fsnapshot[i]) ;
00164 remove_ext(pdb_code) ;
00165 remove_path(pdb_code) ;
00166 sprintf(cf_name, "%s_out.pdb", pdb_code) ;
00167 cf=fopen(cf_name,"w");
00168 cpdb=open_pdb_file(par->fsnapshot[i]);
00169 rpdb_read(cpdb, NULL, M_DONT_KEEP_LIG) ;
00170 project_grid_on_atoms(densgrid,cpdb);
00171 write_first_bfactor_density(cf,cpdb);
00172 free_pdb_atoms(cpdb);
00173 fclose(cf);
00174 }
00175 }
00176
00177
00178
00179
00180
00181 write_md_grid(freqgrid, fout[1],fout[3],par,M_MDP_DEFAULT_ISO_VALUE_FREQ);
00182 write_md_grid(densgrid, fout[2],fout[4],par,M_MDP_DEFAULT_ISO_VALUE_DENS);
00183 for( i = 1 ; i < 6 ; i++ ) fclose(fout[i]) ;
00184 }
00185 else {
00186
00187
00188
00189
00190
00191 for( i = 1 ; i < 6 ; i++ ){
00192 if (! fout[i] ) {
00193 fprintf(stdout, "! Output file couldn't be opened.\n");
00194 }
00195 }
00196 }
00197 fclose(timef);
00198
00199 }
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 void mdpocket_characterize(s_mdparams *par)
00218 {
00219 int i,natms,j;
00220 FILE *null=fopen("/dev/null","w");
00221 FILE *descfile=NULL;
00222 FILE *fout[2] ;
00223 int *wanted_atom_ids = NULL;
00224 int nwanted_atom_ids = 0;
00225 c_lst_pockets *pockets=NULL;
00226 c_lst_pockets *mdpockets=c_lst_pockets_alloc();
00227 s_pocket *cpocket=NULL;
00228 s_pdb *wantedpocket = rpdb_open(par->fwantedpocket, NULL, M_DONT_KEEP_LIG);
00229 rpdb_read(wantedpocket, NULL, M_DONT_KEEP_LIG) ;
00230 s_pdb *cpdb=NULL;
00231
00232 if(par) {
00233 descfile=fopen(par->f_desc,"w");
00234 fout[0]=fopen(par->f_ppdb,"w");
00235 fout[1]=fopen(par->f_apdb,"w");
00236
00237 fprintf(descfile,M_MDP_OUTP_HEADER);
00238 for( j = 0 ; j < 20 ; j++ ) fprintf(descfile, " %s", get_aa_name3(j));
00239 fprintf(descfile, "\n");
00240
00241
00242 for(i = 0 ; i < par->nfiles ; i++) {
00243 fprintf(stdout, "<mdpocket>s %d/%d - %s:",
00244 i+1, par->nfiles, par->fsnapshot[i]) ;
00245 fflush(stdout);
00246 fprintf(fout[0],"MODEL %d\n",i);
00247 cpdb=open_pdb_file(par->fsnapshot[i]);
00248 pockets=mdprocess_pdb(cpdb, par,null,i+1);
00249 if(i==0)wanted_atom_ids=get_wanted_atom_ids(cpdb,wantedpocket,&nwanted_atom_ids);
00250 write_md_pocket_atoms(fout[1],wanted_atom_ids,cpdb,nwanted_atom_ids, i);
00251 if(pockets){
00252 cpocket=extract_wanted_vertices(pockets,wantedpocket);
00253 c_lst_pockets_add_last(mdpockets,cpocket,0,0);
00254
00255
00256 s_vvertice **tab_vert = (s_vvertice **)
00257 my_malloc(cpocket->v_lst->n_vertices*sizeof(s_vvertice*)) ;
00258 j = 0 ;
00259 node_vertice *nvcur = cpocket->v_lst->first ;
00260 while(nvcur) {
00261 write_pqr_vert(fout[0], nvcur->vertice) ;
00262
00263 tab_vert[j] = nvcur->vertice ;
00264 nvcur = nvcur->next ;
00265 j++ ;
00266 }
00267
00268
00269 s_atm **pocket_atoms = get_pocket_contacted_atms(cpocket, &natms) ;
00270
00271
00272 set_descriptors(pocket_atoms, natms, tab_vert,cpocket->v_lst->n_vertices, cpocket->pdesc,par->fpar->nb_mcv_iter,cpdb,par->fpar->flag_do_asa_and_volume_calculations) ;
00273 write_md_descriptors(descfile,cpocket,i+1);
00274
00275 my_free(pocket_atoms) ;
00276 my_free(tab_vert) ;
00277
00278 }
00279 free_pdb_atoms(cpdb);
00280
00281
00282 if(i == par->nfiles - 1) fprintf(stdout,"\n") ;
00283 else fprintf(stdout,"\r") ;
00284 fflush(stdout);
00285 fprintf(fout[0],"ENDMDL\n\n");
00286 c_lst_pocket_free(pockets);
00287 }
00288
00289 fclose(descfile);
00290
00291 for( i = 0 ; i < 2 ; i++ ) fclose(fout[i]) ;
00292 }
00293 fclose(wantedpocket->fpdb);
00294 fclose(null);
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 void write_md_descriptors(FILE *f, s_pocket *p, int i){
00314 s_desc *d=p->pdesc;
00315 fprintf(f, M_MDP_OUTP_FORMAT, M_MDP_OUTP_VAR(i, d)) ;
00316 int j ;
00317 for(j = 0 ; j < 20 ; j++) fprintf(f, " %3d", d->aa_compo[j]) ;
00318
00319 fprintf(f, "\n") ;
00320 }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 s_pocket* extract_wanted_vertices(c_lst_pockets *pockets,s_pdb *pdb){
00340 s_pocket *p=alloc_pocket();
00341 p->v_lst=c_lst_vertices_alloc();
00342 s_pocket *cp=NULL;
00343 node_pocket *cur = NULL ;
00344 cur = pockets->first ;
00345 s_vvertice** pverts=NULL;
00346 size_t i;
00347 int z;
00348 s_atm *cura=NULL;
00349 while(cur) {
00350 cp=cur->pocket;
00351 pverts=get_pocket_pvertices(cp);
00352 for(i=0;i<cp->v_lst->n_vertices;i++){
00353 for(z=0;z<pdb->natoms;z++){
00354 cura=pdb->latoms_p[z];
00355 if(dist(cura->x,cura->y,cura->z,pverts[i]->x,pverts[i]->y,pverts[i]->z)<=(float)M_MDP_CUBE_SIDE/2.0){
00356 c_lst_vertices_add_last(p->v_lst, pverts[i]);
00357 }
00358 }
00359 }
00360 cur=cur->next;
00361 }
00362 return(p);
00363 }
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 int *get_wanted_atom_ids(s_pdb *prot,s_pdb *pocket, int *n){
00387 int *ids=(int *)my_malloc(sizeof(int));
00388 int v,a;
00389 *n=1;
00390 s_atm *cura=NULL;
00391 s_atm *curv=NULL;
00392 int flag=0;
00393 for(a=0;a<prot->natoms;a++){
00394 cura=prot->latoms_p[a];
00395 v=0;
00396 flag=0;
00397 while(flag==0 && v<pocket->natoms){
00398 curv=pocket->latoms_p[v];
00399 if(dist(cura->x,cura->y,cura->z,curv->x,curv->y,curv->z)<=M_MDP_WP_ATOM_DIST){
00400 ids[*n-1]=cura->id;
00401 *n=*n+1;
00402 ids=(int *)my_realloc(ids,sizeof(int)*(*n));
00403 flag=1;
00404 }
00405 v++;
00406 }
00407 }
00408 return(ids);
00409
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 s_pdb *open_pdb_file(char *pdbname){
00427 if(pdbname == NULL) return NULL;
00428
00429 int len = strlen(pdbname) ;
00430 if(len >= M_MAX_PDB_NAME_LEN || len <= 0) {
00431 fprintf(stderr, "! Invalid length for the pdb file name. (Max: %d, Min 1)\n",
00432 M_MAX_PDB_NAME_LEN) ;
00433 return NULL;
00434 }
00435
00436
00437 s_pdb *pdb = rpdb_open(pdbname, NULL, M_DONT_KEEP_LIG) ;
00438 if(pdb) return(pdb);
00439 return NULL;
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 c_lst_pockets* mdprocess_pdb(s_pdb *pdb, s_mdparams *mdparams,FILE *pqrout, int snnumber)
00461 {
00462 c_lst_pockets *pockets=NULL;
00463 s_fparams *params=mdparams->fpar;
00464
00465
00466 if(pdb) {
00467
00468 rpdb_read(pdb, NULL, M_DONT_KEEP_LIG) ;
00469
00470 pockets = search_pocket(pdb, params,NULL);
00471
00472 }
00473 else fprintf(stderr, "! PDB reading failed on snapshot %d\n",snnumber);
00474 return pockets;
00475 }
00476
00477