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{
8public:
9 UcellTestPrepare()=default;
10 UcellTestPrepare(std::string latname_in,
11 int lmaxmax_in,
12 bool init_vel_in,
13 bool selective_dynamics_in,
14 bool relax_new_in,
15 std::string fixed_axes_in,
16 double lat0_in,
17 std::valarray<double> latvec_in,
18 std::vector<std::string> elements_in,
19 std::vector<std::string> pp_files_in,
20 std::vector<std::string> pp_types_in,
21 std::vector<std::string> orb_files_in,
22 std::valarray<int> natom_in,
23 std::vector<double> atomic_mass_in,
24 std::string coor_type_in,
25 std::valarray<double> coordinates_in);
26 UcellTestPrepare(std::string latname_in,
27 int lmaxmax_in,
28 bool init_vel_in,
29 bool selective_dynamics_in,
30 bool relax_new_in,
31 std::string fixed_axes_in,
32 double lat0_in,
33 std::valarray<double> latvec_in,
34 std::vector<std::string> elements_in,
35 std::vector<std::string> pp_files_in,
36 std::vector<std::string> pp_types_in,
37 std::vector<std::string> orb_files_in,
38 std::valarray<int> natom_in,
39 std::vector<double> atomic_mass_in,
40 std::string coor_type_in,
41 std::valarray<double> coordinates_in,
42 std::valarray<double> mbl_in,
43 std::valarray<double> velocity_in);
45
46 std::string latname;
47 int lmaxmax;
48 bool init_vel;
50 bool relax_new;
51 std::string fixed_axes;
52 double lat0;
53 std::valarray<double> latvec;
54 std::vector<std::string> elements;
55 std::vector<std::string> pp_files;
56 std::vector<std::string> pp_types;
57 std::vector<std::string> orb_files;
58 std::valarray<int> natom;
59 std::vector<double> atomic_mass;
60 std::string coor_type;
61 std::valarray<double> coordinates;
62 std::valarray<double> mbl;
63 std::valarray<double> velocity;
64 // ntype
65 int ntype;
66 int atomic_index;
67
68 std::unique_ptr<UnitCell> SetUcellInfo()
69 {
70 //basic info
71 this->ntype = this->elements.size();
72 std::unique_ptr<UnitCell> ucell(new UnitCell);
73 ucell->setup_from_input(this->latname,
74 this->ntype,
75 this->lmaxmax,
76 this->init_vel,
77 this->fixed_axes);
78
79 ucell->pseudo_fn.resize(ucell->ntype);
80 ucell->pseudo_type.resize(ucell->ntype);
81 ucell->orbital_fn.resize(ucell->ntype);
82 ucell->magnet.ux_[0] = 0.0; // ux_ set here
83 ucell->magnet.ux_[1] = 0.0;
84 ucell->magnet.ux_[2] = 0.0;
85 for(int it=0;it<ucell->ntype;++it)
86 {
87 ucell->pseudo_fn[it] = this->pp_files[it];
88 ucell->pseudo_type[it] = this->pp_types[it];
89 ucell->orbital_fn[it] = this->orb_files[it];
90 }
91 //lattice info
92 ucell->lat0 = this->lat0;
93 ucell->lat0_angstrom = ucell->lat0 * ModuleBase::BOHR_TO_A;
94 ucell->tpiba = ModuleBase::TWO_PI/ucell->lat0;
95 ucell->tpiba2 = ucell->tpiba * ucell->tpiba;
96 ucell->latvec.e11 = this->latvec[0];
97 ucell->latvec.e12 = this->latvec[1];
98 ucell->latvec.e13 = this->latvec[2];
99 ucell->latvec.e21 = this->latvec[3];
100 ucell->latvec.e22 = this->latvec[4];
101 ucell->latvec.e23 = this->latvec[5];
102 ucell->latvec.e31 = this->latvec[6];
103 ucell->latvec.e32 = this->latvec[7];
104 ucell->latvec.e33 = this->latvec[8];
105 ucell->a1.x = ucell->latvec.e11;
106 ucell->a1.y = ucell->latvec.e12;
107 ucell->a1.z = ucell->latvec.e13;
108 ucell->a2.x = ucell->latvec.e21;
109 ucell->a2.y = ucell->latvec.e22;
110 ucell->a2.z = ucell->latvec.e23;
111 ucell->a3.x = ucell->latvec.e31;
112 ucell->a3.y = ucell->latvec.e32;
113 ucell->a3.z = ucell->latvec.e33;
114 ucell->GT = ucell->latvec.Inverse();
115 ucell->G = ucell->GT.Transpose();
116 ucell->GGT = ucell->G*ucell->GT;
117 ucell->invGGT = ucell->GGT.Inverse();
118 ucell->omega = std::abs(ucell->latvec.Det())*(ucell->lat0)*(ucell->lat0)*(ucell->lat0);
119 //atomic info
120 ucell->Coordinate = this->coor_type;
121 ucell->atoms = new Atom[ucell->ntype];
122 ucell->set_atom_flag = true;
123 this->atomic_index = 0;
124 for(int it=0;it<ucell->ntype;++it)
125 {
126 ucell->atoms[it].label = this->elements[it];
127 ucell->atoms[it].nw = 0;
128 ucell->atoms[it].nwl = 2;
129 ucell->atoms[it].l_nchi.resize(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 ucell->atoms[it].na = this->natom[it];
136 //coordinates and related physical quantities
137 ucell->atoms[it].tau.resize(ucell->atoms[it].na);
138 ucell->atoms[it].dis.resize(ucell->atoms[it].na);
139 ucell->atoms[it].taud.resize(ucell->atoms[it].na);
140 ucell->atoms[it].vel.resize(ucell->atoms[it].na);
141 ucell->atoms[it].mag.resize(ucell->atoms[it].na);
142 ucell->atoms[it].angle1.resize(ucell->atoms[it].na);
143 ucell->atoms[it].angle2.resize(ucell->atoms[it].na);
144 ucell->atoms[it].m_loc_.resize(ucell->atoms[it].na);
145 ucell->atoms[it].mbl.resize(ucell->atoms[it].na);
146 ucell->atoms[it].lambda.resize(ucell->atoms[it].na);
147 ucell->atoms[it].constrain.resize(ucell->atoms[it].na);
148 ucell->atoms[it].mass = this->atomic_mass[it];
149 for(int ia=0; ia<ucell->atoms[it].na; ++ia)
150 {
151 if (ucell->Coordinate == "Direct")
152 {
153 ucell->atoms[it].taud[ia].x = this->coordinates[this->atomic_index*3+0];
154 ucell->atoms[it].taud[ia].y = this->coordinates[this->atomic_index*3+1];
155 ucell->atoms[it].taud[ia].z = this->coordinates[this->atomic_index*3+2];
156 ucell->atoms[it].tau[ia] = ucell->atoms[it].taud[ia]*ucell->latvec;
157 }
158 else if (ucell->Coordinate == "Cartesian")
159 {
160 ucell->atoms[it].tau[ia].x = this->coordinates[this->atomic_index*3+0];
161 ucell->atoms[it].tau[ia].y = this->coordinates[this->atomic_index*3+1];
162 ucell->atoms[it].tau[ia].z = this->coordinates[this->atomic_index*3+2];
164 ucell->atoms[it].tau[ia].x, ucell->atoms[it].tau[ia].y, ucell->atoms[it].tau[ia].z,
165 ucell->latvec.e11, ucell->latvec.e12, ucell->latvec.e13,
166 ucell->latvec.e21, ucell->latvec.e22, ucell->latvec.e23,
167 ucell->latvec.e31, ucell->latvec.e32, ucell->latvec.e33,
168 ucell->atoms[it].taud[ia].x, ucell->atoms[it].taud[ia].y, ucell->atoms[it].taud[ia].z);
169 }
170 ucell->atoms[it].dis[ia].set(0, 0, 0);
171 if(this->init_vel)
172 {
173 ucell->atoms[it].vel[ia].x = this->velocity[this->atomic_index*3+0];
174 ucell->atoms[it].vel[ia].y = this->velocity[this->atomic_index*3+1];
175 ucell->atoms[it].vel[ia].z = this->velocity[this->atomic_index*3+2];
176 }
177 else
178 {
179 ucell->atoms[it].vel[ia].set(0,0,0);
180 }
181 ucell->atoms[it].m_loc_[ia].set(0,0,0);
182 ucell->atoms[it].angle1[ia] = 0;
183 ucell->atoms[it].angle2[ia] = 0;
184 if(this->selective_dynamics)
185 {
186 ucell->atoms[it].mbl[ia].x = this->mbl[this->atomic_index*3+0];
187 ucell->atoms[it].mbl[ia].y = this->mbl[this->atomic_index*3+1];
188 ucell->atoms[it].mbl[ia].z = this->mbl[this->atomic_index*3+2];
189 }
190 else
191 {
192 ucell->atoms[it].mbl[ia] = {1,1,1};
193 }
194 ++(this->atomic_index);
195 }
196 }
197 ucell->nat = this->natom.sum();
198 return ucell;
199 }
200};
201
202UcellTestPrepare::UcellTestPrepare(std::string latname_in,
203 int lmaxmax_in,
204 bool init_vel_in,
205 bool selective_dynamics_in,
206 bool relax_new_in,
207 std::string fixed_axes_in,
208 double lat0_in,
209 std::valarray<double> latvec_in,
210 std::vector<std::string> elements_in,
211 std::vector<std::string> pp_files_in,
212 std::vector<std::string> pp_types_in,
213 std::vector<std::string> orb_files_in,
214 std::valarray<int> natom_in,
215 std::vector<double> atomic_mass_in,
216 std::string coor_type_in,
217 std::valarray<double> coordinates_in):
218 latname(latname_in),
219 lmaxmax(lmaxmax_in),
220 init_vel(init_vel_in),
221 selective_dynamics(selective_dynamics_in),
222 relax_new(relax_new_in),
223 fixed_axes(fixed_axes_in),
224 lat0(lat0_in),
225 latvec(latvec_in),
226 elements(elements_in),
227 pp_files(pp_files_in),
228 pp_types(pp_types_in),
229 orb_files(orb_files_in),
230 natom(natom_in),
231 atomic_mass(atomic_mass_in),
232 coor_type(coor_type_in),
233 coordinates(coordinates_in)
234{
235 mbl = std::valarray<double>(0.0, coordinates_in.size());
236 velocity = std::valarray<double>(0.0, coordinates_in.size());
237}
238
239UcellTestPrepare::UcellTestPrepare(std::string latname_in,
240 int lmaxmax_in,
241 bool init_vel_in,
242 bool selective_dynamics_in,
243 bool relax_new_in,
244 std::string fixed_axes_in,
245 double lat0_in,
246 std::valarray<double> latvec_in,
247 std::vector<std::string> elements_in,
248 std::vector<std::string> pp_files_in,
249 std::vector<std::string> pp_types_in,
250 std::vector<std::string> orb_files_in,
251 std::valarray<int> natom_in,
252 std::vector<double> atomic_mass_in,
253 std::string coor_type_in,
254 std::valarray<double> coordinates_in,
255 std::valarray<double> mbl_in,
256 std::valarray<double> velocity_in):
257 latname(latname_in),
258 lmaxmax(lmaxmax_in),
259 init_vel(init_vel_in),
260 selective_dynamics(selective_dynamics_in),
261 relax_new(relax_new_in),
262 fixed_axes(fixed_axes_in),
263 lat0(lat0_in),
264 latvec(latvec_in),
265 elements(elements_in),
266 pp_files(pp_files_in),
267 pp_types(pp_types_in),
268 orb_files(orb_files_in),
269 natom(natom_in),
270 atomic_mass(atomic_mass_in),
271 coor_type(coor_type_in),
272 coordinates(coordinates_in),
273 mbl(mbl_in),
274 velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file()
275{}
276
278 latname(utp.latname),
279 lmaxmax(utp.lmaxmax),
280 init_vel(utp.init_vel),
281 selective_dynamics(utp.selective_dynamics),
282 relax_new(utp.relax_new),
284 lat0(utp.lat0),
285 latvec(utp.latvec),
286 elements(utp.elements),
287 pp_files(utp.pp_files),
288 pp_types(utp.pp_types),
289 orb_files(utp.orb_files),
290 natom(utp.natom),
291 atomic_mass(utp.atomic_mass),
292 coor_type(utp.coor_type),
293 coordinates(utp.coordinates),
294 mbl(utp.mbl),
295 velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file()
296{}
297
298std::map<std::string,UcellTestPrepare> UcellTestLib
299{
300 {"C1H2-Index", UcellTestPrepare(
301 "bcc", //latname
302 2, //lmaxmax
303 true, //init_vel
304 true, //selective_dyanmics
305 true, //relax_new
306 "volume", //fixed_axes
307 1.8897261254578281, //lat0
308 {10.0,0.0,0.0, //latvec
309 0.0,10.0,0.0,
310 0.0,0.0,10.0},
311 {"C","H"}, //elements
312 {"C.upf","H.upf"}, //upf file
313 {"upf201","upf201"}, //upf types
314 {"C.orb","H.orb"}, //orb file
315 {1,2}, //number of each elements
316 {12.0,1.0}, //atomic mass
317 "Direct", //coordination type
318 {0.1,0.1,0.1, //atomic coordinates
319 0.15,0.15,0.15,
320 0.05,0.05,0.05},
321 {1,1,1, //if atom can move: mbl
322 0,0,0,
323 0,0,1},
324 {0.1,0.1,0.1, //velocity: vel
325 0.1,0.1,0.1,
326 0.1,0.1,0.1})},
327 {"C1H2-Cartesian", UcellTestPrepare(
328 "bcc", //latname
329 2, //lmaxmax
330 true, //init_vel
331 true, //selective_dyanmics
332 true, //relax_new
333 "volume", //fixed_axes
334 1.8897261254578281, //lat0
335 {10.0,0.0,0.0, //latvec
336 0.0,10.0,0.0,
337 0.0,0.0,10.0},
338 {"C","H"}, //elements
339 {"C.upf","H.upf"}, //upf file
340 {"upf201","upf201"}, //upf types
341 {"C.orb","H.orb"}, //orb file
342 {1,2}, //number of each elements
343 {12.0,1.0}, //atomic mass
344 "Cartesian", //coordination type
345 {1,1,1, //atomic coordinates
346 1.5,1.5,1.5,
347 0.5,0.5,0.5})},
348 {"C1H2-CheckDTau", UcellTestPrepare(
349 "bcc", //latname
350 2, //lmaxmax
351 false, //init_vel
352 false, //selective_dyanmics
353 true, //relax_new
354 "volume", //fixed_axes
355 1.8897261254578281, //lat0
356 {0.1,0.1,0.1, //latvec
357 0.15,0.15,0.15,
358 0.05,0.05,0.05},
359 {"C","H"}, //elements
360 {"C.upf","H.upf"}, //upf file
361 {"upf201","upf201"}, //upf types
362 {"C.orb","H.orb"}, //orb file
363 {1,2}, //number of each elements
364 {12.0,1.0}, //atomic mass
365 "Direct", //coordination type
366 {1.6,2.5,3.8, //atomic coordinates
367 -0.15,1.0,-0.15,
368 -3.05,-2.8,0.0})},
369 {"C1H2-CheckTau", UcellTestPrepare(
370 "bcc", //latname
371 2, //lmaxmax
372 false, //init_vel
373 false, //selective_dyanmics
374 true, //relax_new
375 "volume", //fixed_axes
376 1.8897261254578281, //lat0
377 {0.1,0.1,0.1, //latvec
378 0.15,0.15,0.15,
379 0.05,0.05,0.05},
380 {"C","H"}, //elements
381 {"C.upf","H.upf"}, //upf file
382 {"upf201","upf201"}, //upf types
383 {"C.orb","H.orb"}, //orb file
384 {1,2}, //number of each elements
385 {12.0,1.0}, //atomic mass
386 "Direct", //coordination type
387 {0.0,0.0,0.0, //atomic coordinates
388 0.00001,0.00001,0.00001,
389 -3.05,-2.8,0.0})},
390 {"C1H2-SD", UcellTestPrepare(
391 "bcc", //latname
392 2, //lmaxmax
393 false, //init_vel
394 false, //selective_dyanmics
395 true, //relax_new
396 "volume", //fixed_axes
397 1.8897261254578281, //lat0
398 {0.1,0.1,0.1, //latvec
399 0.15,0.15,0.15,
400 0.05,0.05,0.05},
401 {"C","H"}, //elements
402 {"C.upf","H.upf"}, //upf file
403 {"upf201","upf201"}, //upf types
404 {"C.orb","H.orb"}, //orb file
405 {1,2}, //number of each elements
406 {12.0,1.0}, //atomic mass
407 "Direct", //coordination type
408 {0.1,0.1,0.1, //atomic coordinates
409 0.15,0.15,0.15,
410 0.05,0.05,0.05})},
411 {"C1H2-PBA", UcellTestPrepare(
412 "bcc", //latname
413 2, //lmaxmax
414 false, //init_vel
415 false, //selective_dyanmics
416 true, //relax_new
417 "volume", //fixed_axes
418 1.8897261254578281, //lat0
419 {0.1,0.1,0.1, //latvec
420 0.15,0.15,0.15,
421 0.05,0.05,0.05},
422 {"C","H"}, //elements
423 {"C.upf","H.upf"}, //upf file
424 {"upf201","upf201"}, //upf types
425 {"C.orb","H.orb"}, //orb file
426 {1,2}, //number of each elements
427 {12.0,1.0}, //atomic mass
428 "Direct", //coordination type
429 {-0.1,-0.1,-0.1, //atomic coordinates
430 1.2,1.2,1.2,
431 -3.05,-2.8,0.0})},
432 {"C1H2-Read", UcellTestPrepare(
433 "bcc", //latname
434 2, //lmaxmax
435 true, //init_vel
436 true, //selective_dyanmics
437 true, //relax_new
438 "volume", //fixed_axes
439 1.8897261254578281, //lat0
440 {10.0,0.0,0.0, //latvec
441 0.0,10.0,0.0,
442 0.0,0.0,10.0},
443 {"C","H"}, //elements
444 {"C.upf","H.upf"}, //upf file
445 {"upf201","upf201"}, //upf types
446 {"C.orb","H.orb"}, //orb file
447 {1,2}, //number of each elements
448 {12.0,1.0}, //atomic mass
449 "Direct", //coordination type
450 {0.1,0.1,0.1, //atomic coordinates
451 0.12,0.12,0.12,
452 0.08,0.08,0.08})},
453 {"flz-Read", UcellTestPrepare(
454 "bcc", //latname
455 2, //lmaxmax
456 false, //init_vel
457 false, //selective_dyanmics
458 false, //relax_new
459 "volume", //fixed_axes
460 1.8897261254578281, //lat0
461 {10.0,0.0,0.0, //latvec
462 0.0,10.0,0.0,
463 0.0,0.0,10.0},
464 {"C","H"}, //elements
465 {"C.upf","H.upf"}, //upf file
466 {"upf201","upf201"}, //upf types
467 {"C_gga_8au_100Ry_2s2p1d.orb","H_gga_8au_100Ry_2s1p.orb"}, //orb file
468 {1,2}, //number of each elements
469 {12.0,1.0}, //atomic mass
470 "Direct", //coordination type
471 {0.1,0.1,0.1, //atomic coordinates
472 0.12,0.12,0.12,
473 0.08,0.08,0.08}
474 )
475 }
476};
477#endif
Atom class for storing atom information.
Definition atom_spec.h:14
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
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
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
std::unique_ptr< UnitCell > SetUcellInfo()
Definition prepare_unitcell.h:68
Provide the basic information about unitcell.
Definition unitcell.h:16
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