FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
abacus-develop/source/source_cell/cell_index.cpp at develop · pplab/abacus-develop · GitHub
pplab
/
abacus-develop
Public
forked from
deepmodeling/abacus-develop
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
abacus-develop
/
source
/
source_cell
/
cell_index.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
294 lines (272 loc) · 8.27 KB
Breadcrumbs
abacus-develop
/
source
/
source_cell
/
cell_index.cpp
Copy path
File metadata and controls
294 lines (272 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#
include
"
cell_index.h
"
#
include
"
source_base/name_angular.h
"
#
include
"
source_base/tool_quit.h
"
#
include
<
stdexcept
>
CellIndex::CellIndex
(
const
std::vector<std::string>& atomLabels_in,
const
std::vector<
int
>& atomCounts_in,
const
std::vector<std::vector<
int
>>& lnchiCounts_in,
const
int
& nspin)
: atomLabels(atomLabels_in), atomCounts(atomCounts_in), lnchiCounts(lnchiCounts_in)
{
if
(
this
->
check_nspin
(nspin))
{
this
->
npol_
= (nspin ==
4
) ?
2
:
1
;
}
this
->
check_atomCounts
();
this
->
cal_orbitalCounts
();
}
int
CellIndex::get_ntype
()
{
return
this
->
atomCounts
.
size
();
}
int
CellIndex::get_nat
()
{
int
nat =
0
;
for
(
int
it =
0
; it <
this
->
atomCounts
.
size
(); ++it)
{
nat +=
this
->
atomCounts
[it];
}
return
nat;
}
int
CellIndex::get_nat
(
int
it)
{
return
this
->
atomCounts
[it];
}
int
CellIndex::get_nw
()
{
int
nw =
0
;
for
(
int
it =
0
; it <
this
->
orbitalCounts
.
size
(); ++it)
{
nw +=
this
->
orbitalCounts
[it] *
this
->
atomCounts
[it] *
this
->
npol_
;
}
return
nw;
}
int
CellIndex::get_nw
(
int
iat)
{
int
it =
this
->
iat2it
(iat);
return
this
->
orbitalCounts
[it];
}
int
CellIndex::get_iwt
(
int
iat,
int
orbital_index)
{
if
(iat <
0
|| iat >=
this
->
get_nat
())
{
ModuleBase::WARNING_QUIT
(
"
SpinConstrain::get_iwt
"
,
"
iat out of range [0, nat)
"
);
}
int
it =
this
->
iat2it
(iat);
int
ia =
this
->
iat2ia
(iat);
if
(orbital_index <
0
|| orbital_index >=
this
->
orbitalCounts
[it] *
this
->
npol_
)
{
ModuleBase::WARNING_QUIT
(
"
SpinConstrain::get_iwt
"
,
"
orbital index out of range [0, atom_nw*npol)
"
);
}
int
iwt =
0
;
for
(
int
it0 =
0
; it0 <
this
->
orbitalCounts
.
size
(); ++it0)
{
if
(it0 == it)
{
break
;
}
iwt +=
this
->
orbitalCounts
[it0] *
this
->
atomCounts
[it0] *
this
->
npol_
;
}
for
(
int
i =
0
; i < ia; ++i)
{
iwt +=
this
->
orbitalCounts
[it] *
this
->
npol_
;
}
iwt += orbital_index;
return
iwt;
}
int
CellIndex::get_maxL
(
int
iat)
{
int
it =
this
->
iat2it
(iat);
return
this
->
lnchiCounts
[it].
size
() -
1
;
}
//
/ @brief get nchi
int
CellIndex::get_nchi
(
int
iat,
int
L)
{
int
it =
this
->
iat2it
(iat);
if
(L <
0
|| L >=
this
->
lnchiCounts
[it].
size
())
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::get_nchi
"
,
"
L out of range [0, maxL]
"
);
}
return
this
->
lnchiCounts
[it][L];
}
void
CellIndex::check_atomCounts
()
{
if
(!
this
->
atomCounts
.
size
())
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::check_atomCounts
"
,
"
atomCounts is not set
"
);
}
if
(
this
->
get_nat
() <=
0
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::check_atomCounts
"
,
"
nat <= 0
"
);
}
for
(
int
it =
0
; it <
this
->
atomCounts
.
size
(); ++it)
{
if
(
this
->
atomCounts
[it] <=
0
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::check_atomCounts
"
,
"
number of atoms <= 0 for some element
"
);
}
}
}
std::string
CellIndex::get_atom_label
(
int
iat,
bool
order)
{
int
it =
this
->
iat2it
(iat);
int
ia =
this
->
iat2ia
(iat);
std::string atomType = atomLabels[it];
if
(order)
return
atomType +
std::to_string
(ia +
1
);
return
atomType;
}
int
CellIndex::iat2it
(
int
iat)
{
int
running_iat =
0
;
int
it = -
1
;
//
Tracks the index of the atom in atomLabels
//
Find the type of atom associated with the total order
for
(
int
i =
0
; i <
this
->
atomCounts
.
size
(); ++i)
{
if
(running_iat + atomCounts[i] > iat)
{
it = i;
break
;
}
running_iat += atomCounts[i];
}
if
(it == -
1
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::get_atom_label
"
,
"
iat out of range [0, nat)
"
);
}
return
it;
}
int
CellIndex::iat2ia
(
int
iat)
{
int
it =
this
->
iat2it
(iat);
//
sum of atoms of previous types
int
running_iat =
0
;
for
(
int
i =
0
; i < it; ++i)
{
running_iat += atomCounts[i];
}
return
iat - running_iat;
}
int
CellIndex::iw2l
(
int
iat,
int
iw)
{
int
it =
this
->
iat2it
(iat);
int
maxL =
this
->
lnchiCounts
[it].
size
() -
1
;
for
(
int
L =
0
; L <= maxL; ++L)
{
int
nchi =
this
->
lnchiCounts
[it][L];
int
blockSize = nchi * (
2
* L +
1
);
if
(iw < blockSize)
{
return
L;
}
iw -= blockSize;
if
(iw <
0
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::iw2l
"
,
"
localized wave funciton index out of range [0, nw)
"
);
}
}
if
(iw >=
0
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::iw2l
"
,
"
localized wave funciton index out of range [0, nw)
"
);
}
throw
std::out_of_range
(
std::string
(__FILE__)+
"
line
"
+
std::to_string
(__LINE__));
}
int
CellIndex::iw2z
(
int
iat,
int
iw)
{
int
it =
this
->
iat2it
(iat);
int
maxL =
this
->
lnchiCounts
[it].
size
() -
1
;
for
(
int
L =
0
; L <= maxL; ++L)
{
int
nchi =
this
->
lnchiCounts
[it][L];
int
blockSize = nchi * (
2
* L +
1
);
if
(iw < blockSize)
{
return
iw / (
2
* L +
1
);
}
iw -= blockSize;
if
(iw <
0
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::iw2l
"
,
"
localized wave funciton index out of range [0, nw)
"
);
}
}
if
(iw >=
0
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::iw2l
"
,
"
localized wave funciton index out of range [0, nw)
"
);
}
throw
std::out_of_range
(
std::string
(__FILE__)+
"
line
"
+
std::to_string
(__LINE__));
}
int
CellIndex::iw2m
(
int
iat,
int
iw)
{
int
it =
this
->
iat2it
(iat);
int
maxL =
this
->
lnchiCounts
[it].
size
() -
1
;
for
(
int
L =
0
; L <= maxL; ++L)
{
int
nchi =
this
->
lnchiCounts
[it][L];
int
blockSize = nchi * (
2
* L +
1
);
if
(iw < blockSize)
{
return
iw % (
2
* L +
1
);
}
iw -= blockSize;
if
(iw <
0
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::iw2l
"
,
"
localized wave funciton index out of range [0, nw)
"
);
}
}
if
(iw >=
0
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::iw2l
"
,
"
localized wave funciton index out of range [0, nw)
"
);
}
throw
std::out_of_range
(
std::string
(__FILE__)+
"
line
"
+
std::to_string
(__LINE__));
}
bool
CellIndex::check_nspin
(
int
nspin)
{
if
(nspin !=
1
&& nspin !=
2
&& nspin !=
4
)
{
ModuleBase::WARNING_QUIT
(
"
CellIndex::check_nspin
"
,
"
nspin must be 1, 2, or 4
"
);
}
return
true
;
}
void
CellIndex::cal_orbitalCounts
()
{
int
ntype =
this
->
lnchiCounts
.
size
();
this
->
orbitalCounts
.
resize
(ntype,
0
);
for
(
int
it =
0
; it < ntype; ++it)
{
int
orbitalCount =
0
;
for
(
int
L =
0
; L <
this
->
lnchiCounts
[it].
size
(); ++L)
{
orbitalCount +=
this
->
lnchiCounts
[it][L] * (
2
* L +
1
);
}
this
->
orbitalCounts
[it] = orbitalCount;
}
}
void
CellIndex::write_orb_info
(std::string out_dir)
{
std::stringstream os;
os << out_dir <<
"
Orbital
"
;
std::ofstream
out
(os.
str
().
c_str
());
out <<
std::setw
(
5
) <<
"
#io
"
<<
std::setw
(
8
) <<
"
spec
"
<<
std::setw
(
5
) <<
"
l
"
<<
std::setw
(
5
) <<
"
m
"
<<
std::setw
(
5
)
<<
"
z
"
<<
std::setw
(
5
) <<
"
sym
"
<< std::endl;
for
(
int
iat =
0
; iat <
this
->
get_nat
(); iat++)
{
for
(
int
iw =
0
; iw <
this
->
get_nw
(iat); ++iw)
{
const
int
L =
this
->
iw2l
(iat, iw);
const
int
Z =
this
->
iw2z
(iat, iw);
const
int
M =
this
->
iw2m
(iat, iw);
out <<
std::setw
(
5
) << iat <<
std::setw
(
8
) <<
this
->
get_atom_label
(iat) <<
std::setw
(
5
) << L <<
std::setw
(
5
)
<< M <<
std::setw
(
5
) << Z +
1
<<
std::setw
(
15
) << ModuleBase::Name_Angular[L][M] << std::endl;
}
}
out << std::endl << std::endl;
out <<
std::setw
(
5
) <<
"
#io
"
<<
std::setw
(
2
) <<
"
=
"
<<
std::setw
(
2
) <<
"
Orbital index in supercell
"
<< std::endl;
out <<
std::setw
(
5
) <<
"
#spec
"
<<
std::setw
(
2
) <<
"
=
"
<<
std::setw
(
2
) <<
"
Atomic species label
"
<< std::endl;
out <<
std::setw
(
5
) <<
"
#l
"
<<
std::setw
(
2
) <<
"
=
"
<<
std::setw
(
2
) <<
"
Angular mumentum quantum number
"
<< std::endl;
out <<
std::setw
(
5
) <<
"
#m
"
<<
std::setw
(
2
) <<
"
=
"
<<
std::setw
(
2
) <<
"
Magnetic quantum number
"
<< std::endl;
out <<
std::setw
(
5
) <<
"
#z
"
<<
std::setw
(
2
) <<
"
=
"
<<
std::setw
(
2
) <<
"
Zeta index of orbital
"
<< std::endl;
out <<
std::setw
(
5
) <<
"
#sym
"
<<
std::setw
(
2
) <<
"
=
"
<<
std::setw
(
2
) <<
"
Symmetry name of real orbital
"
<< std::endl;
out.
close
();
}
Back
|
FazBrowse Home
|
New Git URL