-
Notifications
You must be signed in to change notification settings - Fork 0
/
min.hpp
executable file
·106 lines (79 loc) · 2.11 KB
/
min.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once
#ifndef MIN_H
#define MIN_H
#include <cassert>
#include <cmath>
#include <numeric>
#include <vector>
#include "INM.hpp"
class Function {
public:
Function(size_t dim_) :
dim(dim_),
grad(dim_, 0) {
}
double operator () (std::vector<double> const& params) {
return calculate(params);
}
double calculate(std::vector<double> const& params) {
assert(params.size() == dim);
return calc_(params);
}
size_t ndim() const {
return dim;
}
virtual std::vector<double> const& gradient(std::vector<double> const& params) {
assert(params.size() == dim);
return grad_(params);
}
protected:
size_t dim;
std::vector<double> grad;
private:
virtual double calc_(std::vector<double> const& params) = 0;
virtual std::vector<double> const& grad_(std::vector<double> const& params) = 0;
};
class ENM : public Function {
public:
ENM(Structure const& molstruct, double max = 10);
private:
virtual double calc_(std::vector<double> const& params);
virtual std::vector<double> const& grad_(std::vector<double> const& params);
void gradInt(Interaction const& inter, std::vector<double> const& positions);
double cutoff;
std::vector<Interaction> interactions;
};
class INM : public Function {
public:
INM(Structure const& molstruct, std::vector<ENM> nrgs);
void setDelta(double newdelta);
private:
virtual double calc_(std::vector<double> const& params);
virtual std::vector<double> const& grad_(std::vector<double> const& params);
double delta;
double qdelta;
std::vector<ENM> enms;
};
template<typename T>
double dist(T const * id1, T const * id2, size_t range) {
T val = T();
T temp = T();
for(size_t i = 0; i < range; ++i) {
temp = *(id1+i) - *(id2+i);
val += temp*temp;
}
return sqrt(val);
}
template<typename T>
T normsq(std::vector<T> const& vec) {
return std::inner_product(vec.begin(), vec.end(), vec.begin(), T());
}
template<typename T>
double norm(std::vector<T> const& vec) {
return sqrt(normsq(vec));
}
template<typename T>
double grms(std::vector<T> const& vec) {
return sqrt(normsq(vec) / vec.size());
}
#endif