00001
00002 #include "../headers/mdparams.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 s_mdparams *init_def_mdparams(void)
00077 {
00078 s_mdparams *par = (s_mdparams*) my_malloc(sizeof(s_mdparams)) ;
00079
00080 par->f_pqr = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00081 par->f_freqdx = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00082 par->f_densdx = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00083 par->f_freqiso = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00084 par->f_densiso = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00085 par->f_desc = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00086 par->f_ppdb = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00087 par->f_apdb = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char)) ;
00088 par->f_appdb = (char *)my_malloc(M_MAX_FILE_NAME_LENGTH*sizeof(char));
00089 strcpy(par->f_pqr, M_MDP_OUTPUT_FILE1_DEFAULT) ;
00090 strcpy(par->f_freqdx, M_MDP_OUTPUT_FILE2_DEFAULT) ;
00091 strcpy(par->f_freqiso, M_MDP_OUTPUT_FILE3_DEFAULT) ;
00092 strcpy(par->f_desc, M_MDP_OUTPUT_FILE4_DEFAULT) ;
00093 strcpy(par->f_ppdb, M_MDP_OUTPUT_FILE5_DEFAULT) ;
00094 strcpy(par->f_apdb, M_MDP_OUTPUT_FILE6_DEFAULT) ;
00095 strcpy(par->f_appdb, M_MDP_OUTPUT_FILE7_DEFAULT);
00096 strcpy(par->f_densdx, M_MDP_OUTPUT_FILE8_DEFAULT) ;
00097 strcpy(par->f_densiso, M_MDP_OUTPUT_FILE9_DEFAULT) ;
00098 par->fsnapshot = NULL ;
00099 par->fwantedpocket[0] = 0 ;
00100 par->nfiles = 0 ;
00101 par->flag_scoring=0;
00102 par->bfact_on_all=0;
00103
00104 return par ;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 s_mdparams* get_mdpocket_args(int nargs, char **args)
00124 {
00125 int i,
00126 status = 0,
00127 nstats = 0,
00128 npdb=0;
00129
00130 char *str_list_file = NULL ;
00131
00132 s_mdparams *par = init_def_mdparams() ;
00133 par->fpar = get_fpocket_args(nargs, args) ;
00134
00135
00136 for (i = 1; i < nargs; i++) {
00137 if (strlen(args[i]) == 2 && args[i][0] == '-') {
00138 switch (args[i][1]) {
00139 case M_MDPAR_OUTPUT_FILE :
00140 if(nstats >= 1) fprintf(stdout, "! More than one single file for the stats output file has been given. Ignoring this one.\n") ;
00141 else {
00142 if(i < nargs-1) {
00143 if(strlen(args[++i]) < M_MAX_FILE_NAME_LENGTH) {
00144 remove_ext(args[i]) ;
00145 sprintf(par->f_pqr, "%s.pqr", args[i]) ;
00146 sprintf(par->f_freqdx, "%s.dx", args[i]) ;
00147 sprintf(par->f_densdx, "%s.dx", args[i]) ;
00148 sprintf(par->f_freqiso, "%s_freq_iso_0_5.pdb", args[i]) ;
00149 sprintf(par->f_densiso, "%s_dens_iso_8.pdb", args[i]) ;
00150 sprintf(par->f_desc, "%s_descriptors.txt", args[i]) ;
00151 sprintf(par->f_ppdb, "%s_mdpocket.pdb", args[i]) ;
00152 sprintf(par->f_apdb, "%s_mdpocket_atoms.pdb", args[i]) ;
00153 sprintf(par->f_appdb, "%s_all_atom_pdensities.pdb", args[i]) ;
00154 }
00155 else fprintf(stdout, "! Output file name is too long... Keeping default.") ;
00156 }
00157 else {
00158 fprintf(stdout, "! Invalid output file name argument missing.\n") ;
00159 status += 1 ;
00160 }
00161 }
00162 break ;
00163
00164 case M_MDPAR_INPUT_FILE :
00165 if(i < nargs-1) str_list_file = args[++i] ;
00166 else {
00167 fprintf(stdout, "! Input file name argument missing.\n") ;
00168 status += 1 ;
00169 }
00170 break ;
00171 case M_MDPAR_INPUT_FILE2 :
00172 if(npdb >= 1) fprintf(stderr,
00173 "! Only first input pdb will be used.\n") ;
00174 else {
00175 strcpy(par->fwantedpocket, args[++i]) ; npdb++ ;
00176 }
00177 break ;
00178 case M_MDPAR_SCORING_MODE :
00179 par->flag_scoring=1;
00180 break;
00181 case M_MDPAR_OUTPUT_ALL_SNAPSHOTS :
00182 par->bfact_on_all=1;
00183 break;
00184 default:
00185
00186 if(!is_fpocket_opt(args[i][1])) {
00187 fprintf(stdout, "> Unknown option '%s'. Ignoring it.\n",
00188 args[i]) ;
00189 }
00190 break ;
00191 }
00192 }
00193 }
00194
00195 if(status > 0) {
00196 free_mdparams(par) ;
00197 par = NULL ;
00198 print_mdpocket_usage(stdout);
00199 }
00200 else {
00201 if(str_list_file) {
00202 int res = add_list_snapshots(str_list_file, par) ;
00203 if(res <= 0) {
00204 fprintf(stdout, "! No data has been read.\n") ;
00205 free_mdparams(par) ;
00206 par = NULL ;
00207 print_mdpocket_usage(stdout);
00208 }
00209 }
00210 else {
00211 fprintf(stdout, "! No input file given... Try again :).\n") ;
00212 free_mdparams(par) ;
00213 par = NULL ;
00214 print_mdpocket_usage(stdout);
00215 }
00216 }
00217
00218 return par;
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 int add_list_snapshots(char *str_list_file, s_mdparams *par)
00245 {
00246 FILE *f;
00247 int n,
00248 nread = 0,
00249 status ;
00250
00251 char buf[M_MAX_PDB_NAME_LEN*2 + 6],
00252 snapbuf[M_MAX_PDB_NAME_LEN];
00253
00254
00255 f = fopen(str_list_file, "r") ;
00256
00257
00258
00259 if(f) {
00260 while(fgets(buf, 210, f)) {
00261
00262
00263
00264 n = par->nfiles ;
00265 status = sscanf(buf, "%s", snapbuf) ;
00266 if(status < 1) {
00267
00268 fprintf(stderr, "! Skipping row '%s' with bad format (status %d).\n",
00269 buf, status) ;
00270 }
00271 else {
00272 nread += add_snapshot(snapbuf, par) ;
00273 }
00274
00275 }
00276 }
00277 else {
00278 fprintf(stderr, "! File %s doesn't exists\n", str_list_file) ;
00279 }
00280 fclose(f);
00281 return nread ;
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 int add_snapshot(char *snapbuf, s_mdparams *par)
00304 {
00305 int nm1 ;
00306
00307 FILE *f = fopen_pdb_check_case(snapbuf, "r") ;
00308 if(f) {
00309 nm1 = par->nfiles ;
00310 par->nfiles += 1 ;
00311
00312
00313 par->fsnapshot = (char**) my_realloc(par->fsnapshot, (par->nfiles)*sizeof(char*)) ;
00314
00315 par->fsnapshot[nm1] = (char *)my_malloc((strlen(snapbuf)+1)*sizeof(char)) ;
00316
00317 strcpy(par->fsnapshot[nm1], snapbuf) ;
00318
00319 fclose(f) ;
00320
00321 }
00322 else {
00323 fprintf(stdout, "! The pdb file '%s' doesn't exists.\n", snapbuf) ;
00324 return 0 ;
00325 }
00326
00327 return 1 ;
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 void print_mdparams(s_mdparams *p, FILE *f)
00346 {
00347
00348 if(p) {
00349 fprintf(f, "==============\nParameters of the program: \n");
00350 int i ;
00351 for(i = 0 ; i < p->nfiles ; i++) {
00352 fprintf(f, "> Snaphot %d: '%s'\n", i+1, p->fsnapshot[i]) ;
00353 }
00354 fprintf(f, "==============\n");
00355 if(p->fwantedpocket[0]!=0){
00356 fprintf(f,"Wanted pocket given in file : %s\n",p->fwantedpocket);
00357 fprintf(f, "==============\n");
00358 }
00359 }
00360 else fprintf(f, "> No parameters detected\n");
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 void print_mdpocket_usage(FILE *f)
00377 {
00378 f = (f == NULL) ? stdout:f ;
00379
00380 fprintf(f, M_MDP_USAGE) ;
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 void free_mdparams(s_mdparams *p)
00398 {
00399 if(p) {
00400
00401 if(p->fsnapshot) {
00402 my_free(p->fsnapshot);
00403 p->fsnapshot = NULL;
00404 }
00405 if(p->f_pqr) {
00406 my_free(p->f_pqr);
00407 p->f_pqr = NULL;
00408 }
00409 if(p->f_densdx) {
00410 my_free(p->f_densdx);
00411 p->f_densdx = NULL ;
00412 }
00413 if(p->f_freqdx) {
00414 my_free(p->f_freqdx);
00415 p->f_freqdx = NULL ;
00416 }
00417 if(p->f_desc) {
00418 my_free(p->f_desc);
00419 p->f_desc = NULL;
00420 }
00421 free_fparams(p->fpar);
00422 my_free(p) ;
00423 }
00424 }