1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
6 |
|
* redistribute this software in source and binary code form, provided |
7 |
|
* that the following conditions are met: |
8 |
|
* |
9 |
< |
* 1. Acknowledgement of the program authors must be made in any |
10 |
< |
* publication of scientific results based in part on use of the |
11 |
< |
* program. An acceptable form of acknowledgement is citation of |
12 |
< |
* the article in which the program was described (Matthew |
13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
< |
* |
18 |
< |
* 2. Redistributions of source code must retain the above copyright |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
* documentation and/or other materials provided with the |
15 |
|
* distribution. |
28 |
|
* arising out of the use of or inability to use software, even if the |
29 |
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
* such damages. |
31 |
+ |
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
35 |
+ |
* |
36 |
+ |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
+ |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
+ |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
< |
#ifndef MINIMIZERS_OOPSEMINIMIZER_HPP |
44 |
< |
#define MINIMIZERS_OOPSEMINIMIZER_HPP |
43 |
> |
#ifndef MINIMIZERS_MINIMIZER_HPP |
44 |
> |
#define MINIMIZERS_MINIMIZER_HPP |
45 |
|
|
46 |
|
#include <iostream> |
47 |
|
|
47 |
– |
#include "integrators/Integrator.hpp" |
48 |
|
#include "io/DumpWriter.hpp" |
49 |
|
#include "io/StatWriter.hpp" |
50 |
|
#include "minimizers/MinimizerParameterSet.hpp" |
52 |
|
|
53 |
|
// base class of minimizer |
54 |
|
|
55 |
< |
namespace oopse { |
55 |
> |
namespace OpenMD { |
56 |
|
|
57 |
< |
/** @todo need refactorying */ |
58 |
< |
const int MIN_LSERROR = -1; |
59 |
< |
const int MIN_MAXITER = 0; |
60 |
< |
const int MIN_CONVERGE = 1; |
57 |
> |
/** @todo need refactorying */ |
58 |
> |
const int MIN_LSERROR = -1; |
59 |
> |
const int MIN_MAXITER = 0; |
60 |
> |
const int MIN_CONVERGE = 1; |
61 |
|
|
62 |
< |
const int CONVG_UNCONVG = 0; |
63 |
< |
const int CONVG_FTOL = 1; |
64 |
< |
const int CONVG_GTOL = 2; |
65 |
< |
const int CONVG_ABSGTOL = 3; |
66 |
< |
const int CONVG_STEPTOL = 4; |
62 |
> |
const int CONVG_UNCONVG = 0; |
63 |
> |
const int CONVG_FTOL = 1; |
64 |
> |
const int CONVG_GTOL = 2; |
65 |
> |
const int CONVG_ABSGTOL = 3; |
66 |
> |
const int CONVG_STEPTOL = 4; |
67 |
|
|
68 |
< |
const int LS_SUCCEED =1; |
69 |
< |
const int LS_ERROR = -1; |
68 |
> |
const int LS_SUCCEED =1; |
69 |
> |
const int LS_ERROR = -1; |
70 |
|
|
71 |
< |
/** @todo move to math module */ |
72 |
< |
double dotProduct(const std::vector<double>& v1, const std::vector<double>& v2); |
71 |
> |
/** @todo move to math module */ |
72 |
> |
RealType dotProduct(const std::vector<RealType>& v1, const std::vector<RealType>& v2); |
73 |
|
|
74 |
< |
/** |
75 |
< |
* @class Minimizer |
76 |
< |
* base minimizer class |
77 |
< |
*/ |
78 |
< |
class Minimizer { |
79 |
< |
public: |
74 |
> |
/** |
75 |
> |
* @class Minimizer |
76 |
> |
* base minimizer class |
77 |
> |
*/ |
78 |
> |
class Minimizer { |
79 |
> |
public: |
80 |
|
|
81 |
< |
Minimizer(SimInfo *rhs); |
81 |
> |
Minimizer(SimInfo *rhs); |
82 |
|
|
83 |
< |
virtual ~Minimizer(); |
83 |
> |
virtual ~Minimizer(); |
84 |
|
|
85 |
< |
// |
86 |
< |
virtual void init() {} |
85 |
> |
// |
86 |
> |
virtual void init() {} |
87 |
|
|
88 |
< |
//driver function of minimization method |
89 |
< |
virtual void minimize(); |
88 |
> |
//driver function of minimization method |
89 |
> |
virtual void minimize(); |
90 |
|
|
91 |
< |
// |
92 |
< |
virtual int step() = 0; |
91 |
> |
// |
92 |
> |
virtual int step() = 0; |
93 |
|
|
94 |
< |
// |
95 |
< |
virtual void prepareStep() {}; |
94 |
> |
// |
95 |
> |
virtual void prepareStep() {}; |
96 |
|
|
97 |
< |
//line search algorithm, for the time being, we use back track algorithm |
98 |
< |
virtual int doLineSearch(std::vector<double>& direction, double stepSize); |
97 |
> |
//line search algorithm, for the time being, we use back track algorithm |
98 |
> |
virtual int doLineSearch(std::vector<RealType>& direction, RealType stepSize); |
99 |
|
|
100 |
< |
virtual int checkConvg() = 0; |
100 |
> |
virtual int checkConvg() = 0; |
101 |
|
|
102 |
< |
//save the result when minimization method is done |
103 |
< |
virtual void saveResult(){} |
102 |
> |
//save the result when minimization method is done |
103 |
> |
virtual void saveResult(){} |
104 |
|
|
105 |
< |
//get the status of minimization |
106 |
< |
int getMinStatus() {return minStatus;} |
105 |
> |
//get the status of minimization |
106 |
> |
int getMinStatus() {return minStatus;} |
107 |
|
|
108 |
< |
// get the dimension of the model |
109 |
< |
int getDim() { return ndim; } |
108 |
> |
// get the dimension of the model |
109 |
> |
int getDim() { return ndim; } |
110 |
|
|
111 |
< |
//get the name of minimizer method |
112 |
< |
std::string getMinimizerName() { return minimizerName; } |
111 |
> |
//get the name of minimizer method |
112 |
> |
std::string getMinimizerName() { return minimizerName; } |
113 |
|
|
114 |
< |
//return number of current Iteration |
115 |
< |
int getCurIter() { return curIter; } |
114 |
> |
//return number of current Iteration |
115 |
> |
int getCurIter() { return curIter; } |
116 |
|
|
117 |
< |
// set the verbose mode of minimizer |
118 |
< |
void setVerbose(bool verbose) { bVerbose = verbose;} |
117 |
> |
// set the verbose mode of minimizer |
118 |
> |
void setVerbose(bool verbose) { bVerbose = verbose;} |
119 |
|
|
120 |
< |
//get and set the coordinate |
121 |
< |
std::vector<double> getX() { return curX; } |
122 |
< |
void setX(std::vector<double>& x); |
120 |
> |
//get and set the coordinate |
121 |
> |
std::vector<RealType> getX() { return curX; } |
122 |
> |
void setX(std::vector<RealType>& x); |
123 |
|
|
124 |
< |
//get and set the value of object function |
125 |
< |
double getF() { return curF; } |
126 |
< |
void setF(double f) { curF = f; } |
124 |
> |
//get and set the value of object function |
125 |
> |
RealType getF() { return curF; } |
126 |
> |
void setF(RealType f) { curF = f; } |
127 |
|
|
128 |
< |
std::vector<double> getG() { return curG; } |
129 |
< |
void setG(std::vector<double>& g); |
128 |
> |
std::vector<RealType> getG() { return curG; } |
129 |
> |
void setG(std::vector<RealType>& g); |
130 |
|
|
131 |
< |
//get and set the gradient |
132 |
< |
std::vector<double> getGrad() { return curG; } |
133 |
< |
void setGrad(std::vector<double>& g) { curG = g; } |
131 |
> |
//get and set the gradient |
132 |
> |
std::vector<RealType> getGrad() { return curG; } |
133 |
> |
void setGrad(std::vector<RealType>& g) { curG = g; } |
134 |
|
|
135 |
< |
//interal function to evaluate the energy and gradient in OOPSE |
136 |
< |
void calcEnergyGradient(std::vector<double>& x, std::vector<double>& grad, double& |
137 |
< |
energy, int& status); |
135 |
> |
//interal function to evaluate the energy and gradient in OpenMD |
136 |
> |
void calcEnergyGradient(std::vector<RealType>& x, std::vector<RealType>& grad, RealType& |
137 |
> |
energy, int& status); |
138 |
|
|
139 |
< |
//calculate the value of object function |
140 |
< |
virtual void calcF(); |
141 |
< |
virtual void calcF(std::vector<double>& x, double&f, int& status); |
139 |
> |
//calculate the value of object function |
140 |
> |
virtual void calcF(); |
141 |
> |
virtual void calcF(std::vector<RealType>& x, RealType&f, int& status); |
142 |
|
|
143 |
< |
//calculate the gradient |
144 |
< |
virtual void calcG(); |
145 |
< |
virtual void calcG(std::vector<double>& x, std::vector<double>& g, double& f, int& status); |
143 |
> |
//calculate the gradient |
144 |
> |
virtual void calcG(); |
145 |
> |
virtual void calcG(std::vector<RealType>& x, std::vector<RealType>& g, RealType& f, int& status); |
146 |
|
|
147 |
< |
//calculate the hessian |
148 |
< |
//virtual void calcH(int& status); |
149 |
< |
//virtual void calcH(vector<double>& x, std::vector<dobule>& g, SymMatrix& h, int& status); |
147 |
> |
//calculate the hessian |
148 |
> |
//virtual void calcH(int& status); |
149 |
> |
//virtual void calcH(vector<RealType>& x, std::vector<dobule>& g, SymMatrix& h, int& status); |
150 |
|
|
151 |
< |
friend std::ostream& operator<<(std::ostream& os, const Minimizer& minimizer); |
151 |
> |
friend std::ostream& operator<<(std::ostream& os, const Minimizer& minimizer); |
152 |
|
|
153 |
< |
protected: |
153 |
> |
protected: |
154 |
|
|
155 |
< |
// transfrom cartesian and rotational coordinates into minimization coordinates |
156 |
< |
std::vector<double> getCoor(); |
155 |
> |
// transfrom cartesian and rotational coordinates into minimization coordinates |
156 |
> |
std::vector<RealType> getCoor(); |
157 |
|
|
158 |
< |
// transfrom minimization coordinates into cartesian and rotational coordinates |
159 |
< |
void setCoor(std::vector<double>& x); |
158 |
> |
// transfrom minimization coordinates into cartesian and rotational coordinates |
159 |
> |
void setCoor(std::vector<RealType>& x); |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
< |
//constraint the bonds; |
164 |
< |
int shakeR() { return 0;} |
163 |
> |
//constraint the bonds; |
164 |
> |
int shakeR() { return 0;} |
165 |
|
|
166 |
< |
//remove the force component along the bond direction |
167 |
< |
int shakeF() { return 0;} |
166 |
> |
//remove the force component along the bond direction |
167 |
> |
int shakeF() { return 0;} |
168 |
|
|
169 |
< |
double calcPotential(); |
169 |
> |
RealType calcPotential(); |
170 |
|
|
171 |
< |
SimInfo* info; |
171 |
> |
SimInfo* info; |
172 |
|
|
173 |
< |
ForceManager* forceMan; |
173 |
> |
ForceManager* forceMan; |
174 |
|
|
175 |
< |
//parameter set of minimization method |
176 |
< |
MinimizerParameterSet* paramSet; |
175 |
> |
//parameter set of minimization method |
176 |
> |
MinimizerParameterSet* paramSet; |
177 |
|
|
178 |
< |
//flag of turning on shake algorithm |
179 |
< |
bool usingShake; |
178 |
> |
//flag of turning on shake algorithm |
179 |
> |
bool usingShake; |
180 |
|
|
181 |
< |
// dimension of the model |
182 |
< |
int ndim; |
181 |
> |
// dimension of the model |
182 |
> |
int ndim; |
183 |
|
|
184 |
< |
//name of the minimizer |
185 |
< |
std::string minimizerName; |
184 |
> |
//name of the minimizer |
185 |
> |
std::string minimizerName; |
186 |
|
|
187 |
< |
// current iteration number |
188 |
< |
int curIter; |
189 |
< |
//status of minimization |
190 |
< |
int minStatus; |
187 |
> |
// current iteration number |
188 |
> |
int curIter; |
189 |
> |
//status of minimization |
190 |
> |
int minStatus; |
191 |
|
|
192 |
< |
//flag of verbose mode |
193 |
< |
bool bVerbose; |
192 |
> |
//flag of verbose mode |
193 |
> |
bool bVerbose; |
194 |
|
|
195 |
< |
//status of energy and gradient evaluation |
196 |
< |
int egEvalStatus; |
195 |
> |
//status of energy and gradient evaluation |
196 |
> |
int egEvalStatus; |
197 |
|
|
198 |
< |
//initial coordinates |
199 |
< |
//vector<double> initX; |
198 |
> |
//initial coordinates |
199 |
> |
//vector<RealType> initX; |
200 |
|
|
201 |
< |
//current value of the function |
202 |
< |
double curF; |
201 |
> |
//current value of the function |
202 |
> |
RealType curF; |
203 |
|
|
204 |
< |
// current coordinates |
205 |
< |
std::vector<double> curX; |
204 |
> |
// current coordinates |
205 |
> |
std::vector<RealType> curX; |
206 |
|
|
207 |
< |
//gradient at curent coordinates |
208 |
< |
std::vector<double> curG; |
207 |
> |
//gradient at curent coordinates |
208 |
> |
std::vector<RealType> curG; |
209 |
|
|
210 |
< |
//hessian at current coordinates |
211 |
< |
//SymMatrix curH; |
210 |
> |
//hessian at current coordinates |
211 |
> |
//SymMatrix curH; |
212 |
|
|
213 |
< |
private: |
213 |
> |
private: |
214 |
|
|
215 |
< |
//calculate the dimension od the model for minimization |
216 |
< |
void calcDim(); |
215 |
> |
//calculate the dimension od the model for minimization |
216 |
> |
void calcDim(); |
217 |
|
|
218 |
< |
}; |
218 |
> |
}; |
219 |
|
|
220 |
|
} |
221 |
|
#endif |