Skip to content

Commit 6d26194

Browse files
authored
Refactor: Remove the functions about pseudopotential from Unitcell. (#5673)
* Refactor: Remove read_pseudo and read_cell_pseudopots from Unitcell. * Test: Update Unit test. * Refactor: Remove print_unitcell_pseudo from UnitCell. Delete module_cell/read_cell_pseudopots.cpp * Test: Update Makefile
1 parent 02b07c6 commit 6d26194

File tree

21 files changed

+429
-403
lines changed

21 files changed

+429
-403
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ OBJS_CELL=atom_pseudo.o\
182182
read_pp_vwr.o\
183183
unitcell.o\
184184
read_atoms.o\
185-
read_cell_pseudopots.o\
186185
setup_nonlocal.o\
187186
klist.o\
188187
cell_index.o\
@@ -229,6 +228,7 @@ OBJS_ELECSTAT=elecstate.o\
229228
H_TDDFT_pw.o\
230229
pot_xc.o\
231230
cal_ux.o\
231+
read_pseudo.o\
232232

233233
OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
234234
elecstate_lcao_cal_tau.o\

source/module_cell/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ add_library(
1818
read_pp_vwr.cpp
1919
unitcell.cpp
2020
read_atoms.cpp
21-
read_cell_pseudopots.cpp
2221
setup_nonlocal.cpp
2322
klist.cpp
2423
parallel_kpoints.cpp

source/module_cell/read_cell_pseudopots.cpp

Lines changed: 0 additions & 138 deletions
This file was deleted.

source/module_cell/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ install(FILES unitcell_test_parallel.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
1515
list(APPEND cell_simple_srcs
1616
../unitcell.cpp
1717
../read_atoms.cpp
18-
../read_cell_pseudopots.cpp
1918
../atom_spec.cpp
2019
../atom_pseudo.cpp
2120
../pseudo.cpp
@@ -26,6 +25,7 @@ list(APPEND cell_simple_srcs
2625
../read_pp_vwr.cpp
2726
../read_pp_blps.cpp
2827
../check_atomic_stru.cpp
28+
../../module_elecstate/read_pseudo.cpp
2929
)
3030

3131
add_library(cell_info OBJECT ${cell_simple_srcs})

source/module_cell/test/support/mock_unitcell.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ int UnitCell::read_atom_species(std::ifstream& ifa,
6868
std::ofstream& ofs_running) {
6969
return 0;
7070
}
71-
void UnitCell::read_cell_pseudopots(const std::string& pp_dir,
72-
std::ofstream& log) {}
7371
bool UnitCell::read_atom_positions(std::ifstream& ifpos,
7472
std::ofstream& ofs_running,
7573
std::ofstream& ofs_warning) {
@@ -94,7 +92,6 @@ void UnitCell::read_orb_file(int it,
9492
std::string& orb_file,
9593
std::ofstream& ofs_running,
9694
Atom* atom) {}
97-
void UnitCell::read_pseudo(std::ofstream& ofs) {}
9895
int UnitCell::find_type(const std::string& label) { return 0; }
9996
void UnitCell::print_tau() const {}
10097
void UnitCell::print_stru_file(const std::string& fn,
@@ -111,7 +108,6 @@ void UnitCell::remake_cell() {}
111108
void UnitCell::cal_nwfc(std::ofstream& log) {}
112109
void UnitCell::cal_meshx() {}
113110
void UnitCell::cal_natomwfc(std::ofstream& log) {}
114-
void UnitCell::print_unitcell_pseudo(const std::string& fn) {}
115111
bool UnitCell::check_tau() const { return true; }
116112
bool UnitCell::if_atoms_can_move() const { return true; }
117113
bool UnitCell::if_cell_can_change() const { return true; }

source/module_cell/test/unitcell_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#undef private
66
#include "module_cell/unitcell.h"
77
#include "module_elecstate/cal_ux.h"
8+
#include "module_elecstate/read_pseudo.h"
89

910
#include "memory"
1011
#include "module_base/global_variable.h"
@@ -822,7 +823,7 @@ TEST_F(UcellTest, PrintUnitcellPseudo)
822823
ucell = utp.SetUcellInfo();
823824
PARAM.input.test_pseudo_cell = 1;
824825
std::string fn = "printcell.log";
825-
ucell->print_unitcell_pseudo(fn);
826+
elecstate::print_unitcell_pseudo(fn, *ucell);
826827
std::ifstream ifs;
827828
ifs.open("printcell.log");
828829
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());

source/module_cell/test/unitcell_test_para.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "module_base/global_variable.h"
88
#include "module_base/mathzone.h"
99
#include "module_cell/unitcell.h"
10+
#include "module_elecstate/read_pseudo.h"
1011
#include <valarray>
1112
#include <vector>
1213
#ifdef __MPI
@@ -93,7 +94,7 @@ class UcellTest : public ::testing::Test
9394
#ifdef __MPI
9495
TEST_F(UcellTest, BcastUnitcell2)
9596
{
96-
ucell->read_cell_pseudopots(pp_dir, ofs);
97+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
9798
ucell->bcast_unitcell2();
9899
if (GlobalV::MY_RANK != 0)
99100
{
@@ -153,7 +154,7 @@ TEST_F(UcellTest, ReadPseudo)
153154
{
154155
PARAM.input.pseudo_dir = pp_dir;
155156
PARAM.input.out_element_info = true;
156-
ucell->read_pseudo(ofs);
157+
elecstate::read_pseudo(ofs, *ucell);
157158
// check_structure will print some warning info
158159
// output nonlocal file
159160
if (GlobalV::MY_RANK == 0)

source/module_cell/test/unitcell_test_readpp.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "module_base/mathzone.h"
99
#include "module_cell/check_atomic_stru.h"
1010
#include "module_cell/unitcell.h"
11+
#include "module_elecstate/read_pseudo.h"
1112
#include <valarray>
1213
#include <vector>
1314
#ifdef __MPI
@@ -136,7 +137,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning1) {
136137
PARAM.input.lspinorb = true;
137138
ucell->pseudo_fn[1] = "H_sr.upf";
138139
testing::internal::CaptureStdout();
139-
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
140+
EXPECT_EXIT(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell),
140141
::testing::ExitedWithCode(1),
141142
"");
142143
output = testing::internal::GetCapturedStdout();
@@ -147,7 +148,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning1) {
147148
TEST_F(UcellDeathTest, ReadCellPPWarning2) {
148149
pp_dir = "./arbitrary/";
149150
testing::internal::CaptureStdout();
150-
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
151+
EXPECT_EXIT(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell),
151152
::testing::ExitedWithCode(1),
152153
"");
153154
output = testing::internal::GetCapturedStdout();
@@ -158,7 +159,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning2) {
158159
TEST_F(UcellDeathTest, ReadCellPPWarning3) {
159160
ucell->pseudo_type[0] = "upf";
160161
testing::internal::CaptureStdout();
161-
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
162+
EXPECT_EXIT(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell),
162163
::testing::ExitedWithCode(1),
163164
"");
164165
output = testing::internal::GetCapturedStdout();
@@ -169,7 +170,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning3) {
169170
TEST_F(UcellDeathTest, ReadCellPPWarning4) {
170171
PARAM.input.dft_functional = "LDA";
171172
testing::internal::CaptureStdout();
172-
EXPECT_NO_THROW(ucell->read_cell_pseudopots(pp_dir, ofs));
173+
EXPECT_NO_THROW(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell));
173174
output = testing::internal::GetCapturedStdout();
174175
EXPECT_THAT(output, testing::HasSubstr("dft_functional readin is: LDA"));
175176
EXPECT_THAT(output,
@@ -181,7 +182,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning4) {
181182
TEST_F(UcellDeathTest, ReadCellPPWarning5) {
182183
ucell->pseudo_type[0] = "upf0000";
183184
testing::internal::CaptureStdout();
184-
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
185+
EXPECT_EXIT(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell),
185186
::testing::ExitedWithCode(1),
186187
"");
187188
output = testing::internal::GetCapturedStdout();
@@ -190,7 +191,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning5) {
190191

191192
TEST_F(UcellTest, ReadCellPP) {
192193
ucell->atoms[1].flag_empty_element = true;
193-
ucell->read_cell_pseudopots(pp_dir, ofs);
194+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
194195
EXPECT_EQ(ucell->atoms[0].ncpp.pp_type, "NC");
195196
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so); // becomes false in average_p
196197
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
@@ -213,15 +214,15 @@ TEST_F(UcellTest, ReadCellPP) {
213214
}
214215

215216
TEST_F(UcellTest, CalMeshx) {
216-
ucell->read_cell_pseudopots(pp_dir, ofs);
217+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
217218
ucell->cal_meshx();
218219
EXPECT_EQ(ucell->atoms[0].ncpp.msh, 1247);
219220
EXPECT_EQ(ucell->atoms[1].ncpp.msh, 1165);
220221
EXPECT_EQ(ucell->meshx, 1247);
221222
}
222223

223224
TEST_F(UcellTest, CalNatomwfc1) {
224-
ucell->read_cell_pseudopots(pp_dir, ofs);
225+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
225226
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
226227
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
227228
ucell->cal_natomwfc(ofs);
@@ -235,7 +236,7 @@ TEST_F(UcellTest, CalNatomwfc1) {
235236
TEST_F(UcellTest, CalNatomwfc2) {
236237
PARAM.input.lspinorb = false;
237238
PARAM.input.nspin = 4;
238-
ucell->read_cell_pseudopots(pp_dir, ofs);
239+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
239240
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
240241
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
241242
ucell->cal_natomwfc(ofs);
@@ -249,7 +250,7 @@ TEST_F(UcellTest, CalNatomwfc2) {
249250
TEST_F(UcellTest, CalNatomwfc3) {
250251
PARAM.input.lspinorb = true;
251252
PARAM.input.nspin = 4;
252-
ucell->read_cell_pseudopots(pp_dir, ofs);
253+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
253254
EXPECT_TRUE(ucell->atoms[0].ncpp.has_so);
254255
EXPECT_TRUE(ucell->atoms[1].ncpp.has_so);
255256
ucell->cal_natomwfc(ofs);
@@ -262,7 +263,7 @@ TEST_F(UcellTest, CalNatomwfc3) {
262263
}
263264

264265
TEST_F(UcellTest, CalNwfc1) {
265-
ucell->read_cell_pseudopots(pp_dir, ofs);
266+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
266267
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
267268
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
268269
PARAM.sys.nlocal = 3 * 9;
@@ -328,15 +329,15 @@ TEST_F(UcellTest, CalNwfc1) {
328329
TEST_F(UcellTest, CalNwfc2) {
329330
PARAM.input.nspin = 4;
330331
PARAM.input.basis_type = "lcao";
331-
ucell->read_cell_pseudopots(pp_dir, ofs);
332+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
332333
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
333334
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
334335
PARAM.sys.nlocal = 3 * 9 * 2;
335336
EXPECT_NO_THROW(ucell->cal_nwfc(ofs));
336337
}
337338

338339
TEST_F(UcellDeathTest, CheckStructure) {
339-
ucell->read_cell_pseudopots(pp_dir, ofs);
340+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
340341
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
341342
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
342343
// trial 1
@@ -379,7 +380,7 @@ TEST_F(UcellDeathTest, ReadPseudoWarning1) {
379380
PARAM.input.out_element_info = true;
380381
ucell->pseudo_fn[1] = "H_sr_lda.upf";
381382
testing::internal::CaptureStdout();
382-
EXPECT_EXIT(ucell->read_pseudo(ofs), ::testing::ExitedWithCode(1), "");
383+
EXPECT_EXIT(elecstate::read_pseudo(ofs, *ucell), ::testing::ExitedWithCode(1), "");
383384
output = testing::internal::GetCapturedStdout();
384385
EXPECT_THAT(output,
385386
testing::HasSubstr("All DFT functional must consistent."));
@@ -390,7 +391,7 @@ TEST_F(UcellDeathTest, ReadPseudoWarning2) {
390391
PARAM.input.out_element_info = true;
391392
ucell->pseudo_fn[0] = "Al_ONCV_PBE-1.0.upf";
392393
testing::internal::CaptureStdout();
393-
EXPECT_NO_THROW(ucell->read_pseudo(ofs));
394+
EXPECT_NO_THROW(elecstate::read_pseudo(ofs, *ucell));
394395
output = testing::internal::GetCapturedStdout();
395396
EXPECT_THAT(
396397
output,
@@ -399,7 +400,7 @@ TEST_F(UcellDeathTest, ReadPseudoWarning2) {
399400
}
400401

401402
TEST_F(UcellTest, CalNelec) {
402-
ucell->read_cell_pseudopots(pp_dir, ofs);
403+
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
403404
EXPECT_EQ(4, ucell->atoms[0].ncpp.zv);
404405
EXPECT_EQ(1, ucell->atoms[1].ncpp.zv);
405406
EXPECT_EQ(1, ucell->atoms[0].na);

0 commit comments

Comments
 (0)