00001 00007 // written by David Hurwitz, March to May 1998. 00008 00009 #include <memory.h> 00010 #include <string.h> 00011 // #include <iomanip.h> 00012 #include "InfoStream.h" 00013 #include "FreeEnergyEnums.h" 00014 #include "FreeEnergyAssert.h" 00015 #include "Vector.h" 00016 #include "FreeEnergyVector.h" 00017 #include "FreeEnergyGroup.h" 00018 #include "FreeEnergyRestrain.h" 00019 #include "FreeEnergyRMgr.h" 00020 #include "FreeEnergyLambda.h" 00021 #include "FreeEnergyLambdMgr.h" 00022 00023 #include "NamdTypes.h" 00024 #include "GlobalMaster.h" 00025 #include "GlobalMasterFreeEnergy.h" 00026 00027 ARestraintManager::ARestraintManager() { 00028 //------------------------------------------------------------------------ 00029 // allocate space for restraint POINTERS 00030 //------------------------------------------------------------------------ 00031 m_ppRestraints = new pRestr[kNumToStart]; 00032 m_NumRestraints = 0; 00033 m_MaxNum = kNumToStart; 00034 } 00035 00036 00037 ARestraintManager::~ARestraintManager() { 00038 //------------------------------------------------------------------------ 00039 // when the RestraintManager goes out of scope, 00040 // free the space that was allocated for each restraint 00041 // (see: ARestraint* GetRestraint(char*, int&) 00042 // then, free the space that was allocated for the pointers 00043 //------------------------------------------------------------------------ 00044 for (int i=0; i<m_NumRestraints; i++) { 00045 delete m_ppRestraints[i]; 00046 } 00047 delete []m_ppRestraints; 00048 } 00049 00050 00051 ARestraint* ARestraintManager::operator[] (int Index) { 00052 //------------------------------------------------------------------------ 00053 // get a pointer 00054 //------------------------------------------------------------------------ 00055 ASSERT( (Index>=0) && (Index<m_NumRestraints) ); 00056 return(m_ppRestraints[Index]); 00057 } 00058 00059 00060 void ARestraintManager::Add(ARestraint* pRestraint) { 00061 //------------------------------------------------------------------------ 00062 // add a pointer to the list. if there's not enough room, make room. 00063 //------------------------------------------------------------------------ 00064 ARestraint** ppRestraints; 00065 00066 // if there's no room for a new pointer 00067 if (m_NumRestraints == m_MaxNum) { 00068 // create an array with more space 00069 m_MaxNum *= kMultiplier; 00070 ppRestraints = new pRestr[m_MaxNum]; 00071 // fast copy from the full array to the new one (memcpy(dest, src, bytes)) 00072 memcpy(ppRestraints, m_ppRestraints, sizeof(ARestraint*)*m_NumRestraints); 00073 // return the space used for the full array 00074 delete []m_ppRestraints; 00075 // point to the bigger array 00076 m_ppRestraints = ppRestraints; 00077 } 00078 00079 // add the int to the int array 00080 m_ppRestraints[m_NumRestraints] = pRestraint; 00081 m_NumRestraints++; 00082 } 00083 00084 00085 void ARestraintManager::UpdateCOMs(GlobalMasterFreeEnergy& CFE) { 00086 //------------------------------------------------------------------------ 00087 // update the centers-of-mass in each restraint in the list 00088 // note: m_ppRestraints points to a list of restraint pointers 00089 // m_ppRestraints[i] references one of the pointers 00090 // m_ppRestraints[i]-> accesses a restraint function 00091 //------------------------------------------------------------------------ 00092 for (int i=0; i<m_NumRestraints; i++) { 00093 m_ppRestraints[i]->UpdateCOMs(CFE); 00094 } 00095 } 00096 00097 00098 void ARestraintManager::AddForces(GlobalMasterFreeEnergy& CFE) { 00099 //--------------------------------------------------------------------------- 00100 // for each restraint, apply restraining force to each COM (center-of-mass). 00101 //--------------------------------------------------------------------------- 00102 int i, j, NumCOMs; 00103 AVector Force; 00104 00105 // for each restraint 00106 for (i=0; i<m_NumRestraints; i++) { 00107 // for each center-of-mass 00108 NumCOMs = m_ppRestraints[i]->GetNumGroups(); 00109 for (j=0; j<NumCOMs; j++) { 00110 Force = m_ppRestraints[i]->GetGradient(j); 00111 // apply restraining force in opposite direction from gradient 00112 Force *= -1.0; 00113 m_ppRestraints[i]->DistributeForce(j, Force, CFE); 00114 } 00115 } 00116 } 00117 00118 00119 double ARestraintManager::Sum_dU_dLambdas() { 00120 //--------------------------------------------------------------------------- 00121 // sum up dU/dLambda from each forcing restraint 00122 //--------------------------------------------------------------------------- 00123 double Sum=0; 00124 00125 for (int i=0; i<m_NumRestraints; i++) { 00126 Sum += m_ppRestraints[i]->Get_dU_dLambda(); 00127 } 00128 return(Sum); 00129 } 00130 00131 00132 Bool_t ARestraintManager::ThereIsAForcingRestraint() { 00133 //--------------------------------------------------------------------------- 00134 // return kTrue if there's at least one forcing restraint 00135 //--------------------------------------------------------------------------- 00136 for (int i=0; i<m_NumRestraints; i++) { 00137 if (m_ppRestraints[i]->IsForcing()) { 00138 return(kTrue); 00139 } 00140 } 00141 return(kFalse); 00142 } 00143 00144 00145 void ARestraintManager::PrintEnergyInfo() { 00146 //--------------------------------------------------------------------------- 00147 // for a restraint, print restraint type and Energy. 00148 //--------------------------------------------------------------------------- 00149 #if defined(_VERBOSE_PMF) 00150 for (int i=0; i<m_NumRestraints; i++) { 00151 PrintPreInfo(i); 00152 iout << "Energy = "; 00153 iout << m_ppRestraints[i]->GetEnergy() << std::endl << endi; 00154 } 00155 #endif 00156 } 00157 00158 00159 void ARestraintManager::PrintRestraintInfo() { 00160 //--------------------------------------------------------------------------- 00161 // for a restraint, print its position, distance, angle, or dihedral angle. 00162 //--------------------------------------------------------------------------- 00163 for (int i=0; i<m_NumRestraints; i++) { 00164 #if defined(_VERBOSE_PMF) 00165 PrintPreInfo(i); 00166 #endif 00167 m_ppRestraints[i]->PrintInfo(); 00168 } 00169 #if !defined(_VERBOSE_PMF) 00170 iout << std::endl << endi; 00171 #endif 00172 } 00173 00174 00175 void ARestraintManager::Print_dU_dLambda_Info() { 00176 //--------------------------------------------------------------------------- 00177 // if restraint is a forcing restraint, print dU/dLambda. 00178 //--------------------------------------------------------------------------- 00179 #if defined(_VERBOSE_PMF) 00180 for (int i=0; i<m_NumRestraints; i++) { 00181 if (m_ppRestraints[i]->IsForcing()) { 00182 PrintPreInfo(i); 00183 iout << "dU/dLambda = "; 00184 iout << m_ppRestraints[i]->Get_dU_dLambda() << std::endl << endi; 00185 } 00186 } 00187 #endif 00188 } 00189 00190 00191 void ARestraintManager::PrintPreInfo(int Index) { 00192 //--------------------------------------------------------------------------- 00193 // print "Restraint xxx: Type of Restraint: " 00194 //--------------------------------------------------------------------------- 00195 char Str[100]; 00196 char NumStr[20]; 00197 00198 sprintf(NumStr, "%3d", Index+1); 00199 iout << "FreeEnergy: " << "Restraint " << NumStr << ": "; 00200 m_ppRestraints[Index]->GetStr(Str); 00201 iout << Str << ": "; 00202 } 00203
1.3.9.1