1 #ifndef __VIENNA_RNA_PACKAGE_LOOP_ENERGIES_H__
2 #define __VIENNA_RNA_PACKAGE_LOOP_ENERGIES_H__
11 #include "energy_par.h"
14 # define INLINE inline
54 INLINE PRIVATE
int E_MLstem(
int type,
65 INLINE PRIVATE
double exp_E_MLstem(
int type,
89 INLINE PRIVATE
int E_ExtLoop(
int type,
100 INLINE PRIVATE
double exp_E_ExtLoop(
int type,
243 INLINE PRIVATE
int E_Stem(
int type,
322 INLINE PRIVATE
int E_Hairpin(
int size,
int type,
int si1,
int sj1,
const char *
string,
paramT *P){
325 energy = (size <= 30) ? P->hairpin[size] : P->hairpin[30]+(
int)(P->lxc*log((size)/30.));
329 strncpy(tl,
string, 6);
330 if ((ts=strstr(P->Tetraloops, tl)))
331 return (P->Tetraloop_E[(ts - P->Tetraloops)/7]);
333 else if (size == 6) {
335 strncpy(tl,
string, 8);
336 if ((ts=strstr(P->Hexaloops, tl)))
337 return (energy = P->Hexaloop_E[(ts - P->Hexaloops)/9]);
339 else if (size == 3) {
340 char tl[6]={0,0,0,0,0,0}, *ts;
341 strncpy(tl,
string, 5);
342 if ((ts=strstr(P->Triloops, tl))) {
343 return (P->Triloop_E[(ts - P->Triloops)/6]);
345 return (energy + (type>2 ? P->TerminalAU : 0));
348 energy += P->mismatchH[type][si1][sj1];
353 INLINE PRIVATE
int E_IntLoop(
int n1,
int n2,
int type,
int type_2,
int si1,
int sj1,
int sp1,
int sq1,
paramT *P){
358 if (n1>n2) { nl=n1; ns=n2;}
362 return P->stack[type][type_2];
365 energy = (nl<=
MAXLOOP)?P->bulge[nl]:
366 (P->bulge[30]+(
int)(P->lxc*log(nl/30.)));
367 if (nl==1) energy += P->stack[type][type_2];
369 if (type>2) energy += P->TerminalAU;
370 if (type_2>2) energy += P->TerminalAU;
377 return P->int11[type][type_2][si1][sj1];
380 energy = P->int21[type][type_2][si1][sq1][sj1];
382 energy = P->int21[type_2][type][sq1][si1][sp1];
386 energy = (nl+1<=
MAXLOOP)?(P->internal_loop[nl+1]) : (P->internal_loop[30]+(int)(P->lxc*log((nl+1)/30.)));
387 energy +=
MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
388 energy += P->mismatch1nI[type][si1][sj1] + P->mismatch1nI[type_2][sq1][sp1];
394 return P->int22[type][type_2][si1][sp1][sq1][sj1];}
396 energy = P->internal_loop[5]+P->ninio[2];
397 energy += P->mismatch23I[type][si1][sj1] + P->mismatch23I[type_2][sq1][sp1];
403 energy = (n1+n2<=
MAXLOOP)?(P->internal_loop[n1+n2]) : (P->internal_loop[30]+(int)(P->lxc*log((n1+n2)/30.)));
405 energy +=
MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
407 energy += P->mismatchI[type][si1][sj1] + P->mismatchI[type_2][sq1][sp1];
413 INLINE PRIVATE
int E_Stem(
int type,
int si1,
int sj1,
int extLoop,
paramT *P){
415 int d5 = (si1 >= 0) ? P->dangle5[type][si1] : 0;
416 int d3 = (sj1 >= 0) ? P->dangle3[type][sj1] : 0;
419 energy += P->TerminalAU;
421 if(si1 >= 0 && sj1 >= 0)
422 energy += (extLoop) ? P->mismatchExt[type][si1][sj1] : P->mismatchM[type][si1][sj1];
426 if(!extLoop) energy += P->MLintern[type];
430 INLINE PRIVATE
int E_ExtLoop(
int type,
int si1,
int sj1,
paramT *P){
432 if(si1 >= 0 && sj1 >= 0){
433 energy += P->mismatchExt[type][si1][sj1];
436 energy += P->dangle5[type][si1];
439 energy += P->dangle3[type][sj1];
443 energy += P->TerminalAU;
448 INLINE PRIVATE
int E_MLstem(
int type,
int si1,
int sj1,
paramT *P){
450 if(si1 >= 0 && sj1 >= 0){
451 energy += P->mismatchM[type][si1][sj1];
454 energy += P->dangle5[type][si1];
457 energy += P->dangle3[type][sj1];
461 energy += P->TerminalAU;
463 energy += P->MLintern[type];
473 q = P->exphairpin[u];
475 q = P->exphairpin[30] * exp( -(P->lxc*log( u/30.))*10./kT);
481 char tl[7]={0,0,0,0,0,0,0}, *ts;
482 strncpy(tl,
string, 6);
483 if ((ts=strstr(P->Tetraloops, tl))){
485 return (P->exptetra[(ts-P->Tetraloops)/7]);
487 q *= P->exptetra[(ts-P->Tetraloops)/7];
491 char tl[9]={0,0,0,0,0,0,0,0,0}, *ts;
492 strncpy(tl,
string, 8);
493 if ((ts=strstr(P->Hexaloops, tl)))
494 return (P->exphex[(ts-P->Hexaloops)/9]);
497 char tl[6]={0,0,0,0,0,0}, *ts;
498 strncpy(tl,
string, 5);
499 if ((ts=strstr(P->Triloops, tl)))
500 return (P->exptri[(ts-P->Triloops)/6]);
502 return q * P->expTermAU;
507 q *= P->expmismatchH[type][si1][sj1];
512 INLINE PRIVATE
double exp_E_IntLoop(
int u1,
int u2,
int type,
int type2,
short si1,
short sj1,
short sp1,
short sq1,
pf_paramT *P){
513 int ul, us, no_close = 0;
516 if ((
no_closingGU) && ((type2==3)||(type2==4)||(type==3)||(type==4)))
519 if (u1>u2) { ul=u1; us=u2;}
523 z = P->expstack[type][type2];
527 if (ul==1) z *= P->expstack[type][type2];
529 if (type>2) z *= P->expTermAU;
530 if (type2>2) z *= P->expTermAU;
536 return P->expint11[type][type2][si1][sj1];
540 return P->expint21[type][type2][si1][sq1][sj1];
542 return P->expint21[type2][type][sq1][si1][sp1];
545 z = P->expinternal[ul+us] * P->expmismatch1nI[type][si1][sj1] * P->expmismatch1nI[type2][sq1][sp1];
546 return z * P->expninio[2][ul-us];
551 return P->expint22[type][type2][si1][sp1][sq1][sj1];
553 z = P->expinternal[5]*P->expmismatch23I[type][si1][sj1]*P->expmismatch23I[type2][sq1][sp1];
554 return z * P->expninio[2][1];
558 z = P->expinternal[ul+us] * P->expmismatchI[type][si1][sj1] * P->expmismatchI[type2][sq1][sp1];
559 return z * P->expninio[2][ul-us];
567 double d5 = (si1 >= 0) ? P->expdangle5[type][si1] : 1.;
568 double d3 = (sj1 >= 0) ? P->expdangle3[type][sj1] : 1.;
571 energy *= P->expTermAU;
573 if(si1 >= 0 && sj1 >= 0)
574 energy *= (extLoop) ? P->expmismatchExt[type][si1][sj1] : P->expmismatchM[type][si1][sj1];
578 if(!extLoop) energy *= P->expMLintern[type];
582 INLINE PRIVATE
double exp_E_MLstem(
int type,
int si1,
int sj1,
pf_paramT *P){
584 if(si1 >= 0 && sj1 >= 0){
585 energy *= P->expmismatchM[type][si1][sj1];
588 energy *= P->expdangle5[type][si1];
591 energy *= P->expdangle3[type][sj1];
595 energy *= P->expTermAU;
597 energy *= P->expMLintern[type];
601 INLINE PRIVATE
double exp_E_ExtLoop(
int type,
int si1,
int sj1,
pf_paramT *P){
603 if(si1 >= 0 && sj1 >= 0){
604 energy *= P->expmismatchExt[type][si1][sj1];
607 energy *= P->expdangle5[type][si1];
610 energy *= P->expdangle3[type][sj1];
614 energy *= P->expTermAU;
619 INLINE PRIVATE
int E_IntLoop_Co(
int type,
int type_2,
int i,
int j,
int p,
int q,
int cutpoint,
short si1,
short sj1,
short sp1,
short sq1,
int dangles,
paramT *P){
621 if(type > 2) energy += P->TerminalAU;
622 if(type_2 > 2) energy += P->TerminalAU;
624 if(!dangles)
return energy;
626 int ci = (i>=cutpoint)||((i+1)<cutpoint);
627 int cj = ((j-1)>=cutpoint)||(j<cutpoint);
628 int cp = ((p-1)>=cutpoint)||(p<cutpoint);
629 int cq = (q>=cutpoint)||((q+1)<cutpoint);
631 int d3 = ci ? P->dangle3[type][si1] : 0;
632 int d5 = cj ? P->dangle5[type][sj1] : 0;
633 int d5_2 = cp ? P->dangle5[type_2][sp1] : 0;
634 int d3_2 = cq ? P->dangle3[type_2][sq1] : 0;
636 int tmm = (cj && ci) ? P->mismatchExt[type][sj1][si1] : d5 + d3;
637 int tmm_2 = (cp && cq) ? P->mismatchExt[type_2][sp1][sq1] : d5_2 + d3_2;
639 if(dangles == 2)
return energy + tmm + tmm_2;
643 if(q+2 < j){ energy += tmm + tmm_2;}
644 else if(q+2 == j){ energy += (cj && cq) ?
MIN2(tmm + d5_2, tmm_2 + d3) : tmm + tmm_2;}
645 else energy += d3 + d5_2;
648 if(q+2 < j){ energy += (ci && cp) ?
MIN2(tmm + d3_2, tmm_2 + d5) : tmm + tmm_2;}
650 energy +=
MIN2(tmm,
MIN2(tmm_2,
MIN2(d5 + d5_2, d3 + d3_2)));
652 else energy +=
MIN2(d3, d5_2);
655 if(q+2 < j){ energy += d5 + d3_2;}
656 else if(q+2 == j){ energy +=
MIN2(d5, d3_2);}