Skip to content
Snippets Groups Projects
Commit 4c8d346e authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Added tool to recover total bias

This is useful to compute acceptance.
I did it in the "dirty" way: if a value named "bias" exist inside any
action, it is accumulated into the total bias. I also changed the name
of values in Restraint and MovingRestraint so that the energy is now called
"bias" and non-capital letters are more consistent
parent 9dfbc8f6
No related branches found
No related tags found
No related merge requests found
......@@ -125,9 +125,9 @@ PLUMED_BIAS_INIT(ao)
log.printf("\n");
};
addValue("Energy");
addValue("Force2");
addValue("Work");
addValue("bias");
addValue("force2");
addValue("work");
}
......@@ -163,9 +163,9 @@ void BiasMovingRestraint::calculate(){
totf2+=f*f;
};
Value* value;
value=getValue("Energy");
value=getValue("bias");
setValue(value,ene);
value=getValue("Force2");
value=getValue("force2");
setValue(value,totf2);
}
......
......@@ -30,7 +30,7 @@ values, and it is printing the energy of the restraint
DISTANCE ATOMS=3,5 LABEL=d1
DISTANCE ATOMS=2,4 LABEL=d2
RESTRAINT ARG=d1,d2 AT=1.0,1.5 KAPPA=150.0,150.0 LABEL=restraint
PRINT ARG=restraint.Energy
PRINT ARG=restraint.bias
\endverbatim
(See also \ref DISTANCE and \ref PRINT).
......@@ -65,8 +65,8 @@ kappa(getNumberOfArguments(),0.0)
for(unsigned i=0;i<kappa.size();i++) log.printf(" %f",kappa[i]);
log.printf("\n");
addValue("Energy");
addValue("Force2");
addValue("bias");
addValue("force2");
}
......@@ -82,8 +82,8 @@ void BiasRestraint::calculate(){
totf2+=f*f;
};
Value* value;
value=getValue("Energy"); setValue(value,ene);
value=getValue("Force2"); setValue(value,totf2);
value=getValue("bias"); setValue(value,ene);
value=getValue("force2"); setValue(value,totf2);
}
}
......
......@@ -79,6 +79,7 @@ PlumedMain::PlumedMain():
active(false),
atoms(*this),
actionSet((*this)),
bias(0.0),
novirial(false)
{}
......@@ -426,21 +427,26 @@ void PlumedMain::waitData(){
void PlumedMain::justCalculate(){
bias=0.0;
// calculate the active actions in order (assuming *backward* dependence)
for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){
ActionWithValue*av=dynamic_cast<ActionWithValue*>(*p);
ActionAtomistic*aa=dynamic_cast<ActionAtomistic*>(*p);
{
ActionWithValue*a=dynamic_cast<ActionWithValue*>(*p);
if(a) a->clearInputForces();
if(a) a->clearDerivatives();
if(av) av->clearInputForces();
if(av) av->clearDerivatives();
}
{
ActionAtomistic*a=dynamic_cast<ActionAtomistic*>(*p);
if(a) a->clearOutputForces();
if(a) if(a->isActive()) a->retrieveAtoms();
if(aa) aa->clearOutputForces();
if(aa) if(aa->isActive()) aa->retrieveAtoms();
}
if((*p)->isActive()){
if((*p)->checkNumericalDerivatives()) (*p)->calculateNumericalDerivatives();
else (*p)->calculate();
if(av)for(int i=0;i<av->getNumberOfValues();++i){
if(av->getValue(i)->getName()=="bias") bias+=av->getValue(i)->get();
}
}
}
}
......@@ -490,6 +496,10 @@ void PlumedMain::load(std::vector<std::string> & words){
log<<"Here is the new list of available actions\n";
log<<actionRegister();
}
double PlumedMain::getBias() const{
return bias;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -80,6 +80,9 @@ private:
/// Suffix string for file opening, useful for multiple simulations in the same directory
std::string suffix;
/// The total bias (=total energy of the restraints)
double bias;
public:
/// Flag to switch off virial calculation (for debug)
bool novirial;
......@@ -131,6 +134,8 @@ public:
const std::string & getSuffix()const;
/// Set the suffix string
void setSuffix(const std::string&);
/// get the value of the bias
double getBias()const;
};
/////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment