ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
prepare_unitcell.h
Go to the documentation of this file.
1#ifndef PREPARE_UNITCELL_H
2#define PREPARE_UNITCELL_H
3#include <map>
4#include <string>
5
7
9{
10 public:
11 UcellTestPrepare() = default;
12 UcellTestPrepare(std::string latname_in,
13 int lmaxmax_in,
14 bool init_vel_in,
15 bool selective_dynamics_in,
16 bool relax_new_in,
17 std::string fixed_axes_in,
18 double lat0_in,
19 std::valarray<double> latvec_in,
20 std::vector<std::string> elements_in,
21 std::vector<std::string> pp_files_in,
22 std::vector<std::string> pp_types_in,
23 std::vector<std::string> orb_files_in,
24 std::valarray<int> natom_in,
25 std::vector<double> atomic_mass_in,
26 std::string coor_type_in,
27 std::valarray<double> coordinates_in);
28 UcellTestPrepare(std::string latname_in,
29 int lmaxmax_in,
30 bool init_vel_in,
31 bool selective_dynamics_in,
32 bool relax_new_in,
33 std::string fixed_axes_in,
34 double lat0_in,
35 std::valarray<double> latvec_in,
36 std::vector<std::string> elements_in,
37 std::vector<std::string> pp_files_in,
38 std::vector<std::string> pp_types_in,
39 std::vector<std::string> orb_files_in,
40 std::valarray<int> natom_in,
41 std::vector<double> atomic_mass_in,
42 std::string coor_type_in,
43 std::valarray<double> coordinates_in,
44 std::valarray<double> mbl_in,
45 std::valarray<double> velocity_in);
47
48 std::string latname;
49 int lmaxmax;
50 bool init_vel;
52 bool relax_new;
53 std::string fixed_axes;
54 double lat0;
55 std::valarray<double> latvec;
56 std::vector<std::string> elements;
57 std::vector<std::string> pp_files;
58 std::vector<std::string> pp_types;
59 std::vector<std::string> orb_files;
60 std::valarray<int> natom;
61 std::vector<double> atomic_mass;
62 std::string coor_type;
63 std::valarray<double> coordinates;
64 std::valarray<double> mbl;
65 std::valarray<double> velocity;
66 // ntype
67 int ntype;
68 int atomic_index;
69
70 UnitCell* SetUcellInfo(const std::vector<int>& nw, int& nlocal)
71 {
72 // basic info
73 this->ntype = this->elements.size();
74 static UnitCell ucell;
75 ucell.setup_from_input(this->latname, this->ntype, this->lmaxmax, this->init_vel, this->fixed_axes);
76
77 ucell.pseudo_fn.resize(ucell.ntype);
78 ucell.pseudo_type.resize(ucell.ntype);
79 ucell.orbital_fn.resize(ucell.ntype);
80 ucell.magnet.ux_[0] = 0.0; // ux_ set here
81 ucell.magnet.ux_[1] = 0.0;
82 ucell.magnet.ux_[2] = 0.0;
83 for (int it = 0; it < ucell.ntype; ++it)
84 {
85 ucell.pseudo_fn[it] = this->pp_files[it];
86 ucell.pseudo_type[it] = this->pp_types[it];
87 ucell.orbital_fn[it] = this->orb_files[it];
88 }
89 // lattice info
90 ucell.lat0 = this->lat0;
92 ucell.tpiba = ModuleBase::TWO_PI / ucell.lat0;
93 ucell.tpiba2 = ucell.tpiba * ucell.tpiba;
94 ucell.latvec.e11 = this->latvec[0];
95 ucell.latvec.e12 = this->latvec[1];
96 ucell.latvec.e13 = this->latvec[2];
97 ucell.latvec.e21 = this->latvec[3];
98 ucell.latvec.e22 = this->latvec[4];
99 ucell.latvec.e23 = this->latvec[5];
100 ucell.latvec.e31 = this->latvec[6];
101 ucell.latvec.e32 = this->latvec[7];
102 ucell.latvec.e33 = this->latvec[8];
103 ucell.a1.x = ucell.latvec.e11;
104 ucell.a1.y = ucell.latvec.e12;
105 ucell.a1.z = ucell.latvec.e13;
106 ucell.a2.x = ucell.latvec.e21;
107 ucell.a2.y = ucell.latvec.e22;
108 ucell.a2.z = ucell.latvec.e23;
109 ucell.a3.x = ucell.latvec.e31;
110 ucell.a3.y = ucell.latvec.e32;
111 ucell.a3.z = ucell.latvec.e33;
112 ucell.GT = ucell.latvec.Inverse();
113 ucell.G = ucell.GT.Transpose();
114 ucell.GGT = ucell.G * ucell.GT;
115 ucell.invGGT = ucell.GGT.Inverse();
116 ucell.omega = std::abs(ucell.latvec.Det()) * (ucell.lat0) * (ucell.lat0) * (ucell.lat0);
117 // atomic info
118 ucell.Coordinate = this->coor_type;
119 ucell.atoms = new Atom[ucell.ntype];
120 ucell.set_atom_flag = true;
121 this->atomic_index = 0;
122 for (int it = 0; it < ucell.ntype; ++it)
123 {
124 ucell.atoms[it].label = this->elements[it];
125 /*
126 ucell.atoms[it].nw = 0;
127 ucell.atoms[it].nwl = 2;
128 delete[] ucell.atoms[it].l_nchi;
129 ucell.atoms[it].l_nchi = new int[ ucell.atoms[it].nwl+1];
130 for(int L=0; L<ucell.atoms[it].nwl+1; L++)
131 {
132 ucell.atoms[it].l_nchi[L] = 1;
133 ucell.atoms[it].nw += (2*L + 1) * ucell.atoms[it].l_nchi[L];
134 }
135 */
136 ucell.atoms[it].na = this->natom[it];
137 // coordinates and related physical quantities
138 ucell.atoms[it].tau.resize(ucell.atoms[it].na);
139 ucell.atoms[it].dis.resize(ucell.atoms[it].na);
140 ucell.atoms[it].taud.resize(ucell.atoms[it].na);
141 ucell.atoms[it].vel.resize(ucell.atoms[it].na);
142 ucell.atoms[it].mag.resize(ucell.atoms[it].na);
143 ucell.atoms[it].angle1.resize(ucell.atoms[it].na);
144 ucell.atoms[it].angle2.resize(ucell.atoms[it].na);
145 ucell.atoms[it].m_loc_.resize(ucell.atoms[it].na);
146 ucell.atoms[it].mbl.resize(ucell.atoms[it].na);
147 ucell.atoms[it].mass = this->atomic_mass[it];
148 for (int ia = 0; ia < ucell.atoms[it].na; ++ia)
149 {
150 if (ucell.Coordinate == "Direct")
151 {
152 ucell.atoms[it].taud[ia].x = this->coordinates[this->atomic_index * 3 + 0];
153 ucell.atoms[it].taud[ia].y = this->coordinates[this->atomic_index * 3 + 1];
154 ucell.atoms[it].taud[ia].z = this->coordinates[this->atomic_index * 3 + 2];
155 ucell.atoms[it].tau[ia] = ucell.atoms[it].taud[ia] * ucell.latvec;
156 }
157 else if (ucell.Coordinate == "Cartesian")
158 {
159 ucell.atoms[it].tau[ia].x = this->coordinates[this->atomic_index * 3 + 0];
160 ucell.atoms[it].tau[ia].y = this->coordinates[this->atomic_index * 3 + 1];
161 ucell.atoms[it].tau[ia].z = this->coordinates[this->atomic_index * 3 + 2];
163 ucell.atoms[it].tau[ia].y,
164 ucell.atoms[it].tau[ia].z,
165 ucell.latvec.e11,
166 ucell.latvec.e12,
167 ucell.latvec.e13,
168 ucell.latvec.e21,
169 ucell.latvec.e22,
170 ucell.latvec.e23,
171 ucell.latvec.e31,
172 ucell.latvec.e32,
173 ucell.latvec.e33,
174 ucell.atoms[it].taud[ia].x,
175 ucell.atoms[it].taud[ia].y,
176 ucell.atoms[it].taud[ia].z);
177 }
178 ucell.atoms[it].dis[ia].set(0, 0, 0);
179 if (this->init_vel)
180 {
181 ucell.atoms[it].vel[ia].x = this->velocity[this->atomic_index * 3 + 0];
182 ucell.atoms[it].vel[ia].y = this->velocity[this->atomic_index * 3 + 1];
183 ucell.atoms[it].vel[ia].z = this->velocity[this->atomic_index * 3 + 2];
184 }
185 else
186 {
187 ucell.atoms[it].vel[ia].set(0, 0, 0);
188 }
189 ucell.atoms[it].m_loc_[ia].set(0, 0, 0);
190 ucell.atoms[it].angle1[ia] = 0;
191 ucell.atoms[it].angle2[ia] = 0;
192 if (this->selective_dynamics)
193 {
194 ucell.atoms[it].mbl[ia].x = this->mbl[this->atomic_index * 3 + 0];
195 ucell.atoms[it].mbl[ia].y = this->mbl[this->atomic_index * 3 + 1];
196 ucell.atoms[it].mbl[ia].z = this->mbl[this->atomic_index * 3 + 2];
197 }
198 else
199 {
200 ucell.atoms[it].mbl[ia] = {1, 1, 1};
201 }
202 ++(this->atomic_index);
203 }
204 }
205 ucell.nat = this->natom.sum();
206 // set_nw
207 assert(nw.size() == ucell.ntype);
208 for (int it = 0; it < ucell.ntype; ++it)
209 {
210 ucell.atoms[it].nw = nw[it];
211 }
212 // cal_nloc
213 for (int it = 0; it < ucell.ntype; ++it)
214 {
215 nlocal += ucell.atoms[it].na * ucell.atoms[it].nw;
216 }
217 // cal_namax
218 int namax = 0;
219 for (int it = 0; it < ucell.ntype; ++it)
220 {
221 namax = std::max(namax, ucell.atoms[it].na);
222 }
223 ucell.namax = namax;
224 // cal_index
225 assert(nlocal > 0);
226 ucell.iwt2iat.resize(nlocal);
227 ucell.iwt2iw.resize(nlocal);
228 ucell.iat2it.resize(ucell.nat);
229 ucell.iat2ia.resize(ucell.nat); // set_iat2itia
230 ucell.itia2iat.create(ucell.ntype, ucell.namax);
231 ucell.set_iat2iwt(1);
232 int iat = 0;
233 int iwt = 0;
234 for (int it = 0; it < ucell.ntype; it++)
235 {
236 for (int ia = 0; ia < ucell.atoms[it].na; ia++)
237 {
238 ucell.iat2it[iat] = it;
239 ucell.iat2ia[iat] = ia;
240 ucell.itia2iat(it, ia) = iat;
241 for (int iw = 0; iw < ucell.atoms[it].nw; iw++)
242 {
243 ucell.iwt2iat[iwt] = iat;
244 ucell.iwt2iw[iwt] = iw;
245 ++iwt;
246 }
247 ++iat;
248 }
249 }
250 return &ucell;
251 }
252};
253
254UcellTestPrepare::UcellTestPrepare(std::string latname_in,
255 int lmaxmax_in,
256 bool init_vel_in,
257 bool selective_dynamics_in,
258 bool relax_new_in,
259 std::string fixed_axes_in,
260 double lat0_in,
261 std::valarray<double> latvec_in,
262 std::vector<std::string> elements_in,
263 std::vector<std::string> pp_files_in,
264 std::vector<std::string> pp_types_in,
265 std::vector<std::string> orb_files_in,
266 std::valarray<int> natom_in,
267 std::vector<double> atomic_mass_in,
268 std::string coor_type_in,
269 std::valarray<double> coordinates_in)
270 : latname(latname_in),
271 lmaxmax(lmaxmax_in),
272 init_vel(init_vel_in),
273 selective_dynamics(selective_dynamics_in),
274 relax_new(relax_new_in),
275 fixed_axes(fixed_axes_in),
276 lat0(lat0_in),
277 latvec(latvec_in),
278 elements(elements_in),
279 pp_files(pp_files_in),
280 pp_types(pp_types_in),
281 orb_files(orb_files_in),
282 natom(natom_in),
283 atomic_mass(atomic_mass_in),
284 coor_type(coor_type_in),
285 coordinates(coordinates_in)
286{
287 mbl = std::valarray<double>(0.0, coordinates_in.size());
288 velocity = std::valarray<double>(0.0, coordinates_in.size());
289}
290
291UcellTestPrepare::UcellTestPrepare(std::string latname_in,
292 int lmaxmax_in,
293 bool init_vel_in,
294 bool selective_dynamics_in,
295 bool relax_new_in,
296 std::string fixed_axes_in,
297 double lat0_in,
298 std::valarray<double> latvec_in,
299 std::vector<std::string> elements_in,
300 std::vector<std::string> pp_files_in,
301 std::vector<std::string> pp_types_in,
302 std::vector<std::string> orb_files_in,
303 std::valarray<int> natom_in,
304 std::vector<double> atomic_mass_in,
305 std::string coor_type_in,
306 std::valarray<double> coordinates_in,
307 std::valarray<double> mbl_in,
308 std::valarray<double> velocity_in)
309 : latname(latname_in),
310 lmaxmax(lmaxmax_in),
311 init_vel(init_vel_in),
312 selective_dynamics(selective_dynamics_in),
313 relax_new(relax_new_in),
314 fixed_axes(fixed_axes_in),
315 lat0(lat0_in),
316 latvec(latvec_in),
317 elements(elements_in),
318 pp_files(pp_files_in),
319 pp_types(pp_types_in),
320 orb_files(orb_files_in),
321 natom(natom_in),
322 atomic_mass(atomic_mass_in),
323 coor_type(coor_type_in),
324 coordinates(coordinates_in),
325 mbl(mbl_in),
326 velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file()
327{
328}
329
331 : latname(utp.latname),
332 lmaxmax(utp.lmaxmax),
333 init_vel(utp.init_vel),
334 selective_dynamics(utp.selective_dynamics),
335 relax_new(utp.relax_new),
337 lat0(utp.lat0),
338 latvec(utp.latvec),
339 elements(utp.elements),
340 pp_files(utp.pp_files),
341 pp_types(utp.pp_types),
342 orb_files(utp.orb_files),
343 natom(utp.natom),
344 atomic_mass(utp.atomic_mass),
345 coor_type(utp.coor_type),
346 coordinates(utp.coordinates),
347 mbl(utp.mbl),
348 velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file()
349{
350}
351
352std::map<std::string, UcellTestPrepare> UcellTestLib{
353 {"Si",
354 UcellTestPrepare("fcc", // latname
355 2, // lmaxmax
356 true, // init_vel
357 true, // selective_dyanmics
358 true, // relax_new
359 "volume", // fixed_axes
360 10.2, // lat0
361 {-0.5,
362 0.0,
363 0.5, // latvec
364 0.0,
365 0.5,
366 0.5,
367 -0.5,
368 0.5,
369 0.0},
370 {"Si"}, // elements
371 {"Si.upf"}, // upf file
372 {"upf201"}, // upf types
373 {"Si.orb"}, // orb file
374 {2}, // number of each elements
375 {28.0}, // atomic mass
376 "Cartesian", // coordination type
377 {0.0,
378 0.0,
379 0.0, // atomic coordinates
380 0.25,
381 0.25,
382 0.25})}
383};
384#endif
Atom class for storing atom information.
Definition atom_spec.h:14
std::vector< ModuleBase::Vector3< double > > m_loc_
local magnetic moment
Definition atom_spec.h:65
int na
Number of atoms in this type.
Definition atom_spec.h:44
std::vector< double > angle2
spin angle, added by zhengdy-soc
Definition atom_spec.h:64
int nw
number of local orbitals (l,n,m) of this type
Definition atom_spec.h:36
std::vector< ModuleBase::Vector3< double > > vel
velocities of each atom in this type
Definition atom_spec.h:56
double mass
the mass of atom
Definition atom_spec.h:27
std::string label
atomic symbol
Definition atom_spec.h:51
std::vector< ModuleBase::Vector3< double > > dis
direct displacements of each atom in this type in current step (liuyu modify 2023-03-22)
Definition atom_spec.h:53
std::vector< ModuleBase::Vector3< double > > taud
Direct coordinates of each atom in this type.
Definition atom_spec.h:54
std::vector< double > mag
magnetic moment
Definition atom_spec.h:62
std::vector< ModuleBase::Vector3< double > > tau
Cartesian coordinates of each atom in this type, in unit of lat0.
Definition atom_spec.h:52
std::vector< ModuleBase::Vector3< int > > mbl
whether the atoms can move or not
Definition atom_spec.h:28
std::vector< double > angle1
spin angle, added by zhengdy-soc
Definition atom_spec.h:63
double ux_[3]
ux_
Definition magnetism.h:53
void create(const int d1, const int d2)
Create integer arrays.
Definition intarray.cpp:307
static void Cartesian_to_Direct(const double &cx, const double &cy, const double &cz, const double &R11, const double &R12, const double &R13, const double &R21, const double &R22, const double &R23, const double &R31, const double &R32, const double &R33, double &dx, double &dy, double &dz)
Change Cartesian coordinate (cx,cy,cz) to direct coordinate (dx,dy,dz), (cx,cy,cz) = (dx,...
Definition mathzone.h:128
double e13
Definition matrix3.h:22
Matrix3 Inverse(void) const
Inverse a 3x3 matrix.
Definition matrix3.cpp:44
double e31
Definition matrix3.h:22
double e11
element e_ij: i_row, j_column
Definition matrix3.h:22
double e33
Definition matrix3.h:22
double e32
Definition matrix3.h:22
double e21
Definition matrix3.h:22
double e12
Definition matrix3.h:22
double Det(void) const
Calculate the determinant of a 3x3 matrix.
Definition matrix3.cpp:29
double e23
Definition matrix3.h:22
double e22
Definition matrix3.h:22
Matrix3 Transpose(void) const
Transpose a 3x3 matrix.
Definition matrix3.cpp:39
T x
Definition vector3.h:23
T y
Definition vector3.h:24
T z
Definition vector3.h:25
Definition prepare_unitcell.h:8
std::valarray< double > mbl
Definition prepare_unitcell.h:63
std::vector< std::string > elements
Definition prepare_unitcell.h:55
UcellTestPrepare()=default
UcellTestPrepare(std::string latname_in, int lmaxmax_in, bool init_vel_in, bool selective_dynamics_in, bool relax_new_in, std::string fixed_axes_in, double lat0_in, std::valarray< double > latvec_in, std::vector< std::string > elements_in, std::vector< std::string > pp_files_in, std::vector< std::string > pp_types_in, std::vector< std::string > orb_files_in, std::valarray< int > natom_in, std::vector< double > atomic_mass_in, std::string coor_type_in, std::valarray< double > coordinates_in)
std::vector< std::string > pp_files
Definition prepare_unitcell.h:56
bool relax_new
Definition prepare_unitcell.h:51
std::valarray< double > velocity
Definition prepare_unitcell.h:64
std::valarray< double > coordinates
Definition prepare_unitcell.h:62
std::valarray< double > latvec
Definition prepare_unitcell.h:54
int atomic_index
Definition prepare_unitcell.h:67
std::vector< std::string > orb_files
Definition prepare_unitcell.h:58
UcellTestPrepare(const UcellTestPrepare &utp)
double lat0
Definition prepare_unitcell.h:53
int ntype
Definition prepare_unitcell.h:66
std::vector< double > atomic_mass
Definition prepare_unitcell.h:60
std::valarray< int > natom
Definition prepare_unitcell.h:59
UnitCell * SetUcellInfo(const std::vector< int > &nw, int &nlocal)
Definition prepare_unitcell.h:70
std::string coor_type
Definition prepare_unitcell.h:61
int lmaxmax
Definition prepare_unitcell.h:48
bool selective_dynamics
Definition prepare_unitcell.h:50
std::string fixed_axes
Definition prepare_unitcell.h:52
std::string latname
Definition prepare_unitcell.h:47
bool init_vel
Definition prepare_unitcell.h:49
UcellTestPrepare(std::string latname_in, int lmaxmax_in, bool init_vel_in, bool selective_dynamics_in, bool relax_new_in, std::string fixed_axes_in, double lat0_in, std::valarray< double > latvec_in, std::vector< std::string > elements_in, std::vector< std::string > pp_files_in, std::vector< std::string > pp_types_in, std::vector< std::string > orb_files_in, std::valarray< int > natom_in, std::vector< double > atomic_mass_in, std::string coor_type_in, std::valarray< double > coordinates_in, std::valarray< double > mbl_in, std::valarray< double > velocity_in)
std::vector< std::string > pp_types
Definition prepare_unitcell.h:57
Provide the basic information about unitcell.
Definition unitcell.h:16
std::vector< int > iwt2iat
iwt ==> iat
Definition unitcell.h:158
int ntype
number of atom species in UnitCell
Definition unitcell.h:154
Atom * atoms
Definition unitcell.h:165
ModuleBase::Matrix3 & GT
Definition unitcell.h:147
double & lat0
Definition unitcell.h:135
std::vector< std::string > orbital_fn
filenames of orbitals, liuyu add 2022-10-19
Definition unitcell.h:204
ModuleBase::Matrix3 & latvec
Definition unitcell.h:142
Magnetism magnet
magnetism Yu Liu 2021-07-03
Definition unitcell.h:170
double & tpiba
Definition unitcell.h:137
std::vector< int > iat2ia
iat==>ia
Definition unitcell.h:157
double & tpiba2
Definition unitcell.h:138
void set_iat2iwt(const int &npol_in)
Definition mock_unitcell.cpp:9
void setup_from_input(const std::string &latname_in, const int &ntype_in, const int &lmaxmax_in, const bool &init_vel_in, const std::string &fixed_axes_in)
Initialize basic cell parameters (latname, ntype, lmaxmax, init_vel) from INPUT and parse fixed_axes ...
Definition mock_unitcell.cpp:31
double & omega
Definition unitcell.h:139
ModuleBase::Matrix3 & GGT
Definition unitcell.h:148
ModuleBase::Vector3< double > & a2
Definition unitcell.h:143
ModuleBase::IntArray itia2iat
(it, ia)==>iat, the index in nat (add 2009-3-2 by mohan)
Definition unitcell.h:160
ModuleBase::Vector3< double > & a3
Definition unitcell.h:143
bool set_atom_flag
added on 2009-3-8 by mohan
Definition unitcell.h:215
int nat
total number of atoms of all species in unitcell
Definition unitcell.h:155
std::string & Coordinate
Definition unitcell.h:133
std::vector< std::string > pseudo_fn
filenames of orbitals, liuyu add 2022-10-19
Definition unitcell.h:201
ModuleBase::Matrix3 & invGGT
Definition unitcell.h:149
std::vector< int > iwt2iw
iwt ==> iw (Peize Lin add 2018-07-02)
Definition unitcell.h:159
ModuleBase::Vector3< double > & a1
Definition unitcell.h:143
int namax
the max na among all atom species
Definition unitcell.h:161
ModuleBase::Matrix3 & G
Definition unitcell.h:146
std::vector< int > iat2it
iat==>it, distinguish a atom belong to which type
Definition unitcell.h:156
std::vector< std::string > pseudo_type
filenames of orbitals, liuyu add 2022-10-19
Definition unitcell.h:202
double & lat0_angstrom
Definition unitcell.h:136
std::string fixed_axes
Fixed axes constraint ("None", "shape", "volume", or specific axes).
Definition lattice_change_basic.cpp:12
void init_vel(MDCell &mdcell, const bool &init_vel, const bool &restart, double &temperature, std::int64_t &frozen_freedom)
Definition md_func.cpp:206
const double TWO_PI
Definition constants.h:21
const double BOHR_TO_A
Definition constants.h:55
constexpr double lat0
Definition dfpt_test_tool.h:36
std::map< std::string, UcellTestPrepare > UcellTestLib
Definition prepare_unitcell.h:299