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 static UnitCell ucell;
74 ucell.setup_from_input(this->latname, this->ntype, this->lmaxmax, this->init_vel, this->fixed_axes);
75 delete[] ucell.orbital_fn;
76 delete[] ucell.magnet.start_magnetization; // mag set here
77 ucell->pseudo_fn.resize(ucell->ntype);
78 ucell->pseudo_type.resize(ucell->ntype);
79
80 ucell.orbital_fn.resize(ucell.ntype);
81 ucell.magnet.start_magnetization = new double[ucell.ntype]; // mag set here
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 ucell.magnet.start_magnetization[it] = 0.0; // mag set here
91 }
92 // lattice info
93 ucell.lat0 = this->lat0;
95 ucell.tpiba = ModuleBase::TWO_PI / ucell.lat0;
96 ucell.tpiba2 = ucell.tpiba * ucell.tpiba;
97 ucell.latvec.e11 = this->latvec[0];
98 ucell.latvec.e12 = this->latvec[1];
99 ucell.latvec.e13 = this->latvec[2];
100 ucell.latvec.e21 = this->latvec[3];
101 ucell.latvec.e22 = this->latvec[4];
102 ucell.latvec.e23 = this->latvec[5];
103 ucell.latvec.e31 = this->latvec[6];
104 ucell.latvec.e32 = this->latvec[7];
105 ucell.latvec.e33 = this->latvec[8];
106 ucell.a1.x = ucell.latvec.e11;
107 ucell.a1.y = ucell.latvec.e12;
108 ucell.a1.z = ucell.latvec.e13;
109 ucell.a2.x = ucell.latvec.e21;
110 ucell.a2.y = ucell.latvec.e22;
111 ucell.a2.z = ucell.latvec.e23;
112 ucell.a3.x = ucell.latvec.e31;
113 ucell.a3.y = ucell.latvec.e32;
114 ucell.a3.z = ucell.latvec.e33;
115 ucell.GT = ucell.latvec.Inverse();
116 ucell.G = ucell.GT.Transpose();
117 ucell.GGT = ucell.G * ucell.GT;
118 ucell.invGGT = ucell.GGT.Inverse();
119 ucell.omega = std::abs(ucell.latvec.Det()) * (ucell.lat0) * (ucell.lat0) * (ucell.lat0);
120 // atomic info
121 ucell.Coordinate = this->coor_type;
122 ucell.atoms = new Atom[ucell.ntype];
123 ucell.set_atom_flag = true;
124 this->atomic_index = 0;
125 for (int it = 0; it < ucell.ntype; ++it)
126 {
127 ucell.atoms[it].label = this->elements[it];
128 ucell.atoms[it].nw = 0;
129 ucell.atoms[it].nwl = 2;
130 delete[] ucell.atoms[it].l_nchi;
131 ucell.atoms[it].l_nchi = new int[ ucell.atoms[it].nwl+1];
132 for(int L=0; L<ucell.atoms[it].nwl+1; L++)
133 {
134 ucell.atoms[it].l_nchi[L] = 1;
135 ucell.atoms[it].nw += (2*L + 1) * ucell.atoms[it].l_nchi[L];
136 }
137 ucell.atoms[it].na = this->natom[it];
138 // coordinates and related physical quantities
139 delete[] ucell.atoms[it].tau;
140 delete[] ucell.atoms[it].dis;
141 delete[] ucell.atoms[it].taud;
142 delete[] ucell.atoms[it].vel;
143 delete[] ucell.atoms[it].mag;
144 delete[] ucell.atoms[it].angle1;
145 delete[] ucell.atoms[it].angle2;
146 delete[] ucell.atoms[it].m_loc_;
147 delete[] ucell.atoms[it].mbl;
148 ucell.atoms[it].tau = new ModuleBase::Vector3<double>[ucell.atoms[it].na];
149 ucell.atoms[it].dis = new ModuleBase::Vector3<double>[ucell.atoms[it].na];
150 ucell.atoms[it].taud = new ModuleBase::Vector3<double>[ucell.atoms[it].na];
151 ucell.atoms[it].vel = new ModuleBase::Vector3<double>[ucell.atoms[it].na];
152 ucell.atoms[it].mag = new double[ucell.atoms[it].na];
153 ucell.atoms[it].angle1 = new double[ucell.atoms[it].na];
154 ucell.atoms[it].angle2 = new double[ucell.atoms[it].na];
155 ucell.atoms[it].m_loc_ = new ModuleBase::Vector3<double>[ucell.atoms[it].na];
156 ucell.atoms[it].mbl = new ModuleBase::Vector3<int>[ucell.atoms[it].na];
157 ucell.atoms[it].mass = this->atomic_mass[it];
158 for (int ia = 0; ia < ucell.atoms[it].na; ++ia)
159 {
160 if (ucell.Coordinate == "Cartesian")
161 {
162 ucell.atoms[it].tau[ia].x = this->coordinates[this->atomic_index * 3 + 0];
163 ucell.atoms[it].tau[ia].y = this->coordinates[this->atomic_index * 3 + 1];
164 ucell.atoms[it].tau[ia].z = this->coordinates[this->atomic_index * 3 + 2];
166 ucell.atoms[it].tau[ia].y,
167 ucell.atoms[it].tau[ia].z,
168 ucell.latvec.e11,
169 ucell.latvec.e12,
170 ucell.latvec.e13,
171 ucell.latvec.e21,
172 ucell.latvec.e22,
173 ucell.latvec.e23,
174 ucell.latvec.e31,
175 ucell.latvec.e32,
176 ucell.latvec.e33,
177 ucell.atoms[it].taud[ia].x,
178 ucell.atoms[it].taud[ia].y,
179 ucell.atoms[it].taud[ia].z);
180 }
181 ucell.atoms[it].dis[ia].set(0, 0, 0);
182 ucell.atoms[it].vel[ia].set(0, 0, 0);
183 ucell.atoms[it].m_loc_[ia].set(0, 0, 0);
184 ucell.atoms[it].angle1[ia] = 0;
185 ucell.atoms[it].angle2[ia] = 0;
186 ucell.atoms[it].mbl[ia] = {1, 1, 1};
187 ++(this->atomic_index);
188 }
189 }
190 ucell.nat = this->natom.sum();
191 return &ucell;
192 }
193};
194
195UcellTestPrepare::UcellTestPrepare(std::string latname_in,
196 int lmaxmax_in,
197 bool init_vel_in,
198 bool selective_dynamics_in,
199 bool relax_new_in,
200 std::string fixed_axes_in,
201 double lat0_in,
202 std::valarray<double> latvec_in,
203 std::vector<std::string> elements_in,
204 std::vector<std::string> pp_files_in,
205 std::vector<std::string> pp_types_in,
206 std::vector<std::string> orb_files_in,
207 std::valarray<int> natom_in,
208 std::vector<double> atomic_mass_in,
209 std::string coor_type_in,
210 std::valarray<double> coordinates_in):
211 latname(latname_in),
212 lmaxmax(lmaxmax_in),
213 init_vel(init_vel_in),
214 selective_dynamics(selective_dynamics_in),
215 relax_new(relax_new_in),
216 fixed_axes(fixed_axes_in),
217 lat0(lat0_in),
218 latvec(latvec_in),
219 elements(elements_in),
220 pp_files(pp_files_in),
221 pp_types(pp_types_in),
222 orb_files(orb_files_in),
223 natom(natom_in),
224 atomic_mass(atomic_mass_in),
225 coor_type(coor_type_in),
226 coordinates(coordinates_in)
227{
228 mbl = {0};
229 velocity = {0};
230}
231
233 latname(utp.latname),
234 lmaxmax(utp.lmaxmax),
235 init_vel(utp.init_vel),
236 selective_dynamics(utp.selective_dynamics),
237 relax_new(utp.relax_new),
239 lat0(utp.lat0),
240 latvec(utp.latvec),
241 elements(utp.elements),
242 pp_files(utp.pp_files),
243 pp_types(utp.pp_types),
244 orb_files(utp.orb_files),
245 natom(utp.natom),
246 atomic_mass(utp.atomic_mass),
247 coor_type(utp.coor_type),
248 coordinates(utp.coordinates),
249 mbl(utp.mbl),
250 velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file()
251{}
252
253std::map<std::string,UcellTestPrepare> UcellTestLib
254{
255 {"SiO", UcellTestPrepare(
256 "fcc", //latname
257 2, //lmaxmax
258 false, //init_vel
259 false, //selective_dyanmics
260 false, //relax_new
261 "volume", //fixed_axes
262 10.2, //lat0
263 {-0.5,0.0,0.5, //latvec
264 0.0,0.5,0.5,
265 -0.5,0.5,0.0},
266 {"O","Si"}, //elements
267 {"O.upf","Si.upf"}, //upf file
268 {"upf201","upf201"}, //upf types
269 {"O.orb","Si.orb"}, //orb file
270 {1,5}, //number of each elements
271 {16.0,28.0}, //atomic mass
272 "Cartesian", //coordination type
273 {0.0,0.0,0.0, //atomic coordinates
274 0.1,0.0,0.0, //atomic coordinates
275 0.2,0.0,0.0, //atomic coordinates
276 0.3,0.0,0.0, //atomic coordinates
277 0.4,0.0,0.0, //atomic coordinates
278 0.25,0.25,0.25})}
279};
280#endif
Atom class for storing atom information.
Definition atom_spec.h:14
std::vector< ModuleBase::Vector3< double > > m_loc_
local magnetic moment
Definition atom_spec.h:65
int na
Number of atoms in this type.
Definition atom_spec.h:44
std::vector< double > angle2
spin angle, added by zhengdy-soc
Definition atom_spec.h:64
int nw
number of local orbitals (l,n,m) of this type
Definition atom_spec.h:36
int nwl
max L(Angular momentum) (for local basis)
Definition atom_spec.h:46
std::vector< ModuleBase::Vector3< double > > vel
velocities of each atom in this type
Definition atom_spec.h:56
double mass
the mass of atom
Definition atom_spec.h:27
std::string label
atomic symbol
Definition atom_spec.h:51
std::vector< ModuleBase::Vector3< double > > dis
direct displacements of each atom in this type in current step (liuyu modify 2023-03-22)
Definition atom_spec.h:53
std::vector< ModuleBase::Vector3< double > > taud
Direct coordinates of each atom in this type.
Definition atom_spec.h:54
std::vector< double > mag
magnetic moment
Definition atom_spec.h:62
std::vector< int > l_nchi
number of chi for each L
Definition atom_spec.h:48
std::vector< ModuleBase::Vector3< double > > tau
Cartesian coordinates of each atom in this type, in unit of lat0.
Definition atom_spec.h:52
std::vector< ModuleBase::Vector3< int > > mbl
whether the atoms can move or not
Definition atom_spec.h:28
std::vector< double > angle1
spin angle, added by zhengdy-soc
Definition atom_spec.h:63
double ux_[3]
ux_
Definition magnetism.h:53
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
double e13
Definition matrix3.h:22
Matrix3 Inverse(void) const
Inverse a 3x3 matrix.
Definition matrix3.cpp:44
double e31
Definition matrix3.h:22
double e11
element e_ij: i_row, j_column
Definition matrix3.h:22
double e33
Definition matrix3.h:22
double e32
Definition matrix3.h:22
double e21
Definition matrix3.h:22
double e12
Definition matrix3.h:22
double Det(void) const
Calculate the determinant of a 3x3 matrix.
Definition matrix3.cpp:29
double e23
Definition matrix3.h:22
double e22
Definition matrix3.h:22
Matrix3 Transpose(void) const
Transpose a 3x3 matrix.
Definition matrix3.cpp:39
3 elements vector
Definition vector3.h:21
T x
Definition vector3.h:23
T y
Definition vector3.h:24
T z
Definition vector3.h:25
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
Provide the basic information about unitcell.
Definition unitcell.h:16
int ntype
number of atom species in UnitCell
Definition unitcell.h:154
Atom * atoms
Definition unitcell.h:165
ModuleBase::Matrix3 & GT
Definition unitcell.h:147
double & lat0
Definition unitcell.h:135
std::vector< std::string > orbital_fn
filenames of orbitals, liuyu add 2022-10-19
Definition unitcell.h:204
ModuleBase::Matrix3 & latvec
Definition unitcell.h:142
Magnetism magnet
magnetism Yu Liu 2021-07-03
Definition unitcell.h:170
double & tpiba
Definition unitcell.h:137
double & tpiba2
Definition unitcell.h:138
void setup_from_input(const std::string &latname_in, const int &ntype_in, const int &lmaxmax_in, const bool &init_vel_in, const std::string &fixed_axes_in)
Initialize basic cell parameters (latname, ntype, lmaxmax, init_vel) from INPUT and parse fixed_axes ...
Definition mock_unitcell.cpp:31
double & omega
Definition unitcell.h:139
ModuleBase::Matrix3 & GGT
Definition unitcell.h:148
ModuleBase::Vector3< double > & a2
Definition unitcell.h:143
ModuleBase::Vector3< double > & a3
Definition unitcell.h:143
bool set_atom_flag
added on 2009-3-8 by mohan
Definition unitcell.h:215
int nat
total number of atoms of all species in unitcell
Definition unitcell.h:155
std::string & Coordinate
Definition unitcell.h:133
std::vector< std::string > pseudo_fn
filenames of orbitals, liuyu add 2022-10-19
Definition unitcell.h:201
ModuleBase::Matrix3 & invGGT
Definition unitcell.h:149
ModuleBase::Vector3< double > & a1
Definition unitcell.h:143
ModuleBase::Matrix3 & G
Definition unitcell.h:146
std::vector< std::string > pseudo_type
filenames of orbitals, liuyu add 2022-10-19
Definition unitcell.h:202
double & lat0_angstrom
Definition unitcell.h:136
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