Skip to content

Commit

Permalink
Refactor:Use PARAM instead of deepks* (#5104)
Browse files Browse the repository at this point in the history
* change bcast

* change parameter global out dir in the cpp file

* change parameter deepks_unittest in the input_paramter file

* change parameter deepks_bandgap in the cpp file

* change parameter deepks_v_delta in the cpp file

* change parameter deepks_deepks_equiv in the cpp file

* change parameter deepks_setorb in the test&cpp file

* change parameter deepks_scf in the test&cpp file

* change parameter deepks_out_labels in the test&cpp file

* change parameter deepks_variable in the global variable file
  • Loading branch information
A-006 authored Sep 18, 2024
1 parent a29afee commit fec3065
Show file tree
Hide file tree
Showing 43 changed files with 178 additions and 229 deletions.
6 changes: 3 additions & 3 deletions source/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void Driver::print_start_info()

GlobalV::ofs_running << "\n READING GENERAL INFORMATION" << std::endl;
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "global_out_dir", PARAM.globalv.global_out_dir);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "global_in_card", PARAM.globalv.global_in_card);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "global_in_card", PARAM.globalv.global_in_card);
}

void Driver::reading()
Expand All @@ -119,15 +119,15 @@ void Driver::reading()

// (1) read the input file
ModuleIO::ReadInput read_input(PARAM.globalv.myrank);
read_input.read_parameters(PARAM, PARAM.globalv.global_in_card);
read_input.read_parameters(PARAM, PARAM.globalv.global_in_card);

// (2) create the output directory, running_*.log and print info
read_input.create_directory(PARAM);
this->print_start_info();

// (3) write the input file
std::stringstream ss1;
ss1 << PARAM.globalv.global_out_dir << PARAM.globalv.global_in_card;
ss1 << PARAM.globalv.global_out_dir << PARAM.globalv.global_in_card;
read_input.write_parameters(PARAM, ss1.str());

// (*temp*) copy the variables from INPUT to each class
Expand Down
2 changes: 1 addition & 1 deletion source/driver_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void Driver::driver_run() {

// the life of ucell should begin here, mohan 2024-05-12
// delete ucell as a GlobalC in near future
GlobalC::ucell.setup_cell(GlobalV::stru_file, GlobalV::ofs_running);
GlobalC::ucell.setup_cell(PARAM.inp.stru_file, GlobalV::ofs_running);
Check_Atomic_Stru::check_atomic_stru(GlobalC::ucell,
PARAM.inp.min_dist_coef);

Expand Down
19 changes: 0 additions & 19 deletions source/module_base/global_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ double DQ = 0.010; // space between Q points of the reciprocal radial tab
int NQX = 10000; // number of points describing reciprocal radial tab
int NQXQ = 10000; // number of points describing reciprocal radial tab for Q

bool GAMMA_ONLY_PW = false; // mohan add 2012-06-05

int ZEEMAN_IN_H = 1;

// int ocp_n=0;
bool out_mul = false; // qifeng add 2019/9/10
//----------------------------------------------------------
// EXPLAIN : Parallel information
//----------------------------------------------------------
Expand All @@ -70,18 +65,13 @@ int GSIZE = DSIZE;
//----------------------------------------------------------
// EXPLAIN : The input file name and directory
//----------------------------------------------------------
std::string global_in_card = "INPUT";
std::string stru_file = "STRU";


std::ofstream ofs_running;
std::ofstream ofs_warning;
std::ofstream ofs_info; // output math lib info
std::ofstream ofs_device; // output device info

//----------------------------------------------------------
// src_tools
//----------------------------------------------------------

// added by zhengdy-soc
bool NONCOLIN = false;
Expand All @@ -90,15 +80,6 @@ bool DOMAG = false;
bool DOMAG_Z = false;
int NPOL = 1;

bool deepks_out_labels = false; // caoyu add 2021-10-16 for DeePKS, wenfei 2022-1-16
bool deepks_scf = false; // caoyu add 2021-10-16 for DeePKS, wenfei 2022-1-16
bool deepks_bandgap = false; // for bandgap label. QO added 2021-12-15
int deepks_v_delta = 0; // for v_delta label. xinyuan added 2023-2-15

bool deepks_equiv = false;

bool deepks_setorb = false;

std::vector<std::string> rpa_orbitals;

//==========================================================
Expand Down
44 changes: 1 addition & 43 deletions source/module_base/global_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ extern std::string RELAX_METHOD;

extern bool use_uspp;



extern std::string KS_SOLVER; // xiaohui add 2013-09-01
extern double SEARCH_RADIUS; // 11.1 // mohan add 2011-03-10

Expand Down Expand Up @@ -70,6 +68,7 @@ extern int NQXQ; // liuyu add 2023-10-03
// NAME : DCOLOR( color of each group)
// NAME : GRANK( index of grid world)
// NAME : GSIZE( number of processors in each grid world)
// NAME : KPAR_LCAO ( global number of pools for LCAO diagonalization only)
//========================================================================
extern int NPROC;
extern int KPAR;
Expand All @@ -85,12 +84,6 @@ extern int DSIZE;
extern int DCOLOR;
extern int GRANK;
extern int GSIZE;

//========================================================================
// EXPLAIN : Parallel information
// GLOBAL VARIABLES :
// NAME : KPAR_LCAO ( global number of pools for LCAO diagonalization only)
//========================================================================
extern int KPAR_LCAO;

//==========================================================
Expand All @@ -106,49 +99,14 @@ extern int KPAR_LCAO;
// NAME : ofs_running( contain information during runnnig)
// NAME : ofs_warning( contain warning information, including error)
//==========================================================
extern std::string global_in_card;
extern std::string stru_file;
extern std::string global_kpoint_card;

// extern std::string global_pseudo_type; // mohan add 2013-05-20 (xiaohui add
// 2013-06-23)
extern std::ofstream ofs_running;
extern std::ofstream ofs_warning;
extern std::ofstream ofs_info;
extern std::ofstream ofs_device;

//==========================================================
// EXPLAIN : test level for each class
//==========================================================

//==========================================================
// src_onscaling
//==========================================================
//==========================================================
// src_pseudo
//==========================================================
//==========================================================
// src_tools
//==========================================================


extern bool deepks_out_labels; // (need libnpy) prints energy and force labels
// and descriptors for training, wenfei 2022-1-12
extern bool deepks_scf; //(need libnpy and libtorch) if set 1, a trained model
// would be needed to cal V_delta and F_delta
extern bool deepks_bandgap; // for bandgap label. QO added 2021-12-15

extern int deepks_v_delta; // for v_delta label. xinyuan added 2023-2-15

extern bool deepks_equiv; //whether to use equviariant version of DeePKS

extern bool deepks_setorb;



// implicit solvation

// DFTU control
// rpa related
extern std::vector<std::string> rpa_orbitals;

Expand Down
4 changes: 2 additions & 2 deletions source/module_basis/module_nao/two_center_bundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void TwoCenterBundle::build_beta(int ntype, Numerical_Nonlocal* nl)

void TwoCenterBundle::build_alpha(int ndesc, std::string* file_desc0)
{
if (GlobalV::deepks_setorb)
if (PARAM.globalv.deepks_setorb)
{
std::vector<std::string> file_desc(ndesc);
if (GlobalV::MY_RANK == 0)
Expand Down Expand Up @@ -245,7 +245,7 @@ void TwoCenterBundle::to_LCAO_Orbitals(LCAO_Orbitals& ORB,
(*orb_)(itype).to_numerical_orbital(ORB.Phi[itype], ORB.kmesh, ORB.dk);
}

if (GlobalV::deepks_setorb)
if (PARAM.globalv.deepks_setorb)
{
ORB.lmax_d = alpha_->lmax();
ORB.nchimax_d = alpha_->nzeta_max();
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/module_neighbor/sltk_atom_arrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void atom_arrange::search(

assert( search_radius_bohr > 0.0 );

// OUT(ofs_in,"Atom coordinates reading from",GlobalV::stru_file);
// OUT(ofs_in,"Atom coordinates reading from",PARAM.inp.stru_file);
// OUT(ofs_in,"The coordinate type",ucell.Coordinate);
// OUT(ofs_in,"Use cartesian(unit:lat0) coordinate","TRUE");
// if(PARAM.inp.out_level != "m") OUT(ofs_in,"searching radius is (Bohr))", search_radius_bohr);
Expand Down
3 changes: 2 additions & 1 deletion source/module_cell/module_paw/paw_cell_libpaw.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "module_base/tool_quit.h"
#include "module_base/tool_title.h"
#include "module_parameter/parameter.h"
#include "paw_cell.h"
#include "module_base/global_variable.h"
#include "module_base/parallel_common.h"
Expand Down Expand Up @@ -223,7 +224,7 @@ void Paw_Cell::set_libpaw_files()
filename_list = new char[ntypat*264];
if(GlobalV::MY_RANK == 0)
{
std::ifstream ifa(GlobalV::stru_file.c_str(), std::ios::in);
std::ifstream ifa(PARAM.inp.stru_file.c_str(), std::ios::in);
if (!ifa)
{
ModuleBase::WARNING_QUIT("set_libpaw_files", "can not open stru file");
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/read_atoms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int UnitCell::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running)
}
}
// caoyu add 2021-03-16
if(GlobalV::deepks_setorb)
if(PARAM.globalv.deepks_setorb)
{
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "NUMERICAL_DESCRIPTOR")) {
ifa >> descriptor_file;
Expand Down
36 changes: 18 additions & 18 deletions source/module_cell/test/unitcell_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ TEST_F(UcellTest, ReadAtomSpecies)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957);
Expand Down Expand Up @@ -1256,7 +1256,7 @@ TEST_F(UcellTest, ReadAtomPositionsS1)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 1;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1287,7 +1287,7 @@ TEST_F(UcellTest, ReadAtomPositionsS2)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 2;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1318,7 +1318,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Noncolin)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 4;
GlobalV::NONCOLIN = true;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
Expand Down Expand Up @@ -1350,7 +1350,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Colin)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 4;
GlobalV::NONCOLIN = false;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
Expand Down Expand Up @@ -1382,7 +1382,7 @@ TEST_F(UcellTest, ReadAtomPositionsC)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 1;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1413,7 +1413,7 @@ TEST_F(UcellTest, ReadAtomPositionsCA)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 1;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1444,7 +1444,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXY)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 1;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1475,7 +1475,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXZ)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 1;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1506,7 +1506,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACYZ)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 1;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1537,7 +1537,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXYZ)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 1;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1568,7 +1568,7 @@ TEST_F(UcellTest, ReadAtomPositionsCAU)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 1;
PARAM.input.fixed_atoms = true;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
Expand Down Expand Up @@ -1600,7 +1600,7 @@ TEST_F(UcellTest, ReadAtomPositionsAutosetMag)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
GlobalV::NSPIN = 2;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
Expand Down Expand Up @@ -1654,7 +1654,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning1)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957);
Expand Down Expand Up @@ -1697,7 +1697,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning2)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957);
Expand Down Expand Up @@ -1733,7 +1733,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning3)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957);
Expand Down Expand Up @@ -1769,7 +1769,7 @@ TEST_F(UcellDeathTest, ReadAtomPositionsWarning4)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
EXPECT_DOUBLE_EQ(ucell->latvec.e11, 4.27957);
EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957);
Expand Down Expand Up @@ -1801,7 +1801,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning5)
ucell->set_atom_flag = true;
PARAM.input.test_pseudo_cell = 2;
PARAM.input.basis_type = "lcao";
GlobalV::deepks_setorb = true;
PARAM.sys.deepks_setorb = true;
PARAM.input.calculation = "md";
PARAM.input.esolver_type = "arbitrary";
EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running));
Expand Down
2 changes: 1 addition & 1 deletion source/module_elecstate/elecstate_energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void ElecState::cal_energies(const int type)

#ifdef __DEEPKS
// energy from deepks
if (GlobalV::deepks_scf)
if (PARAM.inp.deepks_scf)
{
this->f_en.edeepks_scf = get_deepks_E_delta() - get_deepks_E_delta_band();
}
Expand Down
2 changes: 1 addition & 1 deletion source/module_elecstate/elecstate_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void ElecState::print_etot(const bool converged,
}

#ifdef __DEEPKS
if (GlobalV::deepks_scf) // caoyu add 2021-08-10
if (PARAM.inp.deepks_scf) // caoyu add 2021-08-10
{
titles.push_back("E_DeePKS");
energies_Ry.push_back(GlobalC::ld.E_delta);
Expand Down
Loading

0 comments on commit fec3065

Please sign in to comment.