23 #include <openbabel/babelconfig.h> 28 #if TIME_WITH_SYS_TIME 42 #define M_PI 3.14159265358979323846 71 return((stop - start) / (
double) CLOCKS_PER_SEC);
77 gettimeofday(&start, NULL);
82 gettimeofday(&stop, NULL);
83 return((stop.tv_sec - start.tv_sec)
84 + (stop.tv_usec - start.tv_usec)/1000000.0);
100 double _max,_incr,*_tbl;
103 _max(0.0), _incr(0.0), _tbl(NULL)
110 _max(max*max), _incr(incr), _tbl(NULL)
127 return((d2 < _max) ? _tbl[static_cast<int>(d2*_incr)]:sqrt(d2));
134 void Init(
double max,
double incr)
144 _tbl =
new double [
static_cast<int>((_max/_incr)+10)];
145 for (r = (_incr/2.0),i=0;r <= _max;r += _incr,++i)
156 OBAPI
double calc_rms(
double*,
double*,
unsigned int);
160 OBAPI
double calc_rms(
double*,
double*,
unsigned int);
167 OBAPI
void ToUpper(std::string&);
169 OBAPI
void ToLower(std::string&);
189 OBAPI
bool IsNear(
const double &,
const double &,
const double epsilon=2e-6);
196 OBAPI
bool IsNearZero(
const double &,
const double epsilon=2e-6);
197 OBAPI
bool IsNan(
const double &);
205 const double precision = 1e-11)
207 return( fabs(a) <= precision * fabs(b) );
226 OBAPI
inline bool IsApprox(
const double & a,
const double & b,
227 const double precision = 1e-11)
229 return( fabs(a - b) <= precision * std::min<const double>( fabs(a), fabs(b) ) );
233 const double precision = 1e-11)
235 return( fabs(a - b) <= precision * std::min<const double>( a, b ) );
242 OBAPI
bool SafeOpen(std::ifstream &fs,
const char *filename);
243 OBAPI
bool SafeOpen(std::ofstream &fs,
const char *filename);
250 template <
class T1,
class T2,
class T3>
267 first(T1()),second(T2()),third(T3())
271 triple(
const T1 &a,
const T2 &b,
const T3 &c):
272 first(a), second(b), third(c)
276 template<
class U,
class V,
class W>
278 first(t.first), second(t.second), third(t.third)
286 template <
class T1,
class T2,
class T3,
class T4>
305 first(T1()),second(T2()),third(T3()),fourth(T4())
309 quad(
const T1 &a,
const T2 &b,
const T3 &c,
const T4 &d):
310 first(a), second(b), third(c), fourth(d)
314 template<
class U,
class V,
class W,
class X>
316 first(q.first), second(q.second), third(q.third), fourth(q.fourth)
T3 third_type
Definition: obutil.h:292
bool IsNear(const double &, const double &, const double epsilon=2e-6)
Comparison for doubles: returns fabs(a - b) < epsilon.
Definition: obutil.cpp:80
T2 second_type
Definition: obutil.h:255
~OBSqrtTbl()
Definition: obutil.h:114
bool OBCompareInt(const int &a, const int &b)
Definition: obutil.cpp:68
bool IsNan(const double &)
Comparison for nan (not a number)
Definition: obutil.cpp:92
quad(const quad< U, V, W, X > &q)
copy constructor with implicit conversions
Definition: obutil.h:315
T1 first
Definition: obutil.h:259
T2 second
Definition: obutil.h:297
T4 fourth
Definition: obutil.h:299
OBSqrtTbl()
Definition: obutil.h:102
quad(const T1 &a, const T2 &b, const T3 &c, const T4 &d)
constructor for 3 values
Definition: obutil.h:309
T2 second
Definition: obutil.h:260
A 4-element templated, based on the design of the STL pair<>
Definition: obutil.h:287
T3 third_type
Definition: obutil.h:256
T3 third
Definition: obutil.h:261
bool IsApprox(const double &a, const double &b, const double precision=1e-11)
Definition: obutil.h:226
double Sqrt(double d2) const
Fast square root calculation using a lookup table.
Definition: obutil.h:124
triple()
Definition: obutil.h:266
A 3-element templated, based on the design of the STL pair<>
Definition: obutil.h:251
void rotate_coords(double *, double m[3][3], unsigned)
Square Root lookup table - given a distance squared returns distance.
Definition: obutil.h:98
bool SafeOpen(std::ifstream &fs, const char *filename)
Definition: obutil.cpp:295
double calc_rms(double *, double *, unsigned int)
Calculate the RMS deviation between the first N coordinates of *r and *f.
Definition: obutil.cpp:173
double Elapsed()
Definition: obutil.h:89
bool IsNearZero(const double &, const double epsilon=2e-6)
Comparison for doubles: returns fabs(a) < epsilon.
Definition: obutil.cpp:86
void Init(double max, double incr)
Initialize the square root lookup table.
Definition: obutil.h:134
OBSqrtTbl(const double max, const double incr)
Create a square root table to handle up to the square root of max (e.g., if you want the square root ...
Definition: obutil.h:109
bool IsNegligible(const double &a, const double &b, const double precision=1e-11)
Definition: obutil.h:204
double Lap()
Definition: obutil.h:80
quad()
Definition: obutil.h:304
triple(const T1 &a, const T2 &b, const T3 &c)
Constructor for 3 values.
Definition: obutil.h:271
T1 first_type
Definition: obutil.h:290
T3 third
Definition: obutil.h:298
bool IsApprox_pos(const double &a, const double &b, const double precision=1e-11)
Same as IsApprox(), but only for positive numbers. Faster.
Definition: obutil.h:232
void CleanAtomType(char *)
"Clean" the supplied atom type
Definition: obutil.cpp:427
T1 first
Definition: obutil.h:296
Stopwatch class used for timing length of execution.
Definition: obutil.h:49
void ToLower(std::string &)
Shift the supplied string to lowercase.
Definition: obutil.cpp:379
void InvertCase(std::string &, int)
T4 fourth_type
Definition: obutil.h:293
T2 second_type
Definition: obutil.h:291
triple(const triple< U, V, W > &t)
Copy constructor with implicit conversions.
Definition: obutil.h:277
bool CanBeSquared(const double &)
Tests whether its argument can be squared without triggering an overflow or underflow.
Definition: obutil.cpp:99
T1 first_type
Definition: obutil.h:254
bool OBCompareUnsigned(const unsigned int &a, const unsigned int &b)
Definition: obutil.cpp:74
Global namespace for all Open Babel code.
Definition: alias.h:22
void ToUpper(std::string &)
Shift the supplied string to uppercase.
Definition: obutil.cpp:359