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>
6
8{
9public:
11 UcellTestPrepare(std::string latname_in,
12 int lmaxmax_in,
13 bool init_vel_in,
14 bool selective_dynamics_in,
15 bool relax_new_in,
16 std::string fixed_axes_in,
17 double lat0_in,
18 std::valarray<double> latvec_in,
19 std::vector<std::string> elements_in,
20 std::vector<std::string> pp_files_in,
21 std::vector<std::string> pp_types_in,
22 std::vector<std::string> orb_files_in,
23 std::valarray<int> natom_in,
24 std::vector<double> atomic_mass_in,
25 std::string coor_type_in,
26 std::valarray<double> coordinates_in);
27 UcellTestPrepare(std::string latname_in,
28 int lmaxmax_in,
29 bool init_vel_in,
30 bool selective_dynamics_in,
31 bool relax_new_in,
32 std::string fixed_axes_in,
33 double lat0_in,
34 std::valarray<double> latvec_in,
35 std::vector<std::string> elements_in,
36 std::vector<std::string> pp_files_in,
37 std::vector<std::string> pp_types_in,
38 std::vector<std::string> orb_files_in,
39 std::valarray<int> natom_in,
40 std::vector<double> atomic_mass_in,
41 std::string coor_type_in,
42 std::valarray<double> coordinates_in,
43 std::valarray<double> mbl_in,
44 std::valarray<double> velocity_in);
46
47 std::string latname;
48 int lmaxmax;
49 bool init_vel;
51 bool relax_new;
52 std::string fixed_axes;
53 double lat0;
54 std::valarray<double> latvec;
55 std::vector<std::string> elements;
56 std::vector<std::string> pp_files;
57 std::vector<std::string> pp_types;
58 std::vector<std::string> orb_files;
59 std::valarray<int> natom;
60 std::vector<double> atomic_mass;
61 std::string coor_type;
62 std::valarray<double> coordinates;
63 std::valarray<double> mbl;
64 std::valarray<double> velocity;
65 // ntype
66 int ntype;
67 int atomic_index;
68
70 {
71 //basic info
72 this->ntype = this->elements.size();
73 UnitCell* ucell = new UnitCell;
74 ucell->setup(this->latname,
75 this->ntype,
76 this->lmaxmax,
77 this->init_vel,
78 this->fixed_axes);
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
85 ucell->orbital_fn.resize(ucell->ntype);
86 ucell->magnet.start_mag = new double[ucell->ntype]; //mag set here
87 ucell->magnet.ux_[0] = 0.0; // ux_ set here
88 ucell->magnet.ux_[1] = 0.0;
89 ucell->magnet.ux_[2] = 0.0;
90 for(int it=0;it<ucell->ntype;++it)
91 {
92 ucell->atom_label[it] = this->elements[it];
93 ucell->atom_mass[it] = this->atomic_mass[it];
94 ucell->pseudo_fn[it] = this->pp_files[it];
95 ucell->pseudo_type[it] = this->pp_types[it];
96 ucell->orbital_fn[it] = this->orb_files[it];
97 ucell->magnet.start_mag[it] = 0.0; //mag set here
98 }
99 //lattice info
100 ucell->lat0 = this->lat0;
101 ucell->lat0_angstrom = ucell->lat0 * 0.529177;
102 ucell->tpiba = ModuleBase::TWO_PI/ucell->lat0;
103 ucell->tpiba2 = ucell->tpiba * ucell->tpiba;
104 ucell->latvec.e11 = this->latvec[0];
105 ucell->latvec.e12 = this->latvec[1];
106 ucell->latvec.e13 = this->latvec[2];
107 ucell->latvec.e21 = this->latvec[3];
108 ucell->latvec.e22 = this->latvec[4];
109 ucell->latvec.e23 = this->latvec[5];
110 ucell->latvec.e31 = this->latvec[6];
111 ucell->latvec.e32 = this->latvec[7];
112 ucell->latvec.e33 = this->latvec[8];
113 ucell->a1.x = ucell->latvec.e11;
114 ucell->a1.y = ucell->latvec.e12;
115 ucell->a1.z = ucell->latvec.e13;
116 ucell->a2.x = ucell->latvec.e21;
117 ucell->a2.y = ucell->latvec.e22;
118 ucell->a2.z = ucell->latvec.e23;
119 ucell->a3.x = ucell->latvec.e31;
120 ucell->a3.y = ucell->latvec.e32;
121 ucell->a3.z = ucell->latvec.e33;
122 ucell->GT = ucell->latvec.Inverse();
123 ucell->G = ucell->GT.Transpose();
124 ucell->GGT = ucell->G*ucell->GT;
125 ucell->invGGT = ucell->GGT.Inverse();
126 ucell->omega = std::abs(ucell->latvec.Det())*(ucell->lat0)*(ucell->lat0)*(ucell->lat0);
127 //atomic info
128 ucell->Coordinate = this->coor_type;
129 ucell->atoms = new Atom[ucell->ntype];
130 ucell->set_atom_flag = true;
131 this->atomic_index = 0;
132 for(int it=0;it<ucell->ntype;++it)
133 {
134 ucell->atoms[it].label = this->elements[it];
135 ucell->atoms[it].nw = 0;
136 ucell->atoms[it].nwl = 2;
137 ucell->atoms[it].l_nchi.resize(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 ucell->atoms[it].na = this->natom[it];
144 //coordinates and related physical quantities
145 ucell->atoms[it].tau.resize(ucell->atoms[it].na);
146 ucell->atoms[it].dis.resize(ucell->atoms[it].na);
147 ucell->atoms[it].taud.resize(ucell->atoms[it].na);
148 ucell->atoms[it].vel.resize(ucell->atoms[it].na);
149 ucell->atoms[it].mag.resize(ucell->atoms[it].na);
150 ucell->atoms[it].angle1.resize(ucell->atoms[it].na);
151 ucell->atoms[it].angle2.resize(ucell->atoms[it].na);
152 ucell->atoms[it].m_loc_.resize(ucell->atoms[it].na);
153 ucell->atoms[it].mbl.resize(ucell->atoms[it].na);
154 ucell->atoms[it].mass = ucell->atom_mass[it]; // mass set here
155 for(int ia=0; ia<ucell->atoms[it].na; ++ia)
156 {
157 if (ucell->Coordinate == "Direct")
158 {
159 ucell->atoms[it].taud[ia].x = this->coordinates[this->atomic_index*3+0];
160 ucell->atoms[it].taud[ia].y = this->coordinates[this->atomic_index*3+1];
161 ucell->atoms[it].taud[ia].z = this->coordinates[this->atomic_index*3+2];
162 ucell->atoms[it].tau[ia] = ucell->atoms[it].taud[ia]*ucell->latvec;
163 }
164 else if (ucell->Coordinate == "Cartesian")
165 {
166 ucell->atoms[it].tau[ia].x = this->coordinates[this->atomic_index*3+0];
167 ucell->atoms[it].tau[ia].y = this->coordinates[this->atomic_index*3+1];
168 ucell->atoms[it].tau[ia].z = this->coordinates[this->atomic_index*3+2];
170 ucell->atoms[it].tau[ia].x, ucell->atoms[it].tau[ia].y, ucell->atoms[it].tau[ia].z,
171 ucell->latvec.e11, ucell->latvec.e12, ucell->latvec.e13,
172 ucell->latvec.e21, ucell->latvec.e22, ucell->latvec.e23,
173 ucell->latvec.e31, ucell->latvec.e32, ucell->latvec.e33,
174 ucell->atoms[it].taud[ia].x, ucell->atoms[it].taud[ia].y, ucell->atoms[it].taud[ia].z);
175 }
176 ucell->atoms[it].dis[ia].set(0, 0, 0);
177 if(this->init_vel)
178 {
179 ucell->atoms[it].vel[ia].x = this->velocity[this->atomic_index*3+0];
180 ucell->atoms[it].vel[ia].y = this->velocity[this->atomic_index*3+1];
181 ucell->atoms[it].vel[ia].z = this->velocity[this->atomic_index*3+2];
182 }
183 else
184 {
185 ucell->atoms[it].vel[ia].set(0,0,0);
186 }
187 ucell->atoms[it].m_loc_[ia].set(0,0,0);
188 ucell->atoms[it].angle1[ia] = 0;
189 ucell->atoms[it].angle2[ia] = 0;
190 if(this->selective_dynamics)
191 {
192 ucell->atoms[it].mbl[ia].x = this->mbl[this->atomic_index*3+0];
193 ucell->atoms[it].mbl[ia].y = this->mbl[this->atomic_index*3+1];
194 ucell->atoms[it].mbl[ia].z = this->mbl[this->atomic_index*3+2];
195 }
196 else
197 {
198 ucell->atoms[it].mbl[ia] = {1,1,1};
199 }
200 ++(this->atomic_index);
201 }
202 }
203 ucell->nat = this->natom.sum();
204 return ucell;
205 }
206};
207
208UcellTestPrepare::UcellTestPrepare(std::string latname_in,
209 int lmaxmax_in,
210 bool init_vel_in,
211 bool selective_dynamics_in,
212 bool relax_new_in,
213 std::string fixed_axes_in,
214 double lat0_in,
215 std::valarray<double> latvec_in,
216 std::vector<std::string> elements_in,
217 std::vector<std::string> pp_files_in,
218 std::vector<std::string> pp_types_in,
219 std::vector<std::string> orb_files_in,
220 std::valarray<int> natom_in,
221 std::vector<double> atomic_mass_in,
222 std::string coor_type_in,
223 std::valarray<double> coordinates_in):
224 latname(latname_in),
225 lmaxmax(lmaxmax_in),
226 init_vel(init_vel_in),
227 selective_dynamics(selective_dynamics_in),
228 relax_new(relax_new_in),
229 fixed_axes(fixed_axes_in),
230 lat0(lat0_in),
231 latvec(latvec_in),
232 elements(elements_in),
233 pp_files(pp_files_in),
234 pp_types(pp_types_in),
235 orb_files(orb_files_in),
236 natom(natom_in),
237 atomic_mass(atomic_mass_in),
238 coor_type(coor_type_in),
239 coordinates(coordinates_in)
240{
241 mbl = std::valarray<double>(0.0, coordinates_in.size());
242 velocity = std::valarray<double>(0.0, coordinates_in.size());
243}
244
245UcellTestPrepare::UcellTestPrepare(std::string latname_in,
246 int lmaxmax_in,
247 bool init_vel_in,
248 bool selective_dynamics_in,
249 bool relax_new_in,
250 std::string fixed_axes_in,
251 double lat0_in,
252 std::valarray<double> latvec_in,
253 std::vector<std::string> elements_in,
254 std::vector<std::string> pp_files_in,
255 std::vector<std::string> pp_types_in,
256 std::vector<std::string> orb_files_in,
257 std::valarray<int> natom_in,
258 std::vector<double> atomic_mass_in,
259 std::string coor_type_in,
260 std::valarray<double> coordinates_in,
261 std::valarray<double> mbl_in,
262 std::valarray<double> velocity_in):
263 latname(latname_in),
264 lmaxmax(lmaxmax_in),
265 init_vel(init_vel_in),
266 selective_dynamics(selective_dynamics_in),
267 relax_new(relax_new_in),
268 fixed_axes(fixed_axes_in),
269 lat0(lat0_in),
270 latvec(latvec_in),
271 elements(elements_in),
272 pp_files(pp_files_in),
273 pp_types(pp_types_in),
274 orb_files(orb_files_in),
275 natom(natom_in),
276 atomic_mass(atomic_mass_in),
277 coor_type(coor_type_in),
278 coordinates(coordinates_in),
279 mbl(mbl_in),
280 velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file()
281{}
282
284 latname(utp.latname),
285 lmaxmax(utp.lmaxmax),
286 init_vel(utp.init_vel),
287 selective_dynamics(utp.selective_dynamics),
288 relax_new(utp.relax_new),
290 lat0(utp.lat0),
291 latvec(utp.latvec),
292 elements(utp.elements),
293 pp_files(utp.pp_files),
294 pp_types(utp.pp_types),
295 orb_files(utp.orb_files),
296 natom(utp.natom),
297 atomic_mass(utp.atomic_mass),
298 coor_type(utp.coor_type),
299 coordinates(utp.coordinates),
300 mbl(utp.mbl),
301 velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file()
302{}
303
304std::map<std::string,UcellTestPrepare> UcellTestLib
305{
306 {"Si", UcellTestPrepare(
307 "fcc", //latname
308 2, //lmaxmax
309 true, //init_vel
310 true, //selective_dyanmics
311 true, //relax_new
312 "volume", //fixed_axes
313 10.2, //lat0
314 {-0.5,0.0,0.5, //latvec
315 0.0,0.5,0.5,
316 -0.5,0.5,0.0},
317 {"Si"}, //elements
318 {"Si.upf"}, //upf file
319 {"upf201"}, //upf types
320 {"Si.orb"}, //orb file
321 {2}, //number of each elements
322 {28.0}, //atomic mass
323 "Cartesian", //coordination type
324 {0.0,0.0,0.0, //atomic coordinates
325 0.25,0.25,0.25})}
326};
327#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
int nwl
Definition atom_spec.h:30
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< int > l_nchi
Definition atom_spec.h:32
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
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)
UnitCell * SetUcellInfo()
Definition prepare_unitcell.h:69
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
Definition unitcell.h:16
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 & ntype
Definition unitcell.h:45
double & tpiba
Definition unitcell.h:30
double & tpiba2
Definition unitcell.h:31
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
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
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
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