Skip to content

Commit 9cf4ba2

Browse files
committed
Merge branch 'tea4' into develop
2 parents f4996ed + c8afa94 commit 9cf4ba2

File tree

7 files changed

+156
-71
lines changed

7 files changed

+156
-71
lines changed

source/module_base/global_function.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,41 @@ void DONE(std::ofstream &ofs, const std::string &description, const bool only_ra
104104
return;
105105
}
106106

107+
107108
bool SCAN_BEGIN(std::ifstream &ifs,
108109
const std::string &TargetName,
109110
const bool restart,
110111
const bool ifwarn)
112+
{
113+
std::string SearchName;
114+
bool find = false;
115+
if (restart)
116+
{
117+
ifs.clear();
118+
ifs.seekg(0);
119+
}
120+
ifs.rdstate();
121+
while (ifs.good())
122+
{
123+
ifs >> SearchName;
124+
if (SearchName == TargetName)
125+
{
126+
find = true;
127+
break;
128+
}
129+
}
130+
if (!find && ifwarn)
131+
{
132+
GlobalV::ofs_warning << " In SCAN_BEGIN, can't find: " << TargetName << " block." << std::endl;
133+
}
134+
return find;
135+
}
136+
137+
138+
bool SCAN_LINE_BEGIN(std::ifstream &ifs,
139+
const std::string &TargetName,
140+
const bool restart,
141+
const bool ifwarn)
111142
{
112143
bool find = false;
113144
if (restart)
@@ -143,7 +174,7 @@ bool SCAN_BEGIN(std::ifstream &ifs,
143174

144175
if (!find && ifwarn)
145176
{
146-
GlobalV::ofs_warning << " In SCAN_BEGIN, can't find: " << TargetName << " block." << std::endl;
177+
GlobalV::ofs_warning << " In SCAN_LINE_BEGIN, can't find: " << TargetName << " block." << std::endl;
147178
}
148179
return find;
149180
}

source/module_base/global_function.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,26 @@ static void READ_VALUE(std::ifstream& ifs, T& v)
145145
return;
146146
}
147147

148-
bool SCAN_BEGIN(std::ifstream& ifs, const std::string& TargetName, const bool restart = true, const bool ifwarn = true);
149-
// ifwarn: whether to call GlobalV::ofs_warning when the TargetName is not found, used to avoid invalid warning.
150-
// Mohan warning : the last term can't be written as const bool &restart,
151-
// I don't know why.
148+
//-------------------------------------------------------------
149+
//! The `SCAN_BEGIN` function efficiently searches
150+
//! text files for specified keywords
151+
//-------------------------------------------------------------
152+
bool SCAN_BEGIN(std::ifstream& ifs,
153+
const std::string& TargetName,
154+
const bool restart = true,
155+
const bool ifwarn = true);
156+
157+
//-------------------------------------------------------------
158+
// The `SCAN_LINE_BEGIN` function efficiently searches
159+
// text files for specified keywords while ignoring comment
160+
// lines and whitespace. It skips any line starting with '#'
161+
//-------------------------------------------------------------
162+
bool SCAN_LINE_BEGIN(std::ifstream& ifs,
163+
const std::string& TargetName,
164+
const bool restart = true,
165+
const bool ifwarn = true);
152166

153167
void SCAN_END(std::ifstream& ifs, const std::string& TargetName, const bool ifwarn = true);
154-
// ifwarn: whether to call GlobalV::ofs_warning when the TargetName is not found, used to avoid invalid warning.
155168

156169
template <class T>
157170
static inline void DCOPY(const T& a, T& b, const int& dim)

source/module_cell/read_atom_species.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bool read_atom_species(std::ifstream& ifa,
2020
//==========================================
2121
// read in information of each type of atom
2222
//==========================================
23-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "ATOMIC_SPECIES") )
23+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "ATOMIC_SPECIES") )
2424
{
2525
ModuleBase::GlobalFunc::OUT(ofs_running,"ntype",ntype);
2626
for (int i = 0;i < ntype;i++)
@@ -51,7 +51,8 @@ bool read_atom_species(std::ifstream& ifa,
5151

5252
if (!end && ss >> one_string && one_string[0] != '#')
5353
{
54-
if (one_string == "auto" || one_string == "upf" || one_string == "vwr" || one_string == "upf201" || one_string == "blps")
54+
if (one_string == "auto" || one_string == "upf"
55+
|| one_string == "vwr" || one_string == "upf201" || one_string == "blps")
5556
{
5657
ucell.pseudo_type[i] = one_string;
5758
}
@@ -61,15 +62,17 @@ bool read_atom_species(std::ifstream& ifa,
6162
}
6263
else
6364
{
64-
GlobalV::ofs_warning << "unrecongnized pseudopotential type: " << one_string << ", check your STRU file." << std::endl;
65+
GlobalV::ofs_warning << "unrecongnized pseudopotential type: "
66+
<< one_string << ", check your STRU file." << std::endl;
6567
ModuleBase::WARNING_QUIT("read_atom_species", "unrecongnized pseudo type.");
6668
}
6769
}
6870

6971
// Peize Lin test for bsse 2021.04.07
7072
const std::string bsse_label = "empty";
7173
ucell.atoms[i].flag_empty_element =
72-
(search( ucell.atom_label[i].begin(), ucell.atom_label[i].end(), bsse_label.begin(), bsse_label.end() ) != ucell.atom_label[i].end())
74+
(search( ucell.atom_label[i].begin(), ucell.atom_label[i].end(),
75+
bsse_label.begin(), bsse_label.end() ) != ucell.atom_label[i].end())
7376
? true : false;
7477
}
7578
}
@@ -80,7 +83,7 @@ bool read_atom_species(std::ifstream& ifa,
8083
||((PARAM.inp.basis_type == "pw")&&(PARAM.inp.init_wfc.substr(0, 3) == "nao"))
8184
|| PARAM.inp.onsite_radius > 0.0)
8285
{
83-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "NUMERICAL_ORBITAL") )
86+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "NUMERICAL_ORBITAL") )
8487
{
8588
for(int i=0; i<ntype; i++)
8689
{
@@ -90,7 +93,7 @@ bool read_atom_species(std::ifstream& ifa,
9093
// caoyu add 2021-03-16
9194
if(PARAM.globalv.deepks_setorb)
9295
{
93-
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "NUMERICAL_DESCRIPTOR")) {
96+
if (ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "NUMERICAL_DESCRIPTOR")) {
9497
ifa >> ucell.descriptor_file;
9598
}
9699
}
@@ -105,7 +108,7 @@ bool read_atom_species(std::ifstream& ifa,
105108
#ifdef __EXX
106109
if( GlobalC::exx_info.info_global.cal_exx || PARAM.inp.rpa )
107110
{
108-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "ABFS_ORBITAL") )
111+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "ABFS_ORBITAL") )
109112
{
110113
for(int i=0; i<ntype; i++)
111114
{
@@ -133,7 +136,7 @@ bool read_lattice_constant(std::ifstream& ifa,
133136
double& lat0_angstrom =lat.lat0_angstrom;
134137
std::string& latName = lat.latName;
135138
ModuleBase::Matrix3& latvec = lat.latvec;
136-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_CONSTANT") )
139+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_CONSTANT") )
137140
{
138141
ModuleBase::GlobalFunc::READ_VALUE(ifa, lat0);
139142
if(lat0<=0.0)
@@ -154,7 +157,7 @@ bool read_lattice_constant(std::ifstream& ifa,
154157
if(latName=="none")
155158
{
156159
// check the existence of keyword "LATTICE_PARAMETERS"
157-
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa,
160+
if (ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa,
158161
"LATTICE_PARAMETERS",
159162
true,
160163
false))
@@ -164,12 +167,12 @@ bool read_lattice_constant(std::ifstream& ifa,
164167
}
165168

166169
// check the existence of keyword "LATTICE_VECTORS"
167-
if( !ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_VECTORS") )
170+
if( !ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_VECTORS") )
168171
{
169172
ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant",
170173
"Please set LATTICE_VECTORS in STRU file");
171174
}
172-
else if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_VECTORS") )
175+
else if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_VECTORS") )
173176
{
174177
// Reading lattice vectors. notice
175178
// here that only one cpu read these
@@ -184,7 +187,7 @@ bool read_lattice_constant(std::ifstream& ifa,
184187
}//supply lattice vectors
185188
else
186189
{
187-
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa,
190+
if (ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa,
188191
"LATTICE_VECTORS",
189192
true,
190193
false))
@@ -216,7 +219,7 @@ bool read_lattice_constant(std::ifstream& ifa,
216219
latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0;
217220
latvec.e21 =-0.5; latvec.e22 = e22; latvec.e23 = 0.0;
218221
latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0;
219-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
222+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
220223
{
221224
ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33);
222225
}
@@ -225,7 +228,7 @@ bool read_lattice_constant(std::ifstream& ifa,
225228
{//trigonal, ibrav = 5
226229
double t1 = 0.0;
227230
double t2 = 0.0;
228-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
231+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
229232
{
230233
double cosab=0.0;
231234
ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab);
@@ -245,15 +248,15 @@ bool read_lattice_constant(std::ifstream& ifa,
245248
latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0;
246249
latvec.e21 = 0.0; latvec.e22 = 1.0; latvec.e23 = 0.0;
247250
latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0;
248-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
251+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
249252
{
250253
ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33);
251254
}
252255
}
253256
else if(latName=="bct")
254257
{//body-centered tetragonal, ibrav = 7
255258
double cba = 0.0;
256-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
259+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
257260
{
258261
ModuleBase::GlobalFunc::READ_VALUE(ifa, cba);
259262
cba = cba / 2.0;
@@ -267,7 +270,7 @@ bool read_lattice_constant(std::ifstream& ifa,
267270
latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0;
268271
latvec.e21 = 0.0; latvec.e22 = 0.0; latvec.e23 = 0.0;
269272
latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0;
270-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
273+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
271274
{
272275
ifa >> latvec.e22;
273276
ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33);
@@ -278,7 +281,7 @@ bool read_lattice_constant(std::ifstream& ifa,
278281
latvec.e11 = 0.5; latvec.e12 = 0.0; latvec.e13 = 0.0;
279282
latvec.e21 =-0.5; latvec.e22 = 0.0; latvec.e23 = 0.0;
280283
latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0;
281-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
284+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
282285
{
283286
ifa >> latvec.e12;
284287
latvec.e12 = latvec.e12 / 2.0;
@@ -289,7 +292,7 @@ bool read_lattice_constant(std::ifstream& ifa,
289292
else if(latName=="fco")
290293
{//face-centered orthorhombic, ibrav = 10
291294
double bba = 0.0; double cba = 0.0;
292-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
295+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
293296
{
294297
ifa >> bba;
295298
ModuleBase::GlobalFunc::READ_VALUE(ifa, cba);
@@ -302,7 +305,7 @@ bool read_lattice_constant(std::ifstream& ifa,
302305
else if(latName=="bco")
303306
{//body-centered orthorhombic, ibrav = 11
304307
double bba = 0.0; double cba = 0.0;
305-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
308+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
306309
{
307310
ifa >> bba;
308311
ModuleBase::GlobalFunc::READ_VALUE(ifa, cba);
@@ -317,7 +320,7 @@ bool read_lattice_constant(std::ifstream& ifa,
317320
double bba = 0.0; double cba = 0.0;
318321
double cosab = 0.0;
319322
double e21 = 0.0; double e22 = 0.0;
320-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
323+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
321324
{
322325
ifa >> bba >> cba;
323326
ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab);
@@ -333,7 +336,7 @@ bool read_lattice_constant(std::ifstream& ifa,
333336
double bba = 0.0; double cba = 0.0;
334337
double cosab = 0.0;
335338
double e21 = 0.0; double e22 = 0.0;
336-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
339+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
337340
{
338341
ifa >> bba >> cba;
339342
ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab);
@@ -354,7 +357,7 @@ bool read_lattice_constant(std::ifstream& ifa,
354357
double cosbc = 0.0;
355358
double sinab = 0.0;
356359
double term = 0.0;
357-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") )
360+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifa, "LATTICE_PARAMETERS") )
358361
{
359362
ifa >> bba >> cba >> cosab >> cosac;
360363
ModuleBase::GlobalFunc::READ_VALUE(ifa, cosbc);

source/module_cell/read_atoms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool unitcell::read_atom_positions(UnitCell& ucell,
2828
std::string& Coordinate = ucell.Coordinate;
2929
const int ntype = ucell.ntype;
3030

31-
if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifpos, "ATOMIC_POSITIONS"))
31+
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifpos, "ATOMIC_POSITIONS"))
3232
{
3333
ModuleBase::GlobalFunc::READ_VALUE(ifpos, Coordinate);
3434

0 commit comments

Comments
 (0)