LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
Loading...
Searching...
No Matches
spring_functions.hpp
1/*
2 This file is part of LOOS.
3
4 LOOS (Lightweight Object-Oriented Structure library)
5 Copyright (c) 2010 Tod D. Romo
6 Department of Biochemistry and Biophysics
7 School of Medicine & Dentistry, University of Rochester
8
9 This package (LOOS) is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation under version 3 of the License.
12
13 This package is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23
28#if !defined(LOOS_SPRING_FUNCTIONS_HPP)
29#define LOOS_SPRING_FUNCTIONS_HPP
30
31
32
33
34#include <loos.hpp>
35
36
37namespace ENM {
38
39 // Exceptions classes (primarily for springFactory())
41 class BadSpringFunction : public std::runtime_error
42 {
43 public:
44 BadSpringFunction(const std::string& s) : runtime_error(s) { }
45 };
46
48 class BadSpringParameter : public std::runtime_error
49 {
50 public:
51 BadSpringParameter(const std::string& s) : runtime_error(s) { }
52 };
53
54
55
57
76 public:
77 typedef std::vector<double> Params;
78 public:
79 SpringFunction() : warned(false) { }
80 virtual ~SpringFunction() { }
81
83 virtual std::string name() const =0;
84
86 virtual Params setParams(const Params& konst) =0;
87
89 virtual bool validParams() const =0;
90
92 virtual uint paramSize() const =0;
93
94
95
97 virtual loos::DoubleMatrix constant(const loos::GCoord& u, const loos::GCoord& v, const loos::GCoord& d) =0;
98
99 protected:
100
102
105 double checkConstant(double d) {
106 if (d < 0.0) {
107 if (!warned) {
108 warned = true;
109 std::cerr << "Warning- negative spring constants found in " << name() << ". Setting to 0.\n";
110 }
111 d = 0.0;
112 }
113
114 return(d);
115 }
116
117 private:
118 bool warned;
119 };
120
121
122
124
135 public:
136
138 double k = checkConstant(constantImpl(u, v, d));
139 loos::DoubleMatrix B(3, 3);
140 for (uint i=0; i<9; ++i)
141 B[i] = k;
142
143 return(B);
144 }
145
146 private:
147
149 virtual double constantImpl(const loos::GCoord& u, const loos::GCoord& v, const loos::GCoord& d) =0;
150 };
151
152
153
154 // The following are all uniform spring constants...
155
156
158
166 public:
167 DistanceCutoff(const double& r) : radius(r*r) { }
168 DistanceCutoff() : radius(15.0*15.0) { }
169
170 std::string name() const { return("DistanceCutoff"); }
171
172 Params setParams(const Params& p) {
173 if (p.size() < 1)
174 throw(BadSpringParameter("Insufficient number of spring parameters"));
175
176 Params q(p);
177 radius = q.back();
178 radius *= radius;
179 q.pop_back();
180 return(q);
181 }
182
183 bool validParams() const { return(radius > 0.0); }
184
185 uint paramSize() const { return(1); }
186
187 double constantImpl(const loos::GCoord& u, const loos::GCoord& v, const loos::GCoord& d) {
188 double s = d.length2();
189 if (s <= radius)
190 return(1./s);
191
192 return(0.0);
193 }
194
195 private:
196 double radius;
197 };
198
199
202 public:
203 DistanceWeight(const double p) : power(p) { }
204 DistanceWeight() : power(-2.0) { }
205
206 std::string name() const { return("DistanceWeight"); }
207
208
209 Params setParams(const Params& p) {
210 if (p.size() < 1)
211 throw(BadSpringParameter("Insufficient number of spring parameters"));
212
213 Params q(p);
214 power = q.back();
215 q.pop_back();
216 return(q);
217 }
218
219 bool validParams() const { return(power < 0.0); }
220
221 uint paramSize() const { return(1); }
222
223
224 double constantImpl(const loos::GCoord& u, const loos::GCoord& v, const loos::GCoord& d) {
225 double s = d.length();
226 return(pow(s, power));
227 }
228
229 private:
230 double power;
231 };
232
233
234
235
238 public:
239 ExponentialDistance(const double s) : scale(s) { }
240 ExponentialDistance() : scale(-1.5) { }
241
242 std::string name() const { return("ExponentialDistance"); }
243
244 Params setParams(const Params& p) {
245 if (p.size() < 1)
246 throw(BadSpringParameter("Insufficient number of spring parameters"));
247
248 Params q(p);
249 scale = q.back();
250 q.pop_back();
251 return(q);
252 }
253
254 bool validParams() const { return(scale != 0.0); }
255
256 uint paramSize() const { return(1); }
257
258
259 double constantImpl(const loos::GCoord& u, const loos::GCoord& v, const loos::GCoord& d) {
260 double s = d.length();
261 return(exp(scale * s));
262 }
263
264 private:
265 double scale;
266 };
267
268
269
270
271
273
284 class HCA : public UniformSpringFunction {
285 public:
286 HCA(const double rc, const double a, const double b, const double c, const double d) :
287 rcut(rc), k1(a), k2(b), k3(c), k4(d) { }
288
289 HCA() :
290 rcut(4.0), k1(205.5), k2(571.2), k3(305.9e3), k4(6.0) { }
291
292 std::string name() const { return("HCA"); }
293
294 Params setParams(const Params& p) {
295 if (p.size() < 5)
296 throw(BadSpringParameter("Insufficient number of spring parameters"));
297
298 Params q(p);
299
300 k4 = q.back();
301 q.pop_back();
302
303 k3 = q.back();
304 q.pop_back();
305
306 k2 = q.back();
307 q.pop_back();
308
309 k1 = q.back();
310 q.pop_back();
311
312 rcut = q.back();
313 q.pop_back();
314
315 return(q);
316 }
317
318 bool validParams() const { return(rcut >= 0.0 && k4 >= 0.0); }
319
320 uint paramSize() const { return(5); }
321
322
323 double constantImpl(const loos::GCoord& u, const loos::GCoord& v, const loos::GCoord& d) {
324 double s = d.length();
325 double k;
326
327 if (s <= rcut)
328 k = k1 * s - k2;
329 else
330 k = k3 * pow(s, -k4);
331
332 return(k);
333 }
334
335 private:
336 double rcut, k1, k2, k3, k4;
337 };
338
341public:
342 ConstBonded(const double& s) : scale(s) { }
343 ConstBonded() : scale(1) { }
344
345 std::string name() const { return("ConstBonded"); }
346
347 Params setParams(const Params& p) {
348 if (p.size() < 1)
349 throw(BadSpringParameter("Insufficient number of spring parameters"));
350
351 Params q(p);
352 scale = q.back();
353 q.pop_back();
354 return(q);
355 }
356
357 bool validParams() const { return(scale > 0.0); }
358
359 uint paramSize() const { return(1); }
360
361 double constantImpl(const loos::GCoord& u, const loos::GCoord& v, const loos::GCoord& d) {
362 //std::cerr << "In impl in constbonded :)\n";
363 return(scale);
364 }
365
366private:
367 double scale;
368};
369
371 SpringFunction* springFactory(const std::string& spring_desc);
372
374 std::vector<std::string> springNames();
375
376};
377
378#endif
379
Bad spring function was requested.
Definition spring_functions.hpp:42
Unspecified problem with parameters in SpringFunction.
Definition spring_functions.hpp:49
Use a spring function that is a constant weight regardless of distance.
Definition spring_functions.hpp:340
std::string name() const
Name for this particular spring function.
Definition spring_functions.hpp:345
Params setParams(const Params &p)
Sets the internal constants, returning the unused ones.
Definition spring_functions.hpp:347
double constantImpl(const loos::GCoord &u, const loos::GCoord &v, const loos::GCoord &d)
Implementation of the spring constant calculation.
Definition spring_functions.hpp:361
uint paramSize() const
How many internal constants there are.
Definition spring_functions.hpp:359
bool validParams() const
Determines if the internal constants are "valid".
Definition spring_functions.hpp:357
Basic distance cutoff for "traditional" ENM.
Definition spring_functions.hpp:165
uint paramSize() const
How many internal constants there are.
Definition spring_functions.hpp:185
bool validParams() const
Determines if the internal constants are "valid".
Definition spring_functions.hpp:183
Params setParams(const Params &p)
Sets the internal constants, returning the unused ones.
Definition spring_functions.hpp:172
double constantImpl(const loos::GCoord &u, const loos::GCoord &v, const loos::GCoord &d)
Implementation of the spring constant calculation.
Definition spring_functions.hpp:187
std::string name() const
Name for this particular spring function.
Definition spring_functions.hpp:170
Distance weighting (i.e. )
Definition spring_functions.hpp:201
Params setParams(const Params &p)
Sets the internal constants, returning the unused ones.
Definition spring_functions.hpp:209
double constantImpl(const loos::GCoord &u, const loos::GCoord &v, const loos::GCoord &d)
Implementation of the spring constant calculation.
Definition spring_functions.hpp:224
uint paramSize() const
How many internal constants there are.
Definition spring_functions.hpp:221
bool validParams() const
Determines if the internal constants are "valid".
Definition spring_functions.hpp:219
std::string name() const
Name for this particular spring function.
Definition spring_functions.hpp:206
Exponential distance weighting (i.e. )
Definition spring_functions.hpp:237
uint paramSize() const
How many internal constants there are.
Definition spring_functions.hpp:256
Params setParams(const Params &p)
Sets the internal constants, returning the unused ones.
Definition spring_functions.hpp:244
double constantImpl(const loos::GCoord &u, const loos::GCoord &v, const loos::GCoord &d)
Implementation of the spring constant calculation.
Definition spring_functions.hpp:259
bool validParams() const
Determines if the internal constants are "valid".
Definition spring_functions.hpp:254
std::string name() const
Name for this particular spring function.
Definition spring_functions.hpp:242
HCA method (bimodal distance-based function)
Definition spring_functions.hpp:284
Params setParams(const Params &p)
Sets the internal constants, returning the unused ones.
Definition spring_functions.hpp:294
double constantImpl(const loos::GCoord &u, const loos::GCoord &v, const loos::GCoord &d)
Implementation of the spring constant calculation.
Definition spring_functions.hpp:323
bool validParams() const
Determines if the internal constants are "valid".
Definition spring_functions.hpp:318
uint paramSize() const
How many internal constants there are.
Definition spring_functions.hpp:320
std::string name() const
Name for this particular spring function.
Definition spring_functions.hpp:292
Interface for ENM spring functions.
Definition spring_functions.hpp:75
virtual loos::DoubleMatrix constant(const loos::GCoord &u, const loos::GCoord &v, const loos::GCoord &d)=0
Actually compute the spring constant as a 3x3 matrix.
virtual uint paramSize() const =0
How many internal constants there are.
double checkConstant(double d)
Check for negative spring-constants.
Definition spring_functions.hpp:105
virtual std::string name() const =0
Name for this particular spring function.
virtual Params setParams(const Params &konst)=0
Sets the internal constants, returning the unused ones.
virtual bool validParams() const =0
Determines if the internal constants are "valid".
Spring functions that are uniform in all directions (ie return a single value)
Definition spring_functions.hpp:134
loos::DoubleMatrix constant(const loos::GCoord &u, const loos::GCoord &v, const loos::GCoord &d)
Actually compute the spring constant as a 3x3 matrix.
Definition spring_functions.hpp:137
Simple matrix template class using policy classes to determine behavior.
Definition MatrixImpl.hpp:148
Namespace to encapsulate Elastic Network Model routines.
Definition anm-lib.hpp:32
std::vector< std::string > springNames()
List of possible names for springFactory()
Definition spring_functions.cpp:76
SpringFunction * springFactory(const std::string &spring_desc)
Factory function for generating new SpringFunction instances based on a user string.
Definition spring_functions.cpp:36