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