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