RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
NMCriteria.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13#ifndef _RBTNMCRITERIA_H_
14#define _RBTNMCRITERIA_H_
15
16#include <loguru.hpp>
17
18#include <cmath>
19#include <limits>
20
21namespace rxdock {
22
23namespace neldermead {
24
26private:
27 int m_maxIterations;
28
29public:
30 IterationCriterion(long max_iterations) : m_maxIterations(max_iterations) {}
31
32 template <class State> bool operator()(const State &state) {
33 bool result = state.iteration < m_maxIterations;
34 LOG_F(1, "IterationCriteria: {}", result);
35 return result;
36 }
37};
38
39template <class DataType> class RelativeValueCriterion {
40private:
41 DataType m_ftol;
42
43public:
44 RelativeValueCriterion(DataType ftol) : m_ftol(ftol) {}
45
46 template <class State> bool operator()(const State &state) {
47 bool result =
48 2 * std::abs(state.currentValue - state.formerValue) /
49 (std::abs(state.currentValue) + std::abs(state.formerValue) +
50 std::numeric_limits<DataType>::epsilon()) >
51 m_ftol;
52 LOG_F(1, "RelativeValueCriterion: {}", result);
53 return result;
54 }
55};
56
57template <class Criteria1, class Criteria2> class AndCriteria {
58private:
59 Criteria1 m_criteria1;
60 Criteria2 m_criteria2;
61
62public:
63 AndCriteria(const Criteria1 &criteria1, const Criteria2 &criteria2)
64 : m_criteria1(criteria1), m_criteria2(criteria2) {}
65
66 template <class State> bool operator()(const State &state) {
67 return m_criteria1(state) && m_criteria2(state);
68 }
69};
70
71template <class Criteria1, class Criteria2>
73CreateAndCriteria(const Criteria1 &criteria1, const Criteria2 &criteria2) {
74 return AndCriteria<Criteria1, Criteria2>(criteria1, criteria2);
75}
76
77} // namespace neldermead
78
79} // namespace rxdock
80
81#endif /* _RBTNMCRITERIA_H_ */
Definition NMCriteria.h:57
Definition NMCriteria.h:25
Definition NMState.h:27