FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
abacus-develop/source/source_lcao/setup_deepks.cpp at develop · deepmodeling/abacus-develop · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
deepmodeling
/
abacus-develop
Public
forked from
abacusmodeling/abacus-develop
Notifications
You must be signed in to change notification settings
Fork
243
Star
286
Code
Issues
258
Pull requests
17
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
abacus-develop
/
source
/
source_lcao
/
setup_deepks.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
201 lines (187 loc) · 8.27 KB
Breadcrumbs
abacus-develop
/
source
/
source_lcao
/
setup_deepks.cpp
Copy path
File metadata and controls
201 lines (187 loc) · 8.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#
include
"
source_lcao/setup_deepks.h
"
#
include
"
source_io/module_parameter/parameter.h
"
//
use parameter
#
include
"
source_lcao/lcao_domain.h
"
#
ifdef
__MLALGO
#
include
"
source_lcao/module_deepks/lcao_deepks_io.h
"
#
include
"
source_lcao/module_deepks/deepks_basic.h
"
#
include
"
source_lcao/module_deepks/deepks_pdm.h
"
#
include
"
source_lcao/module_deepks/deepks_phialpha.h
"
#
endif
template
<
typename
TK
>
Setup_DeePKS<
TK
>::Setup_DeePKS()
{
}
template
<
typename
TK
>
Setup_DeePKS<
TK
>::
~Setup_DeePKS
()
{
}
template
<
typename
TK
>
void
Setup_DeePKS<
TK
>::build_overlap(
const
UnitCell& ucell,
const
LCAO_Orbitals& orb,
const
Parallel_Orbitals& pv,
const
Grid_Driver& gd,
TwoCenterIntegrator& overlap_orb_alpha,
const
Input_para& inp)
{
#
ifdef
__MLALGO
//
9) for each ionic step, the overlap <phi|alpha> must be rebuilt
//
since it depends on ionic positions
if
(
PARAM
.
globalv
.
deepks_setorb
)
{
//
allocate <phi(0)|alpha(R)>, phialpha is different every ion step, so it is allocated here
DeePKS_domain::allocate_phialpha
(inp.
cal_force
, ucell, orb, gd, &pv,
this
->
ld
.
phialpha
);
//
build and save <phi(0)|alpha(R)> at beginning
DeePKS_domain::build_phialpha
(inp.
cal_force
, ucell, orb, gd, &pv, overlap_orb_alpha,
this
->
ld
.
phialpha
);
if
(inp.
deepks_out_unittest
)
{
DeePKS_domain::check_phialpha
(inp.
cal_force
, ucell, orb, gd, &pv,
this
->
ld
.
phialpha
, GlobalV::
MY_RANK
);
}
}
#
endif
}
template
<
typename
TK
>
void
Setup_DeePKS<
TK
>::before_runner(
const
UnitCell& ucell,
//
unitcell
const
int
nks,
//
number of k points
const
LCAO_Orbitals& orb,
//
orbital info
Parallel_Orbitals& pv,
//
parallel orbitals
const
Input_para& inp)
{
#
ifdef
__MLALGO
LCAO_domain::DeePKS_init
(ucell, pv, nks, orb,
this
->
ld
, GlobalV::ofs_running);
if
(inp.
deepks_scf
)
{
//
load the DeePKS model from deep neural network
DeePKS_domain::load_model
(inp.
deepks_model
,
this
->
ld
.
model_deepks
);
//
read pdm from file for NSCF or SCF-restart, do it only once in whole calculation
DeePKS_domain::read_pdm
((inp.
init_chg
==
"
file
"
),
inp.
deepks_equiv
,
this
->
ld
.
init_pdm
,
ucell.
nat
,
this
->
ld
.
deepks_param
,
*orb.
Alpha
,
this
->
ld
.
pdm
);
}
#
endif
}
template
<
typename
TK
>
void
Setup_DeePKS<
TK
>::delta_e(
const
UnitCell& ucell,
const
K_Vectors& kv,
const
LCAO_Orbitals& orb,
const
Parallel_Orbitals& pv,
//
parallel orbitals
const
Grid_Driver& gd,
const
std::vector<std::vector<
TK
>>& dm_vec,
elecstate::fenergy& f_en,
const
Input_para& inp)
{
#
ifdef
__MLALGO
if
(inp.
deepks_scf
)
{
this
->
ld
.
dpks_cal_e_delta_band
(dm_vec, kv.
get_nks
());
DeePKS_domain::update_dmr
(kv.
kvec_d
, dm_vec, ucell, orb, pv, gd,
this
->
ld
.
dm_r
);
if
(inp.
nspin
==
2
&& !inp.
deepks_equiv
)
//
magnetization-channel real-space DM
{
DeePKS_domain::update_dmr
(kv.
kvec_d
, dm_vec, ucell, orb, pv, gd,
this
->
ld
.
dm_r_mag
,
2
,
true
);
}
f_en.
edeepks_scf
=
this
->
ld
.
E_delta
-
this
->
ld
.
e_delta_band
;
f_en.
edeepks_delta
=
this
->
ld
.
E_delta
;
}
#
endif
}
template
<
typename
TK
>
void
Setup_DeePKS<
TK
>::write_forces(
const
ModuleBase::matrix& fcs,
const
ModuleBase::matrix& fvnl_dalpha,
const
Input_para& inp)
{
#
ifdef
__MLALGO
//
DeePKS force
if
(inp.
deepks_out_labels
)
//
not parallelized yet
{
if
(inp.
deepks_out_base
==
"
none
"
|| (inp.
deepks_out_base
!=
"
none
"
&&
this
->
dpks_out_type
==
"
tot
"
))
{
const
std::string file_ftot
=
PARAM
.
globalv
.
global_out_dir
+ (inp.
deepks_out_labels
==
1
?
"
deepks_ftot.npy
"
:
"
deepks_force.npy
"
);
LCAO_deepks_io::save_matrix2npy
(file_ftot, fcs, GlobalV::
MY_RANK
);
//
Hartree/Bohr, F_tot
if
(inp.
deepks_out_labels
==
1
)
{
//
this base only considers subtracting the deepks_scf part
const
std::string file_fbase =
PARAM
.
globalv
.
global_out_dir
+
"
deepks_fbase.npy
"
;
if
(inp.
deepks_scf
)
{
LCAO_deepks_io::save_matrix2npy
(file_fbase,
fcs - fvnl_dalpha,
GlobalV::
MY_RANK
);
//
Hartree/Bohr, F_base
}
else
{
LCAO_deepks_io::save_matrix2npy
(file_fbase, fcs, GlobalV::
MY_RANK
);
//
no scf, F_base=F_tot
}
}
}
if
(inp.
deepks_out_base
!=
"
none
"
)
{
//
output fcs as tot or base in another dir
//
this base considers changing xc functional to base functional
const
std::string file_f
=
PARAM
.
globalv
.
global_deepks_label_elec_dir
+ (dpks_out_type ==
"
tot
"
?
"
ftot.npy
"
:
"
fbase.npy
"
);
LCAO_deepks_io::save_matrix2npy
(file_f, fcs, GlobalV::
MY_RANK
);
}
}
#
endif
}
template
<
typename
TK
>
void
Setup_DeePKS<
TK
>::write_stress(
const
ModuleBase::matrix& scs,
const
ModuleBase::matrix& svnl_dalpha,
const
double
& omega,
const
Input_para& inp)
{
#
ifdef
__MLALGO
if
(inp.
deepks_out_labels
==
1
)
{
assert
(omega >
0.0
);
if
(inp.
deepks_out_base
==
"
none
"
|| (inp.
deepks_out_base
!=
"
none
"
&&
this
->
dpks_out_type
==
"
tot
"
))
{
const
std::string file_stot =
PARAM
.
globalv
.
global_out_dir
+
"
deepks_stot.npy
"
;
LCAO_deepks_io::save_matrix2npy
(file_stot,
scs,
GlobalV::
MY_RANK
,
omega,
'
U
'
);
//
change to energy unit Ry when printing, S_tot;
//
this base only considers subtracting the deepks_scf part
const
std::string file_sbase =
PARAM
.
globalv
.
global_out_dir
+
"
deepks_sbase.npy
"
;
if
(inp.
deepks_scf
)
{
LCAO_deepks_io::save_matrix2npy
(file_sbase,
scs - svnl_dalpha,
GlobalV::
MY_RANK
,
omega,
'
U
'
);
//
change to energy unit Ry when printing, S_base;
}
else
{
LCAO_deepks_io::save_matrix2npy
(file_sbase, scs, GlobalV::
MY_RANK
, omega,
'
U
'
);
//
sbase = stot
}
}
if
(inp.
deepks_out_base
!=
"
none
"
)
{
//
output scs as tot or base in another dir
//
this base considers changing xc functional to base functional
const
std::string file_s =
PARAM
.
globalv
.
global_deepks_label_elec_dir
+ (
this
->
dpks_out_type
==
"
tot
"
?
"
stot.npy
"
:
"
sbase.npy
"
);
LCAO_deepks_io::save_matrix2npy
(file_s,
scs,
GlobalV::
MY_RANK
,
omega,
'
U
'
);
//
change to energy unit Ry when printing, S_tot;
}
}
else
if
(inp.
deepks_out_labels
==
2
)
{
const
std::string file_stot =
PARAM
.
globalv
.
global_out_dir
+
"
deepks_stress.npy
"
;
LCAO_deepks_io::save_matrix2npy
(file_stot, scs, GlobalV::
MY_RANK
, omega,
'
F
'
);
//
flat mode
}
#
endif
}
template
class
Setup_DeePKS
<
double
>;
template
class
Setup_DeePKS
<std::
complex
<
double
>>;
Back
|
FazBrowse Home
|
New Git URL