Skip to content
Snippets Groups Projects
Commit a3936fe2 authored by Carlo Camilloni's avatar Carlo Camilloni
Browse files

HISTOGRAM: small changes to have nice free energy

parent 81e3c912
No related branches found
No related tags found
No related merge requests found
......@@ -165,7 +165,6 @@ fenergy(false)
parseFlag("FREQUENCY",frequency);
parseFlag("FREE-ENERGY",fenergy);
if(fenergy) frequency=true;
if(getTemp()<=0&&fenergy) plumed_merror("Set the temperature (TEMP) if you want a free energy.");
checkRead();
......@@ -222,7 +221,10 @@ void Histogram::performAnalysis(){
// Normalize the histogram
if(!frequency) gg->scaleAllValuesAndDerivatives( 1.0 / getNormalization() );
if(fenergy) gg->logAllValuesAndDerivatives( -getTemp() * plumed.getAtoms().getKBoltzmann() );
if(fenergy) {
gg->logAllValuesAndDerivatives( -getTemp() * plumed.getAtoms().getKBoltzmann() );
gg->setMinToZero();
}
// Write the grid to a file
OFile gridfile; gridfile.link(*this); gridfile.setBackupString("analysis");
......
......@@ -517,6 +517,12 @@ void Grid::logAllValuesAndDerivatives( const double& scalef ){
}
}
void Grid::setMinToZero(){
double min=grid_[0];
for(unsigned i=1;i<grid_.size();++i) if(grid_[i]<min) min=grid_[i];
for(unsigned i=0;i<grid_.size();++i) grid_[i] -= min;
}
void Grid::applyFunctionAllValuesAndDerivatives( double (*func)(double val), double (*funcder)(double valder) ){
if(usederiv_){
for(unsigned i=0;i<grid_.size();++i){
......
......@@ -175,6 +175,8 @@ public:
virtual void scaleAllValuesAndDerivatives( const double& scalef );
/// Takes the scalef times the logarithm of all grid values and derivatives
virtual void logAllValuesAndDerivatives( const double& scalef );
/// Set the minimum value of the grid to zero and translates accordingly
virtual void setMinToZero();
/// apply function: takes pointer to function that accepts a double and apply
virtual void applyFunctionAllValuesAndDerivatives( double (*func)(double val), double (*funcder)(double valder) );
/// add a kernel function to the grid
......
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