Skip to content

Commit a96e342

Browse files
authored
Merge pull request #1119 from deepmodeling/deeph
feature : print sparse S for deeph
2 parents eba0ac6 + 4276a29 commit a96e342

File tree

7 files changed

+136
-107
lines changed

7 files changed

+136
-107
lines changed

source/input.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,8 +2300,7 @@ void Input::Check(void)
23002300
if (!this->relax_nmax)
23012301
this->relax_nmax = 50;
23022302
}
2303-
2304-
else if (calculation == "nscf")
2303+
else if (calculation == "nscf" || calculation == "get_S")
23052304
{
23062305
GlobalV::CALCULATION = "nscf";
23072306
this->relax_nmax = 1;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,56 @@ namespace ModuleESolver
4444
{
4545
ESolver_KS::Init(inp,ucell);
4646

47-
48-
#ifdef __MPI
49-
if (GlobalV::CALCULATION == "nscf")
47+
// if we are only calculating S, then there is no need
48+
// to prepare for potentials and so on
49+
if(GlobalV::CALCULATION!="calc_S")
5050
{
51-
switch (GlobalC::exx_global.info.hybrid_type)
51+
#ifdef __MPI
52+
if (GlobalV::CALCULATION == "nscf")
5253
{
53-
case Exx_Global::Hybrid_Type::HF:
54-
case Exx_Global::Hybrid_Type::PBE0:
55-
case Exx_Global::Hybrid_Type::SCAN0:
56-
case Exx_Global::Hybrid_Type::HSE:
57-
XC_Functional::set_xc_type(ucell.atoms[0].xc_func);
58-
break;
54+
switch (GlobalC::exx_global.info.hybrid_type)
55+
{
56+
case Exx_Global::Hybrid_Type::HF:
57+
case Exx_Global::Hybrid_Type::PBE0:
58+
case Exx_Global::Hybrid_Type::SCAN0:
59+
case Exx_Global::Hybrid_Type::HSE:
60+
XC_Functional::set_xc_type(ucell.atoms[0].xc_func);
61+
break;
62+
}
5963
}
60-
}
6164
#endif
6265

6366
#ifdef __DEEPKS
64-
//wenfei 2021-12-19
65-
//if we are performing DeePKS calculations, we need to load a model
66-
if (GlobalV::deepks_scf)
67-
{
68-
// load the DeePKS model from deep neural network
69-
GlobalC::ld.load_model(INPUT.deepks_model);
70-
}
67+
//wenfei 2021-12-19
68+
//if we are performing DeePKS calculations, we need to load a model
69+
if (GlobalV::deepks_scf)
70+
{
71+
// load the DeePKS model from deep neural network
72+
GlobalC::ld.load_model(INPUT.deepks_model);
73+
}
7174
#endif
7275

73-
// Initialize the local wave functions.
74-
// npwx, eigenvalues, and weights
75-
// npwx may change according to cell change
76-
// this function belongs to cell LOOP
77-
GlobalC::wf.allocate_ekb_wg(GlobalC::kv.nks);
76+
// Initialize the local wave functions.
77+
// npwx, eigenvalues, and weights
78+
// npwx may change according to cell change
79+
// this function belongs to cell LOOP
80+
GlobalC::wf.allocate_ekb_wg(GlobalC::kv.nks);
7881

79-
// Initialize the FFT.
80-
// this function belongs to cell LOOP
82+
// Initialize the FFT.
83+
// this function belongs to cell LOOP
8184

82-
// output is GlobalC::ppcell.vloc 3D local pseudopotentials
83-
// without structure factors
84-
// this function belongs to cell LOOP
85-
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, GlobalC::rhopw);
85+
// output is GlobalC::ppcell.vloc 3D local pseudopotentials
86+
// without structure factors
87+
// this function belongs to cell LOOP
88+
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, GlobalC::rhopw);
8689

87-
// Initialize the sum of all local potentials.
88-
// if ion_step==0, read in/initialize the potentials
89-
// this function belongs to ions LOOP
90-
int ion_step = 0;
91-
GlobalC::pot.init_pot(ion_step, GlobalC::sf.strucFac);
92-
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT POTENTIAL");
90+
// Initialize the sum of all local potentials.
91+
// if ion_step==0, read in/initialize the potentials
92+
// this function belongs to ions LOOP
93+
int ion_step = 0;
94+
GlobalC::pot.init_pot(ion_step, GlobalC::sf.strucFac);
95+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT POTENTIAL");
96+
} // end ifnot calc_S
9397

9498
//------------------init Basis_lcao----------------------
9599
// Init Basis should be put outside of Ensolver.
@@ -98,6 +102,15 @@ namespace ModuleESolver
98102
this->Init_Basis_lcao(this->orb_con, inp, ucell);
99103
//------------------init Basis_lcao----------------------
100104

105+
if(GlobalV::CALCULATION=="get_S")
106+
{
107+
//pass Hamilt-pointer to Operator
108+
this->UHM.genH.LM = this->UHM.LM = &this->LM;
109+
//pass basis-pointer to EState and Psi
110+
this->LOC.ParaV = this->LOWF.ParaV = this->LM.ParaV;
111+
return;
112+
}
113+
101114
//------------------init Hamilt_lcao----------------------
102115
// * allocate H and S matrices according to computational resources
103116
// * set the 'trace' between local H/S and global H/S

source/module_esolver/esolver_ks_lcao.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace ModuleESolver
2424
void cal_Stress(ModuleBase::matrix& stress) override;
2525
void postprocess() override;
2626
void nscf() override;
27+
void get_S();
2728

2829
protected:
2930
virtual void beforescf(const int istep) override;

source/module_esolver/esolver_ks_lcao_elec.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ namespace ModuleESolver
275275
{
276276
ModuleBase::TITLE("ESolver_KS_LCAO", "othercalculation");
277277
ModuleBase::timer::tick("ESolver_KS_LCAO", "othercalculation");
278+
if(GlobalV::CALCULATION == "get_S")
279+
{
280+
this->get_S();
281+
return;
282+
}
278283
this->beforesolver(istep);
279284
// self consistent calculations for electronic ground state
280285
if (GlobalV::CALCULATION == "nscf")
@@ -303,6 +308,41 @@ namespace ModuleESolver
303308
return;
304309
}
305310

311+
void ESolver_KS_LCAO::get_S()
312+
{
313+
ModuleBase::TITLE("ESolver_KS_LCAO", "get_S");
314+
if(GlobalV::GAMMA_ONLY_LOCAL)
315+
{
316+
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::get_S", "not implemented for");
317+
}
318+
else
319+
{
320+
// (1) Find adjacent atoms for each atom.
321+
GlobalV::SEARCH_RADIUS = atom_arrange::set_sr_NL(
322+
GlobalV::ofs_running,
323+
GlobalV::OUT_LEVEL,
324+
GlobalC::ORB.get_rcutmax_Phi(),
325+
GlobalC::ucell.infoNL.get_rcutmax_Beta(),
326+
GlobalV::GAMMA_ONLY_LOCAL);
327+
328+
atom_arrange::search(
329+
GlobalV::SEARCH_PBC,
330+
GlobalV::ofs_running,
331+
GlobalC::GridD,
332+
GlobalC::ucell,
333+
GlobalV::SEARCH_RADIUS,
334+
GlobalV::test_atom_input);
335+
336+
this->RA.for_2d(this->orb_con.ParaV, GlobalV::GAMMA_ONLY_LOCAL);
337+
this->UHM.genH.LM->ParaV = &this->orb_con.ParaV;
338+
this->LM.allocate_HS_R(this->orb_con.ParaV.nnr);
339+
this->LM.zeros_HSR('S');
340+
this->UHM.genH.calculate_S_no(this->LM.SlocR.data());
341+
this->output_SR("SR.csr");
342+
343+
}
344+
}
345+
306346
void ESolver_KS_LCAO::nscf()
307347
{
308348
ModuleBase::TITLE("ESolver_KS_LCAO", "nscf");

source/module_orbital/ORB_gen_tables.cpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,47 @@ void ORB_gen_tables::gen_tables(
4040
orb.get_dR(),
4141
orb.get_dk());
4242

43-
tbeta.allocate(
44-
orb.get_ntype(),
45-
orb.get_lmax(),
46-
orb.get_kmesh(),
47-
orb.get_Rmax(),
48-
orb.get_dR(),
49-
orb.get_dk());
50-
51-
//caoyu add 2021-03-18
52-
//mohan update 2021-04-22
53-
if (deepks_setorb)
43+
if(GlobalV::CALCULATION!="get_S")
5444
{
55-
talpha.allocate(
56-
orb.get_ntype(),
45+
tbeta.allocate(
46+
orb.get_ntype(),
5747
orb.get_lmax(),
58-
orb.get_kmesh(),
59-
orb.get_Rmax(),
48+
orb.get_kmesh(),
49+
orb.get_Rmax(),
6050
orb.get_dR(),
6151
orb.get_dk());
52+
53+
//caoyu add 2021-03-18
54+
//mohan update 2021-04-22
55+
if (deepks_setorb)
56+
{
57+
talpha.allocate(
58+
orb.get_ntype(),
59+
orb.get_lmax(),
60+
orb.get_kmesh(),
61+
orb.get_Rmax(),
62+
orb.get_dR(),
63+
orb.get_dk());
64+
}
6265
}
6366

6467
// OV: overlap
6568
MOT.init_OV_Tpair(orb);
6669
MOT.init_OV_Opair(orb);
6770

68-
// NL: nonlocal
69-
tbeta.init_NL_Tpair(orb.Phi, beta_);
70-
tbeta.init_NL_Opair(orb, nprojmax, nproj); // add 2009-5-8
71-
72-
//caoyu add 2021-03-18
73-
// DS: Descriptor
74-
if (deepks_setorb)
71+
if(GlobalV::CALCULATION!="get_S")
7572
{
76-
talpha.init_DS_Opair(orb);
77-
talpha.init_DS_2Lplus1(orb);
73+
// NL: nonlocal
74+
tbeta.init_NL_Tpair(orb.Phi, beta_);
75+
tbeta.init_NL_Opair(orb, nprojmax, nproj); // add 2009-5-8
76+
77+
//caoyu add 2021-03-18
78+
// DS: Descriptor
79+
if (deepks_setorb)
80+
{
81+
talpha.init_DS_Opair(orb);
82+
talpha.init_DS_2Lplus1(orb);
83+
}
7884
}
7985

8086
//////////////////////////////
@@ -100,15 +106,18 @@ void ORB_gen_tables::gen_tables(
100106

101107
//calculate S(R) for interpolation
102108
MOT.init_Table(job0, orb);
103-
tbeta.init_Table_Beta(MOT.pSB, orb.Phi, beta_, nproj); // add 2009-5-8
104109

105-
//caoyu add 2021-03-18
106-
if (deepks_setorb)
107-
{
108-
talpha.init_Table_Alpha(MOT.pSB, orb);
109-
if(GlobalV::deepks_out_unittest) talpha.print_Table_DSR(orb);
110-
}
110+
if(GlobalV::CALCULATION!="get_S")
111+
{
112+
tbeta.init_Table_Beta(MOT.pSB, orb.Phi, beta_, nproj); // add 2009-5-8
111113

114+
//caoyu add 2021-03-18
115+
if (deepks_setorb)
116+
{
117+
talpha.init_Table_Alpha(MOT.pSB, orb);
118+
if(GlobalV::deepks_out_unittest) talpha.print_Table_DSR(orb);
119+
}
120+
}
112121
/////////////////////////////
113122
/// (3) make Gaunt coefficients table
114123
/////////////////////////////

source/run_lcao.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ void Run_lcao::lcao_line(ModuleESolver::ESolver* p_esolver)
6060
//------------------------------------------------------------
6161
//---------------------Init ESolver-------------------------
6262
p_esolver->Init(INPUT, GlobalC::ucell);
63+
if(GlobalV::CALCULATION=="get_S")
64+
{
65+
p_esolver->Run(0, GlobalC::ucell);
66+
ModuleBase::timer::tick("Run_lcao", "lcao_line");
67+
return;
68+
}
6369
//------------------------------------------------------------
6470

6571

source/src_lcao/LOOP_ions.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,45 +71,6 @@ void LOOP_ions::opt_ions(ModuleESolver::ESolver* p_esolver)
7171
if (GlobalV::OUT_LEVEL == "ie" || GlobalV::OUT_LEVEL == "m")
7272
{
7373
Print_Info::print_screen(stress_step, force_step, istep);
74-
/* std::cout << " ---------------------------------------------------------" << std::endl;
75-
if(GlobalV::CALCULATION=="relax")
76-
{
77-
std::cout << " RELAX IONS : " << istep << std::endl;
78-
}
79-
else if(GlobalV::CALCULATION=="cell-relax")
80-
{
81-
std::cout << " RELAX CELL : " << stress_step << std::endl;
82-
std::cout << " RELAX IONS : " << force_step << " (in total: " << istep << ")" << std::endl;
83-
}
84-
else if(GlobalV::CALCULATION=="scf")
85-
{
86-
std::cout << " SELF-CONSISTENT : " << std::endl;
87-
}
88-
else if(GlobalV::CALCULATION=="nscf")
89-
{
90-
std::cout << " NONSELF-CONSISTENT : " << std::endl;
91-
}
92-
std::cout << " ---------------------------------------------------------" << std::endl;
93-
94-
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
95-
if(GlobalV::CALCULATION=="relax")
96-
{
97-
GlobalV::ofs_running << " RELAX IONS : " << istep << std::endl;
98-
}
99-
else if(GlobalV::CALCULATION=="cell-relax")
100-
{
101-
GlobalV::ofs_running << " RELAX CELL : " << stress_step << std::endl;
102-
GlobalV::ofs_running << " RELAX IONS : " << force_step << " (in total: " << istep << ")" << std::endl;
103-
}
104-
else if(GlobalV::CALCULATION=="scf")
105-
{
106-
GlobalV::ofs_running << " SELF-CONSISTENT" << std::endl;
107-
}
108-
else if(GlobalV::CALCULATION=="nscf")
109-
{
110-
GlobalV::ofs_running << " NONSELF-CONSISTENT" << std::endl;
111-
}
112-
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;*/
11374
}
11475

11576
//----------------------------------------------------------

0 commit comments

Comments
 (0)