1 #ifndef VIENNA_RNA_PACKAGE_LOOPS_INTERNAL_H
2 #define VIENNA_RNA_PACKAGE_LOOPS_INTERNAL_H
5 #include <ViennaRNA/params/default.h>
12 #ifdef VRNA_WARN_DEPRECATED
13 # if defined(DEPRECATED)
16 # if defined(__clang__)
17 # define DEPRECATED(func, msg) func __attribute__ ((deprecated("", msg)))
18 # elif defined(__GNUC__)
19 # define DEPRECATED(func, msg) func __attribute__ ((deprecated(msg)))
21 # define DEPRECATED(func, msg) func
24 # define DEPRECATED(func, msg) func
28 # define INLINE inline
155 #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY
162 #ifdef ON_SAME_STRAND
163 #undef ON_SAME_STRAND
166 #define ON_SAME_STRAND(I, J, C) (((I) >= (C)) || ((J) < (C)))
253 PRIVATE INLINE
int E_IntLoop_Co(
int type,
279 ubf_eval_int_loop(
int i,
292 unsigned char type_2,
304 if ((cp < 0) || (ON_SAME_STRAND(i, p, cp) && ON_SAME_STRAND(q, j, cp))) {
306 energy =
E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
310 Si = ON_SAME_STRAND(i, i1, cp) ? si : -1;
311 Sj = ON_SAME_STRAND(j1, j, cp) ? sj : -1;
312 energy = E_IntLoop_Co(rtype[type], rtype[type_2],
348 ubf_eval_int_loop2(
int i,
361 unsigned char type_2,
374 if ((sn[i] == sn[p]) && (sn[q] == sn[j])) {
376 energy =
E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
380 Si = (sn[i1] == sn[i]) ? si : -1;
381 Sj = (sn[j] == sn[j1]) ? sj : -1;
382 energy = E_IntLoop_Co(rtype[type], rtype[type_2],
428 ubf_eval_ext_int_loop(
int i,
441 unsigned char type_2,
446 int energy, u1, u2, u3;
452 energy =
E_IntLoop(u2, u1 + u3, type, type_2, si, sj, sp, sq, P);
463 if (u1 + u2 + u3 == 0)
489 int nl, ns, u, energy;
502 return P->stack[type][type_2];
506 energy = (nl <=
MAXLOOP) ? P->bulge[nl] :
507 (P->bulge[30] + (
int)(P->lxc * log(nl / 30.)));
509 energy += P->stack[type][type_2];
512 energy += P->TerminalAU;
515 energy += P->TerminalAU;
523 return P->int11[type][type_2][si1][sj1];
528 energy = P->int21[type][type_2][si1][sq1][sj1];
530 energy = P->int21[type_2][type][sq1][si1][sp1];
537 MAXLOOP) ? (P->internal_loop[nl + 1]) : (P->internal_loop[30] +
538 (int)(P->lxc * log((nl + 1) / 30.)));
539 energy +=
MIN2(MAX_NINIO, (nl - ns) * P->ninio[2]);
540 energy += P->mismatch1nI[type][si1][sj1] + P->mismatch1nI[type_2][sq1][sp1];
543 }
else if (ns == 2) {
546 return P->int22[type][type_2][si1][sp1][sq1][sj1];
547 }
else if (nl == 3) {
549 energy = P->internal_loop[5] + P->ninio[2];
550 energy += P->mismatch23I[type][si1][sj1] + P->mismatch23I[type_2][sq1][sp1];
560 MAXLOOP) ? (P->internal_loop[u]) : (P->internal_loop[30] + (int)(P->lxc * log((u) / 30.)));
562 energy +=
MIN2(MAX_NINIO, (nl - ns) * P->ninio[2]);
564 energy += P->mismatchI[type][si1][sj1] + P->mismatchI[type_2][sq1][sp1];
583 int ul, us, no_close = 0;
587 if ((noGUclosure) && ((type2 == 3) || (type2 == 4) || (type == 3) || (type == 4)))
600 z = P->expstack[type][type2];
601 }
else if (!no_close) {
606 z *= P->expstack[type][type2];
616 }
else if (us == 1) {
618 return (
FLT_OR_DBL)(P->expint11[type][type2][si1][sj1]);
623 return (
FLT_OR_DBL)(P->expint21[type][type2][si1][sq1][sj1]);
625 return (
FLT_OR_DBL)(P->expint21[type2][type][sq1][si1][sp1]);
628 z = P->expinternal[ul + us] * P->expmismatch1nI[type][si1][sj1] *
629 P->expmismatch1nI[type2][sq1][sp1];
630 return (
FLT_OR_DBL)(z * P->expninio[2][ul - us]);
632 }
else if (us == 2) {
635 return (
FLT_OR_DBL)(P->expint22[type][type2][si1][sp1][sq1][sj1]);
636 }
else if (ul == 3) {
638 z = P->expinternal[5] * P->expmismatch23I[type][si1][sj1] *
639 P->expmismatch23I[type2][sq1][sp1];
645 z = P->expinternal[ul + us] * P->expmismatchI[type][si1][sj1] *
646 P->expmismatchI[type2][sq1][sp1];
647 return (
FLT_OR_DBL)(z * P->expninio[2][ul - us]);
655 E_IntLoop_Co(
int type,
669 int energy, ci, cj, cp, cq, d3, d5, d5_2, d3_2, tmm, tmm_2;
673 energy += P->TerminalAU;
676 energy += P->TerminalAU;
681 ci = ON_SAME_STRAND(i, i + 1, cutpoint);
682 cj = ON_SAME_STRAND(j - 1, j, cutpoint);
683 cp = ON_SAME_STRAND(p - 1, p, cutpoint);
684 cq = ON_SAME_STRAND(q, q + 1, cutpoint);
686 d3 = ci ? P->dangle3[type][si1] : 0;
687 d5 = cj ? P->dangle5[type][sj1] : 0;
688 d5_2 = cp ? P->dangle5[type_2][sp1] : 0;
689 d3_2 = cq ? P->dangle3[type_2][sq1] : 0;
691 tmm = (cj && ci) ? P->mismatchExt[type][sj1][si1] : d5 + d3;
692 tmm_2 = (cp && cq) ? P->mismatchExt[type_2][sp1][sq1] : d5_2 + d3_2;
695 return energy + tmm + tmm_2;
700 energy += tmm + tmm_2;
702 energy += (cj && cq) ?
MIN2(tmm + d5_2, tmm_2 + d3) : tmm + tmm_2;
705 }
else if (p - i == 2) {
707 energy += (ci && cp) ?
MIN2(tmm + d3_2, tmm_2 + d5) : tmm + tmm_2;
709 energy +=
MIN2(tmm,
MIN2(tmm_2,
MIN2(d5 + d5_2, d3 + d3_2)));
711 energy +=
MIN2(d3, d5_2);
716 energy +=
MIN2(d5, d3_2);