00001 #include <math.h>
00002 #include <stdio.h>
00003 #include <assert.h>
00004
00005 #define energy_global_define 1
00006 #include "open_prospect.h"
00007 #include "sm_matrix.h"
00008
00009 extern "C" {
00010 #include "filter_net.h"
00011 }
00012
00013 #define ABS(a) ( (a) < 0 ? (-(a)) : (a) )
00014
00015
00016 pValType calc_raw_score( WeightArray weights, EnergyArray energies ) {
00017 pValType total = 0.0;
00018 for (int i = 0; i < e_count; i++ ) {
00019 total += weights[i] * energies[i];
00020 }
00021 return total;
00022 }
00023
00024 pValType calc_single_energy(ProspectParam *param,
00025 WeightArray weights,
00026 TemplateStruct *template_data,
00027 TargetStruct *target_data,
00028 int template_res_num,
00029 int target_res_num) {
00030 pValType score = 0;
00031
00032 if ( target_res_num >= 0 && target_res_num < target_data->len) {
00033
00034 if (weights[e_mutation] != 0)
00035 score += weights[e_mutation] * calc_mutation(param, template_data, target_data, template_res_num, target_res_num);
00036
00037
00038
00039
00040 if (weights[e_mutationlog] != 0)
00041 score += weights[e_mutationlog] * calc_mutationlog(param, template_data, target_data, template_res_num, target_res_num);
00042
00043 if (weights[e_singleton] != 0)
00044 score += weights[e_singleton] * calc_singleton(param, template_data, target_data, template_res_num, target_res_num);
00045
00046 if (weights[e_mutscore] != 0)
00047 score += weights[e_mutscore] * calc_mutscore(param, template_data, target_data, template_res_num, target_res_num);
00048
00049 if (weights[e_sec_struct] != 0)
00050 score += weights[e_sec_struct] * calc_sec_struct(param, template_data, target_data, template_res_num, target_res_num);
00051
00052 if (weights[e_contact] != 0)
00053 score += weights[e_contact] * calc_contact_frozen(param, template_data, target_data, template_res_num, target_res_num);
00054
00055
00056
00057
00058 }
00059
00060 return score;
00061 }
00062
00063
00064
00065 pValType calc_pair_energy(ProspectParam *param,
00066 WeightArray weights,
00067 TemplateStruct *template_data,
00068 TargetStruct *target_data,
00069 int template_res_num_1, int template_res_num_2,
00070 int target_res_num_1, int target_res_num_2) {
00071 pValType score = 0;
00072
00073 if (weights[e_twobody] != 0.0)
00074 score += weights[e_twobody] * calc_twobody(param, template_data, target_data,
00075 template_res_num_1, template_res_num_2,
00076 target_res_num_1, target_res_num_2);
00077
00078 if (weights[e_dfire] != 0.0)
00079 score += weights[e_dfire] * calc_dfire(param, template_data, target_data,
00080 template_res_num_1, template_res_num_2,
00081 target_res_num_1, target_res_num_2);
00082
00083
00084 if (weights[e_distconst] != 0.0)
00085 score += weights[e_distconst] * calc_distconst(param, template_data, target_data,
00086 template_res_num_1, template_res_num_2,
00087 target_res_num_1, target_res_num_2);
00088
00089 return score;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 pValType calc_mutation(ProspectParam *param,
00127 TemplateStruct *template_data,
00128 TargetStruct *target_data,
00129 int template_res_num,
00130 int target_res_num) {
00131 int k;
00132 pValType mutation=0.0;
00133
00134 #ifdef ALTIVEC
00135 vector float partialProduct = (vector float) (0.0f, 0.0f, 0.0f, 0.0f),
00136 temp, sum;
00137 vector unsigned int minusZero;
00138 float vDotProduct;
00139 vector float x,y;
00140 float *a,*b;
00141 #if 0
00142 minusZero = vec_splat_u32 ( -1 );
00143 minusZero = vec_sl ( minusZero, minusZero );
00144 partialProduct = ( vector float ) minusZero;
00145 #endif
00146
00147
00148 a = template_data->residue[template_res_num].PROFILE;
00149 b = target_data->residue[target_res_num].FREQ;
00150
00151 x = vec_ld(0, a);
00152 y = vec_ld(0, b);
00153 a+=4;
00154 b+=4;
00155 for (i = 1; i < 5; i++) {
00156 partialProduct = vec_madd ( x, y, partialProduct );
00157 x = vec_ld(0, a );
00158 y = vec_ld(0, b );
00159 a+=4;
00160 b+=4;
00161 }
00162
00163 temp = vec_sld ( partialProduct, partialProduct, 4 );
00164 sum = vec_add ( partialProduct, temp );
00165 temp = vec_sld ( sum, sum, 8 );
00166 sum = vec_add ( sum, temp);
00167
00168 vec_ste ( sum, 0, &vDotProduct );
00169 return -vDotProduct;
00170 #else
00171 if (template_res_num < template_data->len && template_res_num >= 0 &&
00172 target_res_num < target_data->len && target_res_num >= 0) {
00173
00174
00175 for (k=0;k<20;k++) {
00176 mutation=mutation+template_data->residue[template_res_num].FREQ[k]*
00177 target_data->residue[target_res_num].FREQ[k];
00178 }
00179 }
00180 return (-mutation);
00181 #endif
00182
00183 }
00184
00185
00186 pValType calc_mutationfull(ProspectParam *param,
00187 TemplateStruct *template_data,
00188 TargetStruct *target_data,
00189 int template_res_num,
00190 int target_res_num) {
00191 int i,j;
00192 pValType mutation=0.0;
00193
00194
00195 if (template_res_num < template_data->len && template_res_num >= 0 &&
00196 target_res_num < target_data->len && target_res_num >= 0) {
00197
00198 for (i = 0; i < 20; i++) {
00199 for (j = 0; j < 20; j++) {
00200 mutation = mutation +
00201 (template_data->residue[template_res_num].FREQ[i]*
00202 target_data->residue[target_res_num].FREQ[j] *
00203 param->GONNET_MATRIX[ i ][ j ] );
00204 }
00205 }
00206 }
00207
00208 return (-mutation);
00209 }
00210
00211
00212 typedef struct AA_LetterProb {
00213 char a;
00214 pValType prob;
00215 } AA_LetterProb;
00216
00217 static AA_LetterProb Robinson_prob[] = {
00218 { 'A', 0.07805 },
00219 { 'R', 0.05129 },
00220 { 'N', 0.04487 },
00221 { 'D', 0.05364 },
00222 { 'C', 0.01925 },
00223 { 'Q', 0.04264 },
00224 { 'E', 0.06295 },
00225 { 'G', 0.07377 },
00226 { 'H', 0.02199 },
00227 { 'I', 0.05142 },
00228 { 'L', 0.09019 },
00229 { 'K', 0.05744 },
00230 { 'M', 0.02243 },
00231 { 'F', 0.03856 },
00232 { 'P', 0.05203 },
00233 { 'S', 0.07120 },
00234 { 'T', 0.05841 },
00235 { 'W', 0.01330 },
00236 { 'Y', 0.03216 },
00237 { 'V', 0.06441 }
00238 };
00239
00240
00241
00242 pValType calc_mutationlog(ProspectParam *param,
00243 TemplateStruct *template_data,
00244 TargetStruct *target_data,
00245 int template_res_num,
00246 int target_res_num) {
00247 long i;
00248 pValType sum = 0;
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 for (i = 0; i < 20; i++) {
00264 sum += target_data->residue[target_res_num].FREQ[i] * template_data->t_residue_info[template_res_num].Score[i];
00265 }
00266 assert( !isnan(sum) );
00267 return -sum;
00268 }
00269
00270 pValType calc_mutscore(ProspectParam *param,
00271 TemplateStruct *template_data,
00272 TargetStruct *target_data,
00273 int template_res_num,
00274 int target_res_num) {
00275 return template_data->t_residue_info[ template_res_num ].Score[ AA1toAANum( target_data->residue[target_res_num].RS ) ];
00276 }
00277
00278 pValType calc_sec_struct(ProspectParam *param,
00279 TemplateStruct *template_data,
00280 TargetStruct *target_data,
00281 int template_res_num,
00282 int target_res_num) {
00283 pValType ss_fit=0.0;
00284 if (template_data->residue[template_res_num].SS=='H') {
00285
00286 ss_fit = 0.3 - (target_data->residue[target_res_num].SS_PROB[HELIX]);
00287 } else if (template_data->residue[template_res_num].SS=='E') {
00288
00289 ss_fit = 0.3 - (target_data->residue[target_res_num].SS_PROB[SHEET]);
00290 } else {
00291
00292 ss_fit = 0.3 - (target_data->residue[target_res_num].SS_PROB[LOOP]);
00293 }
00294 return (ss_fit);
00295 }
00296
00297
00298 pValType calc_singleton(ProspectParam *param,
00299 TemplateStruct *template_data,
00300 TargetStruct *target_data,
00301 int template_res_num,
00302 int target_res_num) {
00303
00304 int k,index;
00305
00306 index = solvent_sec_struct(template_data,template_res_num);
00307
00308 if (index==-1)
00309 return (0.0);
00310
00311 pValType singleton=0.0;
00312 for (k=0;k<20;k++) {
00313 singleton = singleton + param->SINGLETON[k][index]*target_data->residue[target_res_num].FREQ[k];
00314 }
00315
00316 return (singleton);
00317
00318 }
00319
00320
00321 int solvent_sec_struct(TemplateStruct *template_data,
00322 int template_res_num)
00323 {
00324
00325 int i,max;
00326
00327 switch (template_data->residue[template_res_num].SS)
00328 {
00329 case 'H': i=0; break;
00330 case 'G': i=0; break;
00331 case 'I': i=0; break;
00332 case 'E': i=3; break;
00333 case 'B': i=3; break;
00334 default : i=6; break;
00335 }
00336
00337 switch (template_data->residue[template_res_num].RS)
00338 {
00339 case 'A': max = 101; break;
00340 case 'C': max = 127; break;
00341 case 'D': max = 161; break;
00342 case 'E': max = 195; break;
00343 case 'F': max = 214; break;
00344 case 'G': max = 73; break;
00345 case 'H': max = 193; break;
00346 case 'I': max = 174; break;
00347 case 'K': max = 200; break;
00348 case 'L': max = 182; break;
00349 case 'M': max = 192; break;
00350 case 'N': max = 171; break;
00351 case 'P': max = 127; break;
00352 case 'Q': max = 190; break;
00353 case 'R': max = 242; break;
00354 case 'S': max = 122; break;
00355 case 'T': max = 144; break;
00356 case 'V': max = 148; break;
00357 case 'W': max = 259; break;
00358 case 'Y': max = 235; break;
00359 default : max = -1; break;
00360 }
00361
00362 if (max==-1)
00363 return (-1);
00364
00365 pValType check;
00366 check = (pValType)template_data->t_residue_info[template_res_num].ACC/(pValType)max;
00367
00368 if (check <= 0.069) {
00369 return (i+0);
00370 } else if (check <= 0.368) {
00371 return (i+1);
00372 } else {
00373 return (i+2);
00374 }
00375
00376 }
00377
00378
00379 pValType calc_contact_frozen(ProspectParam *param,
00380 TemplateStruct *template_data,
00381 TargetStruct *target_data,
00382 int template_res_num,
00383 int target_res_num) {
00384 int count = 0;
00385 if ( !template_data->structure )
00386 return 0;
00387
00388 for (int i = 0; i < template_data->len; i++) {
00389 if ( i != template_res_num ) {
00390 if ( smDistance( template_data->structure[i].atom[ template_data->structure[i].bb_num[ anCb ] ],
00391 template_data->structure[template_res_num].atom[ template_data->structure[template_res_num].bb_num[ anCb ] ] )
00392 < PairDistCutoffSqrt ) {
00393 count++;
00394 }
00395 }
00396 }
00397 if (count < MaxContactCount ) {
00398 pValType score = 0.0;
00399 for (int i = 0; i < 20; i++)
00400 score += target_data->residue[ target_res_num ].FREQ[i] * param->CONTACT_MATRIX[ i ][ count ];
00401 return score;
00402 }
00403 return 3200;
00404 }
00405
00406
00407 pValType calc_twobody_frozen(ProspectParam *param,
00408 TemplateStruct *template_data,
00409 TargetStruct *target_data,
00410 int template_res_num,
00411 int target_res_num) {
00412 pValType score = 0;
00413 long i,j,k;
00414 if ( !template_data->twobody_interactions)
00415 return 0;
00416
00417 for (i = 0; i < template_data->twobody_count; i++) {
00418 if (template_data->twobody_interactions[i].core_number[0] != -1 &&
00419 template_data->twobody_interactions[i].core_number[1] != -1 &&
00420 template_data->twobody_interactions[i].core_number[0] != template_data->twobody_interactions[i].core_number[1]) {
00421 if (template_res_num == template_data->twobody_interactions[i].residue_number[0]) {
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 score += param->PAIR_POT[ AA1toAANum(target_data->residue[target_res_num].RS) ]
00433 [ AA1toAANum(template_data->residue[template_data->twobody_interactions[i].residue_number[1]].RS) ];
00434
00435 }
00436 if (template_res_num == template_data->twobody_interactions[i].residue_number[1]) {
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 score += param->PAIR_POT[ AA1toAANum(target_data->residue[target_res_num].RS) ]
00448 [ AA1toAANum(template_data->residue[template_data->twobody_interactions[i].residue_number[0]].RS) ];
00449
00450 }
00451 }
00452 }
00453 return score;
00454 }
00455
00456
00457 pValType calc_twobody(ProspectParam *param,
00458 TemplateStruct *template_data,
00459 TargetStruct *target_data,
00460 int template_res_num_1, int template_res_num_2,
00461 int target_res_num_1, int target_res_num_2) {
00462 if ( ABS( (template_res_num_1 - template_res_num_2) ) > MinDistTwoBody &&
00463 template_data->cb_dist[ template_res_num_1 ][template_res_num_2 ] <= PairDistCutoffSqrt ) {
00464 assert( target_res_num_1 >= 0 && target_res_num_1 < target_data->len && target_res_num_2 >= 0 && target_res_num_2 < target_data->len);
00465 assert( target_data->residue[ target_res_num_1 ].orig_num >= 0 && target_data->residue[ target_res_num_1 ].orig_num < target_data->len &&
00466 target_data->residue[ target_res_num_2 ].orig_num >= 0 && target_data->residue[ target_res_num_2 ].orig_num < target_data->len );
00467 return target_data->twobody[ target_data->residue[ target_res_num_1 ].orig_num ][ target_data->residue[ target_res_num_2 ].orig_num ];
00468 } else
00469 return 0;
00470 }
00471
00472
00473 pValType calc_twobody_val(ProspectParam *param,
00474 TargetStruct *target_data,
00475 int target_res_num_1, int target_res_num_2) {
00476 int i,j;
00477 pValType twobody = 0.0;
00478 twobody = 0;
00479 if ( param->simple_twobody ) {
00480 return param->PAIR_POT[ AA1toAANum( target_data->residue[target_res_num_1].RS ) ]
00481 [ AA1toAANum( target_data->residue[target_res_num_2].RS ) ];
00482 } else {
00483 for (i=0;i<20;i++) {
00484 for (j=0;j<20;j++) {
00485 twobody += target_data->residue[target_res_num_1].FREQ[i] *
00486 target_data->residue[target_res_num_2].FREQ[j] *
00487 param->PAIR_POT[i][j];
00488 }
00489 }
00490 }
00491 return (twobody);
00492 }
00493
00494
00495 pValType calc_dfire(ProspectParam *param,
00496 TemplateStruct *template_data,
00497 TargetStruct *target_data,
00498 int template_res_num_1, int template_res_num_2,
00499 int target_res_num_1, int target_res_num_2) {
00500 long i;
00501 if (target_res_num_1 >= 0 && target_res_num_1 < target_data->len &&
00502 target_res_num_2 >= 0 && target_res_num_2 < target_data->len &&
00503 template_res_num_1 >= 0 && template_res_num_1 < template_data->len &&
00504 template_res_num_2 >= 0 && template_res_num_2 < template_data->len ) {
00505 pValType dist = template_data->cb_dist[ template_res_num_1 ][ template_res_num_2 ];
00506
00507 #if 0
00508 for (i = 0; i < param->dfire.bin_count; i++) {
00509 if ( param->dfire.bin_min[i] <= dist && param->dfire.bin_max[i] > dist) {
00510 return param->dfire.bin[i][ AA1toAANum(target_data->residue[target_res_num_1].RS) ]
00511 [ AA1toAANum(target_data->residue[target_res_num_2].RS) ];
00512 }
00513 }
00514 #else
00515 i = (long)(dist * 10.0);
00516 if (i < param->dfire.dist_hash_size && param->dfire.dist_hash[i] != -1) {
00517 return param->dfire.bin[ param->dfire.dist_hash[i] ][ AA1toAANum(target_data->residue[target_res_num_1].RS) ]
00518 [ AA1toAANum(target_data->residue[target_res_num_2].RS) ];
00519 }
00520 #endif
00521 }
00522 return 0;
00523 }
00524
00525
00526 pValType calc_dfire( ProspectParam *param, char res_a, char res_b, float dist ) {
00527 long i = (long)(dist * 10.0);
00528 if (i < param->dfire.dist_hash_size && param->dfire.dist_hash[i] != -1) {
00529 return param->dfire.bin[ param->dfire.dist_hash[i] ]
00530 [ AA1toAANum(res_a) ]
00531 [ AA1toAANum(res_b) ];
00532 }
00533 return 0;
00534 }
00535
00536
00537 pValType calc_distconst(ProspectParam *param,
00538 TemplateStruct *template_data,
00539 TargetStruct *target_data,
00540 int template_res_num_1, int template_res_num_2,
00541 int target_res_num_1, int target_res_num_2) {
00542 pValType score = 0;
00543 long i;
00544
00545 if (target_data->distconst) {
00546 for (i = 0; i < target_data->distconst_count; i++) {
00547 if ( (target_data->distconst[i].aa[0] == target_res_num_1 &&
00548 target_data->distconst[i].aa[1] == target_res_num_2) ||
00549 (target_data->distconst[i].aa[1] == target_res_num_1 &&
00550 target_data->distconst[i].aa[0] == target_res_num_2) ) {
00551 if ( fabs( template_data->cb_dist[ template_res_num_1 ][ template_res_num_2 ] -
00552 target_data->distconst[i].dist) < target_data->distconst[i].var ) {
00553 score--;
00554 } else {
00555
00556
00557 }
00558 }
00559 }
00560 }
00561
00562 return score;
00563 }
00564
00565
00566
00567 float residue_max_sasa[21] = {
00568
00569 240.0 ,
00570 295.0 ,
00571 221.0 ,
00572 247.0 ,
00573 174.0 ,
00574 245.0 ,
00575 254.0 ,
00576 262.0 ,
00577 254.0 ,
00578 235.0 ,
00579 234.0 ,
00580 318.0 ,
00581 242.0 ,
00582 246.0 ,
00583 230.0 ,
00584 238.0 ,
00585 217.0 ,
00586 262.0 ,
00587 290.0 ,
00588 227.0 ,
00589 1
00590 };
00591
00592 float residue_ave_sasa[21] = {
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 35.7522151899 ,
00618 102.584053794 ,
00619 74.2146892655 ,
00620 76.1526104418 ,
00621 26.4561101549 ,
00622 83.9657701711 ,
00623 88.9936708861 ,
00624 38.6197583511 ,
00625 69.592469546 ,
00626 37.14604811 ,
00627 41.0129971406 ,
00628 99.2901748543 ,
00629 55.1653439153 ,
00630 48.2477650064 ,
00631 61.3702882483 ,
00632 52.223880597 ,
00633 55.0547826087 ,
00634 61.4861878453 ,
00635 63.7211838006 ,
00636 35.5517128874 ,
00637
00638 1.0
00639 };
00640
00641
00642 pValType calc_del_val(ProspectParam *param,
00643 WeightArray weights,
00644 TemplateStruct *template_data,
00645 TargetStruct *target_data,
00646 int template_res_num, int target_res_num ) {
00647 pValType total = 0.0;
00648 if ( weights[ e_tsingledel ] != 0.0 ) {
00649 total += weights[ e_tsingledel ] * calc_singledel( param, template_data, template_res_num );
00650 }
00651 if ( weights[ e_coredel ] != 0.0 ) {
00652 total += weights[ e_coredel ] * calc_coredel( param, template_data, template_res_num );
00653 }
00654 if ( weights[ e_contactdel ] != 0.0 ) {
00655 total += weights[ e_contactdel ] * calc_contactdel( param, template_data, template_res_num );
00656 }
00657 if ( weights[ e_qsingleins ] != 0.0 ) {
00658 total += weights[ e_qsingleins ] * target_data->residue[ target_res_num ].single_ins;
00659 }
00660
00661 return total;
00662 }
00663
00664
00665 pValType calc_ins_val( ProspectParam *param,
00666 WeightArray weights,
00667 TemplateStruct *template_data,
00668 TargetStruct *target_data,
00669 int template_res_num, int target_res_num ) {
00670 pValType total = 0.0;
00671 if ( weights[ e_tsingleins ] != 0.0 ) {
00672 total += weights[ e_tsingleins ] * calc_singleins(param, template_data, template_res_num);
00673 }
00674 if ( weights[ e_qsingledel ] != 0.0 ) {
00675 total += weights[ e_qsingledel ] * target_data->residue[ target_res_num ].single_del;
00676 }
00677 return total;
00678 }
00679
00680
00681 pValType calc_singledel(ProspectParam *param,
00682 TemplateStruct *template_data,
00683 int template_res_num) {
00684 return (template_data->residue[template_res_num].single_del);
00685
00686
00687
00688
00689 }
00690
00691
00692 pValType calc_coredel(ProspectParam *param,
00693 TemplateStruct *template_data,
00694 int template_res_num) {
00695 if ( template_data->t_residue_info == NULL ||
00696 template_data->cores == NULL ||
00697 template_data->t_residue_info[ template_res_num ].core_num == -1 )
00698 return 0;
00699
00700 return 1.0 / (float) ( template_data->cores[ template_data->t_residue_info[ template_res_num ].core_num ].len );
00701
00702 }
00703
00704 pValType calc_contactdel(ProspectParam *param,
00705 TemplateStruct *template_data,
00706 int template_res_num) {
00707 float total_contact = 0;
00708 ResidueAtoms *res_1 = &template_data->structure[ template_res_num ];
00709 for ( int i = 0; i < template_data->len; i++ ) {
00710 if ( i != template_res_num ) {
00711 ResidueAtoms *res_2 = &template_data->structure[i];
00712 float dist = smDistance( res_1->atom[ res_1->bb_num[ anCa ] ],
00713 res_2->atom[ res_2->bb_num[ anCa ] ] );
00714 if ( dist < 7.6 ) {
00715 total_contact++;
00716 }
00717 }
00718 }
00719 return total_contact;
00720 }
00721
00722
00723 pValType calc_singleins(ProspectParam *param,
00724 TemplateStruct *template_data,
00725 int template_res_num) {
00726 return (template_data->residue[template_res_num].single_ins);
00727 }
00728
00729
00730 #define kCoreMinSize 6
00731 #define filter_cut 0.01
00732
00733
00734
00735 char energy_mask[ e_count ] = {1,0,0,0,1,1,0,0,0,0,0};
00736
00737
00738 int ss_filter(ProspectParam *param,
00739 TemplateStruct *template_data,
00740 TargetStruct *target_data,
00741 int core_num, int core_position) {
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 return 0;
00764 }
00765