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.
void 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 12 of file colvarbias_abf.C.

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

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

colvarbias_abf::~colvarbias_abf  ) 
 

Destructor.

Definition at line 91 of file colvarbias_abf.C.

00092 {
00093   if (gradients_os.good())      gradients_os.close();
00094   if (samples_os.good())        samples_os.close();
00095 
00096   if (samples) {
00097     delete samples;
00098     samples = NULL;
00099   }
00100 
00101   if (gradients) {
00102     delete gradients;
00103     gradients = NULL;
00104   }
00105 
00106   delete [] prev_force;
00107 }


Member Function Documentation

void 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 113 of file colvarbias_abf.C.

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

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


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 04:59:33 2009 for NAMD by  doxygen 1.3.9.1