bool conf_rxn_delphi(SMCCE * mcce_data,float rxn[]) { bool bDelPhiReturn = false; char FileName[80]; /* * save log and errors in the same file */ sprintf(FileName,"%s%02d.log","rxn",1); ofstream logFile(FileName); StreamRedirector redirect_cout(cout,logFile.rdbuf()); StreamRedirector redirect_cerr(cerr,logFile.rdbuf()); bDelPhiReturn = runDelphi(mcce_data); if (false == bDelPhiReturn) { printf("\n WARNING: Delphi failed at focusing depth %d of %s, retry\n", 1, mcce_data->uniqID.c_str()); return false; } rxn[0] = mcce_data->ergs; /* * prepare for focusing runs */ mcce_data->bndcon = 3; for (int i = 1; i < mcce_data->del_runs; i++) { /* * update mcce_data to prepare for focusing runs */ mcce_data->del_runs -= i; /* * save log and errors in the same file */ sprintf(FileName,"%s%02d.log","rxn",i+1); ofstream logFile(FileName); StreamRedirector redirect_cout(cout,logFile.rdbuf()); StreamRedirector redirect_cerr(cerr,logFile.rdbuf()); bDelPhiReturn = runDelphi(mcce_data); if (false == bDelPhiReturn) { printf("\n WARNING: Delphi failed at focusing depth %d of %s, retry\n", 1, mcce_data->uniqID.c_str()); return false; } rxn[i] = mcce_data->ergs; } return true; }
void runDelphi(shared_ptr<SPrime> param) { #ifdef DELPHI_OUTPUT string delphi_ntime = "delphi_run_" + to_string(param->ntimes) + ".log"; #endif #ifndef DELPHI_OUTPUT string delphi_ntime = "delphi_run_" + to_string(param->ntimes) + ".log"; #endif ofstream logFile(delphi_ntime); StreamRedirector redirect_cout(cout,logFile.rdbuf()); StreamRedirector redirect_cerr(cerr,logFile.rdbuf()); cout << boolalpha; cerr << boolalpha; try { CTimer * pTester = new CTimer; // record execution time pTester->start(); shared_ptr<CTimer> pTimer( new CTimer); // record execution time shared_ptr<IDataContainer> pDataContainer( new CDelphiData(param,pTimer) ); // pDataContainer->showMap("showmap_atbegin.dat"); int& inhomo(pDataContainer->getKey_Ref<int>("inhomo")); const int& iGaussian(pDataContainer->getKey_constRef<int>("gaussian")); bool& logs (pDataContainer->getKey_Ref<bool>("logs")); bool& logg (pDataContainer->getKey_Ref<bool>("logg")); inhomo=0; if( iGaussian==1 && logs ) { logg=true; //for gaussian inhomo=1; } //********************************************************************************// // // // realize an object of CDelphiSpace class to construct molecular surfaces // // // //********************************************************************************// unique_ptr<IAbstractModule> pSpace( new CDelphiSpace(pDataContainer,pTimer) ); pSpace->run(); pSpace.reset(); // pDataContainer->showMap("showmap_aftersuf.dat"); if( !(iGaussian==1&&inhomo==0&&logs) ) { cout << " number of atom coordinates read :" << right << setw(10) << pDataContainer->getKey_constRef<delphi_integer>("natom") << endl; } if (pDataContainer->getKey_constRef<bool>("isolv")) { if( !(iGaussian==1&&inhomo==0&&logs) ) { cout << " total number of assigned charges :" << right << setw(10) << pDataContainer->getKey_constRef<delphi_integer>("nqass") << endl; cout << " net assigned charge :" << right << setw(10) << pDataContainer->getKey_constRef<delphi_real>("qnet") << endl; cout << " assigned positive charge :" << right << setw(10) << pDataContainer->getKey_constRef<delphi_real>("qplus") << endl; cout << " centred at (gu) :" << right << setw(10) << pDataContainer->getKey_constRef< SGrid<delphi_real> >("cqplus").nX << " " << right << setw(10) << pDataContainer->getKey_constRef< SGrid<delphi_real> >("cqplus").nY << " " << right << setw(10) << pDataContainer->getKey_constRef< SGrid<delphi_real> >("cqplus").nZ << endl; cout << " assigned negative charge :" << right << setw(10) << pDataContainer->getKey_constRef<delphi_real>("qmin") << endl; cout << " centred at (gu) :" << right << setw(10) << pDataContainer->getKey_constRef< SGrid<delphi_real> >("cqmin").nX << " " << right << setw(10) << pDataContainer->getKey_constRef< SGrid<delphi_real> >("cqmin").nY << " " << right << setw(10) << pDataContainer->getKey_constRef< SGrid<delphi_real> >("cqmin").nZ << endl; cout << "\nnumber of dielectric boundary points" << right << setw(10) << pDataContainer->getKey_constRef<delphi_integer>("ibnum") << endl; } if (pDataContainer->getKey_constRef<bool>("iexun") && 0 == pDataContainer->getKey_constRef<delphi_integer>("ibnum")) throw CNoBndyAndDielec(pTimer); //********************************************************************************// // // // realize an object of CDelphiFastSOR class to calculate potentials on grids // // // //********************************************************************************// unique_ptr<CDelphiFastSOR> pSolver( new CDelphiFastSOR(pDataContainer,pTimer) ); if (param->bndcon == 3) { pSolver->getPRIME(param); } pSolver->run(); pSolver.reset(); // pDataContainer->showMap("showmap_afteritr.dat"); //********************************************************************************// // // // realize an object of CDelphiEnergy class to calculate energies // // // //********************************************************************************// unique_ptr<IAbstractModule> pEnergy( new CDelphiEnergy(pDataContainer,pTimer) ); pEnergy->run(); pEnergy.reset(); // pDataContainer->showMap("showmap_aftereng.dat"); if(iGaussian==1&&inhomo==1&&logs) //second run for Gaussian { inhomo=0; unique_ptr<IAbstractModule> pSpace( new CDelphiSpace(pDataContainer,pTimer) ); pSpace->run(); pSpace.reset(); unique_ptr<IAbstractModule> pSolver( new CDelphiFastSOR(pDataContainer,pTimer) ); pSolver->run(); pSolver.reset(); unique_ptr<IAbstractModule> pEnergy( new CDelphiEnergy(pDataContainer,pTimer) ); pEnergy->run(); pEnergy.reset(); } //********************************************************************************// // // // realize an object of CSite class to write site info // // // //********************************************************************************// unique_ptr<CSite> pSite( new CSite(pDataContainer,pTimer) ); if (pDataContainer->getKey_constRef<bool>("isite")) { int iisitsf = 0; if (pDataContainer->getKey_Ref<bool>("isitsf")) iisitsf = 1; pSite->writeSite(iisitsf); } if (pDataContainer->getKey_constRef<bool>("phiwrt")) pSite->writePhi(); // pDataContainer->showMap("showmap_aftersite.dat"); /* * equivalent to out(frc,file="filename") in the parameter file if (0 == pSite->prime_grdphiv.size()) { pSite.reset(); pTimer->exit(); pTimer.reset(); } */ param->strAtomDes = pSite->prime_atomdes; param->vecGridPot = pSite->prime_grdphiv; param->vecSiteCrg = pSite->prime_crhgv; #ifdef PRIME pSite->clearIO(); #endif pSite.reset(); } //********************************************************************************// // // // retrieve the solvation energy and grid energy from data container // // // //********************************************************************************// param->ergs = pDataContainer->getKey_Val<delphi_real>("ergs"); param->ergg = pDataContainer->getKey_Val<delphi_real>("ergg"); if(pDataContainer->getKey_constRef<int>("ibctyp") == 2) { param->igrid1 = pDataContainer->getKey_constRef<delphi_integer>("igrid"); param->scale1 = pDataContainer->getKey_constRef<delphi_real>("scale"); param->oldmid1 = pDataContainer->getKey_constRef<SGrid<delphi_real> >("oldmid"); param->phimap = pDataContainer->getKey_constRef<vector<delphi_real> >("phimap"); // pDataContainer->showMap("test_phimap"); } pDataContainer.reset(); pTimer->exit(); pTimer.reset(); delete pTester; #ifdef DELPHI_OUTPUT param->ntimes++; #endif remove(&delphi_ntime[0]); } // ---------- end of try block catch (CException&) { cerr << "\n\n ......... PROGRAM ABORTS WITH AN EXCEPTION AND " << CWarning::iWarningNum << " WARNING(S) ........\n\n"; } cout << "\n\n ......... PROGRAM EXITS SUCCESSFULLY : WITH TOTAL " << CWarning::iWarningNum << " WARNING(S) ........\n\n"; cout.unsetf(ios_base::floatfield); // return to cout default notation }
int main (int argc, char**argv) { //option variables bool do_help = false, do_version = false, do_test = false, has_opt = false, opt_armor = false, opt_yes = false, opt_fingerprint = false, opt_clearsign = false, opt_import_no_action = false; std::string recipient, user, input, output, name, filter, action_param, detach_sign, symmetric; char action = 0; int c, option_index; for (;;) { static struct option long_opts[] = { {"help", 0, 0, 'h' }, {"version", 0, 0, 'V' }, {"test", 0, 0, 'T' }, //global options {"armor", 0, 0, 'a' }, {"yes", 0, 0, 'y' }, {"recipient", 1, 0, 'r' }, {"user", 1, 0, 'u' }, //I/O redirection from default stdin/out {"in", 1, 0, 'R' }, {"out", 1, 0, 'o' }, //keyring management {"list", 0, 0, 'k' }, {"import", 0, 0, 'i' }, {"export", 0, 0, 'p' }, {"delete", 1, 0, 'x' }, {"rename", 1, 0, 'm' }, {"list-secret", 0, 0, 'K' }, {"import-secret", 0, 0, 'I' }, {"export-secret", 0, 0, 'P' }, {"delete-secret", 1, 0, 'X' }, {"rename-secret", 1, 0, 'M' }, {"gen-key", 1, 0, 'g' }, {"name", 1, 0, 'N' }, {"filter", 1, 0, 'F' }, {"fingerprint", 0, 0, 'f' }, {"no-action", 0, 0, 'n' }, //actions {"sign", 0, 0, 's' }, {"verify", 0, 0, 'v' }, {"encrypt", 0, 0, 'e' }, {"decrypt", 0, 0, 'd' }, //action options {"clearsign", 0, 0, 'C' }, {"detach-sign", 1, 0, 'b' }, {"symmetric", 1, 0, 'S' }, {0, 0, 0, 0 } }; option_index = -1; c = getopt_long (argc, argv, "hVTayr:u:R:o:kipx:m:KIPX:M:g:N:F:fnsvedCb:S:", long_opts, &option_index); if (c == -1) break; has_opt = true; switch (c) { case '?': case ':': case 'h': do_help = true; break; #define read_flag(ch,var) case ch: var=true; break; #define read_single_opt(ch,var,errmsg) \ case ch: if(var.length()) {progerr(errmsg); do_help=true;}\ else var=optarg; break; #define read_action(ch) read_action_comb(ch,0,0) #define read_action_comb(ch, hit, comb) \ case ch: \ if(hit && action==hit) { \ action=comb; \ if(optarg) action_param=optarg; \ } else if(action) { \ progerr("please specify a single action"); \ do_help=true; \ } else { \ action=ch; \ if(optarg) action_param=optarg; \ } break; read_flag ('V', do_version) read_flag ('T', do_test) read_flag ('a', opt_armor) read_flag ('y', opt_yes) read_single_opt ('r', recipient, "specify only one recipient") read_single_opt ('u', user, "specify only one local user") read_single_opt ('R', input, "cannot accept multiple inputs") read_single_opt ('o', output, "cannot accept multiple outputs") read_action ('k') read_action ('i') read_action ('p') read_action ('x') read_action ('m') read_action ('K') read_action ('I') read_action ('P') read_action ('X') read_action ('M') read_action ('g') read_single_opt ('N', name, "please specify single name") read_single_opt ('F', filter, "please specify single filter string") read_flag ('f', opt_fingerprint) read_flag ('n', opt_import_no_action) /* * combinations of s+e and d+v are possible. result is * 'E' = "big encrypt with sig" and 'D' "big decrypt * with verify". */ read_action_comb ('s', 'e', 'E') read_action_comb ('v', 'd', 'D') read_action_comb ('e', 's', 'E') read_action_comb ('d', 'v', 'D') read_flag ('C', opt_clearsign) read_single_opt ('b', detach_sign, "specify only one detach-sign file") read_single_opt ('S', symmetric, "specify only one symmetric parameter") #undef read_flag #undef read_single_opt #undef read_action default: //which doesn't just happen. do_help = true; break; } } if (optind != argc) { progerr ("unmatched non-option parameters"); do_help = true; } if ( (!has_opt) || do_help) { print_help (argv[0]); return 0; } if (do_version) { print_version(); return 0; } /* * something will be happening, therefore init everything */ keyring KR; algorithm_suite AS; //register all available algorithms fill_algorithm_suite (AS); /* * cin/cout redirection */ int exitval = 0; if (input.length() && !redirect_cin (input) ) { progerr ("could not open input file"); exitval = 1; goto exit; } if (output.length() && !redirect_cout (output) ) { progerr ("could not redirect to output file"); exitval = 1; goto exit; } /* * check the option flags and do whatever was requested */ if (do_test) { test(); goto exit; } if (symmetric.length() ) switch (action) { case 's': case 'v': break; default: progerr ("specified action doesn't support symmetric operation"); exitval = 1; goto exit; } switch (action) { case 'g': exitval = action_gen_key (action_param, name, KR, AS); break; case 'e': exitval = action_encrypt (recipient, opt_armor, KR, AS); break; case 'd': exitval = action_decrypt (opt_armor, KR, AS); break; case 's': exitval = action_sign (user, opt_armor, detach_sign, opt_clearsign, symmetric, KR, AS); break; case 'v': exitval = action_verify (opt_armor, detach_sign, opt_clearsign, opt_yes, symmetric, KR, AS); break; case 'E': exitval = action_sign_encrypt (user, recipient, opt_armor, KR, AS); break; case 'D': exitval = action_decrypt_verify (opt_armor, opt_yes, KR, AS); break; case 'k': exitval = action_list (opt_fingerprint, filter, KR); break; case 'i': exitval = action_import (opt_armor, opt_import_no_action, opt_yes, opt_fingerprint, filter, name, KR); break; case 'p': exitval = action_export (opt_armor, filter, name, KR); break; case 'x': exitval = action_delete (opt_yes, action_param, KR); break; case 'm': exitval = action_rename (opt_yes, action_param, name, KR); break; case 'K': exitval = action_list_sec (opt_fingerprint, filter, KR); break; case 'I': exitval = action_import_sec (opt_armor, opt_import_no_action, opt_yes, opt_fingerprint, filter, name, KR); break; case 'P': exitval = action_export_sec (opt_armor, opt_yes, filter, name, KR); break; case 'X': exitval = action_delete_sec (opt_yes, action_param, KR); break; case 'M': exitval = action_rename_sec (opt_yes, action_param, name, KR); break; default: progerr ("no action specified, use `--help'"); exitval = 1; break; } /* * all done. * keyring is _not_ automatically saved here to prevent frequent * rewriting and due the fact that everything that modifies it _must_ * also ensure and verify that it was written back correctly. */ exit: if (!KR.close() ) { progerr ("could not close keyring, " "something weird is going to happen."); } return exitval; }
/** * interface function to pass the calculated energies, values etc., from delphicpp to mcce * * @param[in,out] mcce_data the struct containing the values required to run delphicpp and to be returned back to mcce * @return true if successfully calling delphicpp */ bool conf_energies_delphi(SMCCE * mcce_data) { int notpassed = 1; bool bDelPhiReturn = false; char FileName[80]; while(notpassed) { if (2 > mcce_data->n_retry) { /* * save log and errors in different files * sprintf(FileName,"%s%02d.log","delphi",1); ofstream logFile(FileName); StreamRedirector redirect_cout(cout,logFile.rdbuf()); sprintf(FileName,"%s%02d.err","delphi",1); ofstream errFile(FileName); StreamRedirector redirect_cerr(cerr,errFile.rdbuf()); */ /* * save log and errors in the same file */ sprintf(FileName,"%s%02d.log","delphi",1); ofstream logFile(FileName); StreamRedirector redirect_cout(cout,logFile.rdbuf()); StreamRedirector redirect_cerr(cerr,logFile.rdbuf()); bDelPhiReturn = runDelphi(mcce_data); } else if (2 <= mcce_data->n_retry && 100 > mcce_data->n_retry) { printf(" Trying changing scale on trial %d\n",mcce_data->n_retry); bDelPhiReturn = runDelphi(mcce_data); } else { printf(" FATAL: too many failed delphi runs (%d), quitting...\n",mcce_data->n_retry); return false; } if (false == bDelPhiReturn) { printf("\n WARNING: Delphi failed at focusing depth %d of %s, retry\n", 1, mcce_data->uniqID.c_str()); mcce_data->n_retry++; mcce_data->del_err = 1; continue; } /* * prepare for focusing runs */ if (1 < mcce_data->del_runs) mcce_data->bndcon = 3; for (int i = 1; i < mcce_data->del_runs; i++) { /* * update mcce_data to prepare for focusing runs */ mcce_data->del_runs -= i; if (100 > mcce_data->n_retry) { /* * save log and errors in different files * sprintf(FileName,"%s%02d.log","delphi",i+1); ofstream logFile(FileName); StreamRedirector redirect_cout(cout,logFile.rdbuf()); sprintf(FileName,"%s%02d.err","delphi",i+1); ofstream errFile(FileName); StreamRedirector redirect_cerr(cerr,errFile.rdbuf()); */ /* * save log and errors in the same file */ sprintf(FileName,"%s%02d.log","delphi",i+1); ofstream logFile(FileName); StreamRedirector redirect_cout(cout,logFile.rdbuf()); StreamRedirector redirect_cerr(cerr,logFile.rdbuf()); bDelPhiReturn = runDelphi(mcce_data); } else { printf(" FATAL: too many failed delphi runs (%d), quitting...\n",mcce_data->n_retry); return false; } if (false == bDelPhiReturn) { printf("\n WARNING: Delphi failed at focusing depth %d of %s, retry\n",i+1,mcce_data->uniqID.c_str()); mcce_data->n_retry++; mcce_data->del_err = 1; break; } mcce_data->del_err = 0; } if (mcce_data->del_err) notpassed = 1; else notpassed = 0; /* so far so good */ } return true; }