Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

colvarbias_abf Class Reference

ABF bias. More...

#include <colvarbias_abf.h>

Inheritance diagram for colvarbias_abf:

colvarbias colvarparse List of all members.

Public Member Functions

 colvarbias_abf (std::string const &conf, char const *key)
 ABF bias constructor; parses the config file.
 ~colvarbias_abf ()
 Destructor.
cvm::real update ()

Detailed Description

ABF bias.

Definition at line 21 of file colvarbias_abf.h.


Constructor & Destructor Documentation

colvarbias_abf::colvarbias_abf std::string const &  conf,
char const *  key
 

ABF bias constructor; parses the config file.

Definition at line 11 of file colvarbias_abf.C.

References colvarmodule::fatal_error(), colvar_grid< T >::has_parent_data, colvarmodule::log(), colvar_grid_gradient::samples, and colvarmodule::temperature().

00012   : colvarbias (conf, key),
00013     gradients (NULL),
00014     samples (NULL)
00015 {
00016   if (cvm::temperature() == 0.0)
00017     cvm::log ("WARNING: ABF should not be run without a thermostat or at 0 Kelvin!\n");
00018   
00019   // ************* parsing general ABF options ***********************
00020 
00021   get_keyval (conf, "applyBias",  apply_bias, true);
00022   if (!apply_bias) cvm::log ("WARNING: ABF biases will *not* be applied!\n");
00023 
00024   get_keyval (conf, "updateBias",  update_bias, true);
00025   if (!update_bias) cvm::log ("WARNING: ABF biases will *not* be updated!\n");
00026 
00027   get_keyval (conf, "hideJacobian", hide_Jacobian, false);
00028   if (hide_Jacobian) {
00029     cvm::log ("Jacobian (geometric) forces will be handled internally.\n");
00030   } else {
00031     cvm::log ("Jacobian (geometric) forces will be included in reported free energy gradients.\n");
00032   }
00033 
00034   get_keyval (conf, "fullSamples", full_samples, 200);
00035   if ( full_samples <= 1 ) full_samples = 1; 
00036   min_samples = full_samples / 2;
00037   // full_samples - min_samples >= 1 is guaranteed
00038 
00039   get_keyval (conf, "inputPrefix",  input_prefix, std::vector<std::string> ());
00040   get_keyval (conf, "outputFreq", output_freq, cvm::restart_out_freq);
00041   get_keyval (conf, "historyFreq", history_freq, 0);
00042   b_history_files = (history_freq > 0);
00043 
00044   // ************* checking the associated colvars *******************
00045 
00046   if (colvars.size() == 0) {
00047     cvm::fatal_error ("Error: no collective variables specified for the ABF bias.\n");
00048   }
00049 
00050   for (size_t i = 0; i < colvars.size(); i++) {
00051 
00052     if (colvars[i]->type() != colvarvalue::type_scalar) {
00053       cvm::fatal_error ("Error: ABF bias can only use scalar-type variables.\n");
00054     }
00055 
00056     colvars[i]->enable (colvar::task_gradients);
00057 
00058     if (update_bias) {
00059       // Request calculation of system force (which also checks for availability)
00060       colvars[i]->enable (colvar::task_system_force);
00061 
00062       if (!colvars[i]->tasks[colvar::task_extended_lagrangian]) {
00063         // request computation of Jacobian force
00064         colvars[i]->enable (colvar::task_Jacobian_force);
00065 
00066         // request Jacobian force as part as system force
00067         // except if the user explicitly requires the "silent" Jacobian
00068         // correction AND the colvar has a single component
00069         if (hide_Jacobian) {
00070           if (colvars[i]->n_components() > 1) {
00071             cvm::log ("WARNING: colvar \"" + colvars[i]->name
00072             + "\" has multiple components; reporting its Jacobian forces\n");
00073             colvars[i]->enable (colvar::task_report_Jacobian_force);
00074           }
00075         } else {
00076           colvars[i]->enable (colvar::task_report_Jacobian_force);
00077         }
00078       }
00079     }
00080 
00081     // Here we could check for orthogonality of the Cartesian coordinates
00082     // and make it just a warning if some parameter is set? 
00083   }
00084 
00085   bin.assign (colvars.size(), 0);
00086   force_bin.assign (colvars.size(), 0);
00087   force = new cvm::real [colvars.size()];
00088 
00089   // Construct empty grids based on the colvars
00090   samples   = new colvar_grid_count    (colvars);
00091   gradients = new colvar_grid_gradient (colvars);
00092   gradients->samples = samples;
00093   samples->has_parent_data = true;
00094 
00095   // If custom grids are provided, read them
00096   if ( input_prefix.size() > 0 ) {
00097     read_gradients_samples ();
00098   }
00099   
00100   cvm::log ("Finished ABF setup.\n");
00101 }

colvarbias_abf::~colvarbias_abf  ) 
 

Destructor.

Definition at line 104 of file colvarbias_abf.C.

00105 {
00106   if (samples) {
00107     delete samples;
00108     samples = NULL;
00109   }
00110 
00111   if (gradients) {
00112     delete gradients;
00113     gradients = NULL;
00114   }
00115 
00116   delete [] force;
00117 }


Member Function Documentation

cvm::real colvarbias_abf::update  )  [virtual]
 

Update the FE gradient, compute and apply biasing force also output data to disk if needed

Implements colvarbias.

Definition at line 123 of file colvarbias_abf.C.

References colvar_grid_gradient::acc_force(), colvar_grid_gradient::average(), colvar_grid< T >::current_bin_scalar(), colvarmodule::debug(), colvar_grid< T >::index_ok(), colvarmodule::log(), colvarmodule::real, colvar_grid< T >::reset(), colvarmodule::step_absolute(), colvarmodule::step_relative(), and colvar_grid< T >::value().

00124 {
00125   if (cvm::debug()) cvm::log ("Updating ABF bias " + this->name);
00126 
00127   if (cvm::step_relative() == 0) {
00128         
00129     // At first timestep, do only:
00130     // initialization stuff (file operations relying on n_abf_biases
00131     // compute current value of colvars
00132 
00133     if ( cvm::n_abf_biases == 1 && cvm::n_meta_biases == 0 ) {
00134       // This is the only ABF bias
00135       output_prefix = cvm::output_prefix;
00136     } else {
00137       output_prefix = cvm::output_prefix + "." + this->name;
00138     }
00139 
00140     for (size_t i=0; i<colvars.size(); i++) {
00141       bin[i] = samples->current_bin_scalar(i);
00142     }
00143 
00144   } else {
00145 
00146     for (size_t i=0; i<colvars.size(); i++) {
00147       bin[i] = samples->current_bin_scalar(i);
00148     }
00149 
00150     if ( update_bias && samples->index_ok (force_bin) ) {
00151       // Only if requested and within bounds of the grid...
00152 
00153       for (size_t i=0; i<colvars.size(); i++) {   // get forces (lagging by 1 timestep) from colvars
00154         force[i] = colvars[i]->system_force();
00155       }
00156       gradients->acc_force (force_bin, force);
00157     }
00158   }
00159 
00160   // save bin for next timestep
00161   force_bin = bin;  
00162 
00163   // Reset biasing forces from previous timestep
00164   for (size_t i=0; i<colvars.size(); i++) {
00165     colvar_forces[i].reset();
00166   }
00167 
00168   // Compute and apply the new bias, if applicable
00169   if ( apply_bias && samples->index_ok (bin) ) {
00170 
00171     size_t  count = samples->value (bin);
00172     cvm::real   fact = 1.0;
00173 
00174     // Factor that ensures smooth introduction of the force
00175     if ( count < full_samples ) {
00176       fact = ( count < min_samples) ? 0.0 :
00177         (cvm::real (count - min_samples)) / (cvm::real (full_samples - min_samples));
00178     }
00179         
00180     const cvm::real * grad  = &(gradients->value (bin));
00181 
00182     if ( fact != 0.0 ) {
00183 
00184       if ( (colvars.size() == 1) && colvars[0]->periodic_boundaries() ) {
00185         // Enforce a zero-mean bias on periodic, 1D coordinates
00186         colvar_forces[0].real_value += fact * (grad[0] / cvm::real (count) - gradients->average ());
00187       } else {
00188         for (size_t i=0; i<colvars.size(); i++) {
00189           // subtracting the mean force (opposite of the FE gradient) means adding the gradient
00190           colvar_forces[i].real_value += fact * grad[i] / cvm::real (count);
00191           // without .real_value, the above would do (cheap) runtime type checking
00192         }
00193       }
00194     }
00195   }
00196 
00197   if (output_freq && (cvm::step_absolute() % output_freq) == 0) {
00198     if (cvm::debug()) cvm::log ("ABF bias trying to write gradients and samples to disk");
00199     write_gradients_samples (output_prefix);
00200   }
00201   if (b_history_files && (cvm::step_absolute() % history_freq) == 0) {
00202     // append to existing file only if cvm::step_absolute() > 0
00203     // otherwise, backup and replace
00204     write_gradients_samples (output_prefix + ".hist", (cvm::step_absolute() > 0));
00205   }
00206   return 0.0; // TODO compute bias energy whenever possible (i.e. 1D with updateBias off)
00207 }


The documentation for this class was generated from the following files:
Generated on Fri May 25 04:07:20 2012 for NAMD by  doxygen 1.3.9.1