39int main(
int argc,
char **argv) {
41 return app.
Exec(argc, argv);
50 "options", boost::program_options::value<string>(),
51 " options file for coarse graining")(
53 boost::program_options::value<bool>(&
gentable_)->default_value(
false),
54 " only generate potential tables from given parameters, "
55 " NO RE update!")(
"interaction", boost::program_options::value<string>(),
56 " [OPTIONAL] generate potential tables only for the "
57 "specified interactions, \n"
58 " only valid when 'gentable' is true")(
61 ->default_value(
"param.cur"),
62 " Extension of the input parameter tables")(
65 ->default_value(
"param.new"),
66 " Extension of the output parameter tables")(
69 ->default_value(
"pot.new"),
70 " Extension of the output potential tables")(
72 boost::program_options::value<bool>(&
hessian_check_)->default_value(
true),
73 " Disable the hessian check (mostly for testing)");
75 " atomistic topology file (only needed for RE update)");
103 string name = prop->get(
"name").value();
110 aardf->
Load(name +
".dist.tgt");
115 beads1.
Generate(*top, prop->get(
"type1").value());
116 beads2.
Generate(*top, prop->get(
"type2").value());
118 if (beads1.
size() == 0) {
119 throw std::runtime_error(
"Topology does not have beads of type \"" +
120 prop->get(
"type1").value() +
122 "This was specified in type1 of interaction \"" +
125 if (beads2.
size() == 0) {
126 throw std::runtime_error(
"Topology does not have beads of type \"" +
127 prop->get(
"type2").value() +
129 "This was specified in type2 of interaction \"" +
134 double *rdfnorm =
new double();
136 if (prop->get(
"type1").value() == prop->get(
"type2").value()) {
146 cout <<
"We have " << i->
potentialName <<
" CG potential" << endl;
147 cout <<
"\t \t Between beads " << i->
type1 <<
"-" << i->
type2 << endl;
153 cout <<
"Potential range:" << endl;
154 cout <<
"\t \t rmin = " << i->
rmin <<
" [nm]" << endl;
155 cout <<
"\t \t rcutoff = " << i->
rcut <<
" [nm]" << endl;
163 cout <<
"Total number of parameters to optimize: " <<
nlamda_ << endl;
171 votca::Index pos_max = pos_start + potential_->ucg->getOptParamSize();
173 for (
votca::Index row = pos_start; row < pos_max; row++) {
176 lamda_(row) = potential_->ucg->getOptParam(lamda_i);
207 string name = prop->get(
"name").value();
212 vector<string> vtok = tok.
ToVector();
213 vector<string>::iterator vtok_iter =
214 find(vtok.begin(), vtok.end(), name);
215 if (vtok_iter == vtok.end()) {
236 throw std::runtime_error(
"No frames to process! Please check your input.");
243 cout <<
"Updating parameters" << endl;
246 cout <<
"AA Ensemble Avg Energy :: " <<
UavgAA_ << endl;
247 cout <<
"CG Ensemble Avg Energy :: " <<
UavgCG_ << endl;
251 cout <<
"Finished RE update!\n";
255 cout <<
"Writing CG parameters and potential(s)\n";
259 file_name = potential_->potentialName;
261 cout <<
"Writing file: " << file_name << endl;
262 potential_->ucg->SavePotTab(file_name,
263 potential_->options_->get(
"step").as<
double>(),
264 potential_->options_->get(
"min").as<
double>(),
265 potential_->options_->get(
"max").as<
double>());
268 file_name = potential_->potentialName;
270 cout <<
"Writing file: " << file_name << endl;
271 potential_->ucg->SaveParam(file_name);
298 if (potinfo->bonded) {
310 Eigen::LLT<Eigen::MatrixXd> cholesky(
HS_);
312 Eigen::VectorXd dlamda = cholesky.solve(-
DS_);
313 if (cholesky.info() == Eigen::ComputationInfo::NumericalIssue) {
321 "Hessian NOT a positive definite!\n"
322 "This can be a result of poor initial guess or "
323 "ill-suited CG potential settings or poor CG sampling.\n");
326 cout <<
"****************** WARNING *****************" << endl;
327 cout <<
"Hessian H NOT a positive definite!" << endl;
328 cout <<
"This can be a result of poor initial guess or ill-suited CG "
329 "potential settings or poor CG sampling."
331 cout <<
"********************************************" << endl;
333 cout <<
"However, you want to proceed despite non-positive definite H."
335 cout <<
"Non-positive H does not gurantee relative entropy iterations to "
336 "converge to minimum."
338 cout <<
"You can turn on Hessian check by setting command line option "
339 "--hessian-check=true."
342 cout <<
"In this case, alternative update option is steepest descent."
354 votca::Index pos_max = pos_start + potential_->ucg->getOptParamSize();
356 for (
votca::Index row = pos_start; row < pos_max; row++) {
359 potential_->ucg->setOptParam(lamda_i,
lamda_(row));
383 double r_hist =
aardfs_[indx]->x(bin);
384 double r1 = r_hist - 0.5 * step;
385 double r2 = r1 + step;
398 for (
votca::Index row = pos_start; row < pos_max; row++) {
408 double r_hist =
aardfs_[indx]->x(bin);
409 double r1 = r_hist - 0.5 * step;
410 double r2 = r1 + step;
432 double r_hist =
aardfs_[indx]->x(bin);
433 double r1 = r_hist - 0.5 * step;
434 double r2 = r1 + step;
460 auto worker = std::make_unique<CsgREupdateWorker>();
474 worker->potentials_.push_back(i);
477 worker->lamda_.resize(worker->nlamda_);
485 for (
votca::Index row = pos_start; row < pos_max; row++) {
494 worker->DS_ = Eigen::VectorXd::Zero(worker->nlamda_);
495 worker->HS_ = Eigen::MatrixXd::Zero(worker->nlamda_, worker->nlamda_);
496 worker->dUFrame_ = Eigen::VectorXd::Zero(worker->nlamda_);
497 worker->nframes_ = 0.0;
499 worker->beta_ = (1.0 / worker->options_.get(
"cg.inverse.kBT").as<double>());
500 worker->UavgCG_ = 0.0;
511 DS_ += myCsgREupdateWorker->
DS_;
512 HS_ += myCsgREupdateWorker->
HS_;
533 if (potinfo->bonded) {
554 if (beads1.
size() == 0) {
555 throw std::runtime_error(
"Topology does not have beads of type \"" +
558 "This was specified in type1 of interaction \"" +
561 if (beads2.
size() == 0) {
562 throw std::runtime_error(
"Topology does not have beads of type \"" +
565 "This was specified in type2 of interaction \"" +
569 std::unique_ptr<NBList> nb;
570 bool gridsearch =
false;
576 }
else if (
options_.
get(
"cg.nbsearch").
as<
string>() ==
"simple") {
579 throw std::runtime_error(
"cg.nbsearch invalid, can be grid or simple");
584 nb = std::make_unique<NBListGrid>();
586 nb = std::make_unique<NBList>();
592 nb->Generate(beads1,
true);
594 nb->Generate(beads1, beads2,
true);
602 for (
auto &pair_iter : *nb) {
609 for (
votca::Index row = pos_start; row < pos_max; row++) {
614 for (
auto &pair_iter : *nb) {
625 for (
auto &pair_iter : *nb) {
680 double new_min = 0.0;
682 if (dist.
y(i) < 1.0e-4) {
683 new_min = dist.
x(i + 1);
690 }
catch (std::runtime_error &) {
691 throw std::runtime_error(
692 "Missing file for CG rdf for the interaction " +
potentialName +
694 " is computed after CG-MD simulation.");
699 throw std::runtime_error(
702 "Please specify either \"lj126, ljg, or cbspl\" " +
"in options file.");
705 string oldparam_file_name =
potentialName +
"." + param_in_ext_;
PotentialContainer potentials_
void EvalConfiguration(Topology *conf, Topology *conf_atom) override
overload with the actual computation
void EvalBonded(Topology *conf, PotentialInfo *potinfo)
void EvalNonbonded(Topology *conf, PotentialInfo *potinfo)
void Run() override
Main body of application.
std::vector< Property * > nonbonded_
PotentialContainer potentials_
void MergeWorker(Worker *worker) override
std::vector< double * > aardfnorms_
void AAavgNonbonded(PotentialInfo *potinfo)
std::unique_ptr< CsgApplication::Worker > ForkWorker(void) override
void LoadOptions(const std::string &file)
void AAavgBonded(PotentialInfo *potinfo)
std::vector< Table * > aardfs_
void EndEvaluate() override
called after the last frame
bool EvaluateOptions() override
Process command line options.
void Initialize() override
Initialize application data.
void BeginEvaluate(Topology *top, Topology *top_atom=nullptr) override
called before the first frame
std::string param_in_ext_
std::string param_out_ext_
Index Generate(Topology &top, const std::string &select)
Select all beads of type "select".
Worker, derived from Thread, does the work.
bool EvaluateOptions() override
Process command line options.
void Initialize() override
Initialize application data.
void Run(void) override
Main body of application.
virtual double CalculateD2F(Index i, Index j, double r) const =0
virtual Index getOptParamSize() const
virtual double CalculateDF(Index i, double r) const =0
virtual double CalculateF(double r) const =0
virtual double getOptParam(Index i) const
virtual void setParam(std::string filename)
topology of the whole system
int main(int argc, char **argv)
votca::Index potentialIndex
std::string potentialName
std::string potentialFunction
PotentialInfo(votca::Index index, bool bonded_, votca::Index vec_pos_, std::string ¶m_in_ext_, Property *options, bool gentable=false)