IntaRNA 3.4.1
RNA-RNA interaction prediction | C++ API
Loading...
Searching...
No Matches
general.h
Go to the documentation of this file.
1
2#ifndef INTARNA_GENERAL_H_
3#define INTARNA_GENERAL_H_
4
5
7
8#ifdef HAVE_CONFIG_H
9 #include "config.h"
10#endif
11
12#include "IntaRNA/intarna_config.h"
13
14#include <algorithm>
15#include <cassert>
16
18#if defined(_DEBUG) || !defined(NDEBUG)
19 #define INTARNA_IN_DEBUG_MODE 1
20#else
21 #define INTARNA_IN_DEBUG_MODE 0
22#endif
23
25
26#include "easylogging++.h"
27
29
30template<class T> void INTARNA_CLEANUP( T *& pointer) { if (pointer != NULL) {delete pointer; pointer=NULL;} }
31
33
34#include <stdexcept>
35
36 #define INTARNA_NOT_IMPLEMENTED(message) \
37 throw std::runtime_error( \
38 std::string("\nSTOP DUE TO MISSING IMPLEMENTATION : ") \
39 + message \
40 );
41
43
44#include <stdexcept>
45
46 #define INTARNA_CHECK_NOT_NULL(pointer,message) if (pointer == NULL) { \
47 throw std::runtime_error( \
48 std::string("\nSTOP DUE TO NULL POINTER : ") \
49 + message \
50 ); }
51
52
54
55#include <boost/lexical_cast.hpp>
56
57 #ifdef toString
58 #error toString already defined
59 #endif
60 #define toString( x ) boost::lexical_cast<std::string>(x)
61
62
64
65#include <cmath>
66#include <limits>
67
68#if INTARNA_MULTIPRECISION
69 #include <boost/multiprecision/float128.hpp>
70#endif
71
72namespace IntaRNA {
73
75 typedef float E_kcal_type;
76
78 typedef int E_type;
79 const E_type E_INF = (std::numeric_limits<E_type>::max() / 8) + 1;
80 const E_type E_MAX = E_INF / 2;
81
83#if INTARNA_MULTIPRECISION
84 typedef boost::multiprecision::float128 Z_type;
85 #define Z_log boost::multiprecision::log
86 #define Z_exp boost::multiprecision::exp
87#else
88 typedef double Z_type;
89 #define Z_log std::log
90 #define Z_exp std::exp
91#endif
92 const Z_type Z_INF = std::numeric_limits<Z_type>::infinity();
93
94} // namespace
95
96#ifdef IntaRNA_precisionEpsilon
97 #error IntaRNA_precisionEpsilon already defined
98#endif
101#define IntaRNA_precisionEpsilon std::sqrt(std::numeric_limits<float>::min())
102
103#ifdef E_2_Ekcal
104 #error E_2_Ekcal already defined
105#endif
107#define E_2_Ekcal( e ) ( static_cast<E_kcal_type>(e) / 100.0 )
108
109#ifdef Ekcal_2_E
110 #error Ekcal_2_E already defined
111#endif
113#define Ekcal_2_E( e ) ( static_cast<E_type>(e * 100) )
114
115#ifdef E_2_Z
116 #error E_2_Z already defined
117#endif
119#define E_2_Z( e ) ( static_cast<Z_type>(e) / 100.0 )
120
121#ifdef Z_2_E
122 #error Z_2_E already defined
123#endif
125#define Z_2_E( e ) ( static_cast<E_type>(e * 100) )
126
127#ifdef E_equal
128 #error E_equal already defined
129#endif
131#define E_equal( e1, e2 ) ( e1 == e2 )
132
133#ifdef E_isNotINF
134 #error E_isNotINF already defined
135#endif
137#define E_isNotINF( e ) ( E_INF > e )
138
139#ifdef E_isINF
140 #error E_isINF already defined
141#endif
143#define E_isINF( e ) ( E_INF <= e )
144
145
146
147#ifdef Z_equal
148 #error Z_equal already defined
149#endif
151#if INTARNA_MULTIPRECISION
152 #define Z_equal( e1, e2 ) ( boost::multiprecision::abs((e1)-(e2)) < IntaRNA_precisionEpsilon)
153#else
154 #define Z_equal( e1, e2 ) ( std::abs((e1)-(e2)) < IntaRNA_precisionEpsilon)
155#endif
156// another option from http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon
157//#define Z_equal_ULP 2
158//#define Z_equal( e1, e2 ) ( \
159// /* the machine epsilon has to be scaled to the magnitude of the values used */ \
160// /* and multiplied by the desired precision in ULPs (units in the last place) */ \
161// std::abs(e1-e2) < std::numeric_limits<T>::epsilon() * std::abs(e1+e2) * Z_equal_ULP \
162// /* unless the result is subnormal */ \
163// || std::abs(e1-e2) < std::numeric_limits<T>::min() \
164//)
165
166#ifdef Z_isNotINF
167 #error Z_isNotINF already defined
168#endif
170#define Z_isNotINF( e ) ( std::numeric_limits<Z_type>::max() >= e )
171
172#ifdef Z_isINF
173 #error Z_isINF already defined
174#endif
176#define Z_isINF( e ) ( std::numeric_limits<Z_type>::max() < e )
177
178
180
181#include <iostream>
182#include <string>
183
184namespace IntaRNA {
185
201std::ostream *
202newOutputStream( const std::string & outName );
203
204
212void
213deleteOutputStream( std::ostream *& outStream );
214
229std::istream *
230newInputStream( const std::string & inName );
231
232
240void
241deleteInputStream( std::istream *& inStream );
242
243} // namespace
244
245#endif /* GENERAL_H_ */
void INTARNA_CLEANUP(T *&pointer)
Definition general.h:30
Definition Accessibility.h:13
void deleteInputStream(std::istream *&inStream)
int E_type
type for energy values (energy + accessibility [ED]) (internally)
Definition general.h:78
float E_kcal_type
type for energy values in kcal/mol units for in-/output only
Definition general.h:75
std::istream * newInputStream(const std::string &inName)
double Z_type
type for probabilities, RT and Boltzmann values
Definition general.h:88
const Z_type Z_INF
Definition general.h:92
void deleteOutputStream(std::ostream *&outStream)
std::ostream * newOutputStream(const std::string &outName)
const E_type E_MAX
Definition general.h:80
const E_type E_INF
Definition general.h:79