NAMD
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ARestraint Class Referenceabstract

#include <FreeEnergyRestrain.h>

Inheritance diagram for ARestraint:
ADiheRestraint ADistRestraint AnAngleRestraint APosRestraint ABoundDiheRestraint AFixedDiheRestraint AForcingDiheRestraint ABoundDistRestraint AFixedDistRestraint AForcingDistRestraint ABoundAngleRestraint AFixedAngleRestraint AForcingAngleRestraint ABoundPosRestraint AFixedPosRestraint AForcingPosRestraint

Public Member Functions

 ARestraint ()
 
virtual ~ARestraint ()
 
int GetNumGroups ()
 
void SetKf (double Kf)
 
double GetKf ()
 
void SetLambdaKf (double LambdaKf)
 
void SetLambdaRef (double LambdaRef)
 
double GetLambdaKf ()
 
double GetLambdaRef ()
 
void SetGroup (AGroup &Group, int GroupIndex)
 
void SetGroups (AGroup &Group1)
 
void SetGroups (AGroup &Group1, AGroup &Group2)
 
void SetGroups (AGroup &Group1, AGroup &Group2, AGroup &Group3)
 
void SetGroups (AGroup &Group1, AGroup &Group2, AGroup &Group3, AGroup &Group4)
 
void UpdateCOMs (GlobalMasterFreeEnergy &CFE)
 
void DistributeForce (int WhichGroup, AVector Force, GlobalMasterFreeEnergy &CFE)
 
virtual AVector GetGradient (int WhichGroup)=0
 
virtual double GetEnergy ()=0
 
virtual void GetStr (char *Str)=0
 
virtual void PrintInfo ()=0
 
virtual Bool_t IsForcing ()
 
virtual double Get_dU_dLambda ()
 
virtual void SetRefPos (AVector)
 
virtual void SetRefDist (double)
 
virtual void SetRefAngle (double)
 
virtual void SetBound (Bound_t)
 
virtual void SetLowerAngle (double)
 
virtual void SetUpperAngle (double)
 
virtual void SetIntervalAngle (double)
 
virtual void SetStartPos (AVector)
 
virtual void SetStopPos (AVector)
 
virtual void SetStartDist (double)
 
virtual void SetStopDist (double)
 
virtual void SetStartAngle (double)
 
virtual void SetStopAngle (double)
 

Protected Member Functions

double GetAngle (AVector &A, AVector &B, AVector &C)
 
double GetDihe (AVector &A, AVector &B, AVector &C, AVector &D)
 
void EarlyExit (const char *Str, int AtomID)
 

Protected Attributes

double m_Kf
 
int m_NumGroups
 
AGroupm_pGroups
 
AVectorm_pCOMs
 

Static Protected Attributes

static double m_LambdaKf = 1.0
 
static double m_LambdaRef = 0.0
 

Detailed Description

Definition at line 17 of file FreeEnergyRestrain.h.

Constructor & Destructor Documentation

ARestraint::ARestraint ( )

Definition at line 42 of file FreeEnergyRestrain.C.

References m_NumGroups, m_pCOMs, and m_pGroups.

42  {
43 //-----------------------------------------------------------------
44 // constructor for base class
45 //-----------------------------------------------------------------
46  m_pGroups = NULL;
47  m_pCOMs = NULL;
48  m_NumGroups = 0;
49 }
AGroup * m_pGroups
AVector * m_pCOMs
ARestraint::~ARestraint ( )
virtual

Definition at line 52 of file FreeEnergyRestrain.C.

References ASSERT, m_pCOMs, and m_pGroups.

52  {
53 //-----------------------------------------------------------------
54 // free space that may have been allocated for Groups and COM's
55 //-----------------------------------------------------------------
56  if (m_pGroups != NULL) {
57  ASSERT(m_pCOMs != NULL);
58  delete []m_pGroups;
59  delete []m_pCOMs;
60  }
61 }
#define ASSERT(E)
AGroup * m_pGroups
AVector * m_pCOMs

Member Function Documentation

void ARestraint::DistributeForce ( int  WhichGroup,
AVector  Force,
GlobalMasterFreeEnergy CFE 
)

Definition at line 179 of file FreeEnergyRestrain.C.

References GlobalMasterFreeEnergy::addForce(), ASSERT, EarlyExit(), GlobalMasterFreeEnergy::getMass(), AGroup::GetNumInGroup(), m_NumGroups, m_pGroups, and SetEqual().

Referenced by ARestraintManager::AddForces().

180  {
181 //----------------------------------------------------------------------
182 // Distribute Force among the group of atoms specified by WhichGroup
183 //
184 // note: m_pGroups points to an array of Groups
185 // m_pGroups[WhichGroup] references one of the Groups
186 // m_pGroups[WhichGroup][i] returns an AtomID from the Group
187 // (operator[] is defined to return an item from the Group)
188 //----------------------------------------------------------------------
189  int i, AtomID, NumAtoms, RetVal;
190  double Mass, TotalMass=0;
191  AVector SmallForce;
192  Vector NAMD_Vector;
193 
194  ASSERT( (WhichGroup>=0) && (WhichGroup<m_NumGroups) );
195 
196  // calculate the total mass for the group
197  NumAtoms = m_pGroups[WhichGroup].GetNumInGroup();
198  for (i=0; i<NumAtoms; i++) {
199  AtomID = m_pGroups[WhichGroup][i];
200  Mass = CFE.getMass(AtomID);
201  if (Mass < 0) {EarlyExit("Negative Mass", AtomID);};
202  TotalMass += Mass;
203  }
204 
205  // distribute Force according to mass of each atom in the group
206  for (i=0; i<NumAtoms; i++) {
207  AtomID = m_pGroups[WhichGroup][i];
208  Mass = CFE.getMass(AtomID);
209  if (Mass < 0) {EarlyExit("Negative Mass", AtomID);}
210  SmallForce = Force * (Mass/TotalMass);
211  // cast SmallForce to a NAMD-type vector (addForce uses Vector class)
212  SetEqual(NAMD_Vector, SmallForce);
213  RetVal = CFE.addForce(AtomID, NAMD_Vector);
214  if (RetVal < 0) {EarlyExit("Can't add Force", AtomID);}
215  }
216 }
int AtomID
Definition: NamdTypes.h:29
Definition: Vector.h:64
int GetNumInGroup()
int addForce(int atomid, Force force)
#define ASSERT(E)
void EarlyExit(const char *Str, int AtomID)
void SetEqual(AVector &Vec1, const Vector &Vec2)
float Mass
Definition: ComputeGBIS.inl:20
AGroup * m_pGroups
void ARestraint::EarlyExit ( const char *  Str,
int  AtomID 
)
protected

Definition at line 64 of file FreeEnergyRestrain.C.

References endi(), iout, and NAMD_die().

Referenced by DistributeForce(), and UpdateCOMs().

64  {
65 //-----------------------------------------------------------------
66 // unrecoverable error
67 //-----------------------------------------------------------------
68  iout << "FreeEnergy: " << std::endl << endi;
69  iout << "FreeEnergy: " << Str;
70  iout << " for AtomID: " << AtomID;
71  iout << std::endl << endi;
72  NAMD_die("FreeEnergy: Fatal Error with Fixed or Forcing Restraints");
73 }
int AtomID
Definition: NamdTypes.h:29
#define iout
Definition: InfoStream.h:87
void NAMD_die(const char *err_msg)
Definition: common.C:83
infostream & endi(infostream &s)
Definition: InfoStream.C:38
virtual double ARestraint::Get_dU_dLambda ( )
inlinevirtual
double ARestraint::GetAngle ( AVector A,
AVector B,
AVector C 
)
protected

Definition at line 127 of file FreeEnergyRestrain.C.

References AVector::Dist().

Referenced by AForcingAngleRestraint::Get_dU_dLambda(), AnAngleRestraint::GetE(), ABoundAngleRestraint::GetEnergy(), ABoundAngleRestraint::GetGradient(), and AnAngleRestraint::PrintInfo().

127  {
128 //-----------------------------------------------------------------
129 // determine the angle formed by the points A-B-C
130 //-----------------------------------------------------------------
131  double u;
132  double a = B.Dist(C);
133  double b = A.Dist(C);
134  double c = A.Dist(B);
135 
136  u = (a*a + c*c - b*b) / (2.0*a*c);
137  // protect against acos(<-1.0) and acos(>1.0)
138  if (u < -1.0) {u = -1.0;}
139  if (u > 1.0) {u = 1.0;}
140  return(acos(u));
141 }
double Dist()
double ARestraint::GetDihe ( AVector A,
AVector B,
AVector C,
AVector D 
)
protected

Definition at line 144 of file FreeEnergyRestrain.C.

References AVector::cross(), AVector::Dist(), AVector::dot(), and dot().

Referenced by AForcingDiheRestraint::Get_dU_dLambda(), ADiheRestraint::GetE(), ABoundDiheRestraint::GetEnergy(), ADiheRestraint::GetGrad(), ABoundDiheRestraint::GetGradient(), and ADiheRestraint::PrintInfo().

144  {
145 //-----------------------------------------------------------------
146 // determine the dihedral angle formed by the points A-B-C-D
147 //-----------------------------------------------------------------
148  AVector CD(D - C);
149  AVector CB(B - C);
150  AVector BC(C - B);
151  AVector BA(A - B);
152  AVector CDxCB, BCxBA;
153  double top, bot, cos_u, sin_u, Angle;
154  AVector topVec;
155 
156  CDxCB = CD.cross(CB);
157  BCxBA = BC.cross(BA);
158 
159  top = CDxCB.dot(BCxBA);
160  bot = CDxCB.Dist() * BCxBA.Dist();
161  cos_u = top/bot;
162 
163  // protect against acos(<-1.0) and acos(>1.0)
164  if (cos_u < -1.0) {cos_u = -1.0;}
165  if (cos_u > 1.0) {cos_u = 1.0;}
166 
167  topVec = CDxCB.cross(BCxBA);
168  sin_u = (topVec/bot).dot(CB/CB.Dist());
169 
170  // protect against asin(<-1.0) and asin(>1.0)
171  if (sin_u < -1.0) {sin_u = -1.0;}
172  if (sin_u > 1.0) {sin_u = 1.0;}
173 
174  Angle = atan2(sin_u, cos_u);
175  return(Angle);
176 }
struct angle Angle
AVector cross(const AVector &Vector)
double dot(const AVector &Vector)
__device__ __forceinline__ float dot(const float3 v1, const float3 v2)
double Dist()
virtual double ARestraint::GetEnergy ( )
pure virtual
virtual AVector ARestraint::GetGradient ( int  WhichGroup)
pure virtual
double ARestraint::GetKf ( )
inline

Definition at line 51 of file FreeEnergyRestrain.h.

References m_Kf.

51 {return(m_Kf);}
double ARestraint::GetLambdaKf ( )
inline

Definition at line 54 of file FreeEnergyRestrain.h.

References m_LambdaKf.

54 {return(m_LambdaKf);}
static double m_LambdaKf
double ARestraint::GetLambdaRef ( )
inline

Definition at line 55 of file FreeEnergyRestrain.h.

References m_LambdaRef.

55 {return(m_LambdaRef);}
static double m_LambdaRef
int ARestraint::GetNumGroups ( )
inline

Definition at line 49 of file FreeEnergyRestrain.h.

References m_NumGroups.

Referenced by ARestraintManager::AddForces().

49 {return(m_NumGroups);}
virtual void ARestraint::GetStr ( char *  Str)
pure virtual
virtual Bool_t ARestraint::IsForcing ( )
inlinevirtual

Reimplemented in AForcingDiheRestraint, AForcingAngleRestraint, AForcingDistRestraint, and AForcingPosRestraint.

Definition at line 76 of file FreeEnergyRestrain.h.

References kFalse.

76 {return(kFalse);}
virtual void ARestraint::PrintInfo ( )
pure virtual
virtual void ARestraint::SetBound ( Bound_t  )
inlinevirtual

Reimplemented in ABoundAngleRestraint, ABoundDistRestraint, and ABoundPosRestraint.

Definition at line 82 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

82 {ASSERT(kFalse);}
#define ASSERT(E)
void ARestraint::SetGroup ( AGroup Group,
int  GroupIndex 
)

Definition at line 76 of file FreeEnergyRestrain.C.

References ASSERT, m_NumGroups, and m_pGroups.

76  {
77 //-----------------------------------------------------------------
78 // set one group of atoms
79 //-----------------------------------------------------------------
80  ASSERT( (GroupIndex>=0) && (GroupIndex<m_NumGroups) );
81  m_pGroups[GroupIndex] = Group;
82 }
#define ASSERT(E)
AGroup * m_pGroups
void ARestraint::SetGroups ( AGroup Group1)

Definition at line 85 of file FreeEnergyRestrain.C.

References ASSERT, m_NumGroups, and m_pGroups.

Referenced by GetRestraint().

85  {
86 //-----------------------------------------------------------------
87 // set one group of atoms
88 //-----------------------------------------------------------------
89  ASSERT(m_NumGroups >= 1);
90  m_pGroups[0] = Group1;
91 }
#define ASSERT(E)
AGroup * m_pGroups
void ARestraint::SetGroups ( AGroup Group1,
AGroup Group2 
)

Definition at line 94 of file FreeEnergyRestrain.C.

References ASSERT, m_NumGroups, and m_pGroups.

94  {
95 //-----------------------------------------------------------------
96 // set two groups of atoms
97 //-----------------------------------------------------------------
98  ASSERT(m_NumGroups >= 2);
99  m_pGroups[0] = Group1;
100  m_pGroups[1] = Group2;
101 }
#define ASSERT(E)
AGroup * m_pGroups
void ARestraint::SetGroups ( AGroup Group1,
AGroup Group2,
AGroup Group3 
)

Definition at line 104 of file FreeEnergyRestrain.C.

References ASSERT, m_NumGroups, and m_pGroups.

104  {
105 //-----------------------------------------------------------------
106 // set three groups of atoms
107 //-----------------------------------------------------------------
108  ASSERT(m_NumGroups >= 3);
109  m_pGroups[0] = Group1;
110  m_pGroups[1] = Group2;
111  m_pGroups[2] = Group3;
112 }
#define ASSERT(E)
AGroup * m_pGroups
void ARestraint::SetGroups ( AGroup Group1,
AGroup Group2,
AGroup Group3,
AGroup Group4 
)

Definition at line 115 of file FreeEnergyRestrain.C.

References ASSERT, m_NumGroups, and m_pGroups.

115  {
116 //-----------------------------------------------------------------
117 // set four groups of atoms
118 //-----------------------------------------------------------------
119  ASSERT(m_NumGroups >= 4);
120  m_pGroups[0] = Group1;
121  m_pGroups[1] = Group2;
122  m_pGroups[2] = Group3;
123  m_pGroups[3] = Group4;
124 }
#define ASSERT(E)
AGroup * m_pGroups
virtual void ARestraint::SetIntervalAngle ( double  )
inlinevirtual

Reimplemented in ABoundDiheRestraint.

Definition at line 85 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

85 {ASSERT(kFalse);}
#define ASSERT(E)
void ARestraint::SetKf ( double  Kf)
inline

Definition at line 50 of file FreeEnergyRestrain.h.

References m_Kf.

Referenced by GetRestraint().

50 {m_Kf=Kf;}
void ARestraint::SetLambdaKf ( double  LambdaKf)
inline

Definition at line 52 of file FreeEnergyRestrain.h.

References m_LambdaKf.

Referenced by ARestraintManager::SetLambdaKf(), and ARestraintManager::SetLambdas().

52 {m_LambdaKf=LambdaKf;}
static double m_LambdaKf
void ARestraint::SetLambdaRef ( double  LambdaRef)
inline

Definition at line 53 of file FreeEnergyRestrain.h.

References m_LambdaRef.

Referenced by ARestraintManager::SetLambdaRef(), and ARestraintManager::SetLambdas().

53 {m_LambdaRef=LambdaRef;}
static double m_LambdaRef
virtual void ARestraint::SetLowerAngle ( double  )
inlinevirtual

Reimplemented in ABoundDiheRestraint.

Definition at line 83 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

83 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetRefAngle ( double  )
inlinevirtual

Reimplemented in AFixedDiheRestraint, ABoundAngleRestraint, and AFixedAngleRestraint.

Definition at line 81 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

81 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetRefDist ( double  )
inlinevirtual

Reimplemented in ABoundDistRestraint, AFixedDistRestraint, and ABoundPosRestraint.

Definition at line 80 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

80 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetRefPos ( AVector  )
inlinevirtual

Reimplemented in ABoundPosRestraint, and AFixedPosRestraint.

Definition at line 79 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

79 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetStartAngle ( double  )
inlinevirtual

Reimplemented in AForcingDiheRestraint, and AForcingAngleRestraint.

Definition at line 90 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

90 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetStartDist ( double  )
inlinevirtual

Reimplemented in AForcingDistRestraint.

Definition at line 88 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

88 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetStartPos ( AVector  )
inlinevirtual

Reimplemented in AForcingPosRestraint.

Definition at line 86 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

86 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetStopAngle ( double  )
inlinevirtual

Reimplemented in AForcingDiheRestraint, and AForcingAngleRestraint.

Definition at line 91 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

91 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetStopDist ( double  )
inlinevirtual

Reimplemented in AForcingDistRestraint.

Definition at line 89 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

89 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetStopPos ( AVector  )
inlinevirtual

Reimplemented in AForcingPosRestraint.

Definition at line 87 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

87 {ASSERT(kFalse);}
#define ASSERT(E)
virtual void ARestraint::SetUpperAngle ( double  )
inlinevirtual

Reimplemented in ABoundDiheRestraint.

Definition at line 84 of file FreeEnergyRestrain.h.

References ASSERT, and kFalse.

Referenced by GetRestraint().

84 {ASSERT(kFalse);}
#define ASSERT(E)
void ARestraint::UpdateCOMs ( GlobalMasterFreeEnergy CFE)

Definition at line 219 of file FreeEnergyRestrain.C.

References ASSERT, EarlyExit(), GlobalMasterFreeEnergy::getMass(), AGroup::GetNumInGroup(), GlobalMasterFreeEnergy::getPosition(), m_NumGroups, m_pCOMs, m_pGroups, AVector::Set(), and SetEqual().

Referenced by ARestraintManager::UpdateCOMs().

219  {
220 //-----------------------------------------------------------------
221 // calculate the center-of-mass of each group of atoms
222 //
223 // note: m_pGroups points to an array of Groups
224 // m_pGroups[i] references one of the Groups
225 // m_pGroups[i][j] returns an AtomID from the Group
226 // (operator[] is defined to return an item from the Group)
227 //-----------------------------------------------------------------
228  int i, j, AtomID, RetVal;
229  Vector NAMD_Vector;
230  AVector COM, Pos;
231  double Mass, TotalMass;
232 
233  ASSERT(m_NumGroups > 0);
234  // for each group of atoms
235  for (i=0; i<m_NumGroups; i++) {
236  TotalMass = 0;
237  COM.Set(0,0,0);
238  // for each atom in the group
239  for (j=0; j<m_pGroups[i].GetNumInGroup(); j++) {
240  AtomID = m_pGroups[i][j];
241  // get its position, weight position with atom's mass
242  RetVal = CFE.getPosition(AtomID, NAMD_Vector);
243  if (RetVal < 0) {EarlyExit("Can't get Position", AtomID);}
244  // cast NAMD_Vector to AVector (getPosition uses Vector class)
245  SetEqual(Pos, NAMD_Vector);
246  Mass = CFE.getMass(AtomID);
247  if (Mass < 0) {EarlyExit("Negative Mass", AtomID);}
248  TotalMass += Mass;
249  COM += Pos * Mass;
250  }
251  m_pCOMs[i] = COM / TotalMass;
252  }
253 }
Bool_t Set(double x, double y, double z)
int getPosition(int atomid, Position &position)
int AtomID
Definition: NamdTypes.h:29
Definition: Vector.h:64
int GetNumInGroup()
#define ASSERT(E)
void EarlyExit(const char *Str, int AtomID)
void SetEqual(AVector &Vec1, const Vector &Vec2)
float Mass
Definition: ComputeGBIS.inl:20
AGroup * m_pGroups
AVector * m_pCOMs

Member Data Documentation

double ARestraint::m_Kf
protected
double ARestraint::m_LambdaKf = 1.0
staticprotected
double ARestraint::m_LambdaRef = 0.0
staticprotected
int ARestraint::m_NumGroups
protected
AVector* ARestraint::m_pCOMs
protected
AGroup* ARestraint::m_pGroups
protected

The documentation for this class was generated from the following files: