11inline int removeFile(
const std::string& filename) {
return remove(filename.c_str()); }
13inline void clearFile(
const std::string& filename) { std::ofstream clear(filename, std::ios::trunc); }
16 if (ofs.is_open()) ofs.close();
19inline bool isFileExists(
const std::string& name) {
return std::ifstream{name.c_str()}.good(); }
35 std::string mndoinp = PM->get_string(
"mndoinp",
LOC(),
"null");
77 for (
int k = 0; k <
Dimension::F; ++k, ++ik)
T[ik] = (i == k) ? 1.0e0 : 0.0e0;
81 for (
int i = 0, idx = 0, idxR = 0; i <
natom; ++i) {
83 for (
int j = 0; j < 3; ++j, ++idxR) {
92 beta = 1.0f / (phys::au::k * temperature);
112 std::string hess_log =
_param->get_string(
"hess_log",
LOC(),
"hess.out");
114 throw std::runtime_error(
utils::concat(
"hess_log file [", hess_log,
"] is missed!"));
120 if (j < 6 ||
w[j] < 1.0e-10) {
124 double Qoverbeta = 0.5f *
w[j] / std::tanh(0.5f *
beta *
w[j]);
127 x_sigma[j] = std::sqrt(Qoverbeta / (
w[j] *
w[j]));
128 p_sigma[j] = std::sqrt(Qoverbeta);
133 std::string hess_mol =
_param->get_string(
"hess_mol",
LOC(),
"hess_molden.dat");
135 throw std::runtime_error(
utils::concat(
"hess_mol file [", hess_mol,
"] is missed!"));
160 for (
int i = 0; i < 6; ++i)
x[i] = 0.0f,
p[i] = 0.0f;
169 x[i] =
x[i] / std::sqrt(
mass[i]) +
x0[i];
170 p[i] =
p[i] * std::sqrt(
mass[i]) +
p0[i];
178 std::string stmp, eachline;
179 std::ifstream ifs(open_file);
180 while (getline(ifs, eachline)) {
181 if (eachline.find(
"init.x") != eachline.npos) {
182 getline(ifs, eachline);
183 for (
int i = 0; i < Dimension::N; ++i) ifs >>
x[i];
185 if (eachline.find(
"init.p") != eachline.npos) {
186 getline(ifs, eachline);
187 for (int i = 0; i < Dimension::N; ++i) ifs >> p[i];
198 std::string hdlr_str =
_param->get_string(
"handler",
LOC());
201 task_control = (hdlr_str ==
"sampling") ?
"samp" :
"nad";
223 control_copy =
"nad-hard";
226 system(rm_exe.c_str());
227 std::cout <<
"last try mndo\n";
232 int stat = system(cmd_exe.c_str());
240 if (j == k)
continue;
241 dE[idx] =
nac[idx] * (
E[k] -
E[j]);
277 enum Stage { KEYWORD, COMMENT, DATA, ADDITION };
278 Stage istage = KEYWORD;
280 std::stringstream mndo_keyword_sstr;
281 std::stringstream mndo_comment_sstr;
282 std::stringstream mndo_addition_sstr;
285 std::ifstream ifs(mndoinp);
286 std::string eachline;
287 while (getline(ifs, eachline)) {
288 eachline.erase(eachline.find_last_not_of(
" ") + 1);
291 mndo_keyword_sstr << eachline << std::endl;
292 std::string data, key, val;
293 std::istringstream input(eachline);
294 while (input >> data) {
295 if (data ==
"+")
continue;
296 std::istringstream pair(data);
297 getline(pair, key,
'=');
298 getline(pair, val,
'=');
299 std::for_each(key.begin(), key.end(), [](
char& c) { c = ::tolower(c); });
301 if (key ==
"ncigrd")
ncigrd = std::stoi(val);
302 if (key ==
"nciref")
nciref = std::stoi(val);
303 if (key ==
"iroot")
iroot = std::stoi(val);
307 if (eachline.back() !=
'+') istage = COMMENT;
311 mndo_comment_sstr << eachline << std::endl;
312 getline(ifs, eachline);
313 mndo_comment_sstr << eachline << std::endl;
319 std::string data, databuf[16];
320 std::istringstream input(eachline);
321 while (input >> data) databuf[ndata++] = data;
322 if (std::stoi(databuf[0]) != 0) {
324 for (
int i = 0; i < ndata; ++i)
mndo_data.push_back(databuf[i]);
327 mndo_addition_sstr << eachline << std::endl;
332 mndo_addition_sstr << eachline << std::endl;
341 assert(count_atom > 0);
343 if (7 * count_atom == data_size) std::cout <<
"read from cartesian format";
344 if (10 * count_atom == data_size)
throw std::runtime_error(
"cannot read from zmat format");
353 std::stringstream sstr;
355 const int ntermperline = 8;
356 for (
auto iter =
keyword.begin(); iter !=
keyword.end(); ++iter, ++i) {
358 if (i != 0 && i % ntermperline == 0) sstr <<
"+" << std::endl;
359 if (newkeyword.find(kw.
key) != newkeyword.end()) {
360 sstr << kw.
key <<
"=" << newkeyword.at(kw.
key) <<
" ";
362 sstr << kw.
key <<
"=" << kw.
val <<
" ";
374 std::string revised_keyword, revised_addition;
375 if (task_flag ==
"sp") {
376 revised_keyword =
new_keyword({{
"jop",
"-1"}, {
"icross",
"0"}});
377 }
else if (task_flag ==
"samp") {
379 {{
"jop",
"-1"}, {
"icross",
"7"}, {
"mprint",
"1"}, {
"iuvcd",
"2"}, {
"imomap",
"0"}, {
"mapthr",
"90"}});
380 }
else if (task_flag ==
"force") {
381 revised_keyword =
new_keyword({{
"jop",
"-2"}, {
"icross",
"1"}});
383 }
else if (task_flag ==
"nad") {
385 new_keyword({{
"jop",
"-2"}, {
"icross",
"7"}, {
"mprint",
"1"}, {
"imomap",
"3"}, {
"mapthr",
"97"}});
387 }
else if (task_flag ==
"nad-hard") {
389 {{
"jop",
"-2"}, {
"icross",
"7"}, {
"mprint",
"1"}, {
"imomap",
"3"}, {
"mapthr",
"75"}, {
"kitscf",
"5000"}});
391 }
else if (task_flag ==
"hess") {
392 revised_keyword =
new_keyword({{
"jop",
"2"}, {
"icross",
"0"}, {
"kprint",
"1"}});
398 const int fixflag = 0;
399 std::ofstream ofs(file);
400 ofs << revised_keyword;
402 for (
int i = 0, idx = 0; i <
natom; ++i) {
404 <<
FMT(8) <<
x[idx++] <<
FMT(4) << fixflag
405 <<
FMT(8) <<
x[idx++] <<
FMT(4) << fixflag
406 <<
FMT(8) <<
x[idx++] <<
FMT(4) << fixflag
409 ofs << revised_addition;
424 if (i == j)
continue;
426 const double norm_eps = 10e-14;
427 double norm_old = 0.0f;
428 double norm_new = 0.0f;
429 double cosangle = 0.0f;
433 norm_new +=
nac[idx] *
nac[idx];
436 norm_old = sqrt(norm_old);
437 norm_new = sqrt(norm_new);
438 if (norm_old < norm_eps || norm_new < norm_eps) {
441 cosangle = cosangle / (norm_old * norm_new);
444 if (norm_new > 10e12 || norm_old > 10e12) {
450 }
else if (cosangle < 0) {
470 int istate_force = 0, istate_force_meet = 0;
473 std::ifstream ifs(log);
474 std::string stmp, eachline;
475 std::string ERROR_MSG =
"";
476 while (getline(ifs, eachline,
'\n')) {
477 if (eachline.find(
"ERROR") != eachline.npos || eachline.find(
"UNABLE") != eachline.npos) {
478 ERROR_MSG += eachline;
484 if (eachline.find(
"Properties of transitions 1 -> #") != eachline.npos) {
485 for (
int i = 0; i < 2; ++i) getline(ifs, eachline);
486 for (
int i = 1; i <
nciref; ++i) {
487 ifs >> stmp >> stmp >> stmp >> stmp >> stmp >> stmp >>
f_r[i] >>
f_p[i] >>
f_rp[i] >> stmp;
494 else if (eachline.find(
"SUMMARY OF MULTIPLE CI CALCULATIONS") != eachline.npos) {
495 for (
int i = 0; i < 4; ++i) getline(ifs, eachline);
497 ifs >> stmp >> stmp >>
E[i] >> stmp >> stmp;
504 else if (eachline.find(
"CI CALCULATION FOR STATE:") != eachline.npos) {
505 std::istringstream sstr(eachline);
506 sstr >> stmp >> stmp >> stmp >> stmp >> istate_force;
510 else if (eachline.find(
"GRADIENTS (KCAL/(MOL*ANGSTROM))") != eachline.npos &&
511 istate_force_meet == istate_force) {
513 for (
int i = 0; i < 8; ++i) ifs >> stmp;
514 for (
int i = 0, idx = 0; i <
natom; ++i) {
515 ifs >> stmp >> stmp >> stmp >> stmp >> stmp
525 else if (eachline.find(
"CI CALCULATION FOR INTERSTATE "
526 "COUPLING OF STATES:") != eachline.npos) {
527 std::istringstream sstr(eachline);
528 sstr >> stmp >> stmp >> stmp >> stmp >> stmp >> stmp >> stmp >> istate >> jstate;
533 while (getline(ifs, eachline)) {
534 if (eachline.find(
"GRADIENTS (KCAL/(MOL*ANGSTROM))") != eachline.npos) {
535 for (
int i = 0; i < 8; ++i) ifs >> stmp;
536 for (
int i = 0, idx = 0; i <
natom; ++i) {
537 ifs >> stmp >> stmp >> stmp >> stmp >> stmp
568 std::cout <<
"fail in calling MNDO! " << ERROR_MSG <<
"\n";
570 int* istep_ptr =
_dataset->def_int(
"iter.istep");
572 "/.mndoinp.", stat_in.
icalc,
".err.", istep_ptr[0]);
573 system(cmd_exe.c_str());
575 stat_in.
icalc,
".err.", istep_ptr[0]);
576 system(cmd_exe.c_str());
580 std::cout <<
"survive in last try mndo\n";
582 std::cout <<
"mndo pass during last try conservation\n";
594 std::ifstream ifs(log);
601 std::string stmp, eachline;
604 while (getline(ifs, eachline)) {
605 if (eachline.find(
"GRADIENT NORM =") != eachline.npos) {
608 std::istringstream sstr(eachline);
609 sstr >> stmp >> stmp >> stmp >> norm;
610 eqstat = (norm < 10.0f) ? 0 : -1;
611 if (eqstat != 0) std::cerr <<
"Warning Hessian is not used under equilibrium!\n";
613 if (eachline.find(
"FORCE CONSTANT MATRIX AFTER SYMMETRIZATION.") != eachline.npos) {
614 for (
int i = 0; i < v1; ++i) {
615 getline(ifs, eachline);
616 for (
int k = 0; k < 10; ++k) ifs >> itmp;
622 if (v2 == 0)
continue;
623 getline(ifs, eachline);
624 for (
int k = 0; k < v2; ++k) ifs >> itmp;
630 if (eachline.find(
"EIGENVECTORS OF THE MASS-WEIGHTED") != eachline.npos) {
631 for (int i = 0; i < v1; ++i) {
632 getline(ifs, eachline);
633 for (int k = 0; k < 10; ++k) ifs >> itmp;
634 for (int k = 0; k < 10; ++k) {
635 if (ifs >> dtmp) w[i * 10 + k] = dtmp / phys::au_2_wn;
637 for (int j = 0; j < Dimension::N; ++j) {
639 for (int k = 0; k < 10; ++k) {
640 if (ifs >> dtmp) Tmod[Dimension::N * j + i * 10 + k] = dtmp;
644 if (v2 == 0)
continue;
645 getline(ifs, eachline);
646 for (
int k = 0; k < v2; ++k) ifs >> itmp;
647 for (
int k = 0; k < v2; ++k) {
652 for (
int k = 0; k < v2; ++k) {
665int Model_Interf_MNDO::parse_hessian2(
const std::string& molden_file) {
666 std::ifstream ifs(molden_file);
673 std::string stmp, eachline;
676 while (getline(ifs, eachline)) {
677 if (eachline.find(
"[FREQ]") != eachline.npos) {
678 for (
int j = 6; j < Dimension::N; ++j) {
679 getline(ifs, eachline);
680 std::stringstream sstr{eachline};
684 if (eachline.find(
"[FR-NORM-COORD]") != eachline.npos) {
685 for (
int i = 6; i < Dimension::N; ++i) {
687 for (
int j = 0; j < Dimension::N; ++j) {
688 if (ifs >> dtmp) Tmod[j * Dimension::N + i] = dtmp * sqrt(mass[j] *
phys::au_2_amu);
710int Model_Interf_MNDO::calc_normalmode() {
713 new_task(
".mndohess.in",
"hess");
714 int stat = system(
"mndo < .mndohess.in > .mndohess.out");
715 if (stat != 0)
return stat;
717 int stat = parse_hessian(
".mndohess.out");
728 for (
int iw = 0; iw < Dimension::N; ++iw) {
729 std::string save =
"normalmode";
730 std::ofstream ofs(save + std::to_string(iw) +
".xyz");
731 for (
int itime = 0; itime < ntime; ++itime) {
732 for (
int i = 0; i < Dimension::N; ++i) {
733 x[i] = x0[i] + Tmod[Dimension::N * i + iw] / std::sqrt(mass[i]) *
736 ofs << natom << std::endl;
738 for (
int i = 0, idx = 0; i < natom; ++i) {
757int Model_Interf_MNDO::calc_samp() {
761 new_task(
".mndohess.in",
"hess");
762 system(
"mndo < .mndohess.in > .mndohess.out");
765 parse_hessian(
".mndohess.out");
771 for (
int i = 0, idx = 0; i < Dimension::N; ++i)
772 for (
int j = 0; j < Dimension::N; ++j, ++idx) hess[idx] /= sqrt(mass[i] * mass[j]);
775 for (
int j = 0; j < Dimension::N; ++j) {
776 if (j < 6 || w[j] < 1.0e-3) {
780 double Qoverbeta = 1.0f / beta;
781 Qeff += Qoverbeta * beta;
782 x_sigma[j] = std::sqrt(Qoverbeta / (w[j] * w[j]));
783 p_sigma[j] = std::sqrt(Qoverbeta);
786 Qeff /= Dimension::N;
787 Qeff = 0.5f * beta * w[Dimension::N - 1] / std::tanh(0.5f * beta * w[Dimension::N - 1]);
789 std::cout <<
"Qeff = " << Qeff;
791 for (
int i = 0; i < Dimension::N; ++i) x[i] = x0[i];
792 executeKernel_impl(stat);
793 double ref_ener = E[0];
794 std::cout << ref_ener;
796 for (
int isamp = 0; isamp < 500; ++isamp) {
797 Kernel_Random::rand_gaussian(x, Dimension::N);
798 Kernel_Random::rand_gaussian(p, Dimension::N);
799 for (
int i = 0; i < 6; ++i) x[i] = 0.0f, p[i] = 0.0f;
800 for (
int i = 0; i < Dimension::N; ++i) {
805 ARRAY_MATMUL(x, Tmod, x, Dimension::N, Dimension::N, 1);
806 ARRAY_MATMUL(p, Tmod, p, Dimension::N, Dimension::N, 1);
807 for (
int i = 0; i < Dimension::N; ++i) {
808 x[i] = x[i] / std::sqrt(mass[i]) + x0[i];
809 p[i] = p[i] * std::sqrt(mass[i]);
814 for (
int i = 0; i < Dimension::N; ++i) Ekin += 0.5f * p[i] * p[i] / mass[i];
817 executeKernel_impl(stat);
818 double Epot = (E[0] - ref_ener);
820 std::cout <<
"::: " << beta * Epot / Qeff <<
" " << beta * Ekin / Qeff;
822 if (beta * Epot > 10 || beta * Ekin > 10) {
823 std::cout <<
"failed sample once";
825 ofs <<
FMT(8) << natom << std::endl;
826 ofs <<
FMT(8) << isamp <<
FMT(8) << beta <<
FMT(8) << Epot <<
FMT(8) << Ekin << std::endl;
827 for (
int i = 0, idx1 = 0, idx2 = 0; i < natom; ++i) {
840 std::cout <<
"test: " << beta * Epot <<
" " << beta * Ekin;
843 ofs <<
FMT(8) << natom << std::endl;
844 ofs <<
FMT(8) << isamp << std::endl;
845 for (
int i = 0, idx1 = 0, idx2 = 0; i < natom; ++i) {
858int Model_Interf_MNDO::calc_scan() {
859 int istep = 0, readn;
861 std::string eachline;
873 std::ifstream ifs(
"scan.xyz");
874 if (!ifs.is_open())
throw std::runtime_error(
"scan.xyz cannot open");
876 while (getline(ifs, eachline)) {
877 std::istringstream isstr(eachline);
879 assert(natom == readn);
880 getline(ifs, eachline);
881 for (
int iatom = 0, idx1 = 0; iatom < natom; ++iatom) {
883 for (
int i = 0; i < 3; ++i, ++idx1) {
887 getline(ifs, eachline);
888 executeKernel_impl(stat);
bool isFileExists(const std::string &name)
void closeOFS(std::ofstream &ofs)
bool isFileExists(const std::string &name)
int removeFile(const std::string &filename)
void clearFile(const std::string &filename)
#define ARRAY_MATMUL(_A, _B, _C, _n1, _n2, _n3)
#define ARRAY_CLEAR(_A, _n)
provide databases in chemistry
const char *const ELEMENTS_LABEL[]
const double ELEMENTS_MASS[]
static int rand_gaussian(kids_real *res_arr, int N=1, kids_real sigma=1.0, kids_real mu=0.0)
static bool onthefly
flag indicated the ab inition calculation
std::shared_ptr< Param > _param
Shared pointer to the Param object associated with this kernel.
std::shared_ptr< DataSet > _dataset
Shared pointer to the DataSet object associated with this kernel.
void setInputParam_impl(std::shared_ptr< Param > &PM)
Virtual function to set input parameters for the kernel implementation.
Status & parse_standard(const std::string &log, Status &stat)
parse energy/gradients/nac from output
std::string new_keyword(const MNDOKW_map &newkeyword)
generate a new set of keywords
void setInputDataSet_impl(std::shared_ptr< DataSet > &DS)
Virtual function to set input data set for the kernel implementation.
int track_nac_sign()
this part track the sign of NAC between current step with the last step, in order to make sure nac ch...
int parse_hessian(const std::string &log)
parse frequency calculation log where the frequency should be calculated by specifying (JOP=2),...
int parse_mndo(const std::string &mndoinp)
this function parse mndo input (only support cartesian format)
virtual const std::string getName()
Get the name of the kernel.
std::vector< MNDOKW > keyword
int parse_hessian2(const std::string &log)
parse frequency calculation (JOP=2) and (KPRINT=1)
Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
kids_bint * last_attempt_ptr
virtual int getType() const
Get the type of the kernel.
int new_task(const std::string &file, const std::string &task_flag)
generate input file for a new task based on the template
int calc_normalmode()
this function generates normalmode trajectories
int calc_samp()
this function generates initialization configuration
std::vector< std::string > mndo_data
Status & initializeKernel_impl(Status &stat)
ForceField_init for mndo.
std::string mndo_addition
#define LOC()
show the location information for debug
VARIABLE< kids_bint > frez
VARIABLE< kids_bint > last_attempt
VARIABLE< kids_int > fail_type
VARIABLE< kids_bint > succ
VARIABLE< kids_real > nac
VARIABLE< kids_real > nac_prev
VARIABLE< kids_real > Tmod
VARIABLE< kids_real > f_r
VARIABLE< kids_real > hess
VARIABLE< kids_real > f_p
VARIABLE< kids_real > p_sigma
VARIABLE< kids_real > vpes
VARIABLE< kids_int > atoms
VARIABLE< kids_real > x_sigma
VARIABLE< kids_real > grad
VARIABLE< kids_real > mass
VARIABLE< kids_real > f_rp
std::size_t NFF
Product of N, F, and F (N * F * F).
std::size_t N
Number of nuclear degrees of freedom.
std::size_t NN
Product of N and N (N * N).
std::size_t F
Number of electronic degrees of freedom.
std::size_t Fadd1
F plus 1 (F + 1).
std::size_t FF
Product of F and F (F * F).
< http://warp.povusers.org/FunctionParser/fparser.html
double kids_real
Alias for real number type.
std::map< std::string, std::string > MNDOKW_map
constexpr real_precision twopi
constexpr dimension7 temperature_d
static CONSTTYPE real_precision au_2_angoverps
static CONSTTYPE real_precision au_2_amu
1mea means we measure a quantity at 1*N level.
static CONSTTYPE real_precision au_2_wn
static CONSTTYPE real_precision au_2_ang
static CONSTTYPE real_precision au_2_kcal_1mea
std::basic_string< CharT > concat(const separator_t< CharT > &sep, Args &&... seq)
constexpr uint32_t hash(const char *str)
declaration of variables used in the program.