ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
cal_atoms_info.h
Go to the documentation of this file.
1
5#ifndef CAL_ATOMS_INFO_H
6#define CAL_ATOMS_INFO_H
9
14{
15 int nlocal = 0;
16 double nelec = 0.0;
17 int nbands = 0;
18 double nupdown = 0.0;
19 bool use_uspp = false;
20 int nbands_l = 0;
21 bool ks_run = false;
22};
23
28{
29 public:
34
39
64 AtomsInfoResult cal_atoms_info(Atom* atoms, const int& ntype,
65 const int nspin, const bool two_fermi,
66 const double nelec_delta,
67 const std::string& esolver_type,
68 const bool lspinorb,
69 const std::string& basis_type,
70 const std::string& smearing_method,
71 const std::string& ks_solver,
72 const int bndpar,
73 const int nbands,
74 const double nelec,
75 const double nupdown)
76 {
77 AtomsInfoResult result;
78
79 // calculate initial total magnetization when NSPIN=2
80 if (nspin == 2 && !two_fermi)
81 {
82 for (int it = 0; it < ntype; ++it)
83 {
84 for (int ia = 0; ia < atoms[it].na; ++ia)
85 {
86 result.nupdown += atoms[it].mag[ia];
87 }
88 }
89 GlobalV::ofs_running << std::endl;
90 ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "The readin total magnetization", result.nupdown);
91 }
92 else if (nspin == 2 && two_fermi)
93 {
94 result.nupdown = nupdown;
95 ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "The user-specified total magnetization", result.nupdown);
96 }
97
98 // decide whether to be USPP
99 for (int it = 0; it < ntype; ++it)
100 {
101 if (atoms[it].ncpp.tvanp)
102 {
103 result.use_uspp = true;
104 }
105 }
106
107 // set index for atoms before calculating nlocal
108 // this ensures consistency with cal_nwfc() which also calls set_index() first
109 for (int it = 0; it < ntype; ++it)
110 {
111 atoms[it].set_index();
112 }
113
114 // calculate the total number of local basis. This value is used by cal_nwfc()
115 // to initialize index arrays (iwt2iat, iwt2iw, itia2iat). The formula lives in
116 // unitcell::cal_nlocal() so that GintInfo::init_trace_lo_() shares it.
117 result.nlocal = unitcell::cal_nlocal(atoms, ntype, nspin);
118
119 result.nelec = nelec;
120 unitcell::cal_nelec(atoms, ntype, result.nelec, nelec_delta);
121
122 // autoset and check GlobalV::NBANDS
123 std::vector<double> nelec_spin(2, 0.0);
124 if (nspin == 2)
125 {
126 nelec_spin[0] = (result.nelec + result.nupdown) / 2.0;
127 nelec_spin[1] = (result.nelec - result.nupdown) / 2.0;
128 }
129 result.nbands = nbands;
130 unitcell::cal_nbands(static_cast<int>(result.nelec), result.nlocal, nelec_spin, result.nbands,
131 esolver_type, lspinorb, nspin, basis_type, smearing_method);
132 // Taoni add check for bndpar > nbands on 2026-08-21
133 if (ks_solver == "bpcg" && result.nbands > 0 && bndpar > result.nbands)
134 {
135 ModuleBase::WARNING_QUIT("CalAtomsInfo", "bndpar cannot exceed nbands when ks_solver is bpcg");
136 }
137
138 // calculate the number of nbands_local
139 result.nbands_l = result.nbands;
140 if (ks_solver == "bpcg")
141 {
142 result.nbands_l = result.nbands / bndpar;
143 if (GlobalV::MY_BNDGROUP < result.nbands % bndpar)
144 {
145 result.nbands_l++;
146 }
147 }
148 // temporary code
149 if (GlobalV::MY_BNDGROUP == 0 || ks_solver == "bpcg")
150 {
151 result.ks_run = true;
152 }
153 return result;
154 }
155};
156#endif
Atom class for storing atom information.
Definition atom_spec.h:14
int na
Number of atoms in this type.
Definition atom_spec.h:44
std::vector< double > mag
magnetic moment
Definition atom_spec.h:62
void set_index()
Set index arrays.
Definition atom_spec.cpp:17
CalAtomsInfo()
Default constructor.
Definition cal_atoms_info.h:33
AtomsInfoResult cal_atoms_info(Atom *atoms, const int &ntype, const int nspin, const bool two_fermi, const double nelec_delta, const std::string &esolver_type, const bool lspinorb, const std::string &basis_type, const std::string &smearing_method, const std::string &ks_solver, const int bndpar, const int nbands, const double nelec, const double nupdown)
Calculate the atom information from pseudopotential.
Definition cal_atoms_info.h:64
~CalAtomsInfo()
Destructor.
Definition cal_atoms_info.h:38
std::ofstream ofs_running
Definition global_variable.cpp:38
int MY_BNDGROUP
Definition global_variable.cpp:23
void OUT(std::ofstream &ofs, const std::string &name)
Definition global_function.cpp:54
void WARNING_QUIT(const std::string &, const std::string &)
Combine the functions of WARNING and QUIT.
Definition test_delley.cpp:15
void cal_nelec(const Atom *atoms, const int &ntype, double &nelec, const double nelec_delta)
calculate the total number of electrons in system
Definition cal_nelec_nband.cpp:29
void cal_nbands(const int &nelec, const int &nlocal, const std::vector< double > &nelec_spin, int &nbands, const std::string &esolver_type, const bool lspinorb, const int nspin, const std::string &basis_type, const std::string &smearing_method)
Calculate the number of bands.
Definition cal_nelec_nband.cpp:61
int cal_nlocal(const Atom *atoms, const int ntype, const int nspin)
Calculate the total number of local numerical atomic orbitals.
Definition cal_nelec_nband.cpp:11
Result struct for atom information calculation.
Definition cal_atoms_info.h:14
double nupdown
spin polarization
Definition cal_atoms_info.h:18
bool ks_run
whether to run KS solver
Definition cal_atoms_info.h:21
int nbands_l
number of local bands
Definition cal_atoms_info.h:20
double nelec
total number of electrons
Definition cal_atoms_info.h:16
int nbands
number of bands
Definition cal_atoms_info.h:17
int nlocal
total number of local basis
Definition cal_atoms_info.h:15
bool use_uspp
whether to use USPP
Definition cal_atoms_info.h:19