7070
7171// DFT-D3(BJ)
7272const std::map<std::string, std::vector<double >> bj = {
73+ {" __default__" , {1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 14.0 , 0.0 }},
7374 {" bp" , {1.0 , 0.3946 , 0.3946 , 3.2822 , 4.8516 , 4.8516 , 1.0 , 14.0 , 0.0 }},
7475 {" blyp" , {1.0 , 0.4298 , 0.4298 , 2.6996 , 4.2359 , 4.2359 , 1.0 , 14.0 , 0.0 }},
7576 {" revpbe" , {1.0 , 0.5238 , 0.5238 , 2.355 , 3.5016 , 3.5016 , 1.0 , 14.0 , 0.0 }},
@@ -231,6 +232,7 @@ const std::map<std::string, std::vector<double>> bj = {
231232};
232233// DFT-D3(0)
233234const std::map<std::string, std::vector<double >> zero = {
235+ {" __default__" , {1.0 , 0.0 , 0.0 , 0.0 , 1.0 , 1.0 , 1.0 , 14.0 , 0.0 }},
234236 {" slaterdirac" , {1.0 , 0.999 , 0.999 , -1.957 , 0.697 , 0.697 , 1.0 , 14.0 , 0.0 }},
235237 {" bp" , {1.0 , 1.139 , 1.139 , 1.683 , 1.0 , 1.0 , 1.0 , 14.0 , 0.0 }},
236238 {" blyp" , {1.0 , 1.094 , 1.094 , 1.682 , 1.0 , 1.0 , 1.0 , 14.0 , 0.0 }},
@@ -318,6 +320,7 @@ const std::map<std::string, std::vector<double>> zero = {
318320};
319321// DFT-D3M(BJ): not implemented for beta
320322const std::map<std::string, std::vector<double >> bjm = {
323+ {" __default__" , {1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 14.0 , 0.0 }},
321324 {" bp" , {1.0 , 0.82185 , 0.82185 , 3.140281 , 2.728151 , 2.728151 , 1.0 , 14.0 , 0.0 }},
322325 {" blyp" , {1.0 , 0.448486 , 0.448486 , 1.875007 , 3.610679 , 3.610679 , 1.0 , 14.0 , 0.0 }},
323326 {" b97_d" , {1.0 , 0.240184 , 0.240184 , 1.206988 , 3.864426 , 3.864426 , 1.0 , 14.0 , 0.0 }},
@@ -329,6 +332,7 @@ const std::map<std::string, std::vector<double>> bjm = {
329332};
330333// DFT-D3M(0): not implemented for beta
331334const std::map<std::string, std::vector<double >> zerom = {
335+ {" __default__" , {1.0 , 0.0 , 0.0 , 0.0 , 1.0 , 1.0 , 1.0 , 14.0 , 0.0 }},
332336 {" bp" , {1.0 , 1.23346 , 1.23346 , 1.945174 , 1.0 , 1.0 , 1.0 , 14.0 , 0.0 }},
333337 {" blyp" , {1.0 , 1.279637 , 1.279637 , 1.841686 , 1.0 , 1.0 , 1.0 , 14.0 , 0.01437 }},
334338 {" b97_d" , {1.0 , 1.151808 , 1.151808 , 1.020078 , 1.0 , 1.0 , 1.0 , 14.0 , 0.035964 }},
@@ -340,6 +344,8 @@ const std::map<std::string, std::vector<double>> zerom = {
340344};
341345// DFT-D3(OptimizedPower)
342346const std::map<std::string, std::vector<double >> op = {
347+ // {'s6', 'rs6', 'a1', 's8', 'rs8', 'a2', 's9', 'alp', 'bet'}
348+ {" __default__" , {0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 14.0 , 0.0 }},
343349 {" blyp" , {1.0 , 0.425 , 0.425 , 1.31867 , 3.5 , 3.5 , 1.0 , 14.0 , 2.0 }},
344350 {" revpbe" , {1.0 , 0.6 , 0.6 , 1.44765 , 2.5 , 2.5 , 1.0 , 14.0 , 0.0 }},
345351 {" b97_d" , {1.0 , 0.6 , 0.6 , 1.46861 , 2.5 , 2.5 , 1.0 , 14.0 , 0.0 }},
@@ -356,7 +362,18 @@ const std::map<std::string, std::vector<double>> op = {
356362 {" ms2h" , {1.0 , 0.65 , 0.65 , 1.69464 , 4.75 , 4.75 , 1.0 , 14.0 , 0.0 }},
357363};
358364
359-
365+ std::vector<double > _search_impl (const std::string& xc,
366+ const std::map<std::string, std::vector<double >>& dict)
367+ {
368+ if (dict.find (xc) != dict.end ())
369+ {
370+ return dict.at (xc);
371+ }
372+ else
373+ {
374+ return std::vector<double >();
375+ }
376+ }
360377// 's6', 'rs6', 'a1', 's8', 'rs8', 'a2', 's9', 'alp', 'bet'
361378/* *
362379 * @brief Get the dftd3 params object.
@@ -368,76 +385,49 @@ const std::map<std::string, std::vector<double>> op = {
368385 * @param param the dftd3 parameters, ALL_KEYS = {'s6', 'rs6', 'a1', 's8', 'rs8', 'a2', 's9', 'alp', 'bet'}
369386 */
370387void _search (const std::string& xc,
371- const std::string& method,
372- std::vector<double >& param)
388+ const std::string& method,
389+ std::vector<double >& param)
373390{
374391 const std::string xc_lowercase = FmtCore::lower (xc);
375392 const std::vector<std::string> allowed_ = { " bj" , " zero" , " bjm" , " zerom" , " op" };
376- assert (std::find (allowed_.begin (), allowed_.end (), method) != allowed_.end ());
377- if (method == " op" )
378- {
379- if (op.find (xc_lowercase) != op.end ())
380- {
381- param = op.at (xc_lowercase);
382- }
383- else
384- {
385- ModuleBase::WARNING_QUIT (" ModuleHamiltGeneral::ModuleVDW::DFTD3::_search" ,
386- " XC (`" + xc + " `)'s DFT-D3(OP) parameters not found" );
387- }
388- }
389- else if (method == " bjm" )
393+ const int i = std::find (allowed_.begin (), allowed_.end (), method) - allowed_.begin ();
394+ std::map<std::string, std::vector<double >> const * pdict = nullptr ;
395+ switch (i)
390396 {
391- if (bjm.find (xc_lowercase) != bjm.end ())
392- {
393- param = bjm.at (xc_lowercase);
394- }
395- else
396- {
397- ModuleBase::WARNING_QUIT (" ModuleHamiltGeneral::ModuleVDW::DFTD3::_search" ,
398- " XC (`" + xc + " `)'s DFT-D3M(BJ) parameters not found" );
399- }
397+ case 0 :
398+ pdict = &bj;
399+ break ;
400+ case 1 :
401+ pdict = &zero;
402+ break ;
403+ case 2 :
404+ pdict = &bjm;
405+ break ;
406+ case 3 :
407+ pdict = &zerom;
408+ break ;
409+ case 4 :
410+ pdict = &op;
411+ break ;
412+ default :
413+ pdict = nullptr ;
414+ break ;
400415 }
401- else if (method == " bj " )
416+ if (pdict == nullptr )
402417 {
403- if (bj.find (xc_lowercase) != bj.end ())
404- {
405- param = bj.at (xc_lowercase);
406- }
407- else
408- {
409- ModuleBase::WARNING_QUIT (" ModuleHamiltGeneral::ModuleVDW::DFTD3::_search" ,
410- " XC (`" + xc + " `)'s DFT-D3(BJ) parameters not found" );
411- }
412- }
413- else if (method == " zerom" )
414- {
415- if (zerom.find (xc_lowercase) != zerom.end ())
416- {
417- param = zerom.at (xc_lowercase);
418- }
419- else
420- {
421- ModuleBase::WARNING_QUIT (" ModuleHamiltGeneral::ModuleVDW::DFTD3::_search" ,
422- " XC (`" + xc + " `)'s DFT-D3M(0) parameters not found" );
423- }
424- }
425- else if (method == " zero" )
426- {
427- if (zero.find (xc_lowercase) != zero.end ())
428- {
429- param = zero.at (xc_lowercase);
430- }
431- else
432- {
433- ModuleBase::WARNING_QUIT (" ModuleHamiltGeneral::ModuleVDW::DFTD3::_search" ,
434- " XC (`" + xc + " `)'s DFT-D3(0) parameters not found" );
435- }
418+ ModuleBase::WARNING_QUIT (" ModuleHamiltGeneral::ModuleVDW::DFTD3::_search" ,
419+ " Unknown DFT-D3 method: " + method);
436420 }
437- else // should not reach here
421+ param = _search_impl (xc_lowercase, *pdict);
422+ if (param.empty ())
438423 {
439424 ModuleBase::WARNING_QUIT (" ModuleHamiltGeneral::ModuleVDW::DFTD3::_search" ,
440- " Unknown DFT-D3 method: " + method);
425+ " XC (`" + xc + " `)'s DFT-D3(" + method + " ) parameters not found" );
426+ // is it meaningful to return a so-called default value?
427+ std::cout << " ***WARNING*** "
428+ << " XC (`" << xc << " `)'s DFT-D3(" << method << " ) parameters not found, "
429+ << " using default values. Please use at your own risk!" << std::endl;
430+ param = _search_impl (" __default__" , *pdict);
441431 }
442432}
443433
0 commit comments