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