00001
00002
00003
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 #include <string.h>
00007 #include <ctype.h>
00008 #include "open_prospect.h"
00009
00010
00011
00012
00013 #ifdef INT_THREADING
00014
00015 #include "src/intpro_threading/intpro_threading.h"
00016 #endif
00017
00018 #ifdef DIVCON_THREADING
00019 #include "src/divcon_threading/divcon_threading.h"
00020 #endif
00021
00022
00023
00024 #include "src/dynamic_threading/dynamic_threading.h"
00025 #ifdef TREEDECOMP_THREADING
00026 #include "src/treedecomp_threading/treedecomp_threading.h"
00027 #endif
00028
00029
00030
00031
00032
00033
00034
00035
00036 typedef struct {
00037 threading_function threading;
00038 ThreaderDesc *desc;
00039 char name[30];
00040 } threading_procedure_structure;
00041
00042
00043 threading_procedure_structure threaders[] = {
00044 #ifdef INT_THREADING
00045 #ifdef USE_COIN
00046 {intpro_thread, &intpro_thread_desc, "integer"},
00047 {intpro_thread_div, &intpro_thread_div_desc, "integer_div"},
00048 {intpro_thread_sift, &intpro_thread_sift_desc, "integer_sift"},
00049 {intpro_thread_coredel, &intpro_thread_coredel_desc, "integer_coredel"},
00050 #endif
00051 #ifdef USE_GTMIP
00052 {intpro_thread_gtmip, &intpro_thread_gtmip_desc, "integer_gtmip"},
00053 #endif
00054 #endif
00055 #ifdef DIVCON_THREADING
00056 {divcon_thread, &divcon_thread_desc, "divcon"},
00057 #endif
00058 #ifdef TREEDECOMP_THREADING
00059 {treedecomp_thread, &treedecomp_thread_desc, "treedecomp"},
00060 #endif
00061 {dynamic_thread, &dynamic_thread_desc, "dynamic"}
00062 };
00063
00064
00065 threading_function ProspectParam::ThreaderFind(char *request_name) {
00066 for (unsigned int i = 0; i < sizeof(threaders)/sizeof(threaders[0]); i++) {
00067 if ( !strcmp(threaders[i].name, request_name) ) {
00068 return threaders[i].threading;
00069 }
00070 }
00071 return NULL;
00072 }
00073
00074
00075
00076
00077 int ProspectParam::Weight_Find(char *request_name, WeightArray weight) {
00078
00079 char conf_path[2000], buffer[3000];
00080 sprintf(conf_path, "%s/%s", ProspectPath, WEIGHT_CONF_FILE);
00081
00082 FILE *file = fopen( conf_path, "r" );
00083 if (file == NULL)
00084 return 1;
00085
00086 while ( fgets( buffer, sizeof(buffer), file) ) {
00087 char *ptr = strtok( buffer, " :\t\n\r" );
00088 if ( !strcmp( request_name, ptr ) ) {
00089 for (int i = 0; i < e_count; i++)
00090 weight[i] = 0.0;
00091 while ( NULL != (ptr = strtok( NULL, " :\t\n\r" ) ) ) {
00092 if ( !strncmp( ptr, "-w", 2 ) ) {
00093 int cur_e = -1;
00094 for (int i = 0; i < e_count; i++) {
00095 if (!strcmp( &(ptr[2]), e_names[i]) ) {
00096 cur_e = i;
00097 }
00098 }
00099 if (cur_e != -1 && NULL != (ptr = strtok( NULL, " :\t\n\r" ) ) ) {
00100 weight[ cur_e ] = atof( ptr );
00101 }
00102 }
00103 }
00104 return 0;
00105 }
00106 }
00107 return 1;
00108 }
00109
00110
00111 PopsParam::PopsParam(ProspectParam *in_parent) : ParamElement( in_parent ) {}
00112
00113
00114 int PopsParam::LoadParam(char *path) {
00115 FILE *file = fopen(path, "r");
00116 if ( file == NULL ) {
00117 return 1;
00118 }
00119 char buffer[2000];
00120 fgets( buffer, sizeof(buffer), file);
00121 sscanf( buffer, "%d %f %f %f %f", ¶m_count, &b_ij, &p_j, &p_14, &p_gt14);
00122
00123 if (param_count < 0 || param_count > 1000) {
00124 param_count = 0;
00125 return 1;
00126 }
00127 params = (PopsParamsElement *)malloc(sizeof(PopsParamsElement) * param_count);
00128 for ( int i = 0; i < param_count; i++) {
00129 fgets( buffer, sizeof(buffer), file);
00130 char atom[2000], atom_name[2000], residue[2000];
00131 float radius, p_i;
00132 sscanf( buffer, "%s %s %s %f %f ", atom, atom_name, residue, &radius, &p_i );
00133
00134 params[i].radius = radius;
00135 params[i].p_i = p_i;
00136 params[i].atom_num = PDBAtomtoNum( atom_name );
00137 params[i].rs_num = AA1toAANum( AA3toAA1( residue ) );
00138 }
00139 fclose(file);
00140 return 0;
00141 }
00142
00143
00144 int ProspectParam::InitPops(void) {
00145 char buffer[3000];
00146
00147 sprintf(buffer, "%s/%s", ProspectPath , "POPS-R-DNA.dat" );
00148 pops_r_param = new PopsParam( this );
00149 pops_r_param->LoadParam( buffer );
00150 pops_param = new PopsParam( this );
00151 sprintf(buffer, "%s/%s", ProspectPath , "POPS-A-DNA.dat" );
00152 pops_param->LoadParam( buffer );
00153
00154 return 0;
00155 }
00156
00157
00158 PopsParam* ProspectParam::GetPopsParam(void) {
00159 if ( pops_param == NULL )
00160 InitPops();
00161 return pops_param;
00162 }
00163
00164 PopsParam* ProspectParam::GetPopsRParam(void) {
00165 if ( pops_param == NULL )
00166 InitPops();
00167 return pops_r_param;
00168 }
00169
00170
00171 ProspectParam::~ProspectParam() {
00172
00173
00174 }
00175
00176
00177
00178 ProspectParam::ProspectParam(char *base_path) {
00179
00180 ProspectPath = NULL;
00181 residue_info = NULL;
00182 rotamer_array = NULL;
00183 atom_data = NULL;
00184 atom_data_count = 0;
00185 pops_param = NULL;
00186 pops_r_param = NULL;
00187
00188
00189 char search_paths[4][4000] = {
00190 PROSPECT_DATADIR,
00191 "/usr/local/share/prospect",
00192 "/usr/share/prospect/",
00193 "/opt/share/prospect/"
00194 };
00195
00196 if (base_path != NULL) {
00197 ProspectPath = strdup( base_path );
00198 } else {
00199 char *ptr = (char* ) getenv("PROSPECTPATH");
00200 if (ptr != NULL) {
00201 ProspectPath = strdup(ptr);
00202 } else {
00203 for (int i = 0; i < 4 && ProspectPath == NULL; i++) {
00204 char buffer[5000];
00205 sprintf(buffer, "%s/%s", search_paths[i], SINGLETON_FILE );
00206 FILE *tmpfile = fopen( buffer, "r" );
00207 if ( tmpfile ) {
00208 fclose(tmpfile);
00209 ProspectPath = strdup( search_paths[i] );
00210 }
00211 }
00212 }
00213 }
00214 template_paths = Template_Paths();
00215 Init();
00216 }
00217
00218
00219 void ProspectParam::CopyGonnetMatrix( class TemplateStruct *template_data ) {
00220 template_data->CopyScoreTable( GONNET_MATRIX );
00221 }
00222
00223
00224
00225 char * ProspectParam::TemplateFind(char *template_name) {
00226 long i = 0;
00227 FILE *file_test = NULL;
00228 char file_path[2000];
00229
00230 while ( template_paths[i] && file_test == NULL) {
00231
00232 sprintf(file_path,"%s/%s.xml", template_paths[i], template_name);
00233
00234 file_test = fopen( file_path, "r" );
00235 i++;
00236 }
00237
00238 if (file_test == NULL) {
00239 return NULL;
00240 }
00241 fclose(file_test);
00242 return strdup(file_path);
00243 }
00244
00245
00246
00247
00248 char ** ProspectParam::Template_Paths(void) {
00249 FILE *fin;
00250 char str[1024];
00251 char outstr[1024], tmp[1024], found;
00252 char **out_strings, *curptr, *ptr, *ptr2;
00253 short path_count = 0;
00254
00255 sprintf(str, "%s/template_paths", ProspectPath);
00256 fin = fopen(str, "r");
00257
00258 path_count = 0;
00259
00260
00261
00262 if (getenv("TEMPLATE_PATH")) {
00263 ptr = strdup(getenv("TEMPLATE_PATH"));
00264 curptr = strtok(ptr, ":");
00265 while(curptr) {
00266 path_count++;
00267 curptr = strtok(NULL, ":");
00268 }
00269 free(ptr);
00270 }
00271
00272
00273 while ( fgets(str, sizeof(str), fin)) {
00274 found = 0;
00275 for (unsigned int i = 0; i < strlen(str); i++) {
00276 if (isalnum(str[i]))
00277 found = 1;
00278 }
00279 if (found)
00280 path_count++;
00281 }
00282
00283 out_strings = (char **)malloc(sizeof(char *) * (path_count+1) );
00284
00285 rewind(fin);
00286 path_count = 0;
00287
00288 if (getenv("TEMPLATE_PATH")) {
00289 ptr = strdup(getenv("TEMPLATE_PATH"));
00290 curptr = strtok(ptr, ":");
00291 while(curptr) {
00292 out_strings[path_count++] = strdup(curptr);
00293 curptr = strtok(NULL, ":");
00294 }
00295 free(ptr);
00296 }
00297
00298 while ( fgets(str, sizeof(str), fin)) {
00299 found = 0;
00300 for (unsigned int i = 0; i < strlen(str); i++) {
00301 if (isalnum(str[i]))
00302 found = 1;
00303 }
00304 if (found) {
00305 for (unsigned int i = 0; i < strlen(str); i++) {
00306 if (str[i] == '\n' || str[i] == '\r') {
00307 str[i] = 0;
00308 }
00309 }
00310
00311 memset(outstr, 0, sizeof(outstr));
00312 curptr = str;
00313 while ( *curptr != 0 && (ptr = strstr( curptr, "$(")) ) {
00314 strncat(outstr, curptr, ptr-curptr);
00315 ptr += 2;
00316 ptr2 = ptr;
00317 if ( (ptr2 = strstr( ptr, ")")) ) {
00318 memset(tmp, 0, sizeof(tmp));
00319 strncpy(tmp, ptr, ptr2 - ptr);
00320 if (getenv( tmp )) {
00321 strcat(outstr, getenv(tmp));
00322 }
00323 ptr2++;
00324 }
00325 curptr = ptr2;
00326 }
00327 strcat(outstr, curptr);
00328 out_strings[path_count++] = strdup( outstr );
00329 }
00330 }
00331 out_strings[path_count++] = NULL;
00332 fclose(fin);
00333
00334 return out_strings;
00335 }
00336
00337
00338
00339
00340
00341
00342
00343
00344 #define kwAminoAcid "AMINOACID"
00345 #define kwTorsionAngle "TORSIONANGLE"
00346 #define kwTorsion "TORSION"
00347 #define kwATOM "ATOM"
00348
00349
00350 ResidueInfoElement * Prospect_ResidueInfo_LoadFile(ProspectParam *param, char *path) {
00351 FILE *input;
00352 ResidueInfoElement *residues;
00353 char buffer[4048], buffer2[4048], tmp[100], res_name[25], atom_name[25], atom_type[25],
00354 res_char;
00355 int atom_count, res_num;
00356 float atom_loc[3];
00357 char *cur_ptr;
00358
00359 input = fopen(path, "r");
00360 if ( input == NULL)
00361 return NULL;
00362
00363 residues = (ResidueInfoElement *)malloc(sizeof(ResidueInfoElement) * 20);
00364
00365 for (int i = 0; i < 20; i++) {
00366 residues[ i ].structure.atom_count = 0;
00367 residues[ i ].torsion_count = 0;
00368 residues[ i ].torsion_a = 0;
00369 residues[ i ].torsion_b = 0;
00370 }
00371
00372 while (fgets(buffer, sizeof(buffer), input)) {
00373 if ( !strncmp(buffer, kwAminoAcid, strlen(kwAminoAcid)) ) {
00374 sscanf(buffer, "%s %s %c %d", tmp,
00375 res_name, &res_char, &atom_count);
00376 res_num = AA1toAANum( res_char );
00377 if (res_num >= 0 && res_num < 20) {
00378 residues[ res_num ].RS = res_char;
00379 residues[ res_num ].structure.atom_count = 0;
00380 } else {
00381
00382 }
00383 } else if ( !strncmp(buffer, kwATOM, strlen(kwATOM)) ) {
00384 if (res_num >= 0 && res_num < 20) {
00385 sscanf(buffer, "%s %s %s %f %f %f",
00386 tmp, atom_name, atom_type,
00387 &atom_loc[0], &atom_loc[1], &atom_loc[2] );
00388 int atom_namenum = PDBAtomtoNum( atom_name );
00389 if ( atom_namenum != -1) {
00390 residues[res_num].structure.atom[ residues[res_num].structure.atom_count ][0] = atom_loc[0];
00391 residues[res_num].structure.atom[ residues[res_num].structure.atom_count ][1] = atom_loc[1];
00392 residues[res_num].structure.atom[ residues[res_num].structure.atom_count ][2] = atom_loc[2];
00393 residues[res_num].structure.atom_name[ residues[res_num].structure.atom_count ] = atom_namenum;
00394
00395
00396
00397
00398
00399
00400
00401 residues[res_num].structure.radius[residues[res_num].structure.atom_count] = param->atom_data->FindRadius( atom_namenum );
00402 if ( atom_namenum == anN || atom_namenum == anCa ||
00403 atom_namenum == anC || atom_namenum == anO ) {
00404 residues[res_num].structure.bb_num[ atom_namenum ] = residues[res_num].structure.atom_count;
00405 }
00406 residues[res_num].structure.atom_count++;
00407 }
00408 assert( residues[ res_num ].structure.atom_count < kMaxResAtoms );
00409 }
00410 } else if ( !strncmp(buffer, kwTorsionAngle, strlen(kwTorsionAngle)) ) {
00411 if (res_num >= 0 && res_num < 20) {
00412 sscanf(buffer, "%s %d:", tmp, &residues[ res_num ].torsion_count);
00413 if ( residues[ res_num ].torsion_count > 0 ) {
00414 residues[ res_num ].torsion_val = (pValType *)malloc(sizeof(pValType) * residues[ res_num ].torsion_count);
00415 residues[ res_num ].torsion_a = (char *)malloc(sizeof(char) * residues[ res_num ].torsion_count);
00416 residues[ res_num ].torsion_b = (char *)malloc(sizeof(char) * residues[ res_num ].torsion_count);
00417
00418 strcpy(buffer2, buffer);
00419 cur_ptr = strtok( buffer2, " \t\n");
00420 cur_ptr = strtok( NULL, " \t\n:");
00421 cur_ptr = strtok( NULL, " \t\n");
00422 for (int i = 0; i < residues[ res_num ].torsion_count && cur_ptr; i++) {
00423 residues[ res_num ].torsion_val[i] = atof(cur_ptr);
00424 cur_ptr = strtok( NULL, " \t\n");
00425 }
00426 residues[ res_num ].torsion_mask = (char **)malloc(sizeof(char *) * residues[ res_num ].torsion_count);
00427 residues[ res_num ].torsion_mask[0] = (char *)malloc(sizeof(char) * residues[ res_num ].torsion_count * residues[ res_num ].structure.atom_count);
00428 for (int i = 0; i < residues[ res_num ].torsion_count; i++) {
00429 residues[ res_num ].torsion_mask[i] = residues[ res_num ].torsion_mask[0] + i * residues[ res_num ].structure.atom_count;
00430 }
00431 memset( residues[ res_num ].torsion_mask[0], 0, residues[ res_num ].torsion_count * residues[ res_num ].structure.atom_count );
00432 } else {
00433 residues[ res_num ].torsion_val = NULL;
00434 residues[ res_num ].torsion_a = NULL;
00435 residues[ res_num ].torsion_b = NULL;
00436 residues[ res_num ].torsion_mask = NULL;
00437 }
00438 }
00439 } else if ( !strncmp(buffer, kwTorsion, strlen(kwTorsion)) ) {
00440 if (res_num >= 0 && res_num < 20) {
00441 int atom_count, torsion_num;
00442 sscanf(buffer, "%s %d: %d", tmp, &torsion_num, &atom_count );
00443 if ( torsion_num < residues[ res_num ].torsion_count ) {
00444 strcpy(buffer2, buffer);
00445 cur_ptr = strtok( buffer2, " \t\n\r");
00446 cur_ptr = strtok( NULL, " \t\n\r:");
00447 cur_ptr = strtok( NULL, " \t\n\r");
00448 cur_ptr = strtok( NULL, " \t\n\r");
00449 for (int i = 0; i < atom_count && cur_ptr; i++) {
00450 for (int j = 0; j < residues[ res_num ].structure.atom_count; j++) {
00451 if ( residues[ res_num ].structure.atom_name[j] == PDBAtomtoNum( cur_ptr ) ) {
00452 if (i == 0) {
00453 residues[res_num].torsion_a[ torsion_num ] = j;
00454 } else if (i == 1) {
00455 residues[res_num].torsion_b[ torsion_num ] = j;
00456 } else {
00457 residues[ res_num ].torsion_mask[ torsion_num ][j] = 1;
00458 }
00459 }
00460 }
00461 cur_ptr = strtok( NULL, " \t\n\r");
00462 }
00463 } else {
00464 fprintf(stderr, "format error in rotamer.lib: %s\n", buffer);
00465 }
00466 }
00467 }
00468 }
00469 fclose(input);
00470 return residues;
00471 }
00472
00473
00474
00475 RotamerArray * Prospect_RotamerArray_LoadBbind(char *path) {
00476 FILE *input;
00477 char buffer[4000], res_type[100], res_char, res_num, *cur_ptr;
00478 RotamerArray *rotamer_array;
00479 int cur_rotamer[20], r[4];
00480
00481 input = fopen(path, "r");
00482 if (input == NULL)
00483 return NULL;
00484
00485 rotamer_array = (RotamerArray *)malloc(sizeof(RotamerArray) * 20);
00486 for (int i = 0; i < 20; i++) {
00487 rotamer_array[i].rotamer_count = 0;
00488 rotamer_array[i].psi_bin = 720;
00489 rotamer_array[i].phi_bin = 720;
00490 }
00491 while (fgets( buffer, sizeof(buffer), input)) {
00492 if ( 5 == sscanf(buffer, "%s %d %d %d %d", res_type, &r[0], &r[1], &r[2], &r[3]) ) {
00493 res_char = AA3toAA1( res_type );
00494 res_num = AA1toAANum( res_char );
00495
00496
00497
00498
00499
00500
00501
00502
00503 rotamer_array[ res_num ].rotamer_count++;
00504 rotamer_array[ res_num ].RS = res_char;
00505 }
00506 }
00507 fseek(input, 0, SEEK_SET);
00508
00509 for (int i = 0; i < 20; i++) {
00510 if ( rotamer_array[i].rotamer_count > 0 )
00511 rotamer_array[i].rotamer = (RotamerElement *)malloc(sizeof(RotamerElement) * rotamer_array[i].rotamer_count );
00512 else
00513 rotamer_array[i].rotamer = NULL;
00514 cur_rotamer[i] = 0;
00515 }
00516
00517 while (fgets( buffer, sizeof(buffer), input)) {
00518 if ( 5 == sscanf(buffer, "%s %d %d %d %d", res_type, &r[0], &r[1], &r[2], &r[3]) ) {
00519 res_char = AA3toAA1( res_type );
00520 res_num = AA1toAANum( res_char );
00521 cur_ptr = strtok(buffer, " \t\n");
00522 for (int i = 0; i < 9; i++) {
00523 cur_ptr = strtok(NULL, " \t\n");
00524 }
00525 rotamer_array[(int)res_num].rotamer[ cur_rotamer[ (int)res_num ] ].prob = atof( cur_ptr );
00526 cur_ptr = strtok(NULL, " \t\n");
00527 cur_ptr = strtok(NULL, " \t\n");
00528
00529 for (int i = 0; cur_ptr != NULL && i < 4; i++) {
00530 rotamer_array[(int)res_num].rotamer[ cur_rotamer[(int)res_num ] ].chi[i] = atof(cur_ptr);
00531 cur_ptr = strtok(NULL, " \t\n");
00532 cur_ptr = strtok(NULL, " \t\n");
00533 }
00534 cur_rotamer[ (int)res_num ]++;
00535 }
00536 }
00537 fclose(input);
00538 return rotamer_array;
00539 }
00540
00541
00542
00543
00544
00545
00546 int ProspectParam::InitRotamer(void) {
00547 char buffer[4000];
00548
00549 atom_data = new AtomData( this );
00550
00551 sprintf(buffer, "%s/%s", ProspectPath, RESIDUELIB_FILE);
00552 residue_info = Prospect_ResidueInfo_LoadFile(this, buffer);
00553 if (residue_info == NULL)
00554 return 1;
00555 sprintf(buffer, "%s/%s", ProspectPath, BBIND_FILE);
00556 rotamer_array = Prospect_RotamerArray_LoadBbind(buffer);
00557 if (rotamer_array == NULL)
00558 return 1;
00559
00560 return 0;
00561 }
00562
00563 AtomData::AtomData(ProspectParam *in_parent) : ParamElement(in_parent) {
00564 char buffer[4000];
00565
00566 sprintf(buffer, "%s/%s", parent->ProspectPath, ATOMDATA_FILE);
00567
00568 atom_data_count = 0;
00569 FILE *atom_file = fopen(buffer, "r");
00570 if (!atom_file)
00571 return;
00572 char tmp[100];
00573 float tmp_float;
00574 while (fgets(buffer, sizeof(buffer), atom_file)) {
00575 if ( 2 == sscanf(buffer, "%s %f", tmp, &tmp_float)) {
00576 atom_data_count++;
00577 }
00578 }
00579 fseek(atom_file, 0, SEEK_SET);
00580 atoms = (AtomDataElement *)malloc(sizeof(AtomDataElement) * atom_data_count);
00581 int i = 0;
00582 while (fgets(buffer, sizeof(buffer), atom_file)) {
00583 if ( 2 == sscanf(buffer, "%s %f", tmp, &tmp_float)) {
00584 strncpy(atoms[i].name, tmp, 4);
00585 atoms[i].radius = tmp_float;
00586 i++;
00587 }
00588 }
00589 fclose(atom_file);
00590 }
00591
00592
00593 float AtomData::FindRadius( char *name ) {
00594 return FindRadius( PDBAtomtoNum( name ) );
00595 }
00596
00597 float AtomData::FindRadius( int name_num ) {
00598 for (int i = 0; i < atom_data_count; i++) {
00599 if ( name_num == PDBAtomtoNum( atoms[i].name) ) {
00600 return atoms[i].radius;
00601 }
00602 }
00603 return -1;
00604 }
00605
00606
00607
00608
00609
00610 float * get_float_file(char *path, long *count) {
00611 FILE *file;
00612 long i;
00613 float temp, *returnval;
00614 char templine[300];
00615
00616 file = fopen(path, "r");
00617 if (file == NULL) {
00618 fprintf(stderr, "Unable to open: %s\n", path);
00619 return NULL;
00620 }
00621 *count = 0;
00622 while ( fgets( templine, sizeof(templine), file) ){
00623 if (strlen(templine) != 0) {
00624 if ( sscanf(templine, "%f", &temp) ) {
00625 (*count)++;
00626 }
00627 }
00628 }
00629 returnval = (float *)malloc(sizeof(float) * (*count) );
00630 fseek(file, 0, SEEK_SET);
00631 i = 0;
00632 while ( fgets( templine, sizeof(templine), file) ){
00633 if (strlen(templine) != 0) {
00634 if ( sscanf(templine, "%f", &temp) ) {
00635 returnval[i] = temp;
00636 i++;
00637 }
00638 }
00639 }
00640 fclose(file);
00641 return returnval;
00642 }
00643
00644
00645
00646 int ProspectParam::Init(void) {
00647 pValType val1, val2;
00648 int i,j, k;
00649 char command[2048];
00650 char dummy[1024], tmp1[1024], tmp2[1024];
00651 char dummyc, *ptr;
00652
00653 second_guess = 0;
00654 filter = 0;
00655 no_loop = 0;
00656 v_level = 0;
00657 max_bytes = -1;
00658 output_timeinfo = 0;
00659 output_weights = 0;
00660 output_pdb = 0;
00661 output_backbone = 0;
00662 output_template_loc = 1;
00663 no_loop = 0;
00664 z_cycles = 1000;
00665 simple_twobody = 0;
00666 rotamer_array = NULL;
00667 residue_info = NULL;
00668 atom_data = NULL;
00669 atom_data_count = 0;
00670 ncpus = 1;
00671 full_twobody = false;
00673
00675
00676 FILE *file_in;
00677 sprintf(command,"%s/%s",ProspectPath, SINGLETON_FILE);
00678 file_in = fopen(command, "r");
00679 if (file_in == NULL) {
00680
00681
00682 return 1;
00683 }
00684 char residue[200];
00685
00686 for (i = 0; i < 21; i++) {
00687 for (j = 0; j < 9; j++) {
00688 SINGLETON[i][j] = 0;
00689 }
00690 }
00691
00692 for (i=0; i < 20;i++) {
00693 fscanf(file_in,"%s",residue);
00694 for (j=0; j < 9;j++) {
00695
00696 fscanf(file_in,"%f",&SINGLETON[i][j]);
00697
00698 }
00699 }
00700 fclose(file_in);
00701
00703
00705
00706 sprintf(command,"%s/%s",ProspectPath,PAIRWISE_FILE);
00707 file_in = fopen(command, "r");
00708 if (file_in == NULL) {
00709
00710
00711 return 1;
00712 }
00713
00714 PAIR_POT = (pValType **)malloc(sizeof(pValType *) * 21);
00715 #ifdef ALTIVEC
00716 PAIR_POT[0] = (pValType *)valloc(sizeof(pValType) * 21*21);
00717 #else
00718 PAIR_POT[0] = (pValType *)malloc(sizeof(pValType) * 21*21);
00719 #endif
00720
00721 for (i = 0; i < 21; i++) {
00722 PAIR_POT[i] = PAIR_POT[0] + i*21;
00723 for (j = 0; j < 21; j++)
00724 PAIR_POT[i][j] = 0;
00725 }
00726
00727 for (i=0; i < 20; i++) {
00728 fscanf(file_in,"%s",residue);
00729 for (j=0; j <= i; j++) {
00730 float tmp_float;
00731 fscanf(file_in, "%f", &tmp_float);
00732 PAIR_POT[j][i]=PAIR_POT[i][j]=tmp_float;
00733 }
00734 }
00735 fclose(file_in);
00736
00737
00739
00741 for (int i=0; i < 21; i++) {
00742 for (int j = 0; j < MaxContactCount; j++) {
00743 CONTACT_MATRIX[i][j] = 3200;
00744 }
00745 }
00746 sprintf(command,"%s/%s",ProspectPath,CONTACT_FILE);
00747 file_in = fopen(command, "r");
00748 for (int i=0; i < 20; i++) {
00749 char buffer[2000];
00750 fgets(buffer, sizeof(buffer), file_in);
00751 char *str = strtok( buffer, "\t \n" );
00752 int j = 0;
00753 while ( (str = strtok( NULL, "\t \n" )) ) {
00754 CONTACT_MATRIX[i][j] = atof( str );
00755 j++;
00756 }
00757 }
00758 fclose(file_in);
00759
00761
00763
00764 for (i=0; i < 21; i++) {
00765 for (j = 0; j < 21; j++) {
00766 ALIGN_MATRIX[i][j] = 0;
00767 }
00768 }
00769
00770 sprintf(command,"%s/%s",ProspectPath,ALIGNMENT_FILE);
00771 file_in = fopen(command, "r");
00772 if (file_in == NULL) {
00773
00774
00775 return 1;
00776 }
00777 fgets(dummy,2000,file_in);
00778 for (i=0;i<20;i++) {
00779 dummyc=fgetc(file_in);
00780 for (j=0;j<20;j++) {
00781 ALIGN_MATRIX[i][j]=fgetc(file_in);
00782 }
00783 fgets(dummy,2000,file_in);
00784 }
00785 fclose(file_in);
00786
00787
00789
00791 sprintf(command, "%s/%s", ProspectPath, GONNETMATRIX_FILE);
00792 file_in = fopen(command, "r");
00793
00794 for (i = 0; i < 21; i++) {
00795 for (j = 0; j < 21; j++) {
00796 GONNET_MATRIX[i][j] = 0;
00797 }
00798 }
00799
00800 while (fgets(dummy, sizeof(dummy), file_in)) {
00801 ptr = strtok(dummy, "\t \n");
00802 if (strcmp(ptr, "REM") ) {
00803 int cur_aa = AA1toAANum( AA3toAA1( ptr ) );
00804 int i = 0;
00805 while ( NULL != (ptr = strtok(NULL, "\t \n") ) ) {
00806 GONNET_MATRIX[i][cur_aa] = -(atof( ptr ));
00807 GONNET_MATRIX[cur_aa][i] = -(atof( ptr ));
00808 i++;
00809 }
00810 }
00811 }
00812 fclose(file_in);
00813
00814
00815
00817
00819
00820
00821
00822
00823 j = -1;
00824 sprintf(command, "%s/%s", ProspectPath, DEFIRE_BIN_DATA);
00825 file_in = fopen(command, "r");
00826 while ( fgets(dummy, sizeof(dummy), file_in) ) {
00827 sscanf(dummy, "%d", &i);
00828 if (i > j) {
00829 j = i;
00830 }
00831 }
00832 fseek(file_in, SEEK_SET, 0);
00833 dfire.bin_count = j;
00834 dfire.bin_min = (pValType*)malloc(sizeof(pValType) * j );
00835 dfire.bin_max = (pValType*)malloc(sizeof(pValType) * j );
00836 dfire.dist_max = 0;
00837
00838 i = 0;
00839 while ( fgets(dummy, sizeof(dummy), file_in) ) {
00840 sscanf(dummy, "%d %f - %f", &i, &val1, &val2);
00841 dfire.bin_min[i-1] = val1;
00842 dfire.bin_max[i-1] = val2;
00843 if ( val2 > dfire.dist_max)
00844 dfire.dist_max = val2;
00845 }
00846 fclose(file_in);
00847
00848 dfire.dist_hash_size = (long)(dfire.dist_max * 10.0);
00849 dfire.dist_hash = (short *)malloc(sizeof(short) * dfire.dist_hash_size);
00850 for (i = 0; i < dfire.dist_hash_size; i++)
00851 dfire.dist_hash[i] = -1;
00852 for (i = 0; i < dfire.bin_count; i++) {
00853 for (val1 = dfire.bin_min[i]; val1 < dfire.bin_max[i]; val1 += .1) {
00854 dfire.dist_hash[ (long)(val1 * 10.0) ] = i;
00855 }
00856 }
00857
00858 dfire.bin = (pValType ***)malloc(sizeof(pValType**) * dfire.bin_count);
00859 dfire.bin[0] = (pValType **)malloc(sizeof(pValType*) * dfire.bin_count * 21);
00860 dfire.bin[0][0] = (pValType *)malloc(sizeof(pValType) * 21 * 21 * dfire.bin_count);
00861 for (i = 0; i < dfire.bin_count; i++) {
00862 dfire.bin[i] = dfire.bin[0] + (i * 21);
00863 for (j = 0; j < 21; j++) {
00864 dfire.bin[i][j] = dfire.bin[0][0] + (i * 21 * 21) + j * 21;
00865 for (k = 0; k < 21; k++) {
00866 dfire.bin[i][j][k] = 0;
00867 }
00868 }
00869 }
00870
00871 sprintf(command, "%s/%s", ProspectPath, DEFIRE_CB_DATA);
00872 file_in = fopen(command, "r");
00873
00874 while (fgets( dummy, sizeof(dummy), file_in) ) {
00875 sscanf(dummy, "%s %s %f %d", tmp1, tmp2, &val1, &i);
00876 j = AA1toAANum( AA3toAA1( tmp1 ) );
00877 k = AA1toAANum( AA3toAA1( tmp2 ) );
00878 dfire.bin[i-1][j][k] = val1;
00879 dfire.bin[i-1][k][j] = val1;
00880 }
00881 fclose(file_in);
00882
00883
00884
00886
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920 return 0;
00921 }
00922
00923
00924
00925
00926
00927
00928 int ProspectParam::DoThreading(
00929 char *threader_name,
00930 WeightArray weight,
00931 TemplateStruct *template_data,
00932 TargetStruct *target_data,
00933 AlignmentStruct *alignment,
00934 ScoreStruct *scores ) {
00935 threading_function threader = this->ThreaderFind( threader_name );
00936 if ( target_data->twobody == NULL )
00937 target_data->Setup( this );
00938 DoThreading( threader,
00939 weight,
00940 template_data,
00941 target_data,
00942 alignment,
00943 scores );
00944 }
00945
00946
00947 int ProspectParam::DoThreading(
00948 threading_function threader,
00949 WeightArray weight,
00950 TemplateStruct *template_data,
00951 TargetStruct *target_data,
00952 AlignmentStruct *alignment,
00953 ScoreStruct *scores ) {
00954
00955
00956
00957 char * status = (*threader)(this, weight, template_data, target_data, alignment );
00958
00959 if (status) {
00960 return -1;
00961 }
00962 if ( scores != NULL ) {
00963 if ( scores->mask & ScoreStruct::DO_SCORE_RAW )
00964 scores->ScoreRaw( this,
00965 weight,
00966 template_data,
00967 target_data,
00968 alignment);
00969 if ( scores->mask & ScoreStruct::DO_SCORE_Z || ( !(scores->mask & ScoreStruct::DO_SCORE_ZFULL) && (scores->mask & ScoreStruct::DO_SCORE_ZENERGY) ) )
00970 scores->ScoreZ( this,
00971 weight,
00972 template_data,
00973 target_data,
00974 alignment);
00975 if ( scores->mask & ScoreStruct::DO_SCORE_ZFULL )
00976 scores->ScoreZFull( this,
00977 weight,
00978 template_data,
00979 target_data,
00980 alignment);
00981 }
00982 return 0;
00983 }
00984
00985