36 #define MIN_DEBUG_LEVEL 1 40 void GlobalMasterFreeEnergy::update() {
46 double LambdaKf, LambdaRef;
47 double Sum_dU_dLambdas;
49 if (m_LambdaManager.
GetLambdas(LambdaKf, LambdaRef)) {
52 m_RestraintManager.
SetLambdas(LambdaKf, LambdaRef);
91 void GlobalMasterFreeEnergy::user_initialize() {
96 iout <<
iINFO <<
" FREE ENERGY PERTURBATION CONFIG\n";
97 iout <<
iINFO <<
"***********************************\n";
98 int config_len = strlen(config);
99 if ( config_len < 10000 ) {
102 char *new_config =
new char[10000 + 10];
103 strncpy(new_config,config,10000);
104 new_config[10000] = 0;
105 strcat(new_config,
"\n...\n");
107 delete [] new_config;
109 iout <<
iINFO <<
"***********************************\n" <<
endi;
111 ReadInput(config, m_RestraintManager, m_LambdaManager, *
this, simParams->
dt);
115 if (Total > simParams->
N) {
116 iout <<
"FreeEnergy: Not enough steps to complete pfm & mcti blocks" << std::endl;
117 iout <<
"FreeEnergy: Num Steps Needed = " << Total << std::endl;
118 iout <<
"FreeEnergy: Num Steps Requested = " << simParams->
N << std::endl <<
endi;
119 NAMD_die(
"FreeEnergy: Fatal Run-Time Error");
124 void GlobalMasterFreeEnergy::user_calculate() {
134 getAtomID(
const char *segid,
int resid,
const char *aname)
153 if ( atomid < 0 || atomid >= molecule->
numAtoms )
return -1.;
160 if ( atomid < 0 || atomid >= molecule->
numAtoms )
return -1;
170 for ( ; a_i != a_e; ++a_i, ++p_i ) {
171 if ( *a_i == atomid ) {
181 DebugM(2,
"Forcing "<<atomid<<
" with "<<force<<
"\n");
182 if ( atomid < 0 || atomid >= molecule->
numAtoms )
return -1;
191 DebugM(3,
"Constructing GlobalMasterFreeEnergy\n");
200 DebugM(3,
"Destructing GlobalMasterFreeEnergy\n");
205 void GlobalMasterFreeEnergy::initialize() {
206 DebugM(4,
"Initializing master\n");
211 config =
new char[1];
214 for ( ; script; script = script->
next) {
215 if ( strstr(script->
data,
"\n") ) {
216 size_t add_len = strlen(script->
data);
217 size_t config_len = 0;
218 config_len = strlen(config);
219 char *new_config =
new char[config_len + add_len + 2];
220 strcpy(new_config,config);
221 strcat(new_config,script->
data);
222 strcat(new_config,
"\n");
226 FILE *infile = fopen(script->
data,
"r");
229 sprintf(errmsg,
"Error trying to read file %s!\n",script->
data);
232 fseek(infile,0,SEEK_END);
233 size_t add_len = ftell(infile);
234 size_t config_len = 0;
235 config_len = strlen(config);
236 char *new_config =
new char[config_len + add_len + 3];
237 strcpy(new_config,config);
240 new_config += config_len;
242 fread(new_config,
sizeof(
char),add_len,infile);
243 new_config += add_len;
244 new_config[0] =
'\n';
245 new_config[1] =
'\0';
255 void GlobalMasterFreeEnergy::calculate() {
256 DebugM(4,
"Calculating forces on master\n");
272 DebugM(4,
"Sending new configuration (" <<
Bool_t IsTimeToPrint_dU_dLambda()
int getPosition(int atomid, Position &position)
ForceList & modifyAppliedForces()
std::ostream & iINFO(std::ostream &s)
AtomIDList & modifyRequestedAtoms()
Bool_t IsTimeToClearAccumulator()
void SetLambdas(double LambdaKf, double LambdaRef)
int getAtomID(const char *segid, int resid, const char *aname)
int requestAtom(int atomid)
void PrintLambdaHeader(double dT)
void Accumulate(double dU_dLambda)
int get_residue_size(const char *segid, int resid) const
void Print_MCTI_Integration()
AtomIDList::const_iterator getAtomIdBegin()
SimParameters * simParameters
std::ostream & endi(std::ostream &s)
~GlobalMasterFreeEnergy()
void PrintHeader(double dT)
int add(const Elem &elem)
PositionList::const_iterator getAtomPositionBegin()
int addForce(int atomid, Force force)
BigRealList::const_iterator getGroupMassEnd()
void Print_dU_dLambda_Info()
void setall(const Elem &elem)
void Print_dU_dLambda_Summary(double Sum_dU_dLambdas)
int get_atom_from_name(const char *segid, int resid, const char *aname) const
const AtomID * const_iterator
void ReadInput(char *Str, ARestraintManager &RMgr, ALambdaManager &LMgr, GlobalMasterFreeEnergy &CFE, double dT)
AtomIDList & modifyForcedAtoms()
void NAMD_die(const char *err_msg)
Bool_t GetLambdas(double &LambdaKf, double &LambdaRef)
BigRealList::const_iterator getGroupMassBegin()
ForceList & modifyGroupForces()
Real atommass(int anum) const
void UpdateCOMs(GlobalMasterFreeEnergy &CFE)
AtomIDList::const_iterator getAtomIdEnd()
Bool_t IsEndOf_MCTI_Step()
void AddForces(GlobalMasterFreeEnergy &CFE)
int get_atom_from_index_in_residue(const char *segid, int resid, int index) const
Bool_t ThereIsAForcingRestraint()
const AtomIDList & forcedAtoms()
StringList * find(const char *name) const
void PrintRestraintInfo()
int getNumAtoms(const char *segid, int resid)
double getMass(int atomid)
const AtomIDList & requestedAtoms()