Skip to content

Commit cb86cc4

Browse files
Critsium-xyclaude
andauthored
Refactor: move read_orb from source_estate to source_cell (#7634) (#7648)
* Refactor: move read_orb from source_estate to source_cell (#7634) read_orb_file only parses an orbital-file header into Atom fields and depends solely on source_cell/unitcell.h and source_base. Its only non-test caller lives in source_cell (read_atoms_helper.cpp), so its placement in source_estate created a circular source_cell -> source_estate dependency. Move read_orb.{h,cpp} down into source_cell and rename the namespace from elecstate to unitcell to match its module. Update the include paths, the call sites, and every CMake target that referenced the old estate path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Fix: link read_orb.cpp into MODULE_CELL_read_atoms_helper_test This test target compiles read_atoms_helper.cpp, which now calls unitcell::read_orb_file, but did not list read_orb.cpp in its SOURCES, causing an undefined-reference link error. Add ../read_orb.cpp so the definition is linked in. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 60ccbff commit cb86cc4

11 files changed

Lines changed: 19 additions & 18 deletions

File tree

source/source_cell/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(
1717
unitcell.cpp
1818
read_atoms.cpp
1919
read_atoms_helper.cpp
20+
read_orb.cpp
2021
setup_nonlocal.cpp
2122
klist.cpp
2223
parallel_kpoints.cpp

source/source_cell/read_atoms_helper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "source_base/mathzone.h"
66
#include "read_stru.h"
77
#include "print_cell.h"
8-
#include "source_estate/read_orb.h"
8+
#include "read_orb.h"
99
#include <cmath>
1010
#include <iostream>
1111
#include <sstream>
@@ -519,7 +519,7 @@ bool read_atom_type_header(int it, UnitCell& ucell,
519519
if ((PARAM.inp.basis_type == "lcao")||(PARAM.inp.basis_type == "lcao_in_pw"))
520520
{
521521
std::string orbital_file = PARAM.inp.orbital_dir + ucell.orbital_fn[it];
522-
bool normal = elecstate::read_orb_file(it, orbital_file, ofs_running, &(ucell.atoms[it]));
522+
bool normal = unitcell::read_orb_file(it, orbital_file, ofs_running, &(ucell.atoms[it]));
523523
if(!normal)
524524
{
525525
return false;
@@ -530,7 +530,7 @@ bool read_atom_type_header(int it, UnitCell& ucell,
530530
if ((PARAM.inp.init_wfc.substr(0, 3) == "nao") || PARAM.inp.onsite_radius > 0.0)
531531
{
532532
std::string orbital_file = PARAM.inp.orbital_dir + ucell.orbital_fn[it];
533-
bool normal = elecstate::read_orb_file(it, orbital_file, ofs_running, &(ucell.atoms[it]));
533+
bool normal = unitcell::read_orb_file(it, orbital_file, ofs_running, &(ucell.atoms[it]));
534534
if(!normal)
535535
{
536536
return false;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "read_orb.h"
22
#include "source_base/formatter.h"
33

4-
namespace elecstate {
4+
namespace unitcell {
55
bool read_orb_file(int it, std::string &orb_file, std::ofstream &ofs_running, Atom* atom)
66
{
77
// the maximum L is 9 like cc-pV9Z, according to the
@@ -14,7 +14,7 @@ namespace elecstate {
1414
{
1515
std::cout << " Element index " << it+1 << std::endl;
1616
std::cout << " orbital file: " << orb_file << std::endl;
17-
ModuleBase::WARNING("elecstate::read_orb_file",
17+
ModuleBase::WARNING("unitcell::read_orb_file",
1818
"cannot open the ORBITAL file (NAO basis sets)");
1919
return false;
2020
}
@@ -55,7 +55,7 @@ namespace elecstate {
5555
}
5656
if (!valid)
5757
{
58-
ModuleBase::WARNING("elecstate::read_orb_file",
58+
ModuleBase::WARNING("unitcell::read_orb_file",
5959
"ABACUS does not support NAO with L > 9, "
6060
"or an invalid orbital label is found in the ORBITAL file.");
6161
return false;
@@ -65,7 +65,7 @@ namespace elecstate {
6565
ifs.close();
6666
if(!atom->nw)
6767
{
68-
ModuleBase::WARNING("elecstate::read_orb_file","get nw = 0, check the ORBITAL file");
68+
ModuleBase::WARNING("unitcell::read_orb_file","get nw = 0, check the ORBITAL file");
6969
return false;
7070
}
7171
return true;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef READ_ORB_H
22
#define READ_ORB_H
33

4-
#include "source_cell/unitcell.h"
4+
#include "unitcell.h"
55

6-
namespace elecstate
6+
namespace unitcell
77
{
88

99
/**

source/source_cell/test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ list(APPEND cell_simple_srcs
4343
../../source_estate/read_pseudo.cpp
4444
../../source_estate/cal_wfc.cpp
4545
../../source_estate/cal_nelec_nband.cpp
46-
../../source_estate/read_orb.cpp
46+
../read_orb.cpp
4747
../sep.cpp
4848
../sep_cell.cpp
4949
)
@@ -108,6 +108,7 @@ AddTest(
108108
LIBS parameter base device
109109
SOURCES read_atoms_helper_test.cpp
110110
../read_atoms_helper.cpp
111+
../read_orb.cpp
111112
../read_stru.cpp
112113
../print_cell.cpp
113114
../atom_spec.cpp

source/source_cell/test/unitcell_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "source_io/module_parameter/parameter.h"
55
#undef private
66
#include "source_estate/cal_ux.h"
7-
#include "source_estate/read_orb.h"
7+
#include "source_cell/read_orb.h"
88
#include "source_estate/read_pseudo.h"
99
#include "source_cell/read_stru.h"
1010
#include "source_cell/print_cell.h"
@@ -1088,7 +1088,7 @@ TEST_F(UcellTest, ReadOrbFile)
10881088
std::string orb_file = "./support/C.orb";
10891089
std::ofstream ofs_running;
10901090
ofs_running.open("tmp_readorbfile");
1091-
bool result = elecstate::read_orb_file(0, orb_file, ofs_running, &(ucell->atoms[0]));
1091+
bool result = unitcell::read_orb_file(0, orb_file, ofs_running, &(ucell->atoms[0]));
10921092
ofs_running << " result=" << result << std::endl;
10931093
EXPECT_TRUE(result);
10941094
ofs_running.close();
@@ -1828,7 +1828,7 @@ TEST_F(UcellTest, ReadOrbFileWarning)
18281828
std::ofstream ofs_running;
18291829
ofs_running.open("tmp_readorbfilewarning");
18301830
testing::internal::CaptureStdout();
1831-
bool result = elecstate::read_orb_file(0, orb_file, ofs_running, &(ucell->atoms[0]));
1831+
bool result = unitcell::read_orb_file(0, orb_file, ofs_running, &(ucell->atoms[0]));
18321832
output = testing::internal::GetCapturedStdout();
18331833
ofs_running << output << std::endl;
18341834
EXPECT_FALSE(result);

source/source_cell/test_pw/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ AddTest(
1717
../read_stru.cpp ../read_atom_species.cpp
1818
../read_pp_vwr.cpp ../read_pp_blps.cpp
1919
../../source_estate/read_pseudo.cpp ../../source_estate/cal_nelec_nband.cpp
20-
../../source_estate/read_orb.cpp ../print_cell.cpp
20+
../../source_cell/read_orb.cpp ../print_cell.cpp
2121
../../source_estate/cal_wfc.cpp ../sep.cpp ../sep_cell.cpp
2222
)
2323

source/source_estate/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ list(APPEND objects
3939
fp_energy.cpp
4040
occupy.cpp
4141
cal_ux.cpp
42-
read_orb.cpp
4342
cal_nelec_nband.cpp
4443
read_pseudo.cpp
4544
cal_wfc.cpp

source/source_lcao/module_deepks/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ set(DEEPKS_UNIT_COMMON_SOURCES
4141
../../../source_io/module_output/sparse_matrix.cpp
4242
../../../source_estate/read_pseudo.cpp
4343
../../../source_estate/cal_wfc.cpp
44-
../../../source_estate/read_orb.cpp
44+
../../../source_cell/read_orb.cpp
4545
../../../source_estate/cal_nelec_nband.cpp
4646
../../../source_estate/module_dm/density_matrix.cpp
4747
../../../source_estate/module_dm/density_matrix_io.cpp

source/source_md/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ list(APPEND depend_files
6060
../../source_estate/read_pseudo.cpp
6161
../../source_estate/cal_wfc.cpp
6262
../../source_estate/cal_nelec_nband.cpp
63-
../../source_estate/read_orb.cpp
63+
../../source_cell/read_orb.cpp
6464
../../source_cell/sep.cpp
6565
../../source_cell/sep_cell.cpp
6666
)

0 commit comments

Comments
 (0)