NAMD
FreeEnergyRestrain.h
Go to the documentation of this file.
1 
7 // written by David Hurwitz, March to May 1998.
8 
9 #if !defined(RESTRAINT_HPP)
10  #define RESTRAINT_HPP
11 
13 
14 //****************************************************************************
15 // ARestraint:
16 //****************************************************************************
17 class ARestraint {
18 //-----------------------------------------------------------------------------
19 // ARestraint is the base class for all restraints
20 // Here's a tree of derived and base classes:
21 // -----------------ARestraint-----------------
22 // / / \ \.
23 // / / \ \.
24 // | | | |
25 // APosRestraint ADistRestraint AnAngleRestraint ADiheRestraint
26 // | | | |
27 // | | | |
28 // AFixedPosRestraint | AFixedAngleRestraint |
29 // ABoundPosRestraint | ABoundAngleRestraint |
30 // AForcingPosRestraint | AForcingAngleRestraint |
31 // | |
32 // AFixedDistRestraint AFixedDiheRestraint
33 // ABoundDistRestraint ABoundDiheRestraint
34 // AForcingDistRestraint AForcingDiheRestraint
35 //-----------------------------------------------------------------------------
36 protected:
37  double m_Kf;
41 
42  // lambda is the same for all forcing restraints
43  static double m_LambdaKf;
44  static double m_LambdaRef;
45 
46 public:
47  ARestraint();
48  virtual ~ARestraint();
49  int GetNumGroups() {return(m_NumGroups);}
50  void SetKf(double Kf) {m_Kf=Kf;}
51  double GetKf() {return(m_Kf);}
52  void SetLambdaKf(double LambdaKf) {m_LambdaKf=LambdaKf;}
53  void SetLambdaRef(double LambdaRef) {m_LambdaRef=LambdaRef;}
54  double GetLambdaKf() {return(m_LambdaKf);}
55  double GetLambdaRef() {return(m_LambdaRef);}
56  void SetGroup(AGroup& Group, int GroupIndex);
57  void SetGroups(AGroup& Group1);
58  void SetGroups(AGroup& Group1, AGroup& Group2);
59  void SetGroups(AGroup& Group1, AGroup& Group2, AGroup& Group3);
60  void SetGroups(AGroup& Group1, AGroup& Group2, AGroup& Group3, AGroup& Group4);
62  void DistributeForce(int WhichGroup, AVector Force, GlobalMasterFreeEnergy& CFE);
63 
64 //---------------- only for testing------------//
65 #if defined(_DEBUG) //
66  void SetCOM(int Index, AVector& Pos); //
67 #endif //
68 //---------------------------------------------//
69 
70  // pure virtual functions
71  virtual AVector GetGradient(int WhichGroup) = 0;
72  virtual double GetEnergy() = 0;
73  virtual void GetStr(char* Str) = 0;
74  virtual void PrintInfo() = 0;
75  // virtual functions that are only meaningful in the forcing restraints
76  virtual Bool_t IsForcing() {return(kFalse);}
77  virtual double Get_dU_dLambda() {return(0.0);}
78  // virtual functions that should only be called in the derived classes
79  virtual void SetRefPos(AVector) {ASSERT(kFalse);}
80  virtual void SetRefDist(double) {ASSERT(kFalse);}
81  virtual void SetRefAngle(double) {ASSERT(kFalse);}
82  virtual void SetBound(Bound_t) {ASSERT(kFalse);}
83  virtual void SetLowerAngle(double) {ASSERT(kFalse);}
84  virtual void SetUpperAngle(double) {ASSERT(kFalse);}
85  virtual void SetIntervalAngle(double) {ASSERT(kFalse);}
86  virtual void SetStartPos(AVector) {ASSERT(kFalse);}
87  virtual void SetStopPos(AVector) {ASSERT(kFalse);}
88  virtual void SetStartDist(double) {ASSERT(kFalse);}
89  virtual void SetStopDist(double) {ASSERT(kFalse);}
90  virtual void SetStartAngle(double) {ASSERT(kFalse);}
91  virtual void SetStopAngle(double) {ASSERT(kFalse);}
92 protected:
93  double GetAngle(AVector& A, AVector& B, AVector& C);
94  double GetDihe(AVector& A, AVector& B, AVector& C, AVector& D);
95  void EarlyExit(const char* Str, int AtomID);
96 };
97 
98 
99 //****************************************************************************
100 // APosRestraint, ADistRestraint, AnAngleRestraint, ADiheRestraint:
101 //****************************************************************************
102 class APosRestraint : public ARestraint {
103 //-------------------------------------------------------------------
104 // APosRestraint is a derived class of ARestraint
105 //-------------------------------------------------------------------
106 public:
107  APosRestraint();
108  void PrintInfo();
109 protected:
110  double GetE(AVector RefPos, double LambdaKf=1.0);
111  AVector GetGrad(int WhichGroup, AVector RefPos, double LambdaKf=1.0);
112 public:
113  // pure virtual functions
114  virtual AVector GetPosTarget() = 0;
115  virtual double GetDistance() = 0;
116 };
117 
118 class ADistRestraint : public ARestraint {
119 //-------------------------------------------------------------------
120 // ADistRestraint is a derived class of ARestraint
121 //-------------------------------------------------------------------
122 public:
123  ADistRestraint();
124  void PrintInfo();
125 protected:
126  double GetE(double RefDist, double LambdaKf=1.0);
127  AVector GetGrad(int WhichGroup, double RefDist, double LambdaKf=1.0);
128 public:
129  virtual double GetDistTarget() = 0;
130 };
131 
132 class AnAngleRestraint : public ARestraint {
133 //-------------------------------------------------------------------
134 // AnAngleRestraint is a derived class of ARestraint
135 //-------------------------------------------------------------------
136 public:
138  void PrintInfo();
139 protected:
140  double GetE(double RefAngle, double LambdaKf=1.0);
141  AVector GetGrad(int WhichGroup, double RefAngle, double LambdaKf=1.0);
142 public:
143  virtual double GetAngleTarget() = 0;
144 };
145 
146 class ADiheRestraint : public ARestraint {
147 //-------------------------------------------------------------------
148 // ADiheRestraint is a derived class of ARestraint
149 //-------------------------------------------------------------------
150 public:
151  ADiheRestraint();
152  void PrintInfo();
153 protected:
154  double GetE(double RefDihe, double Const);
155  AVector GetGrad(int WhichGroup, double RefDihe, double Const);
156  AVector gradU(AVector& P1P2P3, AVector& P4P5P6,
157  AVector& dP1, AVector& dP2, AVector& dP3,
158  AVector& dP4, AVector& dP5, AVector& dP6);
159 public:
160  virtual Bool_t TwoTargets() = 0;
161  virtual double GetDiheTarget1() = 0;
162  virtual double GetDiheTarget2() = 0;
163 };
164 
165 
166 //****************************************************************************
167 // AFixedPosRestraint, ABoundPosRestraint, AForcingPosRestraint:
168 //****************************************************************************
170 //-------------------------------------------------------------------
171 // AFixedPosRestraint is a derived class of APosRestraint
172 //-------------------------------------------------------------------
173 private:
174  AVector m_RefPos;
175 public:
176  void SetRefPos(AVector Pos) {m_RefPos=Pos;}
177  AVector GetRefPos() {return(m_RefPos);}
178  double GetEnergy();
179  AVector GetGradient(int WhichGroup);
180  void GetStr(char* Str) {
181  strcpy(Str, "Fixed Position Restraint");
182  }
183  AVector GetPosTarget() {return(m_RefPos);}
184  double GetDistance() {return(m_RefPos.Dist(m_pCOMs[0]));}
185 };
186 
188 //-------------------------------------------------------------------
189 // ABoundPosRestraint is a derived class of APosRestraint
190 //-------------------------------------------------------------------
191 private:
192  AVector m_RefPos;
193  double m_RefDist;
194  Bound_t m_Bound;
195 public:
196  void SetRefPos(AVector Pos) {m_RefPos=Pos;}
197  void SetRefDist(double Dist) {m_RefDist=Dist;}
198  void SetBound(Bound_t Bound) {m_Bound=Bound;}
199  AVector GetRefPos() {return(m_RefPos);}
200  double GetRefDist() {return(m_RefDist);}
201  Bound_t GetBound() {return(m_Bound);}
202  double GetEnergy();
203  AVector GetGradient(int WhichGroup);
204  void GetStr(char* Str) {
205  strcpy(Str, "Bound Position Restraint");
206  }
207  AVector GetPosTarget() {return(m_RefPos);}
208  double GetDistance() {return(m_RefPos.Dist(m_pCOMs[0]));}
209 };
210 
212 //-------------------------------------------------------------------
213 // AForcingPosRestraint is a derived class of APosRestraint
214 //-------------------------------------------------------------------
215 private:
216  AVector m_StartPos;
217  AVector m_StopPos;
218 public:
219  void SetStartPos(AVector Pos) {m_StartPos=Pos;}
220  void SetStopPos(AVector Pos) {m_StopPos=Pos;}
221  AVector GetStartPos() {return(m_StartPos);}
222  AVector GetStopPos() {return(m_StopPos);}
223  double GetEnergy();
224  AVector GetGradient(int WhichGroup);
225  double Get_dU_dLambda();
226  Bool_t IsForcing() {return(kTrue);}
227  void GetStr(char* Str) {
228  strcpy(Str, "Forcing Position Restraint");
229  }
231  return(m_StopPos*m_LambdaRef + m_StartPos*(1.0-m_LambdaRef));
232  }
233  double GetDistance() {
234  AVector RefPos = m_StopPos*m_LambdaRef + m_StartPos*(1.0-m_LambdaRef);
235  return(RefPos.Dist(m_pCOMs[0]));
236  }
237 };
238 
239 
240 //****************************************************************************
241 // AFixedDistRestraint, ABoundDistRestraint, AForcingDistRestraint:
242 //****************************************************************************
244 //-------------------------------------------------------------------
245 // AFixedDistRestraint is a derived class of ADistRestraint
246 //-------------------------------------------------------------------
247 private:
248  double m_RefDist;
249 public:
250  void SetRefDist(double Dist) {m_RefDist=Dist;}
251  double GetRefDist() {return(m_RefDist);}
252  double GetEnergy();
253  AVector GetGradient(int WhichGroup);
254  void GetStr(char* Str) {
255  strcpy(Str, "Fixed Distance Restraint");
256  }
257  double GetDistTarget() {return(m_RefDist);}
258 };
259 
261 //-------------------------------------------------------------------
262 // ABoundDistRestraint is a derived class of ADistRestraint
263 //-------------------------------------------------------------------
264 private:
265  double m_RefDist;
266  Bound_t m_Bound;
267 public:
268  void SetRefDist(double Dist) {m_RefDist=Dist;}
269  void SetBound(Bound_t Bound) {m_Bound=Bound;}
270  double GetRefDist() {return(m_RefDist);}
271  Bound_t GetBound() {return(m_Bound);}
272  double GetEnergy();
273  AVector GetGradient(int WhichGroup);
274  void GetStr(char* Str) {
275  strcpy(Str, "Bound Distance Restraint");
276  }
277  double GetDistTarget() {return(m_RefDist);}
278 };
279 
281 //-------------------------------------------------------------------
282 // AForcingDistRestraint is a derived class of ADistRestraint
283 //-------------------------------------------------------------------
284 private:
285  double m_StartDist;
286  double m_StopDist;
287 public:
288  void SetStartDist(double Dist) {m_StartDist=Dist;}
289  void SetStopDist(double Dist) {m_StopDist=Dist;}
290  double GetStartDist() {return(m_StartDist);}
291  double GetStopDist() {return(m_StopDist);}
292  double GetEnergy();
293  AVector GetGradient(int WhichGroup);
294  double Get_dU_dLambda();
295  Bool_t IsForcing() {return(kTrue);}
296  void GetStr(char* Str) {
297  strcpy(Str, "Forcing Distance Restraint");
298  }
299  double GetDistTarget() {
300  return(m_StopDist*m_LambdaRef + m_StartDist*(1.0-m_LambdaRef));
301  }
302 };
303 
304 
305 //****************************************************************************
306 // AFixedAngleRestraint, ABoundAngleRestraint, AForcingAngleRestraint:
307 //****************************************************************************
309 //-------------------------------------------------------------------
310 // AFixedAngleRestraint is a derived class of AnAngleRestraint
311 //-------------------------------------------------------------------
312 private:
313  double m_RefAngle; // in radians
314 public:
315  void SetRefAngle(double Angle) {m_RefAngle=Angle;}
316  double GetRefAngle() {return(m_RefAngle);}
317  double GetEnergy();
318  AVector GetGradient(int WhichGroup);
319  void GetStr(char* Str) {
320  strcpy(Str, "Fixed Angle Restraint");
321  }
322  double GetAngleTarget() {return(m_RefAngle);}
323 };
324 
326 //-------------------------------------------------------------------
327 // ABoundAngleRestraint is a derived class of AnAngleRestraint
328 //-------------------------------------------------------------------
329 private:
330  double m_RefAngle; // in radians
331  Bound_t m_Bound;
332 public:
333  void SetRefAngle(double Angle) {m_RefAngle=Angle;}
334  void SetBound(Bound_t Bound) {m_Bound=Bound;}
335  double GetRefAngle() {return(m_RefAngle);}
336  Bound_t GetBound() {return(m_Bound);}
337  double GetEnergy();
338  AVector GetGradient(int WhichGroup);
339  void GetStr(char* Str) {
340  strcpy(Str, "Bound Angle Restraint");
341  }
342  double GetAngleTarget() {return(m_RefAngle);}
343 };
344 
346 //-------------------------------------------------------------------
347 // AForcingAngleRestraint is a derived class of AnAngleRestraint
348 //-------------------------------------------------------------------
349 private:
350  double m_StartAngle; // in radians
351  double m_StopAngle; // in radians
352 public:
353  void SetStartAngle(double Angle) {m_StartAngle=Angle;}
354  void SetStopAngle(double Angle) {m_StopAngle=Angle;}
355  double GetStartAngle() {return(m_StartAngle);}
356  double GetStopAngle() {return(m_StopAngle);}
357  double GetEnergy();
358  AVector GetGradient(int WhichGroup);
359  double Get_dU_dLambda();
360  Bool_t IsForcing() {return(kTrue);}
361  void GetStr(char* Str) {
362  strcpy(Str, "Forcing Angle Restraint");
363  }
364  double GetAngleTarget() {
365  return(m_StopAngle*m_LambdaRef + m_StartAngle*(1.0-m_LambdaRef));
366  }
367 };
368 
369 
370 //****************************************************************************
371 // AFixedDiheRestraint, ABoundDiheRestraint, AForcingDiheRestraint:
372 //****************************************************************************
374 //-------------------------------------------------------------------
375 // AFixedDiheRestraint is a derived class of ADiheRestraint
376 //-------------------------------------------------------------------
377 private:
378  double m_RefAngle; // in radians
379 public:
380  void SetRefAngle(double Angle) {m_RefAngle=Angle;}
381  double GetRefAngle() {return(m_RefAngle);}
382  double GetEnergy();
383  AVector GetGradient(int WhichGroup);
384  void GetStr(char* Str) {
385  strcpy(Str, "Fixed Dihedral Restraint");
386  }
387  Bool_t TwoTargets() {return(kFalse);}
388  double GetDiheTarget1() {return(m_RefAngle);}
389  double GetDiheTarget2() {return(0);}
390 };
391 
393 //-------------------------------------------------------------------
394 // ABoundDiheRestraint is a derived class of ADiheRestraint
395 //-------------------------------------------------------------------
396 private:
397  double m_LowerAngle; // in radians (between 0 and 2pi)
398  double m_UpperAngle; // in radians (between 0 and 2pi)
399  double m_IntervalAngle; // in radians
400 public:
401  void SetLowerAngle(double Angle) {m_LowerAngle=Angle;}
402  void SetUpperAngle(double Angle) {m_UpperAngle=Angle;}
403  void SetIntervalAngle(double Angle) {m_IntervalAngle=Angle;}
404  double GetLowerAngle() {return(m_LowerAngle);}
405  double GetUpperAngle() {return(m_UpperAngle);}
406  double GetIntervalAngle() {return(m_IntervalAngle);}
407  double GetEnergy();
408  AVector GetGradient(int WhichGroup);
409  void GetStr(char* Str) {
410  strcpy(Str, "Bound Dihedral Restraint");
411  }
412  Bool_t TwoTargets() {return(kTrue);}
413  double GetDiheTarget1() {return(m_LowerAngle);}
414  double GetDiheTarget2() {return(m_UpperAngle);}
415 };
416 
418 //-------------------------------------------------------------------
419 // AForcingDiheRestraint is a derived class of ADiheRestraint
420 //-------------------------------------------------------------------
421 private:
422  double m_StartAngle; // in radians
423  double m_StopAngle; // in radians
424 public:
425  void SetStartAngle(double Angle) {m_StartAngle=Angle;}
426  void SetStopAngle(double Angle) {m_StopAngle=Angle;}
427  double GetStartAngle() {return(m_StartAngle);}
428  double GetStopAngle() {return(m_StopAngle);}
429  double GetEnergy();
430  AVector GetGradient(int WhichGroup);
431  double Get_dU_dLambda();
432  Bool_t IsForcing() {return(kTrue);}
433  void GetStr(char* Str) {
434  strcpy(Str, "Forcing Dihedral Restraint");
435  }
436  Bool_t TwoTargets() {return(kFalse);}
437  double GetDiheTarget1() {
438  return(m_StopAngle*m_LambdaRef + m_StartAngle*(1.0-m_LambdaRef));
439  }
440  double GetDiheTarget2() {return(0);}
441 };
442 
443 #endif
444 
void GetStr(char *Str)
struct angle Angle
void SetRefDist(double Dist)
void SetRefPos(AVector Pos)
void SetGroup(AGroup &Group, int GroupIndex)
void SetStartPos(AVector Pos)
AVector GetGrad(int WhichGroup, double RefDihe, double Const)
int AtomID
Definition: NamdTypes.h:29
AVector gradU(AVector &P1P2P3, AVector &P4P5P6, AVector &dP1, AVector &dP2, AVector &dP3, AVector &dP4, AVector &dP5, AVector &dP6)
virtual void SetRefPos(AVector)
double GetE(double RefAngle, double LambdaKf=1.0)
void SetStartAngle(double Angle)
AVector GetGradient(int WhichGroup)
void SetRefAngle(double Angle)
const BigReal A
Definition: Vector.h:64
virtual void SetStopAngle(double)
virtual void SetBound(Bound_t)
double GetDihe(AVector &A, AVector &B, AVector &C, AVector &D)
virtual void SetIntervalAngle(double)
virtual ~ARestraint()
virtual void PrintInfo()=0
double GetE(double RefDist, double LambdaKf=1.0)
double GetE(AVector RefPos, double LambdaKf=1.0)
virtual double GetDiheTarget1()=0
void GetStr(char *Str)
void SetStartDist(double Dist)
virtual void SetStopPos(AVector)
virtual void SetRefAngle(double)
void SetLambdaKf(double LambdaKf)
int Index
Definition: structures.h:26
void SetStopPos(AVector Pos)
virtual double GetDistTarget()=0
virtual void SetStartDist(double)
void SetBound(Bound_t Bound)
AVector GetGradient(int WhichGroup)
virtual double GetEnergy()=0
Bool_t
double GetLambdaKf()
double GetAngle(AVector &A, AVector &B, AVector &C)
void SetRefAngle(double Angle)
double GetLambdaRef()
#define ASSERT(E)
Bound_t
AVector GetGrad(int WhichGroup, double RefAngle, double LambdaKf=1.0)
virtual void SetRefDist(double)
virtual double Get_dU_dLambda()
AVector GetGradient(int WhichGroup)
virtual double GetDiheTarget2()=0
void SetStartAngle(double Angle)
void DistributeForce(int WhichGroup, AVector Force, GlobalMasterFreeEnergy &CFE)
AVector GetGradient(int WhichGroup)
virtual Bool_t TwoTargets()=0
virtual void SetStopDist(double)
AVector GetGradient(int WhichGroup)
virtual AVector GetPosTarget()=0
AVector GetGradient(int WhichGroup)
void GetStr(char *Str)
static double m_LambdaRef
AVector GetGrad(int WhichGroup, AVector RefPos, double LambdaKf=1.0)
AVector GetGradient(int WhichGroup)
virtual void SetStartPos(AVector)
AVector GetGrad(int WhichGroup, double RefDist, double LambdaKf=1.0)
void UpdateCOMs(GlobalMasterFreeEnergy &CFE)
void SetGroups(AGroup &Group1)
void SetStopAngle(double Angle)
AVector GetGradient(int WhichGroup)
AVector GetGradient(int WhichGroup)
void SetLowerAngle(double Angle)
void SetUpperAngle(double Angle)
static double m_LambdaKf
void SetBound(Bound_t Bound)
void EarlyExit(const char *Str, int AtomID)
AVector GetGradient(int WhichGroup)
void SetLambdaRef(double LambdaRef)
void SetRefDist(double Dist)
double GetE(double RefDihe, double Const)
const BigReal B
void SetRefDist(double Dist)
virtual Bool_t IsForcing()
void SetStopAngle(double Angle)
double Dist()
void SetBound(Bound_t Bound)
void SetRefAngle(double Angle)
void SetIntervalAngle(double Angle)
void GetStr(char *Str)
virtual void SetStartAngle(double)
virtual void SetLowerAngle(double)
virtual void SetUpperAngle(double)
void SetKf(double Kf)
virtual void GetStr(char *Str)=0
AVector GetGradient(int WhichGroup)
void SetStopDist(double Dist)
AVector GetGradient(int WhichGroup)
virtual double GetDistance()=0
void SetRefPos(AVector Pos)
void GetStr(char *Str)
AGroup * m_pGroups
virtual double GetAngleTarget()=0
void GetStr(char *Str)
virtual AVector GetGradient(int WhichGroup)=0
AVector * m_pCOMs