git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@12612 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2014-10-07 20:30:25 +00:00
parent 3c0612815f
commit 044084847b
33 changed files with 2284 additions and 2595 deletions

View File

@ -1,3 +1,5 @@
/// -*- c++ -*-
#include <iostream>
#include <sstream>
#include <fstream>
@ -64,7 +66,8 @@ colvarbias_meta::colvarbias_meta (std::string const &conf, char const *key)
get_keyval (conf, "rebinGrids", rebin_grids, false);
expand_grids = false;
for (size_t i = 0; i < colvars.size(); i++) {
size_t i;
for (i = 0; i < colvars.size(); i++) {
if (colvars[i]->expand_boundaries) {
expand_grids = true;
cvm::log ("Metadynamics bias \""+this->name+"\""+
@ -79,7 +82,7 @@ colvarbias_meta::colvarbias_meta (std::string const &conf, char const *key)
get_keyval (conf, "dumpFreeEnergyFile", dump_fes, true, colvarparse::parse_silent);
get_keyval (conf, "saveFreeEnergyFile", dump_fes_save, false);
for (size_t i = 0; i < colvars.size(); i++) {
for (i = 0; i < colvars.size(); i++) {
colvars[i]->enable (colvar::task_grid);
}
@ -91,6 +94,9 @@ colvarbias_meta::colvarbias_meta (std::string const &conf, char const *key)
dump_fes = false;
dump_fes_save = false;
dump_replica_fes = false;
hills_energy = NULL;
hills_energy_gradients = NULL;
}
if (comm != single_replica) {
@ -144,7 +150,7 @@ colvarbias_meta::colvarbias_meta (std::string const &conf, char const *key)
replica_state_file =
(std::string (pwd)+std::string (PATHSEP)+
cvm::output_prefix+".colvars."+this->name+"."+replica_id+".state");
delete pwd;
delete[] pwd;
}
// now register this replica
@ -316,7 +322,7 @@ colvarbias_meta::delete_hill (hill_iter &h)
"")+".\n");
}
if (use_grids && hills_off_grid.size()) {
if (use_grids && !hills_off_grid.empty()) {
for (hill_iter hoff = hills_off_grid.begin();
hoff != hills_off_grid.end(); hoff++) {
if (*h == *hoff) {
@ -458,9 +464,14 @@ cvm::real colvarbias_meta::update()
case single_replica:
if (well_tempered) {
std::vector<int> curr_bin = hills_energy->get_colvars_index();
cvm::real const hills_energy_sum_here = hills_energy->value(curr_bin);
cvm::real const exp_weight = std::exp(-hills_energy_sum_here/(bias_temperature*cvm::boltzmann()));
cvm::real hills_energy_sum_here = 0.0;
if (use_grids) {
std::vector<int> curr_bin = hills_energy->get_colvars_index();
hills_energy_sum_here = hills_energy->value(curr_bin);
} else {
calc_hills (new_hills_begin, hills.end(), hills_energy_sum_here);
}
cvm::real const exp_weight = std::exp(-1.0*hills_energy_sum_here/(bias_temperature*cvm::boltzmann()));
create_hill (hill ((hill_weight*exp_weight), colvars, hill_width));
} else {
create_hill (hill (hill_weight, colvars, hill_width));
@ -469,9 +480,14 @@ cvm::real colvarbias_meta::update()
case multiple_replicas:
if (well_tempered) {
std::vector<int> curr_bin = hills_energy->get_colvars_index();
cvm::real const hills_energy_sum_here = hills_energy->value(curr_bin);
cvm::real const exp_weight = std::exp(-hills_energy_sum_here/(bias_temperature*cvm::boltzmann()));
cvm::real hills_energy_sum_here = 0.0;
if (use_grids) {
std::vector<int> curr_bin = hills_energy->get_colvars_index();
hills_energy_sum_here = hills_energy->value(curr_bin);
} else {
calc_hills (new_hills_begin, hills.end(), hills_energy_sum_here);
}
cvm::real const exp_weight = std::exp(-1.0*hills_energy_sum_here/(bias_temperature*cvm::boltzmann()));
create_hill (hill ((hill_weight*exp_weight), colvars, hill_width, replica_id));
} else {
create_hill (hill (hill_weight, colvars, hill_width, replica_id));
@ -680,10 +696,11 @@ void colvarbias_meta::calc_hills_force (size_t const &i,
// were already saved with their types matching those in the
// colvars)
hill_iter h;
switch (colvars[i]->type()) {
case colvarvalue::type_scalar:
for (hill_iter h = h_first; h != h_last; h++) {
for (h = h_first; h != h_last; h++) {
if (h->value() == 0.0) continue;
colvarvalue const &center = h->centers[i];
cvm::real const half_width = 0.5 * h->widths[i];
@ -695,7 +712,8 @@ void colvarbias_meta::calc_hills_force (size_t const &i,
case colvarvalue::type_vector:
case colvarvalue::type_unitvector:
for (hill_iter h = h_first; h != h_last; h++) {
case colvarvalue::type_unitvectorderiv:
for (h = h_first; h != h_last; h++) {
if (h->value() == 0.0) continue;
colvarvalue const &center = h->centers[i];
cvm::real const half_width = 0.5 * h->widths[i];
@ -705,8 +723,8 @@ void colvarbias_meta::calc_hills_force (size_t const &i,
}
break;
case colvarvalue::type_quaternion:
for (hill_iter h = h_first; h != h_last; h++) {
case colvarvalue::type_quaternionderiv:
for (h = h_first; h != h_last; h++) {
if (h->value() == 0.0) continue;
colvarvalue const &center = h->centers[i];
cvm::real const half_width = 0.5 * h->widths[i];
@ -717,6 +735,7 @@ void colvarbias_meta::calc_hills_force (size_t const &i,
break;
case colvarvalue::type_notset:
case colvarvalue::type_all:
break;
}
}
@ -756,8 +775,8 @@ void colvarbias_meta::project_hills (colvarbias_meta::hill_iter h_first,
for ( ;
(he->index_ok (he_ix)) && (hg->index_ok (hg_ix));
count++) {
for (size_t i = 0; i < colvars.size(); i++) {
size_t i;
for (i = 0; i < colvars.size(); i++) {
colvar_values[i] = hills_energy->bin_to_value_scalar (he_ix[i], i);
}
@ -766,7 +785,7 @@ void colvarbias_meta::project_hills (colvarbias_meta::hill_iter h_first,
calc_hills (h_first, h_last, hills_energy_here, colvar_values);
he->acc_value (he_ix, hills_energy_here);
for (size_t i = 0; i < colvars.size(); i++) {
for (i = 0; i < colvars.size(); i++) {
hills_forces_here[i].reset();
calc_hills_force (i, h_first, h_last, hills_forces_here, colvar_values);
colvar_forces_scalar[i] = hills_forces_here[i].real_value;
@ -935,10 +954,6 @@ void colvarbias_meta::update_replicas_registry()
}
}
}
// continue the cycle
new_replica_file = "";
new_replica = "";
} else {
cvm::fatal_error ("Error: cannot read the replicas registry file \""+
replicas_registry+"\".\n");
@ -1279,7 +1294,7 @@ std::istream & colvarbias_meta::read_restart (std::istream& is)
}
}
bool const existing_hills = (hills.size() > 0);
bool const existing_hills = !hills.empty();
size_t const old_hills_size = hills.size();
hill_iter old_hills_end = hills.end();
hill_iter old_hills_off_grid_end = hills_off_grid.end();
@ -1299,7 +1314,7 @@ std::istream & colvarbias_meta::read_restart (std::istream& is)
cvm::log ("Read "+cvm::to_str (hills.size())+
" hills in addition to the grids.\n");
} else {
if (hills.size())
if (!hills.empty())
cvm::log ("Read "+cvm::to_str (hills.size())+" hills.\n");
}
@ -1314,7 +1329,7 @@ std::istream & colvarbias_meta::read_restart (std::istream& is)
colvar_grid_gradient *new_hills_energy_gradients =
new colvar_grid_gradient (colvars);
if (!grids_from_restart_file || (keep_hills && hills.size())) {
if (!grids_from_restart_file || (keep_hills && !hills.empty())) {
// if there are hills, recompute the new grids from them
cvm::log ("Rebinning the energy and forces grids from "+
cvm::to_str (hills.size())+" hills (this may take a while)...\n");
@ -1337,12 +1352,12 @@ std::istream & colvarbias_meta::read_restart (std::istream& is)
// assuming that some boundaries have expanded, eliminate those
// off-grid hills that aren't necessary any more
if (hills.size())
if (!hills.empty())
recount_hills_off_grid (hills.begin(), hills.end(), hills_energy);
}
if (use_grids) {
if (hills_off_grid.size()) {
if (!hills_off_grid.empty()) {
cvm::log (cvm::to_str (hills_off_grid.size())+" hills are near the "
"grid boundaries: they will be computed analytically "
"and saved to the state files.\n");
@ -1656,15 +1671,16 @@ std::string colvarbias_meta::hill::output_traj()
os.setf (std::ios::scientific, std::ios::floatfield);
size_t i;
os << " ";
for (size_t i = 0; i < centers.size(); i++) {
for (i = 0; i < centers.size(); i++) {
os << " ";
os << std::setprecision (cvm::cv_prec)
<< std::setw (cvm::cv_width) << centers[i];
}
os << " ";
for (size_t i = 0; i < widths.size(); i++) {
for (i = 0; i < widths.size(); i++) {
os << " ";
os << std::setprecision (cvm::cv_prec)
<< std::setw (cvm::cv_width) << widths[i];
@ -1692,8 +1708,9 @@ std::ostream & operator << (std::ostream &os, colvarbias_meta::hill const &h)
if (h.replica.size())
os << " replicaID " << h.replica << "\n";
size_t i;
os << " centers ";
for (size_t i = 0; i < (h.centers).size(); i++) {
for (i = 0; i < (h.centers).size(); i++) {
os << " "
<< std::setprecision (cvm::cv_prec)
<< std::setw (cvm::cv_width)
@ -1702,7 +1719,7 @@ std::ostream & operator << (std::ostream &os, colvarbias_meta::hill const &h)
os << "\n";
os << " widths ";
for (size_t i = 0; i < (h.widths).size(); i++) {
for (i = 0; i < (h.widths).size(); i++) {
os << " "
<< std::setprecision (cvm::cv_prec)
<< std::setw (cvm::cv_width)