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(this->latname, this->ntype, this->lmaxmax, this->init_vel, this->fixed_axes);
76
77 delete[] ucell.magnet.start_mag; // mag set here
78
79 ucell.atom_label.resize(ucell.ntype);
80 ucell.atom_mass.resize(ucell.ntype);
81 ucell.pseudo_fn.resize(ucell.ntype);
82 ucell.pseudo_type.resize(ucell.ntype);
83 ucell.orbital_fn.resize(ucell.ntype);
84 ucell.magnet.start_mag = new double[ucell.ntype]; // mag set here
85 ucell.magnet.ux_[0] = 0.0; // ux_ set here
86 ucell.magnet.ux_[1] = 0.0;
87 ucell.magnet.ux_[2] = 0.0;
88 for (int it = 0; it < ucell.ntype; ++it)
89 {
90 ucell.atom_label[it] = this->elements[it];
91 ucell.atom_mass[it] = this->atomic_mass[it];
92 ucell.pseudo_fn[it] = this->pp_files[it];
93 ucell.pseudo_type[it] = this->pp_types[it];
94 ucell.orbital_fn[it] = this->orb_files[it];
95 ucell.magnet.start_mag[it] = 0.0; // mag set here
96 }
97 // lattice info
98 ucell.lat0 = this->lat0;
99 ucell.lat0_angstrom = ucell.lat0 * 0.529177;
100 ucell.tpiba = ModuleBase::TWO_PI / ucell.lat0;
101 ucell.tpiba2 = ucell.tpiba * ucell.tpiba;
102 ucell.latvec.e11 = this->latvec[0];
103 ucell.latvec.e12 = this->latvec[1];
104 ucell.latvec.e13 = this->latvec[2];
105 ucell.latvec.e21 = this->latvec[3];
106 ucell.latvec.e22 = this->latvec[4];
107 ucell.latvec.e23 = this->latvec[5];
108 ucell.latvec.e31 = this->latvec[6];
109 ucell.latvec.e32 = this->latvec[7];
110 ucell.latvec.e33 = this->latvec[8];
111 ucell.a1.x = ucell.latvec.e11;
112 ucell.a1.y = ucell.latvec.e12;
113 ucell.a1.z = ucell.latvec.e13;
114 ucell.a2.x = ucell.latvec.e21;
115 ucell.a2.y = ucell.latvec.e22;
116 ucell.a2.z = ucell.latvec.e23;
117 ucell.a3.x = ucell.latvec.e31;
118 ucell.a3.y = ucell.latvec.e32;
119 ucell.a3.z = ucell.latvec.e33;
120 ucell.GT = ucell.latvec.Inverse();
121 ucell.G = ucell.GT.Transpose();
122 ucell.GGT = ucell.G * ucell.GT;
123 ucell.invGGT = ucell.GGT.Inverse();
124 ucell.omega = std::abs(ucell.latvec.Det()) * (ucell.lat0) * (ucell.lat0) * (ucell.lat0);
125 // atomic info
126 ucell.Coordinate = this->coor_type;
127 ucell.atoms = new Atom[ucell.ntype];
128 ucell.set_atom_flag = true;
129 this->atomic_index = 0;
130 for (int it = 0; it < ucell.ntype; ++it)
131 {
132 ucell.atoms[it].label = this->elements[it];
133 /*
134 ucell.atoms[it].nw = 0;
135 ucell.atoms[it].nwl = 2;
136 delete[] ucell.atoms[it].l_nchi;
137 ucell.atoms[it].l_nchi = new int[ ucell.atoms[it].nwl+1];
138 for(int L=0; L<ucell.atoms[it].nwl+1; L++)
139 {
140 ucell.atoms[it].l_nchi[L] = 1;
141 ucell.atoms[it].nw += (2*L + 1) * ucell.atoms[it].l_nchi[L];
142 }
143 */
144 ucell.atoms[it].na = this->natom[it];
145 // coordinates and related physical quantities
146 ucell.atoms[it].tau.resize(ucell.atoms[it].na);
147 ucell.atoms[it].dis.resize(ucell.atoms[it].na);
148 ucell.atoms[it].taud.resize(ucell.atoms[it].na);
149 ucell.atoms[it].vel.resize(ucell.atoms[it].na);
150 ucell.atoms[it].mag.resize(ucell.atoms[it].na);
151 ucell.atoms[it].angle1.resize(ucell.atoms[it].na);
152 ucell.atoms[it].angle2.resize(ucell.atoms[it].na);
153 ucell.atoms[it].m_loc_.resize(ucell.atoms[it].na);
154 ucell.atoms[it].mbl.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].y,
172 ucell.atoms[it].tau[ia].z,
173 ucell.latvec.e11,
174 ucell.latvec.e12,
175 ucell.latvec.e13,
176 ucell.latvec.e21,
177 ucell.latvec.e22,
178 ucell.latvec.e23,
179 ucell.latvec.e31,
180 ucell.latvec.e32,
181 ucell.latvec.e33,
182 ucell.atoms[it].taud[ia].x,
183 ucell.atoms[it].taud[ia].y,
184 ucell.atoms[it].taud[ia].z);
185 }
186 ucell.atoms[it].dis[ia].set(0, 0, 0);
187 if (this->init_vel)
188 {
189 ucell.atoms[it].vel[ia].x = this->velocity[this->atomic_index * 3 + 0];
190 ucell.atoms[it].vel[ia].y = this->velocity[this->atomic_index * 3 + 1];
191 ucell.atoms[it].vel[ia].z = this->velocity[this->atomic_index * 3 + 2];
192 }
193 else
194 {
195 ucell.atoms[it].vel[ia].set(0, 0, 0);
196 }
197 ucell.atoms[it].m_loc_[ia].set(0, 0, 0);
198 ucell.atoms[it].angle1[ia] = 0;
199 ucell.atoms[it].angle2[ia] = 0;
200 if (this->selective_dynamics)
201 {
202 ucell.atoms[it].mbl[ia].x = this->mbl[this->atomic_index * 3 + 0];
203 ucell.atoms[it].mbl[ia].y = this->mbl[this->atomic_index * 3 + 1];
204 ucell.atoms[it].mbl[ia].z = this->mbl[this->atomic_index * 3 + 2];
205 }
206 else
207 {
208 ucell.atoms[it].mbl[ia] = {1, 1, 1};
209 }
210 ++(this->atomic_index);
211 }
212 }
213 ucell.nat = this->natom.sum();
214 // set_nw
215 assert(nw.size() == ucell.ntype);
216 for (int it = 0; it < ucell.ntype; ++it)
217 {
218 ucell.atoms[it].nw = nw[it];
219 }
220 // cal_nloc
221 for (int it = 0; it < ucell.ntype; ++it)
222 {
223 nlocal += ucell.atoms[it].na * ucell.atoms[it].nw;
224 }
225 // cal_namax
226 int namax = 0;
227 for (int it = 0; it < ucell.ntype; ++it)
228 {
229 namax = std::max(namax, ucell.atoms[it].na);
230 }
231 ucell.namax = namax;
232 // cal_index
233 assert(nlocal > 0);
234 delete[] ucell.iwt2iat;
235 delete[] ucell.iwt2iw;
236 delete[] ucell.iat2it;
237 delete[] ucell.iat2ia;
238 ucell.iwt2iat = new int[nlocal];
239 ucell.iwt2iw = new int[nlocal];
240 ucell.iat2it = new int[ucell.nat];
241 ucell.iat2ia = new int[ucell.nat]; // set_iat2itia
242 ucell.itia2iat.create(ucell.ntype, ucell.namax);
243 ucell.set_iat2iwt(1);
244 int iat = 0;
245 int iwt = 0;
246 for (int it = 0; it < ucell.ntype; it++)
247 {
248 for (int ia = 0; ia < ucell.atoms[it].na; ia++)
249 {
250 ucell.iat2it[iat] = it;
251 ucell.iat2ia[iat] = ia;
252 ucell.itia2iat(it, ia) = iat;
253 for (int iw = 0; iw < ucell.atoms[it].nw; iw++)
254 {
255 ucell.iwt2iat[iwt] = iat;
256 ucell.iwt2iw[iwt] = iw;
257 ++iwt;
258 }
259 ++iat;
260 }
261 }
262 return &ucell;
263 }
264};
265
266UcellTestPrepare::UcellTestPrepare(std::string latname_in,
267 int lmaxmax_in,
268 bool init_vel_in,
269 bool selective_dynamics_in,
270 bool relax_new_in,
271 std::string fixed_axes_in,
272 double lat0_in,
273 std::valarray<double> latvec_in,
274 std::vector<std::string> elements_in,
275 std::vector<std::string> pp_files_in,
276 std::vector<std::string> pp_types_in,
277 std::vector<std::string> orb_files_in,
278 std::valarray<int> natom_in,
279 std::vector<double> atomic_mass_in,
280 std::string coor_type_in,
281 std::valarray<double> coordinates_in)
282 : latname(latname_in),
283 lmaxmax(lmaxmax_in),
284 init_vel(init_vel_in),
285 selective_dynamics(selective_dynamics_in),
286 relax_new(relax_new_in),
287 fixed_axes(fixed_axes_in),
288 lat0(lat0_in),
289 latvec(latvec_in),
290 elements(elements_in),
291 pp_files(pp_files_in),
292 pp_types(pp_types_in),
293 orb_files(orb_files_in),
294 natom(natom_in),
295 atomic_mass(atomic_mass_in),
296 coor_type(coor_type_in),
297 coordinates(coordinates_in)
298{
299 mbl = std::valarray<double>(0.0, coordinates_in.size());
300 velocity = std::valarray<double>(0.0, coordinates_in.size());
301}
302
303UcellTestPrepare::UcellTestPrepare(std::string latname_in,
304 int lmaxmax_in,
305 bool init_vel_in,
306 bool selective_dynamics_in,
307 bool relax_new_in,
308 std::string fixed_axes_in,
309 double lat0_in,
310 std::valarray<double> latvec_in,
311 std::vector<std::string> elements_in,
312 std::vector<std::string> pp_files_in,
313 std::vector<std::string> pp_types_in,
314 std::vector<std::string> orb_files_in,
315 std::valarray<int> natom_in,
316 std::vector<double> atomic_mass_in,
317 std::string coor_type_in,
318 std::valarray<double> coordinates_in,
319 std::valarray<double> mbl_in,
320 std::valarray<double> velocity_in)
321 : latname(latname_in),
322 lmaxmax(lmaxmax_in),
323 init_vel(init_vel_in),
324 selective_dynamics(selective_dynamics_in),
325 relax_new(relax_new_in),
326 fixed_axes(fixed_axes_in),
327 lat0(lat0_in),
328 latvec(latvec_in),
329 elements(elements_in),
330 pp_files(pp_files_in),
331 pp_types(pp_types_in),
332 orb_files(orb_files_in),
333 natom(natom_in),
334 atomic_mass(atomic_mass_in),
335 coor_type(coor_type_in),
336 coordinates(coordinates_in),
337 mbl(mbl_in),
338 velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file()
339{
340}
341
343 : latname(utp.latname),
344 lmaxmax(utp.lmaxmax),
345 init_vel(utp.init_vel),
346 selective_dynamics(utp.selective_dynamics),
347 relax_new(utp.relax_new),
349 lat0(utp.lat0),
350 latvec(utp.latvec),
351 elements(utp.elements),
352 pp_files(utp.pp_files),
353 pp_types(utp.pp_types),
354 orb_files(utp.orb_files),
355 natom(utp.natom),
356 atomic_mass(utp.atomic_mass),
357 coor_type(utp.coor_type),
358 coordinates(utp.coordinates),
359 mbl(utp.mbl),
360 velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file()
361{
362}
363
364std::map<std::string, UcellTestPrepare> UcellTestLib{
365 {"Si",
366 UcellTestPrepare("fcc", // latname
367 2, // lmaxmax
368 true, // init_vel
369 true, // selective_dyanmics
370 true, // relax_new
371 "volume", // fixed_axes
372 10.2, // lat0
373 {-0.5,
374 0.0,
375 0.5, // latvec
376 0.0,
377 0.5,
378 0.5,
379 -0.5,
380 0.5,
381 0.0},
382 {"Si"}, // elements
383 {"Si.upf"}, // upf file
384 {"upf201"}, // upf types
385 {"Si.orb"}, // orb file
386 {2}, // number of each elements
387 {28.0}, // atomic mass
388 "Cartesian", // coordination type
389 {0.0,
390 0.0,
391 0.0, // atomic coordinates
392 0.25,
393 0.25,
394 0.25})}
395};
396#endif
Definition atom_spec.h:7
std::vector< ModuleBase::Vector3< double > > m_loc_
Definition atom_spec.h:48
int na
Definition atom_spec.h:28
std::vector< double > angle2
Definition atom_spec.h:47
int nw
Definition atom_spec.h:23
std::vector< ModuleBase::Vector3< double > > vel
Definition atom_spec.h:39
double mass
Definition atom_spec.h:14
std::string label
Definition atom_spec.h:35
std::vector< ModuleBase::Vector3< double > > dis
Definition atom_spec.h:37
std::vector< ModuleBase::Vector3< double > > taud
Definition atom_spec.h:38
std::vector< double > mag
Definition atom_spec.h:45
std::vector< ModuleBase::Vector3< double > > tau
Definition atom_spec.h:36
std::vector< ModuleBase::Vector3< int > > mbl
Definition atom_spec.h:15
std::vector< double > angle1
Definition atom_spec.h:46
double * start_mag
Definition magnetism.h:16
double ux_[3]
Definition magnetism.h:37
void create(const int d1, const int d2)
Create integer arrays.
Definition intarray.cpp:137
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
double e13
Definition matrix3.h:26
Matrix3 Inverse(void) const
Inverse a 3x3 matrix.
Definition matrix3.cpp:44
double e31
Definition matrix3.h:26
double e11
element e_ij: i_row, j_column
Definition matrix3.h:26
double e33
Definition matrix3.h:26
double e32
Definition matrix3.h:26
double e21
Definition matrix3.h:26
double e12
Definition matrix3.h:26
double Det(void) const
Calculate the determinant of a 3x3 matrix.
Definition matrix3.cpp:29
double e23
Definition matrix3.h:26
double e22
Definition matrix3.h:26
Matrix3 Transpose(void) const
Transpose a 3x3 matrix.
Definition matrix3.cpp:39
T x
Definition vector3.h:24
T y
Definition vector3.h:25
T z
Definition vector3.h:26
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
Definition unitcell.h:16
int *& iat2it
Definition unitcell.h:47
Atom * atoms
Definition unitcell.h:18
ModuleBase::Matrix3 & GT
Definition unitcell.h:40
double & lat0
Definition unitcell.h:28
std::vector< std::string > orbital_fn
Definition unitcell.h:206
ModuleBase::Matrix3 & latvec
Definition unitcell.h:35
Magnetism magnet
Definition unitcell.h:21
int *& iwt2iw
Definition unitcell.h:50
int & ntype
Definition unitcell.h:45
double & tpiba
Definition unitcell.h:30
double & tpiba2
Definition unitcell.h:31
void set_iat2iwt(const int &npol_in)
Definition mock_unitcell.cpp:11
ModuleBase::IntArray & itia2iat
Definition unitcell.h:51
int & nat
Definition unitcell.h:46
double & omega
Definition unitcell.h:32
ModuleBase::Matrix3 & GGT
Definition unitcell.h:41
ModuleBase::Vector3< double > & a2
Definition unitcell.h:36
ModuleBase::Vector3< double > & a3
Definition unitcell.h:36
bool set_atom_flag
Definition unitcell.h:20
std::vector< std::string > atom_label
Definition unitcell.h:202
std::string & Coordinate
Definition unitcell.h:26
int *& iat2ia
Definition unitcell.h:48
std::vector< std::string > pseudo_fn
Definition unitcell.h:203
ModuleBase::Matrix3 & invGGT
Definition unitcell.h:42
ModuleBase::Vector3< double > & a1
Definition unitcell.h:36
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
int *& iwt2iat
Definition unitcell.h:49
std::vector< std::string > pseudo_type
Definition unitcell.h:204
double & lat0_angstrom
Definition unitcell.h:29
std::vector< double > atom_mass
Definition unitcell.h:201
int & namax
Definition unitcell.h:52
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