Skip to content

Commit 8b777a2

Browse files
committed
Simplify io.
1 parent f3a5dab commit 8b777a2

File tree

5 files changed

+10
-32
lines changed

5 files changed

+10
-32
lines changed

source/source_lcao/module_deepks/LCAO_deepks.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ class LCAO_Deepks
6969
//-------------------
7070
// private:
7171
public: // change to public to reconstuct the code, 2024-07-22 by mohan
72-
// int lmaxd = 0; // max l of descirptors
73-
// int nmaxd = 0; //#. descriptors per l
74-
// int inlmax = 0; // tot. number {i,n,l} - atom, n, l
75-
// int n_descriptor; // natoms * des_per_atom, size of descriptor(projector) basis set
76-
// int des_per_atom; // \sum_L{Nchi(L)*(2L+1)}
77-
// std::vector<int> inl2l; // inl2l[inl] = inl2l[nl] = l (not related to iat) of descriptor with inl_index
78-
// ModuleBase::IntArray* inl_index; // caoyu add 2021-05-07
7972
DeePKS_Param deepks_param; // parameters for DeePKS
8073

8174
bool init_pdm = false; // for DeePKS NSCF calculation, set init_pdm to skip the calculation of pdm in SCF iteration

source/source_lcao/module_deepks/LCAO_deepks_interface.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
8282
using TH = std::conditional_t<std::is_same<TK, double>::value, ModuleBase::matrix, ModuleBase::ComplexMatrix>;
8383

8484
// These variables are frequently used in the following code
85-
const int nlmax = orb.Alpha[0].getTotal_nchi();
86-
const int inlmax = nlmax * nat;
87-
const int lmaxd = orb.get_lmax_d();
88-
const int nmaxd = ld->deepks_param.nmaxd;
89-
90-
const int des_per_atom = ld->deepks_param.des_per_atom;
91-
const std::vector<int> inl2l = ld->deepks_param.inl2l;
92-
const ModuleBase::IntArray* inl_index = ld->deepks_param.inl_index;
9385
const std::vector<hamilt::HContainer<double>*> phialpha = ld->phialpha;
9486

9587
const DeePKS_Param& deepks_param = ld->deepks_param;
@@ -134,10 +126,8 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
134126

135127
const std::string file_d = get_filename("dm_eig", PARAM.inp.deepks_out_labels, iter);
136128
LCAO_deepks_io::save_npy_d(nat,
137-
des_per_atom,
138-
inlmax,
139-
inl2l,
140129
PARAM.inp.deepks_equiv,
130+
deepks_param,
141131
descriptor,
142132
file_d,
143133
rank); // libnpy needed

source/source_lcao/module_deepks/LCAO_deepks_io.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ void LCAO_deepks_io::load_npy_gedm(const int nat,
7575

7676
// saves descriptor into dm_eig.npy
7777
void LCAO_deepks_io::save_npy_d(const int nat,
78-
const int des_per_atom,
79-
const int inlmax,
80-
const std::vector<int>& inl2l,
8178
const bool deepks_equiv,
79+
const DeePKS_Param& deepks_param,
8280
const std::vector<torch::Tensor>& descriptor,
8381
const std::string& dm_eig_file,
8482
const int rank)
@@ -95,16 +93,16 @@ void LCAO_deepks_io::save_npy_d(const int nat,
9593
if (!deepks_equiv)
9694
{
9795
std::vector<double> npy_des;
98-
for (int inl = 0; inl < inlmax; ++inl)
96+
for (int inl = 0; inl < deepks_param.inlmax; ++inl)
9997
{
10098
auto accessor = descriptor[inl].accessor<double, 1>();
101-
int nm = 2 * inl2l[inl] + 1;
99+
int nm = 2 * deepks_param.inl2l[inl] + 1;
102100
for (int im = 0; im < nm; im++)
103101
{
104102
npy_des.push_back(accessor[im]);
105103
}
106104
}
107-
const long unsigned dshape[] = {static_cast<unsigned long>(nat), static_cast<unsigned long>(des_per_atom)};
105+
const long unsigned dshape[] = {static_cast<unsigned long>(nat), static_cast<unsigned long>(deepks_param.des_per_atom)};
108106
if (rank == 0)
109107
{
110108
npy::SaveArrayAsNumpy(dm_eig_file, false, 2, dshape, npy_des);
@@ -117,12 +115,12 @@ void LCAO_deepks_io::save_npy_d(const int nat,
117115
for (int iat = 0; iat < nat; iat++)
118116
{
119117
auto accessor = descriptor[iat].accessor<double, 1>();
120-
for (int i = 0; i < des_per_atom; i++)
118+
for (int i = 0; i < deepks_param.des_per_atom; i++)
121119
{
122120
npy_des.push_back(accessor[i]);
123121
}
124122
}
125-
const long unsigned dshape[] = {static_cast<unsigned long>(nat), static_cast<unsigned long>(des_per_atom)};
123+
const long unsigned dshape[] = {static_cast<unsigned long>(nat), static_cast<unsigned long>(deepks_param.des_per_atom)};
126124
if (rank == 0)
127125
{
128126
npy::SaveArrayAsNumpy(dm_eig_file, false, 2, dshape, npy_des);

source/source_lcao/module_deepks/LCAO_deepks_io.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#ifdef __MLALGO
55

6+
#include "deepks_param.h"
67
#include "source_base/complexmatrix.h"
78
#include "source_base/matrix.h"
89
#include "source_base/tool_title.h"
@@ -44,10 +45,8 @@ void load_npy_gedm(const int nat, const int des_per_atom, double** gedm, double&
4445

4546
/// save descriptor
4647
void save_npy_d(const int nat,
47-
const int des_per_atom,
48-
const int inlmax,
49-
const std::vector<int>& inl2l,
5048
const bool deepks_equiv,
49+
const DeePKS_Param& deepks_param,
5150
const std::vector<torch::Tensor>& descriptor,
5251
const std::string& dm_eig_file,
5352
const int rank);

source/source_lcao/module_deepks/deepks_basic.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@ void DeePKS_domain::cal_edelta_gedm_equiv(const int nat,
145145

146146
const std::string file_d = PARAM.globalv.global_out_dir + "deepks_dm_eig.npy";
147147
LCAO_deepks_io::save_npy_d(nat,
148-
deepks_param.des_per_atom,
149-
deepks_param.inlmax,
150-
deepks_param.inl2l,
151148
PARAM.inp.deepks_equiv,
149+
deepks_param,
152150
descriptor,
153151
file_d,
154152
rank); // libnpy needed

0 commit comments

Comments
 (0)