ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
unitcell.h
Go to the documentation of this file.
1#ifndef UNITCELL_H
2#define UNITCELL_H
3
8#include "source_io/output.h"
10
11#ifdef __LCAO
13#include "setup_nonlocal.h"
14#endif
15
16// provide the basic information about unitcell.
17class UnitCell {
18 public:
19 Atom* atoms = nullptr;
21
22 bool set_atom_flag = false; // added on 2009-3-8 by mohan
23 Magnetism magnet; // magnetism Yu Liu 2021-07-03
24 std::vector<std::vector<double>> atom_mulliken; //[nat][nspin]
25 int n_mag_at = 0;
26
28 std::string& Coordinate = lat.Coordinate;
29 std::string& latName = lat.latName;
30 double& lat0 = lat.lat0;
32 double& tpiba = lat.tpiba;
33 double& tpiba2 = lat.tpiba2;
34 double& omega = lat.omega;
35 int*& lc = lat.lc;
36
45
47 int& ntype = st.ntype;
48 int& nat = st.nat;
49 int*& iat2it = st.iat2it;
50 int*& iat2ia = st.iat2ia;
52 int*& iwt2iw = st.iwt2iw;
54 int& namax = st.namax;
55 int& nwmax = st.nwmax;
56
58
59 // ========================================================
60 // iat2iwt is the atom index iat to the first global index for orbital of
61 // this atom the size of iat2iwt is nat, the value should be
62 // sum_{i=0}^{iat-1} atoms[it].nw * npol where the npol is the number of
63 // polarizations, 1 for non-magnetic(NSPIN=1 or 2), 2 for magnetic(only
64 // NSPIN=4) this part only used for Atomic Orbital based calculation
65 // ========================================================
66 public:
67 // indexing tool for find orbital global index from it,ia,iw
68 template <typename Tiait>
69 inline Tiait
70 itiaiw2iwt(const Tiait& it, const Tiait& ia, const Tiait& iw) const {
71 return Tiait(this->iat2iwt[this->itia2iat(it, ia)] + iw);
72 }
73 // initialize iat2iwt
74 void set_iat2iwt(const int& npol_in);
75 // get iat2iwt
76 inline const int* get_iat2iwt() const { return iat2iwt.data(); }
77 // get npol
78 inline const int& get_npol() const { return npol; }
79
80 private:
81 std::vector<int> iat2iwt; // iat ==> iwt, the first global index for orbital of this atom
82 int npol = 1; // number of spin polarizations, initialized in set_iat2iwt
83 // ----------------- END of iat2iwt part -----------------
84
85 public:
86 //========================================================
87 // indexing tools for ia and it
88 // return true if the last out is reset
89 //========================================================
90 template <typename Tiat, typename Tiait>
91 inline bool iat2iait(const Tiat iat, Tiait* ia, Tiait* it) const {
92 if (iat >= nat) {
93 *ia = 0;
94 *it = ntype;
95 return false;
96 }
97 *ia = (Tiait)iat2ia[iat];
98 *it = (Tiait)iat2it[iat];
99 return true;
100 }
101
102 template <typename Tiat, typename Tiait>
103 inline bool ijat2iaitjajt(const Tiat ijat,
104 Tiait* ia,
105 Tiait* it,
106 Tiait* ja,
107 Tiait* jt) const {
108 Tiat iat = ijat / nat;
109 Tiat jat = ijat % nat;
110 iat2iait(iat, ia, it);
111 iat2iait(jat, ja, jt);
112 return true;
113 }
114
115 template <typename Tiait>
116 inline bool step_it(Tiait* it) const {
117 if (++(*it) >= ntype) {
118 *it = 0;
119 return true;
120 }
121 return false;
122 }
123
124 template <typename Tiait>
125 inline bool step_ia(const Tiait it, Tiait* ia) const {
126 if (++(*ia) >= atoms[it].na) {
127 *ia = 0;
128 return true;
129 }
130 return false;
131 }
132
133 template <typename Tiait>
134 inline bool step_iait(Tiait* ia, Tiait* it) const {
135 if (step_ia(*it, ia)) {
136 return step_it(it);
137 }
138 return false;
139 }
140
141 template <typename Tiait>
142 inline bool
143 step_jajtiait(Tiait* ja, Tiait* jt, Tiait* ia, Tiait* it) const {
144 if (step_iait(ja, jt)) {
145 return step_iait(ia, it);
146 }
147 return false;
148 }
149
150 // get tau for atom iat
151 inline const ModuleBase::Vector3<double>& get_tau(const int& iat) const {
152 return atoms[iat2it[iat]].tau[iat2ia[iat]];
153 }
154
155 // calculate vector between two atoms with R cell
156 inline const ModuleBase::Vector3<double>
157 cal_dtau(const int& iat1,
158 const int& iat2,
159 const ModuleBase::Vector3<int>& R) const {
160 return get_tau(iat2) + double(R.x) * a1 + double(R.y) * a2
161 + double(R.z) * a3 - get_tau(iat1);
162 }
163
164 // LiuXh add 20180515
169
170 // I'm doing a bad thing here! Will change later
172 = false; // whether the ionic position has been updated
174 = false; // whether the cell parameters are updated
175
176 //============================================================
177 // meshx : max number of mesh point in pseudopotential file
178 // natomwfc : number of starting wavefunctions
179 // lmax : Max L used for localized orbital.
180 // nmax : Max N used for localized orbital.
181 // lmax_ppwf : Max L of pseudo wave functinos
182 // nelec : total number of electrons
183 // lmaxmax : revert from INPUT
184 //============================================================
185 int meshx = 0;
186 int natomwfc = 0;
187 int lmax = 0;
188 int nmax = 0;
189 int nmax_total = 0; // mohan add 2009-09-10
190 int lmax_ppwf = 0;
191 int lmaxmax = 0; // liuyu 2021-07-04
192 bool init_vel = false; // liuyu 2021-07-15
193 // double nelec;
194
195 private:
196 ModuleBase::Matrix3 stress; // calculate stress on the cell
197
198 public:
199 UnitCell();
200 ~UnitCell();
201 void print_cell(std::ofstream& ofs) const;
202
203 std::vector<double> atom_mass;
204 std::vector<std::string> atom_label;
205 std::vector<std::string> pseudo_fn;
206 std::vector<std::string> pseudo_type;
207
208 std::vector<std::string> orbital_fn; // filenames of orbitals, liuyu add 2022-10-19
209 std::string descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06
210
211 void set_iat2itia();
212
213 void setup_cell(const std::string& fn, std::ofstream& log);
214
215#ifdef __LCAO
216 InfoNonlocal infoNL; // store nonlocal information of lcao, added by zhengdy
217 // 2021-09-07
218#endif
219
220 // for constrained vc-relaxation where type of lattice
221 // is fixed, adjust the lattice vectors
222
223 //================================================================
224 // cal_natomwfc : calculate total number of atomic wavefunctions
225 // cal_nwfc : calculate total number of local basis and lmax
226 // cal_meshx : calculate max number of mesh points in pp file
227 //================================================================
228 bool if_atoms_can_move() const;
229 bool if_cell_can_change() const;
230 void setup(const std::string& latname_in,
231 const int& ntype_in,
232 const int& lmaxmax_in,
233 const bool& init_vel_in,
234 const std::string& fixed_axes_in);
235
238 void compare_atom_labels(const std::string &label1, const std::string &label2);
240 std::map<int, int> get_atom_Counts() const;
243 std::map<int, int> get_orbital_Counts() const;
246 std::map<int, std::map<int, int>> get_lnchi_Counts() const;
250 std::vector<std::string> get_atomLabels() const;
253 std::vector<int> get_atomCounts() const;
256 std::vector<std::vector<int>> get_lnchiCounts() const;
258 std::vector<ModuleBase::Vector3<double>> get_target_mag() const;
260 std::vector<ModuleBase::Vector3<double>> get_lambda() const;
262 std::vector<ModuleBase::Vector3<int>> get_constrain() const;
263};
264
265#endif // unitcell class
Definition atom_spec.h:7
std::vector< ModuleBase::Vector3< double > > tau
Definition atom_spec.h:36
Definition setup_nonlocal.h:10
Definition magnetism.h:9
Integer array.
Definition intarray.h:20
3x3 matrix and related mathamatical operations
Definition matrix3.h:19
3 elements vector
Definition vector3.h:22
T x
Definition vector3.h:24
T y
Definition vector3.h:25
T z
Definition vector3.h:26
Definition symmetry.h:16
Definition sep_cell.h:13
Definition unitcell.h:17
std::map< int, int > get_orbital_Counts() const
get orbitalCounts, which is a map from element type to orbital number
Definition unitcell.cpp:89
int lmaxmax
Definition unitcell.h:191
void setup_cell(const std::string &fn, std::ofstream &log)
Definition mock_unitcell.cpp:29
~UnitCell()
Definition symmetry_test_analysis.cpp:34
ModuleBase::Vector3< double > & latcenter
Definition unitcell.h:39
int *& iat2it
Definition unitcell.h:49
int *& lc
Definition unitcell.h:35
bool if_cell_can_change() const
Definition mock_unitcell.cpp:33
bool step_iait(Tiait *ia, Tiait *it) const
Definition unitcell.h:134
Tiait itiaiw2iwt(const Tiait &it, const Tiait &ia, const Tiait &iw) const
Definition unitcell.h:70
Atom * atoms
Definition unitcell.h:19
const int & get_npol() const
Definition unitcell.h:78
ModuleBase::Matrix3 & GT
Definition unitcell.h:42
std::vector< int > get_atomCounts() const
get atomCounts, which is a vector of element type with atom number
Definition unitcell.cpp:122
const ModuleBase::Vector3< double > & get_tau(const int &iat) const
Definition unitcell.h:151
std::vector< int > iat2iwt
Definition unitcell.h:81
double & lat0
Definition unitcell.h:30
std::string descriptor_file
Definition unitcell.h:209
ModuleBase::Matrix3 invGGT0
Definition unitcell.h:168
std::vector< std::string > get_atomLabels() const
get atom labels
Definition unitcell.cpp:114
ModuleBase::Matrix3 GT0
Definition unitcell.h:166
std::vector< std::string > orbital_fn
Definition unitcell.h:208
std::vector< ModuleBase::Vector3< double > > get_target_mag() const
get target magnetic moment for deltaspin
Definition unitcell.cpp:141
int n_mag_at
Definition unitcell.h:25
ModuleBase::Matrix3 & latvec
Definition unitcell.h:37
Magnetism magnet
Definition unitcell.h:23
bool ijat2iaitjajt(const Tiat ijat, Tiait *ia, Tiait *it, Tiait *ja, Tiait *jt) const
Definition unitcell.h:103
int meshx
Definition unitcell.h:185
bool ionic_position_updated
Definition unitcell.h:172
bool init_vel
Definition unitcell.h:192
Lattice lat
Definition unitcell.h:27
std::map< int, std::map< int, int > > get_lnchi_Counts() const
get lnchiCounts, which is a map from element type to the l:nchi map
Definition unitcell.cpp:97
int *& iwt2iw
Definition unitcell.h:52
int lmax
Definition unitcell.h:187
UnitCell()
Definition symmetry_test_analysis.cpp:33
int & ntype
Definition unitcell.h:47
double & tpiba
Definition unitcell.h:32
ModuleBase::Matrix3 & latvec_supercell
Definition unitcell.h:40
ModuleSymmetry::Symmetry symm
Definition unitcell.h:57
std::vector< std::vector< double > > atom_mulliken
Definition unitcell.h:24
std::map< int, int > get_atom_Counts() const
get atomCounts, which is a map from element type to atom number
Definition unitcell.cpp:81
bool step_jajtiait(Tiait *ja, Tiait *jt, Tiait *ia, Tiait *it) const
Definition unitcell.h:143
double & tpiba2
Definition unitcell.h:33
Sep_Cell sep_cell
Definition unitcell.h:20
void set_iat2iwt(const int &npol_in)
Definition mock_unitcell.cpp:11
void print_cell(std::ofstream &ofs) const
Definition mock_unitcell.cpp:25
ModuleBase::IntArray & itia2iat
Definition unitcell.h:53
int & nat
Definition unitcell.h:48
std::vector< ModuleBase::Vector3< double > > get_lambda() const
get lagrange multiplier for deltaspin
Definition unitcell.cpp:155
double & omega
Definition unitcell.h:34
std::vector< ModuleBase::Vector3< int > > get_constrain() const
get constrain for deltaspin
Definition unitcell.cpp:169
ModuleBase::Matrix3 & GGT
Definition unitcell.h:43
ModuleBase::Vector3< double > & a2
Definition unitcell.h:38
ModuleBase::Vector3< double > & a3
Definition unitcell.h:38
bool step_ia(const Tiait it, Tiait *ia) const
Definition unitcell.h:125
bool set_atom_flag
Definition unitcell.h:22
bool step_it(Tiait *it) const
Definition unitcell.h:116
std::vector< std::string > atom_label
Definition unitcell.h:204
void set_iat2itia()
Definition mock_unitcell.cpp:27
std::string & Coordinate
Definition unitcell.h:28
std::vector< std::vector< int > > get_lnchiCounts() const
get lnchiCounts, which is a vector of element type with the l:nchi vector
Definition unitcell.cpp:130
int *& iat2ia
Definition unitcell.h:50
int lmax_ppwf
Definition unitcell.h:190
std::vector< std::string > pseudo_fn
Definition unitcell.h:205
int & nwmax
Definition unitcell.h:55
bool cell_parameter_updated
Definition unitcell.h:174
ModuleBase::Matrix3 & invGGT
Definition unitcell.h:44
int nmax
Definition unitcell.h:188
ModuleBase::Vector3< double > & a1
Definition unitcell.h:38
ModuleBase::Matrix3 G0
Definition unitcell.h:165
std::string & latName
Definition unitcell.h:29
Statistics st
Definition unitcell.h:46
ModuleBase::Matrix3 & G
Definition unitcell.h:41
void setup(const std::string &latname_in, const int &ntype_in, const int &lmaxmax_in, const bool &init_vel_in, const std::string &fixed_axes_in)
Definition mock_unitcell.cpp:35
void compare_atom_labels(const std::string &label1, const std::string &label2)
check consistency between two atom labels from STRU and pseudo or orb file
Definition mock_unitcell.cpp:43
int *& iwt2iat
Definition unitcell.h:51
int natomwfc
Definition unitcell.h:186
int nmax_total
Definition unitcell.h:189
const ModuleBase::Vector3< double > cal_dtau(const int &iat1, const int &iat2, const ModuleBase::Vector3< int > &R) const
Definition unitcell.h:157
const int * get_iat2iwt() const
Definition unitcell.h:76
bool iat2iait(const Tiat iat, Tiait *ia, Tiait *it) const
Definition unitcell.h:91
ModuleBase::Matrix3 GGT0
Definition unitcell.h:167
std::vector< std::string > pseudo_type
Definition unitcell.h:206
double & lat0_angstrom
Definition unitcell.h:31
ModuleBase::Matrix3 stress
Definition unitcell.h:196
std::vector< double > atom_mass
Definition unitcell.h:203
int & namax
Definition unitcell.h:54
int npol
Definition unitcell.h:82
bool if_atoms_can_move() const
Definition mock_unitcell.cpp:31
info of lattice
Definition unitcell_data.h:8
ModuleBase::Vector3< double > a1
Definition unitcell_data.h:19
ModuleBase::Matrix3 latvec
Definition unitcell_data.h:18
double omega
Definition unitcell_data.h:15
ModuleBase::Vector3< double > latcenter
Definition unitcell_data.h:20
ModuleBase::Matrix3 invGGT
Definition unitcell_data.h:25
double tpiba2
Definition unitcell_data.h:14
std::string Coordinate
Definition unitcell_data.h:9
ModuleBase::Vector3< double > a3
Definition unitcell_data.h:19
ModuleBase::Matrix3 GT
Definition unitcell_data.h:23
ModuleBase::Matrix3 latvec_supercell
Definition unitcell_data.h:21
double lat0
Definition unitcell_data.h:11
int * lc
Definition unitcell_data.h:16
std::string latName
Definition unitcell_data.h:10
ModuleBase::Matrix3 GGT
Definition unitcell_data.h:24
ModuleBase::Matrix3 G
Definition unitcell_data.h:22
double lat0_angstrom
Definition unitcell_data.h:12
double tpiba
Definition unitcell_data.h:13
ModuleBase::Vector3< double > a2
Definition unitcell_data.h:19
usefull data and index maps
Definition unitcell_data.h:47
ModuleBase::IntArray itia2iat
Definition unitcell_data.h:54
int nwmax
Definition unitcell_data.h:56
int * iwt2iat
Definition unitcell_data.h:52
int nat
Definition unitcell_data.h:49
int * iat2it
Definition unitcell_data.h:50
int namax
Definition unitcell_data.h:55
int * iat2ia
Definition unitcell_data.h:51
int * iwt2iw
Definition unitcell_data.h:53
int ntype
Definition unitcell_data.h:48