Skip to content

Commit

Permalink
Refactor: Remove the functions about pseudopotential from Unitcell. (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
sunliang98 authored Dec 5, 2024
1 parent 02b07c6 commit 6d26194
Show file tree
Hide file tree
Showing 21 changed files with 429 additions and 403 deletions.
2 changes: 1 addition & 1 deletion source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ OBJS_CELL=atom_pseudo.o\
read_pp_vwr.o\
unitcell.o\
read_atoms.o\
read_cell_pseudopots.o\
setup_nonlocal.o\
klist.o\
cell_index.o\
Expand Down Expand Up @@ -229,6 +228,7 @@ OBJS_ELECSTAT=elecstate.o\
H_TDDFT_pw.o\
pot_xc.o\
cal_ux.o\
read_pseudo.o\

OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
elecstate_lcao_cal_tau.o\
Expand Down
1 change: 0 additions & 1 deletion source/module_cell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ add_library(
read_pp_vwr.cpp
unitcell.cpp
read_atoms.cpp
read_cell_pseudopots.cpp
setup_nonlocal.cpp
klist.cpp
parallel_kpoints.cpp
Expand Down
138 changes: 0 additions & 138 deletions source/module_cell/read_cell_pseudopots.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion source/module_cell/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ install(FILES unitcell_test_parallel.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND cell_simple_srcs
../unitcell.cpp
../read_atoms.cpp
../read_cell_pseudopots.cpp
../atom_spec.cpp
../atom_pseudo.cpp
../pseudo.cpp
Expand All @@ -26,6 +25,7 @@ list(APPEND cell_simple_srcs
../read_pp_vwr.cpp
../read_pp_blps.cpp
../check_atomic_stru.cpp
../../module_elecstate/read_pseudo.cpp
)

add_library(cell_info OBJECT ${cell_simple_srcs})
Expand Down
4 changes: 0 additions & 4 deletions source/module_cell/test/support/mock_unitcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ int UnitCell::read_atom_species(std::ifstream& ifa,
std::ofstream& ofs_running) {
return 0;
}
void UnitCell::read_cell_pseudopots(const std::string& pp_dir,
std::ofstream& log) {}
bool UnitCell::read_atom_positions(std::ifstream& ifpos,
std::ofstream& ofs_running,
std::ofstream& ofs_warning) {
Expand All @@ -94,7 +92,6 @@ void UnitCell::read_orb_file(int it,
std::string& orb_file,
std::ofstream& ofs_running,
Atom* atom) {}
void UnitCell::read_pseudo(std::ofstream& ofs) {}
int UnitCell::find_type(const std::string& label) { return 0; }
void UnitCell::print_tau() const {}
void UnitCell::print_stru_file(const std::string& fn,
Expand All @@ -111,7 +108,6 @@ void UnitCell::remake_cell() {}
void UnitCell::cal_nwfc(std::ofstream& log) {}
void UnitCell::cal_meshx() {}
void UnitCell::cal_natomwfc(std::ofstream& log) {}
void UnitCell::print_unitcell_pseudo(const std::string& fn) {}
bool UnitCell::check_tau() const { return true; }
bool UnitCell::if_atoms_can_move() const { return true; }
bool UnitCell::if_cell_can_change() const { return true; }
Expand Down
3 changes: 2 additions & 1 deletion source/module_cell/test/unitcell_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#undef private
#include "module_cell/unitcell.h"
#include "module_elecstate/cal_ux.h"
#include "module_elecstate/read_pseudo.h"

#include "memory"
#include "module_base/global_variable.h"
Expand Down Expand Up @@ -822,7 +823,7 @@ TEST_F(UcellTest, PrintUnitcellPseudo)
ucell = utp.SetUcellInfo();
PARAM.input.test_pseudo_cell = 1;
std::string fn = "printcell.log";
ucell->print_unitcell_pseudo(fn);
elecstate::print_unitcell_pseudo(fn, *ucell);
std::ifstream ifs;
ifs.open("printcell.log");
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
Expand Down
5 changes: 3 additions & 2 deletions source/module_cell/test/unitcell_test_para.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "module_base/global_variable.h"
#include "module_base/mathzone.h"
#include "module_cell/unitcell.h"
#include "module_elecstate/read_pseudo.h"
#include <valarray>
#include <vector>
#ifdef __MPI
Expand Down Expand Up @@ -93,7 +94,7 @@ class UcellTest : public ::testing::Test
#ifdef __MPI
TEST_F(UcellTest, BcastUnitcell2)
{
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
ucell->bcast_unitcell2();
if (GlobalV::MY_RANK != 0)
{
Expand Down Expand Up @@ -153,7 +154,7 @@ TEST_F(UcellTest, ReadPseudo)
{
PARAM.input.pseudo_dir = pp_dir;
PARAM.input.out_element_info = true;
ucell->read_pseudo(ofs);
elecstate::read_pseudo(ofs, *ucell);
// check_structure will print some warning info
// output nonlocal file
if (GlobalV::MY_RANK == 0)
Expand Down
33 changes: 17 additions & 16 deletions source/module_cell/test/unitcell_test_readpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "module_base/mathzone.h"
#include "module_cell/check_atomic_stru.h"
#include "module_cell/unitcell.h"
#include "module_elecstate/read_pseudo.h"
#include <valarray>
#include <vector>
#ifdef __MPI
Expand Down Expand Up @@ -136,7 +137,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning1) {
PARAM.input.lspinorb = true;
ucell->pseudo_fn[1] = "H_sr.upf";
testing::internal::CaptureStdout();
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
EXPECT_EXIT(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell),
::testing::ExitedWithCode(1),
"");
output = testing::internal::GetCapturedStdout();
Expand All @@ -147,7 +148,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning1) {
TEST_F(UcellDeathTest, ReadCellPPWarning2) {
pp_dir = "./arbitrary/";
testing::internal::CaptureStdout();
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
EXPECT_EXIT(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell),
::testing::ExitedWithCode(1),
"");
output = testing::internal::GetCapturedStdout();
Expand All @@ -158,7 +159,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning2) {
TEST_F(UcellDeathTest, ReadCellPPWarning3) {
ucell->pseudo_type[0] = "upf";
testing::internal::CaptureStdout();
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
EXPECT_EXIT(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell),
::testing::ExitedWithCode(1),
"");
output = testing::internal::GetCapturedStdout();
Expand All @@ -169,7 +170,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning3) {
TEST_F(UcellDeathTest, ReadCellPPWarning4) {
PARAM.input.dft_functional = "LDA";
testing::internal::CaptureStdout();
EXPECT_NO_THROW(ucell->read_cell_pseudopots(pp_dir, ofs));
EXPECT_NO_THROW(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell));
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr("dft_functional readin is: LDA"));
EXPECT_THAT(output,
Expand All @@ -181,7 +182,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning4) {
TEST_F(UcellDeathTest, ReadCellPPWarning5) {
ucell->pseudo_type[0] = "upf0000";
testing::internal::CaptureStdout();
EXPECT_EXIT(ucell->read_cell_pseudopots(pp_dir, ofs),
EXPECT_EXIT(elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell),
::testing::ExitedWithCode(1),
"");
output = testing::internal::GetCapturedStdout();
Expand All @@ -190,7 +191,7 @@ TEST_F(UcellDeathTest, ReadCellPPWarning5) {

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

TEST_F(UcellTest, CalMeshx) {
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
ucell->cal_meshx();
EXPECT_EQ(ucell->atoms[0].ncpp.msh, 1247);
EXPECT_EQ(ucell->atoms[1].ncpp.msh, 1165);
EXPECT_EQ(ucell->meshx, 1247);
}

TEST_F(UcellTest, CalNatomwfc1) {
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
ucell->cal_natomwfc(ofs);
Expand All @@ -235,7 +236,7 @@ TEST_F(UcellTest, CalNatomwfc1) {
TEST_F(UcellTest, CalNatomwfc2) {
PARAM.input.lspinorb = false;
PARAM.input.nspin = 4;
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
ucell->cal_natomwfc(ofs);
Expand All @@ -249,7 +250,7 @@ TEST_F(UcellTest, CalNatomwfc2) {
TEST_F(UcellTest, CalNatomwfc3) {
PARAM.input.lspinorb = true;
PARAM.input.nspin = 4;
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
EXPECT_TRUE(ucell->atoms[0].ncpp.has_so);
EXPECT_TRUE(ucell->atoms[1].ncpp.has_so);
ucell->cal_natomwfc(ofs);
Expand All @@ -262,7 +263,7 @@ TEST_F(UcellTest, CalNatomwfc3) {
}

TEST_F(UcellTest, CalNwfc1) {
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
PARAM.sys.nlocal = 3 * 9;
Expand Down Expand Up @@ -328,15 +329,15 @@ TEST_F(UcellTest, CalNwfc1) {
TEST_F(UcellTest, CalNwfc2) {
PARAM.input.nspin = 4;
PARAM.input.basis_type = "lcao";
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
PARAM.sys.nlocal = 3 * 9 * 2;
EXPECT_NO_THROW(ucell->cal_nwfc(ofs));
}

TEST_F(UcellDeathTest, CheckStructure) {
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
EXPECT_FALSE(ucell->atoms[1].ncpp.has_so);
// trial 1
Expand Down Expand Up @@ -379,7 +380,7 @@ TEST_F(UcellDeathTest, ReadPseudoWarning1) {
PARAM.input.out_element_info = true;
ucell->pseudo_fn[1] = "H_sr_lda.upf";
testing::internal::CaptureStdout();
EXPECT_EXIT(ucell->read_pseudo(ofs), ::testing::ExitedWithCode(1), "");
EXPECT_EXIT(elecstate::read_pseudo(ofs, *ucell), ::testing::ExitedWithCode(1), "");
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,
testing::HasSubstr("All DFT functional must consistent."));
Expand All @@ -390,7 +391,7 @@ TEST_F(UcellDeathTest, ReadPseudoWarning2) {
PARAM.input.out_element_info = true;
ucell->pseudo_fn[0] = "Al_ONCV_PBE-1.0.upf";
testing::internal::CaptureStdout();
EXPECT_NO_THROW(ucell->read_pseudo(ofs));
EXPECT_NO_THROW(elecstate::read_pseudo(ofs, *ucell));
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(
output,
Expand All @@ -399,7 +400,7 @@ TEST_F(UcellDeathTest, ReadPseudoWarning2) {
}

TEST_F(UcellTest, CalNelec) {
ucell->read_cell_pseudopots(pp_dir, ofs);
elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell);
EXPECT_EQ(4, ucell->atoms[0].ncpp.zv);
EXPECT_EQ(1, ucell->atoms[1].ncpp.zv);
EXPECT_EQ(1, ucell->atoms[0].na);
Expand Down
Loading

0 comments on commit 6d26194

Please sign in to comment.