From fbf6cc6e56cd1d2eb3f272a5c90c499e977ca16b Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Wed, 22 Jul 2026 17:10:15 +0800 Subject: [PATCH 1/3] Unify the code formatting, align code elements, and replace tabs with spaces. --- source/source_cell/atom_pseudo.cpp | 6 +- source/source_cell/atom_pseudo.h | 66 +- source/source_cell/atom_spec.h | 2 +- source/source_cell/cal_nelec_nband.cpp | 8 +- source/source_cell/k_vector_utils.cpp | 32 +- source/source_cell/magnetism.cpp | 102 +- source/source_cell/magnetism.h | 18 +- .../source_cell/module_neighbor/sltk_atom.cpp | 16 +- .../source_cell/module_neighbor/sltk_atom.h | 50 +- .../module_neighbor/sltk_atom_arrange.cpp | 4 +- .../module_neighbor/sltk_atom_arrange.h | 36 +- .../source_cell/module_neighbor/sltk_grid.cpp | 2 +- .../module_neighbor/sltk_grid_driver.cpp | 16 +- .../module_neighbor/sltk_grid_driver.h | 4 +- .../module_neighbor/test/prepare_unitcell.h | 592 +++---- .../test/sltk_atom_arrange_test.cpp | 2 +- .../module_symmetry/symm_analysis.cpp | 150 +- .../module_symmetry/symm_check.cpp | 28 +- .../module_symmetry/symm_getgroup.cpp | 46 +- .../module_symmetry/symm_hermite.cpp | 204 +-- .../module_symmetry/symm_lattice.cpp | 480 +++--- .../module_symmetry/symm_magnetic.cpp | 68 +- .../module_symmetry/symm_other.cpp | 224 +-- .../source_cell/module_symmetry/symm_other.h | 8 +- .../module_symmetry/symm_pricell.cpp | 8 +- .../source_cell/module_symmetry/symm_rho.cpp | 262 +-- .../source_cell/module_symmetry/symmetry.cpp | 40 +- source/source_cell/module_symmetry/symmetry.h | 198 +-- .../module_symmetry/symmetry_basic.cpp | 1526 ++++++++--------- .../module_symmetry/symmetry_basic.h | 60 +- source/source_cell/parallel_kpoints.cpp | 8 +- source/source_cell/print_cell.cpp | 12 +- source/source_cell/pseudo.cpp | 94 +- source/source_cell/read_orb.cpp | 4 +- source/source_cell/read_pp.cpp | 634 +++---- source/source_cell/read_pp.h | 24 +- source/source_cell/read_pp_blps.cpp | 6 +- source/source_cell/read_pp_complete.cpp | 276 +-- source/source_cell/read_pp_upf100.cpp | 2 +- source/source_cell/read_pp_upf201.cpp | 56 +- source/source_cell/read_pp_vwr.cpp | 600 +++---- source/source_cell/read_stru.cpp | 146 +- source/source_cell/test/atom_pseudo_test.cpp | 104 +- source/source_cell/test/atom_spec_test.cpp | 286 +-- source/source_cell/test/magnetism_test.cpp | 124 +- source/source_cell/test/prepare_unitcell.h | 908 +++++----- source/source_cell/test/pseudo_nc_test.cpp | 150 +- source/source_cell/test/read_pp_test.cpp | 734 ++++---- source/source_cell/test/unitcell_test.cpp | 4 +- .../test/unitcell_test_setupcell.cpp | 230 +-- .../source_cell/test_pw/unitcell_test_pw.cpp | 138 +- source/source_cell/unitcell.cpp | 136 +- source/source_cell/unitcell.h | 2 +- source/source_cell/update_cell.cpp | 506 +++--- 54 files changed, 4721 insertions(+), 4721 deletions(-) diff --git a/source/source_cell/atom_pseudo.cpp b/source/source_cell/atom_pseudo.cpp index 2f968039ec8..483ff7f53c1 100644 --- a/source/source_cell/atom_pseudo.cpp +++ b/source/source_cell/atom_pseudo.cpp @@ -67,7 +67,7 @@ void Atom_pseudo::set_d_so(ModuleBase::ComplexMatrix& d_so_in, else // zhengdy-soc { this->d_so.create(spin_dimension, nproj_soc + 1, nproj_soc + 1); - // std::cout << "lmax=" << lmax << std::endl; + // std::cout << "lmax=" << lmax << std::endl; if (this->lmax > -1) { @@ -87,10 +87,10 @@ void Atom_pseudo::set_d_so(ModuleBase::ComplexMatrix& d_so_in, if (fabs(this->d_so(is, L1, L2).real()) > 1.0e-8 || fabs(this->d_so(is, L1, L2).imag()) > 1.0e-8) { - // std::cout << "tt in atom is=" << is << " L1=" << + // std::cout << "tt in atom is=" << is << " L1=" << //L1 //<< " L2=" - // << L2 << " " << d_so(is, L1, L2) << std::endl; + // << L2 << " " << d_so(is, L1, L2) << std::endl; this->index1_soc[is][non_zero_count_soc[is]] = L1; this->index2_soc[is][non_zero_count_soc[is]] = L2; diff --git a/source/source_cell/atom_pseudo.h b/source/source_cell/atom_pseudo.h index fa0cfdae435..a50ed86f246 100644 --- a/source/source_cell/atom_pseudo.h +++ b/source/source_cell/atom_pseudo.h @@ -11,41 +11,41 @@ class Atom_pseudo : public pseudo { public: - Atom_pseudo(); - ~Atom_pseudo(); - - // mohan add 2021-05-07 - ModuleBase::ComplexArray d_so; //(:,:,:), spin-orbit case - ModuleBase::matrix d_real; //(:,:), non-spin-orbit case - int nproj; - int nproj_soc; // dimension of D_ij^so - std::vector non_zero_count_soc = {0, 0, 0, 0}; - std::vector> index1_soc = {{}, {}, {}, {}}; - std::vector> index2_soc = {{}, {}, {}, {}}; - - void set_d_so( // mohan add 2021-05-07 - ModuleBase::ComplexMatrix &d_so_in, - const int &nproj_in, - const int &nproj_in_so, - const bool has_so, - const bool lspinorb, - const int nspin); - - - inline void get_d(const int& is, const int& p1, const int& p2, const std::complex*& tmp_d) - { - tmp_d = &this->d_so(is, p1, p2); - return; - } - inline void get_d(const int& is, const int& p1, const int& p2, const double*& tmp_d) - { - tmp_d = &this->d_real(p1, p2); - return; - } - + Atom_pseudo(); + ~Atom_pseudo(); + + // mohan add 2021-05-07 + ModuleBase::ComplexArray d_so; //(:,:,:), spin-orbit case + ModuleBase::matrix d_real; //(:,:), non-spin-orbit case + int nproj; + int nproj_soc; // dimension of D_ij^so + std::vector non_zero_count_soc = {0, 0, 0, 0}; + std::vector> index1_soc = {{}, {}, {}, {}}; + std::vector> index2_soc = {{}, {}, {}, {}}; + + void set_d_so( // mohan add 2021-05-07 + ModuleBase::ComplexMatrix &d_so_in, + const int &nproj_in, + const int &nproj_in_so, + const bool has_so, + const bool lspinorb, + const int nspin); + + + inline void get_d(const int& is, const int& p1, const int& p2, const std::complex*& tmp_d) + { + tmp_d = &this->d_so(is, p1, p2); + return; + } + inline void get_d(const int& is, const int& p1, const int& p2, const double*& tmp_d) + { + tmp_d = &this->d_real(p1, p2); + return; + } + #ifdef __MPI - void bcast_atom_pseudo(void); // for upf201 + void bcast_atom_pseudo(void); // for upf201 #endif }; diff --git a/source/source_cell/atom_spec.h b/source/source_cell/atom_spec.h index 18ec8284976..6f3ba4afef2 100644 --- a/source/source_cell/atom_spec.h +++ b/source/source_cell/atom_spec.h @@ -12,7 +12,7 @@ class Atom Atom_pseudo ncpp; double mass = 0.0; // the mass of atom std::vector> mbl; // whether the atoms can move or not - bool flag_empty_element = false; // whether is the empty element for bsse. Peize Lin add 2021.04.07 + bool flag_empty_element = false; // whether is the empty element for bsse. Peize Lin add 2021.04.07 std::vector iw2m; // use iw to find m std::vector iw2n; // use iw to find n diff --git a/source/source_cell/cal_nelec_nband.cpp b/source/source_cell/cal_nelec_nband.cpp index 8dd516e8a79..3a8b24c177f 100644 --- a/source/source_cell/cal_nelec_nband.cpp +++ b/source/source_cell/cal_nelec_nband.cpp @@ -46,10 +46,10 @@ void cal_nbands(const int& nelec, const int& nlocal, const std::vector& } double occupied_bands = static_cast(nelec / ModuleBase::DEGSPIN); - if (lspinorb == 1) - { - occupied_bands = static_cast(nelec); - } + if (lspinorb == 1) + { + occupied_bands = static_cast(nelec); + } if ((occupied_bands - std::floor(occupied_bands)) > 0.0) { diff --git a/source/source_cell/k_vector_utils.cpp b/source/source_cell/k_vector_utils.cpp index 451e002f323..ca9bdfb6f97 100644 --- a/source/source_cell/k_vector_utils.cpp +++ b/source/source_cell/k_vector_utils.cpp @@ -69,10 +69,10 @@ void kvec_c2d(K_Vectors& kv, const ModuleBase::Matrix3& latvec) ModuleBase::Matrix3 RT = latvec.Transpose(); for (int i = 0; i < nks; i++) { - // std::cout << " ik=" << i - // << " kvec.x=" << kvec_c[i].x - // << " kvec.y=" << kvec_c[i].y - // << " kvec.z=" << kvec_c[i].z << std::endl; + // std::cout << " ik=" << i + // << " kvec.x=" << kvec_c[i].x + // << " kvec.y=" << kvec_c[i].y + // << " kvec.z=" << kvec_c[i].z << std::endl; // wrong! kvec_d[i] = RT * kvec_c[i]; // mohan fixed bug 2011-03-07 kv.kvec_d[i] = kv.kvec_c[i] * RT; @@ -588,10 +588,10 @@ void kvec_ibz_kpoint(K_Vectors& kv, ModuleBase::Vector3 kvec_rot; ModuleBase::Vector3 kvec_rot_k; - // for(int i=0; i& kvec) { // in (-0.5, 0.5] kvec.x = fmod(kvec.x + 100.5 - 0.5 * symm.epsilon, 1) - 0.5 + 0.5 * symm.epsilon; @@ -691,20 +691,20 @@ void kvec_ibz_kpoint(K_Vectors& kv, } else // mohan fix bug 2010-1-30 { - // std::cout << "\n\n already exist ! "; + // std::cout << "\n\n already exist ! "; - // std::cout << "\n kvec_rot = " << kvec_rot.x << " " << kvec_rot.y << " " << kvec_rot.z; - // std::cout << "\n kvec_d_ibz = " << kvec_d_ibz[exist_number].x - // << " " << kvec_d_ibz[exist_number].y - // << " " << kvec_d_ibz[exist_number].z; + // std::cout << "\n kvec_rot = " << kvec_rot.x << " " << kvec_rot.y << " " << kvec_rot.z; + // std::cout << "\n kvec_d_ibz = " << kvec_d_ibz[exist_number].x + // << " " << kvec_d_ibz[exist_number].y + // << " " << kvec_d_ibz[exist_number].z; double kmol_new = kv.kvec_d[i].norm2(); double kmol_old = kvec_d_ibz[exist_number].norm2(); kv.ibz_index[i] = exist_number; - // std::cout << "\n kmol_new = " << kmol_new; - // std::cout << "\n kmol_old = " << kmol_old; + // std::cout << "\n kmol_new = " << kmol_new; + // std::cout << "\n kmol_old = " << kmol_old; // why we need this step? // because in pw_basis.cpp, while calculate ggwfc2, @@ -718,7 +718,7 @@ void kvec_ibz_kpoint(K_Vectors& kv, kvec_d_ibz[exist_number] = kv.kvec_d[i]; } } - // BLOCK_HERE("check k point"); + // BLOCK_HERE("check k point"); } delete[] kkmatrix; diff --git a/source/source_cell/magnetism.cpp b/source/source_cell/magnetism.cpp index 09e8b7830bb..b7001b4eedd 100644 --- a/source/source_cell/magnetism.cpp +++ b/source/source_cell/magnetism.cpp @@ -14,13 +14,13 @@ Magnetism::~Magnetism() } void Magnetism::compute_mag(const double& omega, - const int& nrxx, - const int& nxyz, - const double* const * rho, - const int& nspin, - const bool& two_fermi, - const double& nelec, - double* nelec_spin) + const int& nrxx, + const int& nxyz, + const double* const * rho, + const int& nspin, + const bool& two_fermi, + const double& nelec, + double* nelec_spin) { assert(omega>0.0); assert(nxyz>0); @@ -45,61 +45,61 @@ void Magnetism::compute_mag(const double& omega, this->tot_mag *= fac; this->abs_mag *= fac; - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)",this->tot_mag); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag); - - //update number of electrons for each spin - //if TWO_EFERMI, no need to update - if(!two_fermi) - { - nelec_spin[0] = (nelec + this->tot_mag) / 2; - nelec_spin[1] = (nelec - this->tot_mag) / 2; - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron number for spin up", nelec_spin[0]); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron number for spin down", nelec_spin[1]); - } + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)",this->tot_mag); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag); + + //update number of electrons for each spin + //if TWO_EFERMI, no need to update + if(!two_fermi) + { + nelec_spin[0] = (nelec + this->tot_mag) / 2; + nelec_spin[1] = (nelec - this->tot_mag) / 2; + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron number for spin up", nelec_spin[0]); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron number for spin down", nelec_spin[1]); + } } - // noncolliear : - else if(nspin==4) - { - for(int i=0;i<3;i++) - { - this->tot_mag_nc[i] = 0.00; - } - - this->abs_mag = 0.00; - for (int ir=0; irtot_mag_nc[i] = 0.00; + } + + this->abs_mag = 0.00; + for (int ir=0; irtot_mag_nc[i] += rho[i+1][ir]; - } - this->abs_mag += std::abs(diff); - } + for(int i=0;i<3;i++) + { + this->tot_mag_nc[i] += rho[i+1][ir]; + } + this->abs_mag += std::abs(diff); + } #ifdef __MPI Parallel_Reduce::reduce_pool(this->tot_mag_nc, 3); Parallel_Reduce::reduce_pool(this->abs_mag); #endif - for(int i=0;i<3;i++) - { - this->tot_mag_nc[i] *= fac; + for(int i=0;i<3;i++) + { + this->tot_mag_nc[i] *= fac; // mohan add 2025-06-21 - if( std::abs(this->tot_mag_nc[i]) < 1.0e-16) - { - this->tot_mag_nc[i] = 0.0; - } - } + if( std::abs(this->tot_mag_nc[i]) < 1.0e-16) + { + this->tot_mag_nc[i] = 0.0; + } + } - this->abs_mag *= fac; + this->abs_mag *= fac; // mohan update 2025-06-21 - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)", + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)", this->tot_mag_nc[0], this->tot_mag_nc[1], this->tot_mag_nc[2]); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag); - } + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag); + } return; } @@ -112,8 +112,8 @@ bool Magnetism::judge_parallel(const double a[3], const ModuleBase::Vector3 latvec_in, - std::vector elements_in, - std::vector pp_files_in, - std::vector pp_types_in, - std::vector orb_files_in, - std::valarray natom_in, - std::vector atomic_mass_in, - std::string coor_type_in, - std::valarray coordinates_in); - 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 latvec_in, - std::vector elements_in, - std::vector pp_files_in, - std::vector pp_types_in, - std::vector orb_files_in, - std::valarray natom_in, - std::vector atomic_mass_in, - std::string coor_type_in, - std::valarray coordinates_in, - std::valarray mbl_in, - std::valarray velocity_in); - UcellTestPrepare(const UcellTestPrepare &utp); + 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 latvec_in, + std::vector elements_in, + std::vector pp_files_in, + std::vector pp_types_in, + std::vector orb_files_in, + std::valarray natom_in, + std::vector atomic_mass_in, + std::string coor_type_in, + std::valarray coordinates_in); + 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 latvec_in, + std::vector elements_in, + std::vector pp_files_in, + std::vector pp_types_in, + std::vector orb_files_in, + std::valarray natom_in, + std::vector atomic_mass_in, + std::string coor_type_in, + std::valarray coordinates_in, + std::valarray mbl_in, + std::valarray velocity_in); + UcellTestPrepare(const UcellTestPrepare &utp); - std::string latname; - int lmaxmax; - bool init_vel; - bool selective_dynamics; - bool relax_new; - std::string fixed_axes; - double lat0; - std::valarray latvec; - std::vector elements; - std::vector pp_files; - std::vector pp_types; - std::vector orb_files; - std::valarray natom; - std::vector atomic_mass; - std::string coor_type; - std::valarray coordinates; - std::valarray mbl; - std::valarray velocity; - // ntype - int ntype; - int atomic_index; + std::string latname; + int lmaxmax; + bool init_vel; + bool selective_dynamics; + bool relax_new; + std::string fixed_axes; + double lat0; + std::valarray latvec; + std::vector elements; + std::vector pp_files; + std::vector pp_types; + std::vector orb_files; + std::valarray natom; + std::vector atomic_mass; + std::string coor_type; + std::valarray coordinates; + std::valarray mbl; + std::valarray velocity; + // ntype + int ntype; + int atomic_index; - UnitCell* SetUcellInfo() - { - //basic info - this->ntype = this->elements.size(); - UnitCell* ucell = new UnitCell; - ucell->setup(this->latname, - this->ntype, - this->lmaxmax, - this->init_vel, - this->fixed_axes); - - ucell->atom_label.resize(ucell->ntype); - ucell->atom_mass.resize(ucell->ntype); - ucell->pseudo_fn.resize(ucell->ntype); - ucell->pseudo_type.resize(ucell->ntype); - ucell->orbital_fn.resize(ucell->ntype); - ucell->magnet.ux_[0] = 0.0; // ux_ set here - ucell->magnet.ux_[1] = 0.0; - ucell->magnet.ux_[2] = 0.0; - for(int it=0;itntype;++it) - { - ucell->atom_label[it] = this->elements[it]; - ucell->atom_mass[it] = this->atomic_mass[it]; - ucell->pseudo_fn[it] = this->pp_files[it]; - ucell->pseudo_type[it] = this->pp_types[it]; - ucell->orbital_fn[it] = this->orb_files[it]; - } - //lattice info - ucell->lat0 = this->lat0; - ucell->lat0_angstrom = ucell->lat0 * ModuleBase::BOHR_TO_A; - ucell->tpiba = ModuleBase::TWO_PI/ucell->lat0; - ucell->tpiba2 = ucell->tpiba * ucell->tpiba; - ucell->latvec.e11 = this->latvec[0]; - ucell->latvec.e12 = this->latvec[1]; - ucell->latvec.e13 = this->latvec[2]; - ucell->latvec.e21 = this->latvec[3]; - ucell->latvec.e22 = this->latvec[4]; - ucell->latvec.e23 = this->latvec[5]; - ucell->latvec.e31 = this->latvec[6]; - ucell->latvec.e32 = this->latvec[7]; - ucell->latvec.e33 = this->latvec[8]; - ucell->a1.x = ucell->latvec.e11; - ucell->a1.y = ucell->latvec.e12; - ucell->a1.z = ucell->latvec.e13; - ucell->a2.x = ucell->latvec.e21; - ucell->a2.y = ucell->latvec.e22; - ucell->a2.z = ucell->latvec.e23; - ucell->a3.x = ucell->latvec.e31; - ucell->a3.y = ucell->latvec.e32; - ucell->a3.z = ucell->latvec.e33; - ucell->GT = ucell->latvec.Inverse(); - ucell->G = ucell->GT.Transpose(); - ucell->GGT = ucell->G*ucell->GT; - ucell->invGGT = ucell->GGT.Inverse(); - ucell->omega = std::abs(ucell->latvec.Det())*(ucell->lat0)*(ucell->lat0)*(ucell->lat0); - //atomic info - ucell->Coordinate = this->coor_type; - ucell->atoms = new Atom[ucell->ntype]; - ucell->set_atom_flag = true; - this->atomic_index = 0; - for(int it=0;itntype;++it) - { - ucell->atoms[it].label = this->elements[it]; - ucell->atoms[it].nw = 0; - ucell->atoms[it].nwl = 2; - ucell->atoms[it].l_nchi.resize(ucell->atoms[it].nwl+1); - for(int L=0; Latoms[it].nwl+1; L++) - { - ucell->atoms[it].l_nchi[L] = 1; - ucell->atoms[it].nw += (2*L + 1) * ucell->atoms[it].l_nchi[L]; - } - ucell->atoms[it].na = this->natom[it]; - //coordinates and related physical quantities - ucell->atoms[it].tau.resize(ucell->atoms[it].na); - ucell->atoms[it].dis.resize(ucell->atoms[it].na); - ucell->atoms[it].taud.resize(ucell->atoms[it].na); - ucell->atoms[it].vel.resize(ucell->atoms[it].na); - ucell->atoms[it].mag.resize(ucell->atoms[it].na); - ucell->atoms[it].angle1.resize(ucell->atoms[it].na); - ucell->atoms[it].angle2.resize(ucell->atoms[it].na); - ucell->atoms[it].m_loc_.resize(ucell->atoms[it].na); - ucell->atoms[it].mbl.resize(ucell->atoms[it].na); - ucell->atoms[it].mass = ucell->atom_mass[it]; // mass set here + UnitCell* SetUcellInfo() + { + //basic info + this->ntype = this->elements.size(); + UnitCell* ucell = new UnitCell; + ucell->setup(this->latname, + this->ntype, + this->lmaxmax, + this->init_vel, + this->fixed_axes); + + ucell->atom_label.resize(ucell->ntype); + ucell->atom_mass.resize(ucell->ntype); + ucell->pseudo_fn.resize(ucell->ntype); + ucell->pseudo_type.resize(ucell->ntype); + ucell->orbital_fn.resize(ucell->ntype); + ucell->magnet.ux_[0] = 0.0; // ux_ set here + ucell->magnet.ux_[1] = 0.0; + ucell->magnet.ux_[2] = 0.0; + for(int it=0;itntype;++it) + { + ucell->atom_label[it] = this->elements[it]; + ucell->atom_mass[it] = this->atomic_mass[it]; + ucell->pseudo_fn[it] = this->pp_files[it]; + ucell->pseudo_type[it] = this->pp_types[it]; + ucell->orbital_fn[it] = this->orb_files[it]; + } + //lattice info + ucell->lat0 = this->lat0; + ucell->lat0_angstrom = ucell->lat0 * ModuleBase::BOHR_TO_A; + ucell->tpiba = ModuleBase::TWO_PI/ucell->lat0; + ucell->tpiba2 = ucell->tpiba * ucell->tpiba; + ucell->latvec.e11 = this->latvec[0]; + ucell->latvec.e12 = this->latvec[1]; + ucell->latvec.e13 = this->latvec[2]; + ucell->latvec.e21 = this->latvec[3]; + ucell->latvec.e22 = this->latvec[4]; + ucell->latvec.e23 = this->latvec[5]; + ucell->latvec.e31 = this->latvec[6]; + ucell->latvec.e32 = this->latvec[7]; + ucell->latvec.e33 = this->latvec[8]; + ucell->a1.x = ucell->latvec.e11; + ucell->a1.y = ucell->latvec.e12; + ucell->a1.z = ucell->latvec.e13; + ucell->a2.x = ucell->latvec.e21; + ucell->a2.y = ucell->latvec.e22; + ucell->a2.z = ucell->latvec.e23; + ucell->a3.x = ucell->latvec.e31; + ucell->a3.y = ucell->latvec.e32; + ucell->a3.z = ucell->latvec.e33; + ucell->GT = ucell->latvec.Inverse(); + ucell->G = ucell->GT.Transpose(); + ucell->GGT = ucell->G*ucell->GT; + ucell->invGGT = ucell->GGT.Inverse(); + ucell->omega = std::abs(ucell->latvec.Det())*(ucell->lat0)*(ucell->lat0)*(ucell->lat0); + //atomic info + ucell->Coordinate = this->coor_type; + ucell->atoms = new Atom[ucell->ntype]; + ucell->set_atom_flag = true; + this->atomic_index = 0; + for(int it=0;itntype;++it) + { + ucell->atoms[it].label = this->elements[it]; + ucell->atoms[it].nw = 0; + ucell->atoms[it].nwl = 2; + ucell->atoms[it].l_nchi.resize(ucell->atoms[it].nwl+1); + for(int L=0; Latoms[it].nwl+1; L++) + { + ucell->atoms[it].l_nchi[L] = 1; + ucell->atoms[it].nw += (2*L + 1) * ucell->atoms[it].l_nchi[L]; + } + ucell->atoms[it].na = this->natom[it]; + //coordinates and related physical quantities + ucell->atoms[it].tau.resize(ucell->atoms[it].na); + ucell->atoms[it].dis.resize(ucell->atoms[it].na); + ucell->atoms[it].taud.resize(ucell->atoms[it].na); + ucell->atoms[it].vel.resize(ucell->atoms[it].na); + ucell->atoms[it].mag.resize(ucell->atoms[it].na); + ucell->atoms[it].angle1.resize(ucell->atoms[it].na); + ucell->atoms[it].angle2.resize(ucell->atoms[it].na); + ucell->atoms[it].m_loc_.resize(ucell->atoms[it].na); + ucell->atoms[it].mbl.resize(ucell->atoms[it].na); + ucell->atoms[it].mass = ucell->atom_mass[it]; // mass set here - for(int ia=0; iaatoms[it].na; ++ia) - { - if (ucell->Coordinate == "Direct") - { - ucell->atoms[it].taud[ia].x = this->coordinates[this->atomic_index*3+0]; - ucell->atoms[it].taud[ia].y = this->coordinates[this->atomic_index*3+1]; - ucell->atoms[it].taud[ia].z = this->coordinates[this->atomic_index*3+2]; - ucell->atoms[it].tau[ia] = ucell->atoms[it].taud[ia]*ucell->latvec; - } - else if (ucell->Coordinate == "Cartesian") - { - ucell->atoms[it].tau[ia].x = this->coordinates[this->atomic_index*3+0]; - ucell->atoms[it].tau[ia].y = this->coordinates[this->atomic_index*3+1]; - ucell->atoms[it].tau[ia].z = this->coordinates[this->atomic_index*3+2]; - ModuleBase::Mathzone::Cartesian_to_Direct( - ucell->atoms[it].tau[ia].x, ucell->atoms[it].tau[ia].y, ucell->atoms[it].tau[ia].z, - ucell->latvec.e11, ucell->latvec.e12, ucell->latvec.e13, - ucell->latvec.e21, ucell->latvec.e22, ucell->latvec.e23, - ucell->latvec.e31, ucell->latvec.e32, ucell->latvec.e33, - ucell->atoms[it].taud[ia].x, ucell->atoms[it].taud[ia].y, ucell->atoms[it].taud[ia].z); - } + for(int ia=0; iaatoms[it].na; ++ia) + { + if (ucell->Coordinate == "Direct") + { + ucell->atoms[it].taud[ia].x = this->coordinates[this->atomic_index*3+0]; + ucell->atoms[it].taud[ia].y = this->coordinates[this->atomic_index*3+1]; + ucell->atoms[it].taud[ia].z = this->coordinates[this->atomic_index*3+2]; + ucell->atoms[it].tau[ia] = ucell->atoms[it].taud[ia]*ucell->latvec; + } + else if (ucell->Coordinate == "Cartesian") + { + ucell->atoms[it].tau[ia].x = this->coordinates[this->atomic_index*3+0]; + ucell->atoms[it].tau[ia].y = this->coordinates[this->atomic_index*3+1]; + ucell->atoms[it].tau[ia].z = this->coordinates[this->atomic_index*3+2]; + ModuleBase::Mathzone::Cartesian_to_Direct( + ucell->atoms[it].tau[ia].x, ucell->atoms[it].tau[ia].y, ucell->atoms[it].tau[ia].z, + ucell->latvec.e11, ucell->latvec.e12, ucell->latvec.e13, + ucell->latvec.e21, ucell->latvec.e22, ucell->latvec.e23, + ucell->latvec.e31, ucell->latvec.e32, ucell->latvec.e33, + ucell->atoms[it].taud[ia].x, ucell->atoms[it].taud[ia].y, ucell->atoms[it].taud[ia].z); + } ucell->atoms[it].dis[ia].set(0, 0, 0); - if(this->init_vel) - { - ucell->atoms[it].vel[ia].x = this->velocity[this->atomic_index*3+0]; - ucell->atoms[it].vel[ia].y = this->velocity[this->atomic_index*3+1]; - ucell->atoms[it].vel[ia].z = this->velocity[this->atomic_index*3+2]; - } - else - { - ucell->atoms[it].vel[ia].set(0,0,0); - } - ucell->atoms[it].m_loc_[ia].set(0,0,0); - ucell->atoms[it].angle1[ia] = 0; - ucell->atoms[it].angle2[ia] = 0; - if(this->selective_dynamics) - { - ucell->atoms[it].mbl[ia].x = this->mbl[this->atomic_index*3+0]; - ucell->atoms[it].mbl[ia].y = this->mbl[this->atomic_index*3+1]; - ucell->atoms[it].mbl[ia].z = this->mbl[this->atomic_index*3+2]; - } - else - { - ucell->atoms[it].mbl[ia] = {1,1,1}; - } - ++(this->atomic_index); - } - } - ucell->nat = this->natom.sum(); - return ucell; - } + if(this->init_vel) + { + ucell->atoms[it].vel[ia].x = this->velocity[this->atomic_index*3+0]; + ucell->atoms[it].vel[ia].y = this->velocity[this->atomic_index*3+1]; + ucell->atoms[it].vel[ia].z = this->velocity[this->atomic_index*3+2]; + } + else + { + ucell->atoms[it].vel[ia].set(0,0,0); + } + ucell->atoms[it].m_loc_[ia].set(0,0,0); + ucell->atoms[it].angle1[ia] = 0; + ucell->atoms[it].angle2[ia] = 0; + if(this->selective_dynamics) + { + ucell->atoms[it].mbl[ia].x = this->mbl[this->atomic_index*3+0]; + ucell->atoms[it].mbl[ia].y = this->mbl[this->atomic_index*3+1]; + ucell->atoms[it].mbl[ia].z = this->mbl[this->atomic_index*3+2]; + } + else + { + ucell->atoms[it].mbl[ia] = {1,1,1}; + } + ++(this->atomic_index); + } + } + ucell->nat = this->natom.sum(); + return ucell; + } }; UcellTestPrepare::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 latvec_in, - std::vector elements_in, - std::vector pp_files_in, - std::vector pp_types_in, - std::vector orb_files_in, - std::valarray natom_in, - std::vector atomic_mass_in, - std::string coor_type_in, - std::valarray coordinates_in): - latname(latname_in), - lmaxmax(lmaxmax_in), - init_vel(init_vel_in), - selective_dynamics(selective_dynamics_in), - relax_new(relax_new_in), - fixed_axes(fixed_axes_in), - lat0(lat0_in), - latvec(latvec_in), - elements(elements_in), - pp_files(pp_files_in), - pp_types(pp_types_in), - orb_files(orb_files_in), - natom(natom_in), - atomic_mass(atomic_mass_in), - coor_type(coor_type_in), - coordinates(coordinates_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 latvec_in, + std::vector elements_in, + std::vector pp_files_in, + std::vector pp_types_in, + std::vector orb_files_in, + std::valarray natom_in, + std::vector atomic_mass_in, + std::string coor_type_in, + std::valarray coordinates_in): + latname(latname_in), + lmaxmax(lmaxmax_in), + init_vel(init_vel_in), + selective_dynamics(selective_dynamics_in), + relax_new(relax_new_in), + fixed_axes(fixed_axes_in), + lat0(lat0_in), + latvec(latvec_in), + elements(elements_in), + pp_files(pp_files_in), + pp_types(pp_types_in), + orb_files(orb_files_in), + natom(natom_in), + atomic_mass(atomic_mass_in), + coor_type(coor_type_in), + coordinates(coordinates_in) { - mbl = std::valarray(0.0, coordinates_in.size()); - velocity = std::valarray(0.0, coordinates_in.size()); + mbl = std::valarray(0.0, coordinates_in.size()); + velocity = std::valarray(0.0, coordinates_in.size()); } UcellTestPrepare::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 latvec_in, - std::vector elements_in, - std::vector pp_files_in, - std::vector pp_types_in, - std::vector orb_files_in, - std::valarray natom_in, - std::vector atomic_mass_in, - std::string coor_type_in, - std::valarray coordinates_in, - std::valarray mbl_in, - std::valarray velocity_in): - latname(latname_in), - lmaxmax(lmaxmax_in), - init_vel(init_vel_in), - selective_dynamics(selective_dynamics_in), - relax_new(relax_new_in), - fixed_axes(fixed_axes_in), - lat0(lat0_in), - latvec(latvec_in), - elements(elements_in), - pp_files(pp_files_in), - pp_types(pp_types_in), - orb_files(orb_files_in), - natom(natom_in), - atomic_mass(atomic_mass_in), - coor_type(coor_type_in), - coordinates(coordinates_in), - mbl(mbl_in), - velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file() + 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 latvec_in, + std::vector elements_in, + std::vector pp_files_in, + std::vector pp_types_in, + std::vector orb_files_in, + std::valarray natom_in, + std::vector atomic_mass_in, + std::string coor_type_in, + std::valarray coordinates_in, + std::valarray mbl_in, + std::valarray velocity_in): + latname(latname_in), + lmaxmax(lmaxmax_in), + init_vel(init_vel_in), + selective_dynamics(selective_dynamics_in), + relax_new(relax_new_in), + fixed_axes(fixed_axes_in), + lat0(lat0_in), + latvec(latvec_in), + elements(elements_in), + pp_files(pp_files_in), + pp_types(pp_types_in), + orb_files(orb_files_in), + natom(natom_in), + atomic_mass(atomic_mass_in), + coor_type(coor_type_in), + coordinates(coordinates_in), + mbl(mbl_in), + velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file() {} UcellTestPrepare::UcellTestPrepare(const UcellTestPrepare &utp): - latname(utp.latname), - lmaxmax(utp.lmaxmax), - init_vel(utp.init_vel), - selective_dynamics(utp.selective_dynamics), - relax_new(utp.relax_new), - fixed_axes(utp.fixed_axes), - lat0(utp.lat0), - latvec(utp.latvec), - elements(utp.elements), - pp_files(utp.pp_files), - pp_types(utp.pp_types), - orb_files(utp.orb_files), - natom(utp.natom), - atomic_mass(utp.atomic_mass), - coor_type(utp.coor_type), - coordinates(utp.coordinates), - mbl(utp.mbl), - velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file() + latname(utp.latname), + lmaxmax(utp.lmaxmax), + init_vel(utp.init_vel), + selective_dynamics(utp.selective_dynamics), + relax_new(utp.relax_new), + fixed_axes(utp.fixed_axes), + lat0(utp.lat0), + latvec(utp.latvec), + elements(utp.elements), + pp_files(utp.pp_files), + pp_types(utp.pp_types), + orb_files(utp.orb_files), + natom(utp.natom), + atomic_mass(utp.atomic_mass), + coor_type(utp.coor_type), + coordinates(utp.coordinates), + mbl(utp.mbl), + velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file() {} std::map UcellTestLib { - {"Si", UcellTestPrepare( - "fcc", //latname - 2, //lmaxmax - true, //init_vel - true, //selective_dyanmics - true, //relax_new - "volume", //fixed_axes - 10.2, //lat0 - {-0.5,0.0,0.5, //latvec - 0.0,0.5,0.5, - -0.5,0.5,0.0}, - {"Si"}, //elements - {"Si.upf"}, //upf file - {"upf201"}, //upf types - {"Si.orb"}, //orb file - {2}, //number of each elements - {28.0}, //atomic mass - "Cartesian", //coordination type - {0.0,0.0,0.0, //atomic coordinates - 0.25,0.25,0.25})} + {"Si", UcellTestPrepare( + "fcc", //latname + 2, //lmaxmax + true, //init_vel + true, //selective_dyanmics + true, //relax_new + "volume", //fixed_axes + 10.2, //lat0 + {-0.5,0.0,0.5, //latvec + 0.0,0.5,0.5, + -0.5,0.5,0.0}, + {"Si"}, //elements + {"Si.upf"}, //upf file + {"upf201"}, //upf types + {"Si.orb"}, //orb file + {2}, //number of each elements + {28.0}, //atomic mass + "Cartesian", //coordination type + {0.0,0.0,0.0, //atomic coordinates + 0.25,0.25,0.25})} }; #endif diff --git a/source/source_cell/module_neighbor/test/sltk_atom_arrange_test.cpp b/source/source_cell/module_neighbor/test/sltk_atom_arrange_test.cpp index f2937ff0c7c..86e0d8b0f42 100644 --- a/source/source_cell/module_neighbor/test/sltk_atom_arrange_test.cpp +++ b/source/source_cell/module_neighbor/test/sltk_atom_arrange_test.cpp @@ -29,7 +29,7 @@ Magnetism::~Magnetism() * - atom_arrange::delete_vector(void) * - delete vector * - atom_arrange::set_sr_NL - * - set the sr: search radius including nonlocal beta + * - set the sr: search radius including nonlocal beta * - filter_adjs function * - filter AdjacentAtomInfo to the minimized adjacent atoms */ diff --git a/source/source_cell/module_symmetry/symm_analysis.cpp b/source/source_cell/module_symmetry/symm_analysis.cpp index af725c5a028..ea7de437bb4 100644 --- a/source/source_cell/module_symmetry/symm_analysis.cpp +++ b/source/source_cell/module_symmetry/symm_analysis.cpp @@ -11,20 +11,20 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, const double MULT_EPS = 2.0; ModuleBase::TITLE("Symmetry","analy_sys"); - ModuleBase::timer::start("Symmetry","analy_sys"); - - ofs_running << "\n\n"; - ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; - ofs_running << " | |" << std::endl; - ofs_running << " | #Symmetry Analysis# |" << std::endl; - ofs_running << " | We calculate the norm of 3 vectors and the angles between them, |" << std::endl; - ofs_running << " | the type of Bravais lattice is given. We can judge if the unticell |" << std::endl; - ofs_running << " | is a primitive cell. Finally we give the point group operation for |" << std::endl; - ofs_running << " | this unitcell. We use the point group operations to perform |" << std::endl; - ofs_running << " | symmetry analysis on given k-point mesh and the charge density. |" << std::endl; - ofs_running << " | |" << std::endl; - ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; - ofs_running << "\n"; + ModuleBase::timer::start("Symmetry","analy_sys"); + + ofs_running << "\n\n"; + ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; + ofs_running << " | |" << std::endl; + ofs_running << " | #Symmetry Analysis# |" << std::endl; + ofs_running << " | We calculate the norm of 3 vectors and the angles between them, |" << std::endl; + ofs_running << " | the type of Bravais lattice is given. We can judge if the unticell |" << std::endl; + ofs_running << " | is a primitive cell. Finally we give the point group operation for |" << std::endl; + ofs_running << " | this unitcell. We use the point group operations to perform |" << std::endl; + ofs_running << " | symmetry analysis on given k-point mesh and the charge density. |" << std::endl; + ofs_running << " | |" << std::endl; + ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; + ofs_running << "\n"; // -------------------------------- // 1. copy data and allocate memory @@ -46,21 +46,21 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, // atom positions // used in checksym. - newpos = new double[3*nat]; // positions of atoms before rotation + newpos = new double[3*nat]; // positions of atoms before rotation rotpos = new double[3*nat]; // positions of atoms after rotation - ModuleBase::GlobalFunc::ZEROS(newpos, 3*nat); + ModuleBase::GlobalFunc::ZEROS(newpos, 3*nat); ModuleBase::GlobalFunc::ZEROS(rotpos, 3*nat); this->a1 = lat.a1; this->a2 = lat.a2; this->a3 = lat.a3; - ModuleBase::Matrix3 latvec1; - latvec1.e11 = a1.x; latvec1.e12 = a1.y; latvec1.e13 = a1.z; - latvec1.e21 = a2.x; latvec1.e22 = a2.y; latvec1.e23 = a2.z; - latvec1.e31 = a3.x; latvec1.e32 = a3.y; latvec1.e33 = a3.z; + ModuleBase::Matrix3 latvec1; + latvec1.e11 = a1.x; latvec1.e12 = a1.y; latvec1.e13 = a1.z; + latvec1.e21 = a2.x; latvec1.e22 = a2.y; latvec1.e23 = a2.z; + latvec1.e31 = a3.x; latvec1.e32 = a3.y; latvec1.e33 = a3.z; - output::printM3(ofs_running,"LATTICE VECTORS: (CARTESIAN COORDINATE: IN UNIT OF A0)",latvec1); + output::printM3(ofs_running,"LATTICE VECTORS: (CARTESIAN COORDINATE: IN UNIT OF A0)",latvec1); istart[0] = 0; this->itmin_type = 0; @@ -85,55 +85,55 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, s3 = a3; - auto lattice_to_group = [&, this](int& nrot_out, int& nrotk_out, std::ofstream& ofs_running) -> void - { - // a: the optimized lattice vectors, output - // s: the input lattice vectors, input - // find the real_brav type accordiing to lattice vectors. - this->lattice_type(this->a1, this->a2, this->a3, this->s1, this->s2, this->s3, - this->cel_const, this->pre_const, this->real_brav, ilattname, atoms, true, this->newpos, symmetry_prec); - - ofs_running << " For optimal symmetric configuration:" << std::endl; - ModuleBase::GlobalFunc::OUT(ofs_running, "BRAVAIS TYPE", real_brav); - ModuleBase::GlobalFunc::OUT(ofs_running, "BRAVAIS LATTICE NAME", ilattname); - ModuleBase::GlobalFunc::OUT(ofs_running, "ibrav", real_brav); - Symm_Other::print1(real_brav, cel_const, ofs_running); - - optlat.e11 = a1.x; optlat.e12 = a1.y; optlat.e13 = a1.z; - optlat.e21 = a2.x; optlat.e22 = a2.y; optlat.e23 = a2.z; - optlat.e31 = a3.x; optlat.e32 = a3.y; optlat.e33 = a3.z; - - // count the number of primitive cells in the supercell - this->pricell(this->newpos, atoms); - - test_brav = true; // output the real ibrav and point group - - // list all possible point group operations - this->setgroup(this->symop, this->nop, this->real_brav, cal_symm_repr); - - // special case for AFM analysis - // which should be loop over all atoms, f.e only loop over spin-up atoms - // -------------------------------- - // AFM analysis Start - if (nspin > 1) - { - pricell_loop = this->magmom_same_check(atoms); - } - - if (!pricell_loop && nspin == 2) - { - this->analyze_magnetic_group(atoms, st, nrot_out, nrotk_out); - } - else - { - // get the real symmetry operations according to the input structure - // nrot_out: the number of pure point group rotations - // nrotk_out: the number of all space group operations - this->getgroup(nrot_out, nrotk_out, ofs_running, this->nop, this->symop, - this->gmatrix, this->gtrans, this->newpos, this->rotpos, this->index, - this->ntype, this->itmin_type, this->itmin_start, this->istart, this->na); - } - }; + auto lattice_to_group = [&, this](int& nrot_out, int& nrotk_out, std::ofstream& ofs_running) -> void + { + // a: the optimized lattice vectors, output + // s: the input lattice vectors, input + // find the real_brav type accordiing to lattice vectors. + this->lattice_type(this->a1, this->a2, this->a3, this->s1, this->s2, this->s3, + this->cel_const, this->pre_const, this->real_brav, ilattname, atoms, true, this->newpos, symmetry_prec); + + ofs_running << " For optimal symmetric configuration:" << std::endl; + ModuleBase::GlobalFunc::OUT(ofs_running, "BRAVAIS TYPE", real_brav); + ModuleBase::GlobalFunc::OUT(ofs_running, "BRAVAIS LATTICE NAME", ilattname); + ModuleBase::GlobalFunc::OUT(ofs_running, "ibrav", real_brav); + Symm_Other::print1(real_brav, cel_const, ofs_running); + + optlat.e11 = a1.x; optlat.e12 = a1.y; optlat.e13 = a1.z; + optlat.e21 = a2.x; optlat.e22 = a2.y; optlat.e23 = a2.z; + optlat.e31 = a3.x; optlat.e32 = a3.y; optlat.e33 = a3.z; + + // count the number of primitive cells in the supercell + this->pricell(this->newpos, atoms); + + test_brav = true; // output the real ibrav and point group + + // list all possible point group operations + this->setgroup(this->symop, this->nop, this->real_brav, cal_symm_repr); + + // special case for AFM analysis + // which should be loop over all atoms, f.e only loop over spin-up atoms + // -------------------------------- + // AFM analysis Start + if (nspin > 1) + { + pricell_loop = this->magmom_same_check(atoms); + } + + if (!pricell_loop && nspin == 2) + { + this->analyze_magnetic_group(atoms, st, nrot_out, nrotk_out); + } + else + { + // get the real symmetry operations according to the input structure + // nrot_out: the number of pure point group rotations + // nrotk_out: the number of all space group operations + this->getgroup(nrot_out, nrotk_out, ofs_running, this->nop, this->symop, + this->gmatrix, this->gtrans, this->newpos, this->rotpos, this->index, + this->ntype, this->itmin_type, this->itmin_start, this->istart, this->na); + } + }; // -------------------------------- // 2. analyze the symmetry @@ -179,10 +179,10 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, { this->nrotk = tmp_nrotk; ofs_running << " Find new symmtry operations during cell-relax." << std::endl; - if (this->nrotk > this->max_nrotk) - { - this->max_nrotk = this->nrotk; - } + if (this->nrotk > this->max_nrotk) + { + this->max_nrotk = this->nrotk; + } } if (eps_enlarged) { @@ -252,7 +252,7 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, //---------------------------------- // output the point group bool valid_group = this->pointgroup(this->nrot, this->pgnumber, this->pgname, this->gmatrix, ofs_running, cal_symm_repr); - ModuleBase::GlobalFunc::OUT(ofs_running,"POINT GROUP", this->pgname); + ModuleBase::GlobalFunc::OUT(ofs_running,"POINT GROUP", this->pgname); // output the space group valid_group = this->pointgroup(this->nrotk, this->spgnumber, this->spgname, this->gmatrix, ofs_running, cal_symm_repr); ModuleBase::GlobalFunc::OUT(ofs_running, "POINT GROUP IN SPACE GROUP", this->spgname); diff --git a/source/source_cell/module_symmetry/symm_check.cpp b/source/source_cell/module_symmetry/symm_check.cpp index bd51cf9c546..1e12cdeea21 100644 --- a/source/source_cell/module_symmetry/symm_check.cpp +++ b/source/source_cell/module_symmetry/symm_check.cpp @@ -2,15 +2,15 @@ using namespace ModuleSymmetry; bool Symmetry::checksym(const ModuleBase::Matrix3 &s, - ModuleBase::Vector3& gtrans, - double* pos, double* rotpos, int* index, - const int ntype, const int itmin_type, const int itmin_start, - int* istart, int* na)const + ModuleBase::Vector3& gtrans, + double* pos, double* rotpos, int* index, + const int ntype, const int itmin_type, const int itmin_start, + int* istart, int* na)const { - //---------------------------------------------- + //---------------------------------------------- // checks whether a point group symmetry element - // is a valid symmetry operation on a supercell - //---------------------------------------------- + // is a valid symmetry operation on a supercell + //---------------------------------------------- // the start atom index. bool no_diff = false; ModuleBase::Vector3 trans(2.0, 2.0, 2.0); @@ -18,10 +18,10 @@ bool Symmetry::checksym(const ModuleBase::Matrix3 &s, for (int it = 0; it < ntype; it++) { - //------------------------------------ + //------------------------------------ // impose periodic boundary condition - // 0.5 -> -0.5 - //------------------------------------ + // 0.5 -> -0.5 + //------------------------------------ for (int j = istart[it]; j < istart[it] + na[it]; ++j) { this->check_boundary(pos[j*3+0]); @@ -64,9 +64,9 @@ bool Symmetry::checksym(const ModuleBase::Matrix3 &s, ModuleBase::Vector3 diff; - //--------------------------------------------------------- + //--------------------------------------------------------- // itmin_start = the start atom positions of species itmin - //--------------------------------------------------------- + //--------------------------------------------------------- // (s)tart (p)osition of atom (t)ype which has (min)inal number. ModuleBase::Vector3 sptmin(rotpos[itmin_start * 3], rotpos[itmin_start * 3 + 1], rotpos[itmin_start * 3 + 2]); @@ -117,7 +117,7 @@ bool Symmetry::checksym(const ModuleBase::Matrix3 &s, diff.y = this->check_diff( pos[ia*3+1], rotpos[ia*3+1]); diff.z = this->check_diff( pos[ia*3+2], rotpos[ia*3+2]); //only if all "diff" are zero vectors, flag will remain "1" - if ( no_diff == false|| + if ( no_diff == false|| !equal(diff.x,0.0)|| !equal(diff.y,0.0)|| !equal(diff.z,0.0) @@ -127,7 +127,7 @@ bool Symmetry::checksym(const ModuleBase::Matrix3 &s, } } } - + //the current test is successful if (no_diff == true) { diff --git a/source/source_cell/module_symmetry/symm_getgroup.cpp b/source/source_cell/module_symmetry/symm_getgroup.cpp index 7c7085e6ed3..86c12e94782 100644 --- a/source/source_cell/module_symmetry/symm_getgroup.cpp +++ b/source/source_cell/module_symmetry/symm_getgroup.cpp @@ -2,18 +2,18 @@ using namespace ModuleSymmetry; void Symmetry::getgroup(int& nrot, int& nrotk, std::ofstream& ofs_running, - const int& nop, const ModuleBase::Matrix3* symop, ModuleBase::Matrix3* gmatrix, - ModuleBase::Vector3* gtrans, double* pos, double* rotpos, - int* index, const int ntype, const int itmin_type, - const int itmin_start, int* istart, int* na)const + const int& nop, const ModuleBase::Matrix3* symop, ModuleBase::Matrix3* gmatrix, + ModuleBase::Vector3* gtrans, double* pos, double* rotpos, + int* index, const int ntype, const int itmin_type, + const int itmin_start, int* istart, int* na)const { ModuleBase::TITLE("Symmetry", "getgroup"); - //-------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------- //return all possible space group operators that reproduce a lattice with basis //out of a (maximum) pool of point group operations that is compatible with //the symmetry of the pure translation lattice without any basic. - //-------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------- ModuleBase::Matrix3 zero(0,0,0,0,0,0,0,0,0); ModuleBase::Matrix3 help[48]; @@ -22,22 +22,22 @@ void Symmetry::getgroup(int& nrot, int& nrotk, std::ofstream& ofs_running, nrot = 0; nrotk = 0; - //------------------------------------------------------------------------- + //------------------------------------------------------------------------- //pass through the pool of (possibly allowed) symmetry operations and //check each operation whether it can reproduce the lattice with basis - //------------------------------------------------------------------------- + //------------------------------------------------------------------------- //std::cout << "nop = " <checksym(symop[i], gtrans[i], pos, rotpos, index, ntype, itmin_type, itmin_start, istart, na); if (s_flag == 1) { - //------------------------------ + //------------------------------ // this is a symmetry operation - // with no translation vectors + // with no translation vectors // so ,this is pure point group - // operations - //------------------------------ + // operations + //------------------------------ if ( equal(gtrans[i].x,0.0) && equal(gtrans[i].y,0.0) && equal(gtrans[i].z,0.0)) @@ -48,12 +48,12 @@ void Symmetry::getgroup(int& nrot, int& nrotk, std::ofstream& ofs_running, gtrans[nrot - 1].y = 0; gtrans[nrot - 1].z = 0; } - //------------------------------ + //------------------------------ // this is a symmetry operation - // with translation vectors + // with translation vectors // so ,this is space group - // operations - //------------------------------ + // operations + //------------------------------ else { ++nrotk; @@ -65,10 +65,10 @@ void Symmetry::getgroup(int& nrot, int& nrotk, std::ofstream& ofs_running, } } - //----------------------------------------------------- + //----------------------------------------------------- //If there are operations with nontrivial translations //then store them together in the momory - //----------------------------------------------------- + //----------------------------------------------------- if (nrotk > 0) { for (int i = 0; i < nrotk; ++i) @@ -80,20 +80,20 @@ void Symmetry::getgroup(int& nrot, int& nrotk, std::ofstream& ofs_running, } } - //----------------------------------------------------- + //----------------------------------------------------- //total number of space group operations - //----------------------------------------------------- + //----------------------------------------------------- nrotk += nrot; if(test_brav) { - ModuleBase::GlobalFunc::OUT(ofs_running,"PURE POINT GROUP OPERATIONS",nrot); + ModuleBase::GlobalFunc::OUT(ofs_running,"PURE POINT GROUP OPERATIONS",nrot); ModuleBase::GlobalFunc::OUT(ofs_running,"SPACE GROUP OPERATIONS",nrotk); } - //----------------------------------------------------- + //----------------------------------------------------- //fill the rest of matrices and vectors with zeros - //----------------------------------------------------- + //----------------------------------------------------- if (nrotk < 48) { for (int i = nrotk; i < 48; ++i) diff --git a/source/source_cell/module_symmetry/symm_hermite.cpp b/source/source_cell/module_symmetry/symm_hermite.cpp index 9eef65405e0..4b16c37a80e 100644 --- a/source/source_cell/module_symmetry/symm_hermite.cpp +++ b/source/source_cell/module_symmetry/symm_hermite.cpp @@ -2,8 +2,8 @@ using namespace ModuleSymmetry; void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, - ModuleBase::Matrix3 &h3, - ModuleBase::Matrix3 &b3) const + ModuleBase::Matrix3 &h3, + ModuleBase::Matrix3 &b3) const { ModuleBase::TITLE("Symmetry","hermite_normal_form"); // check the non-singularity and integer elements of s @@ -11,17 +11,17 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, assert(!equal(s3.Det(), 0.0)); #endif - auto near_equal = [this](double x, double y) - { - return fabs(x - y) < 10 * epsilon; - }; + auto near_equal = [this](double x, double y) + { + return fabs(x - y) < 10 * epsilon; + }; ModuleBase::matrix s = s3.to_matrix(); - for (int i = 0; i < 3; ++i) - { - for (int j = 0;j < 3;++j) - { + for (int i = 0; i < 3; ++i) + { + for (int j = 0;j < 3;++j) + { double sij_round = std::round(s(i, j)); #ifdef __DEBUG assert(near_equal(s(i, j), sij_round)); @@ -54,15 +54,15 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, imax=0; imin=2; max_min_index(0, imid, imin); max_min_index(0, imax, imid); - max_min_index(0, imid, imin); - if (equal(h(0, imin), 0)) - { - imin = imid; - } - else if (equal(h(0, imax), 0)) - { - imax = imid; - } + max_min_index(0, imid, imin); + if (equal(h(0, imin), 0)) + { + imin = imid; + } + else if (equal(h(0, imax), 0)) + { + imax = imid; + } return; }; @@ -89,36 +89,36 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, { max_min_index_row1(imax, imin); double f = floor((fabs(h(0, imax) )+ epsilon)/fabs(h(0, imin))); - if (h(0, imax) * h(0, imin) < -epsilon) - { - f *= -1; - } - for(int r=0;r<3;++r) - { - h(r, imax) -= f*h(r, imin); - b(r, imax) -= f*b(r, imin); - } + if (h(0, imax) * h(0, imin) < -epsilon) + { + f *= -1; + } + for(int r=0;r<3;++r) + { + h(r, imax) -= f*h(r, imin); + b(r, imax) -= f*b(r, imin); + } } - if (equal(h(0, 0), 0)) - { - equal(h(0, 1), 0) ? swap_col(0, 2) : swap_col(0, 1); - } + if (equal(h(0, 0), 0)) + { + equal(h(0, 1), 0) ? swap_col(0, 2) : swap_col(0, 1); + } - if (h(0, 0) < -epsilon) - { - for (int r = 0; r < 3; ++r) - { - h(r, 0) *= -1; + if (h(0, 0) < -epsilon) + { + for (int r = 0; r < 3; ++r) + { + h(r, 0) *= -1; b(r, 0) *= -1; } } //row 2 - if (equal(h(1, 1), 0)) - { - swap_col(1, 2); - } + if (equal(h(1, 1), 0)) + { + swap_col(1, 2); + } while(!equal(h(1, 2), 0)) { @@ -126,26 +126,26 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, max_min_index(1, imax, imin); double f = floor((fabs(h(1, imax) )+ epsilon)/fabs(h(1, imin))); - if (h(1, imax) * h(1, imin) < -epsilon) - { - f *= -1; - } - - for(int r=0;r<3;++r) - { - h(r, imax) -= f*h(r, imin); - b(r, imax) -= f*b(r, imin); - } - - if (equal(h(1, 1), 0)) - { - swap_col(1, 2); - } + if (h(1, imax) * h(1, imin) < -epsilon) + { + f *= -1; + } + + for(int r=0;r<3;++r) + { + h(r, imax) -= f*h(r, imin); + b(r, imax) -= f*b(r, imin); + } + + if (equal(h(1, 1), 0)) + { + swap_col(1, 2); + } } - if (h(1, 1) < -epsilon) - { - for (int r = 0; r < 3; ++r) - { + if (h(1, 1) < -epsilon) + { + for (int r = 0; r < 3; ++r) + { h(r, 1) *= -1; b(r, 1) *= -1; } @@ -153,48 +153,48 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, //row3 if (h(2, 2) < -epsilon) - { - for (int r = 0; r < 3; ++r) - { - h(r, 2) *= -1; + { + for (int r = 0; r < 3; ++r) + { + h(r, 2) *= -1; b(r, 2) *= -1; } } // deal with off-diagonal elements - while (h(1, 0) > h(1, 1) - epsilon) - { - for(int r=0;r<3;++r) - { - h(r, 0) -= h(r, 1); - b(r, 0) -= b(r, 1); - } - } - while (h(1, 0) < -epsilon) - { - for(int r=0;r<3;++r) - { - h(r, 0) += h(r, 1); - b(r, 0) += b(r, 1); - } - } + while (h(1, 0) > h(1, 1) - epsilon) + { + for(int r=0;r<3;++r) + { + h(r, 0) -= h(r, 1); + b(r, 0) -= b(r, 1); + } + } + while (h(1, 0) < -epsilon) + { + for(int r=0;r<3;++r) + { + h(r, 0) += h(r, 1); + b(r, 0) += b(r, 1); + } + } for(int j=0;j<2;++j) { - while (h(2, j) > h(2, 2) - epsilon) - { - for(int r=0;r<3;++r) - { - h(r, j) -= h(r, 2); - b(r, j) -= b(r, 2); - } - } - while (h(2, j) < -epsilon) - { - for(int r=0;r<3;++r) - { - h(r, j) += h(r, 2); - b(r, j) += b(r, 2); - } + while (h(2, j) > h(2, 2) - epsilon) + { + for(int r=0;r<3;++r) + { + h(r, j) -= h(r, 2); + b(r, j) -= b(r, 2); + } + } + while (h(2, j) < -epsilon) + { + for(int r=0;r<3;++r) + { + h(r, j) += h(r, 2); + b(r, j) += b(r, 2); + } } } @@ -209,13 +209,13 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, //check s*b=h ModuleBase::matrix check_zeros = s3.to_matrix() * b - h; #ifdef __DEBUG - for (int i = 0;i < 3;++i) - { - for(int j=0;j<3;++j) - { - assert(near_equal(check_zeros(i, j), 0)); - } - } + for (int i = 0;i < 3;++i) + { + for(int j=0;j<3;++j) + { + assert(near_equal(check_zeros(i, j), 0)); + } + } #endif return; } diff --git a/source/source_cell/module_symmetry/symm_lattice.cpp b/source/source_cell/module_symmetry/symm_lattice.cpp index e14455486a4..58bd6b10ffd 100644 --- a/source/source_cell/module_symmetry/symm_lattice.cpp +++ b/source/source_cell/module_symmetry/symm_lattice.cpp @@ -17,10 +17,10 @@ int Symmetry::standard_lat( static bool first = true; // there are only 14 types of Bravais lattice. int type = 15; - //---------------------------------------------------- + //---------------------------------------------------- // used to calculte the volume to judge whether - // the lattice vectors corrispond the right-hand-sense - //---------------------------------------------------- + // the lattice vectors corrispond the right-hand-sense + //---------------------------------------------------- double volume = 0; //the lattice vectors have not been changed @@ -36,18 +36,18 @@ int Symmetry::standard_lat( double gamma = ab /( norm_a * norm_b ); // cos(gamma) double alpha = bc /( norm_b * norm_c ); // cos(alpha) double beta = ca /( norm_a * norm_c ); // cos(beta) - double amb = sqrt( aa + bb - 2 * ab ); //amb = |a - b| + double amb = sqrt( aa + bb - 2 * ab ); //amb = |a - b| double bmc = sqrt( bb + cc - 2 * bc ); double cma = sqrt( cc + aa - 2 * ca ); double apb = sqrt( aa + bb + 2 * ab ); //amb = |a + b| double bpc = sqrt( bb + cc + 2 * bc ); double cpa = sqrt( cc + aa + 2 * ca ); - double apbmc = sqrt( aa + bb + cc + 2 * ab - 2 * bc - 2 * ca ); //apbmc = |a + b - c| + double apbmc = sqrt( aa + bb + cc + 2 * ab - 2 * bc - 2 * ca ); //apbmc = |a + b - c| double bpcma = sqrt( bb + cc + aa + 2 * bc - 2 * ca - 2 * ab ); double cpamb = sqrt( cc + aa + bb + 2 * ca - 2 * ab - 2 * bc ); double abc = ab + bc + ca; - if (first) + if (first) { ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"NORM_A",norm_a); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"NORM_B",norm_b); @@ -59,217 +59,217 @@ int Symmetry::standard_lat( } Symm_Other::right_hand_sense(a, b, c); - ModuleBase::GlobalFunc::ZEROS(cel_const, 6); - const double small = symmetry_prec; + ModuleBase::GlobalFunc::ZEROS(cel_const, 6); + const double small = symmetry_prec; - //--------------------------- - // 1. alpha == beta == gamma - //--------------------------- - if( equal(alpha, gamma) && equal(alpha, beta) ) - { - //-------------- - // a == b == c - //-------------- - if( equal(norm_a, norm_b) && equal(norm_b, norm_c)) - { - //--------------------------------------- - // alpha == beta == gamma == 90 degree - //--------------------------------------- - if ( equal(alpha,0.0) ) - { - type=1; - cel_const[0]=norm_a; - } - //---------------------------------------- - // cos(alpha) = -1.0/3.0 - //---------------------------------------- - else if( equal(alpha, -1.0/3.0) ) - { - type=2; - cel_const[0]=norm_a*2.0/sqrt(3.0); - } - //---------------------------------------- - // cos(alpha) = 0.5 - //---------------------------------------- - else if( equal(alpha, 0.5) ) - { - type=3; - cel_const[0]=norm_a*sqrt(2.0); - } - //---------------------------------------- - // cos(alpha) = all the others - //---------------------------------------- - else - { - type=7; - cel_const[0]=norm_a; - cel_const[3]=alpha; - } - } - // Crystal classes with inequal length of lattice vectors but also with - // A1*A2=A1*A3=A2*A3: - // Orthogonal axes: - else if(equal(gamma,0.0)) - { - // Two axes with equal lengths means simple tetragonal: (IBRAV=5) - // Adjustment: 'c-axis' shall be the special axis. - if (equal(norm_a, norm_b)) - { - type=5; - cel_const[0]=norm_a; - cel_const[2]=norm_c/norm_a; - // No axes with equal lengths means simple orthorhombic (IBRAV=8): - // Adjustment: Sort the axis by increasing lengths: - } + //--------------------------- + // 1. alpha == beta == gamma + //--------------------------- + if( equal(alpha, gamma) && equal(alpha, beta) ) + { + //-------------- + // a == b == c + //-------------- + if( equal(norm_a, norm_b) && equal(norm_b, norm_c)) + { + //--------------------------------------- + // alpha == beta == gamma == 90 degree + //--------------------------------------- + if ( equal(alpha,0.0) ) + { + type=1; + cel_const[0]=norm_a; + } + //---------------------------------------- + // cos(alpha) = -1.0/3.0 + //---------------------------------------- + else if( equal(alpha, -1.0/3.0) ) + { + type=2; + cel_const[0]=norm_a*2.0/sqrt(3.0); + } + //---------------------------------------- + // cos(alpha) = 0.5 + //---------------------------------------- + else if( equal(alpha, 0.5) ) + { + type=3; + cel_const[0]=norm_a*sqrt(2.0); + } + //---------------------------------------- + // cos(alpha) = all the others + //---------------------------------------- + else + { + type=7; + cel_const[0]=norm_a; + cel_const[3]=alpha; + } + } + // Crystal classes with inequal length of lattice vectors but also with + // A1*A2=A1*A3=A2*A3: + // Orthogonal axes: + else if(equal(gamma,0.0)) + { + // Two axes with equal lengths means simple tetragonal: (IBRAV=5) + // Adjustment: 'c-axis' shall be the special axis. + if (equal(norm_a, norm_b)) + { + type=5; + cel_const[0]=norm_a; + cel_const[2]=norm_c/norm_a; + // No axes with equal lengths means simple orthorhombic (IBRAV=8): + // Adjustment: Sort the axis by increasing lengths: + } else if(((norm_c-norm_b)>small) && ((norm_b-norm_a)>small) ) - { - type=8; - cel_const[0]=norm_a; - cel_const[1]=norm_b/norm_a; - cel_const[2]=norm_c/norm_a; - } - // Crystal classes with A1*A3=A2*A3=/A1*A2: - } - }//end alpha=beta=gamma - //----------------------- - // TWO EQUAL ANGLES - // alpha == beta != gamma (gamma is special) - //------------------------ - else if (equal(alpha-beta, 0)) - { - //--------------------------------------------------------- - // alpha = beta = 90 degree - // One axis orthogonal with respect to the other two axes: - //--------------------------------------------------------- - if (equal(alpha, 0.0)) - { - //----------------------------------------------- - // a == b - // Equal length of the two nonorthogonal axes: - //----------------------------------------------- - if (equal(norm_a, norm_b)) - { - // Cosine(alpha) equal to -1/2 means hexagonal: (IBRAV=4) - // Adjustment: 'c-axis' shall be the special axis. - if ( equal(gamma, -0.5)) //gamma = 120 degree - { - type=4; - cel_const[0]=norm_a; - cel_const[2]=norm_c/norm_a; - // Other angles mean base-centered orthorhombic: (IBRAV=11) - // Adjustment: Cosine between A1 and A2 shall be lower than zero, the - // 'c-axis' shall be the special axis. - } - else if(gamma<(-1.0*small)) //gamma > 90 degree - { - type=11; + { + type=8; + cel_const[0]=norm_a; + cel_const[1]=norm_b/norm_a; + cel_const[2]=norm_c/norm_a; + } + // Crystal classes with A1*A3=A2*A3=/A1*A2: + } + }//end alpha=beta=gamma + //----------------------- + // TWO EQUAL ANGLES + // alpha == beta != gamma (gamma is special) + //------------------------ + else if (equal(alpha-beta, 0)) + { + //--------------------------------------------------------- + // alpha = beta = 90 degree + // One axis orthogonal with respect to the other two axes: + //--------------------------------------------------------- + if (equal(alpha, 0.0)) + { + //----------------------------------------------- + // a == b + // Equal length of the two nonorthogonal axes: + //----------------------------------------------- + if (equal(norm_a, norm_b)) + { + // Cosine(alpha) equal to -1/2 means hexagonal: (IBRAV=4) + // Adjustment: 'c-axis' shall be the special axis. + if ( equal(gamma, -0.5)) //gamma = 120 degree + { + type=4; + cel_const[0]=norm_a; + cel_const[2]=norm_c/norm_a; + // Other angles mean base-centered orthorhombic: (IBRAV=11) + // Adjustment: Cosine between A1 and A2 shall be lower than zero, the + // 'c-axis' shall be the special axis. + } + else if(gamma<(-1.0*small)) //gamma > 90 degree + { + type=11; cel_const[0]=apb; cel_const[1]=amb/apb; cel_const[2]=norm_c/apb; cel_const[5]=gamma; - } - // Different length of the two axes means simple monoclinic (IBRAV=12): - // Adjustment: Cosine(gamma) should be lower than zero, special axis - // shall be the 'b-axis'(!!!) and |A1|<|A3|: - } - //---------- - // a!=b!=c - //---------- + } + // Different length of the two axes means simple monoclinic (IBRAV=12): + // Adjustment: Cosine(gamma) should be lower than zero, special axis + // shall be the 'b-axis'(!!!) and |A1|<|A3|: + } + //---------- + // a!=b!=c + //---------- else if( gamma<(-1.0*small) && (norm_a-norm_b)>small) - { - type=12; - cel_const[0]=norm_b; - cel_const[1]=norm_c/norm_b; - cel_const[2]=norm_a/norm_b; + { + type=12; + cel_const[0]=norm_b; + cel_const[1]=norm_c/norm_b; + cel_const[2]=norm_a/norm_b; cel_const[4]=gamma; //adjust: a->c, b->a, c->b ModuleBase::Vector3 tmp=c; - c=a; - a=b; - b=tmp; - } - }//end gamma) cel_const[4]=(a+b)*c/apb/norm_c; - } - } - } //end alpha==beta - //------------------------------- - // three angles are not equal - //------------------------------- - else - { - // Crystal classes with A1*A2=/A1*A3=/A2*A3 - // |A1|=|A2|=|A3| means body-centered orthorhombic (IBRAV=9): - // Further additional criterions are: (A1+A2), (A1+A3) and (A2+A3) are - // orthogonal to one another and (adjustment//): |A1+A2|>|A1+A3|>|A2+A3| - if (equal(norm_a, norm_b) && - equal(norm_b, norm_c) && - ((cpa-bpc)>small) && - ((apb-cpa)>small) && - equal(norm_c*norm_c+abc, 0)) - { - type=9; - cel_const[0]=bpc; - cel_const[1]=cpa/bpc; - cel_const[2]=apb/bpc; - } - // |A1|=|A2-A3| and |A2|=|A1-A3| and |A3|=|A1-A2| means face-centered - // orthorhombic (IBRAV=10): - // Adjustment: |A1+A2-A3|>|A1+A3-A2|>|A2+A3-A1| - else if(equal(amb, norm_c) && - equal(cma, norm_b) && - equal(bmc, norm_a) && - ((apbmc-cpamb)>small) && - ((cpamb-bpcma)>small)) - { - type=10; - cel_const[0]=bpcma; - cel_const[1]=cpamb/bpcma; - cel_const[2]=apbmc/bpcma; - } - // Now there exists only one further possibility - triclinic (IBRAV=14): - // Adjustment: All three cosines shall be greater than zero and ordered: - else if((gamma>beta) && (beta>alpha) && (alpha>small)) - { - type=14; - cel_const[0]=norm_a; - cel_const[1]=norm_b/norm_a; - cel_const[2]=norm_c/norm_a; - cel_const[3]=alpha; - cel_const[4]=beta; - cel_const[5]=gamma; - } - } - - return type; + } + } + } //end alpha==beta + //------------------------------- + // three angles are not equal + //------------------------------- + else + { + // Crystal classes with A1*A2=/A1*A3=/A2*A3 + // |A1|=|A2|=|A3| means body-centered orthorhombic (IBRAV=9): + // Further additional criterions are: (A1+A2), (A1+A3) and (A2+A3) are + // orthogonal to one another and (adjustment//): |A1+A2|>|A1+A3|>|A2+A3| + if (equal(norm_a, norm_b) && + equal(norm_b, norm_c) && + ((cpa-bpc)>small) && + ((apb-cpa)>small) && + equal(norm_c*norm_c+abc, 0)) + { + type=9; + cel_const[0]=bpc; + cel_const[1]=cpa/bpc; + cel_const[2]=apb/bpc; + } + // |A1|=|A2-A3| and |A2|=|A1-A3| and |A3|=|A1-A2| means face-centered + // orthorhombic (IBRAV=10): + // Adjustment: |A1+A2-A3|>|A1+A3-A2|>|A2+A3-A1| + else if(equal(amb, norm_c) && + equal(cma, norm_b) && + equal(bmc, norm_a) && + ((apbmc-cpamb)>small) && + ((cpamb-bpcma)>small)) + { + type=10; + cel_const[0]=bpcma; + cel_const[1]=cpamb/bpcma; + cel_const[2]=apbmc/bpcma; + } + // Now there exists only one further possibility - triclinic (IBRAV=14): + // Adjustment: All three cosines shall be greater than zero and ordered: + else if((gamma>beta) && (beta>alpha) && (alpha>small)) + { + type=14; + cel_const[0]=norm_a; + cel_const[1]=norm_b/norm_a; + cel_const[2]=norm_c/norm_a; + cel_const[3]=alpha; + cel_const[4]=beta; + cel_const[5]=gamma; + } + } + + return type; } //--------------------------------------------------- @@ -298,26 +298,26 @@ void Symmetry::lattice_type( { ModuleBase::TITLE("Symmetry","lattice_type"); - //---------------------------------------------- - // (1) adjustement of the basis to right hand - // sense by inversion of all three lattice - // vectors if necessary - //---------------------------------------------- + //---------------------------------------------- + // (1) adjustement of the basis to right hand + // sense by inversion of all three lattice + // vectors if necessary + //---------------------------------------------- const bool right = Symm_Other::right_hand_sense(v1, v2, v3); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Right-handed lattice",right); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Right-handed lattice",right); - //------------------------------------------------- - // (2) save and copy the original lattice vectors. - //------------------------------------------------- + //------------------------------------------------- + // (2) save and copy the original lattice vectors. + //------------------------------------------------- v01 = v1; v02 = v2; v03 = v3; - - //-------------------------------------------- - // (3) calculate the 'pre_const' - //-------------------------------------------- - ModuleBase::GlobalFunc::ZEROS(pre_const, 6); + + //-------------------------------------------- + // (3) calculate the 'pre_const' + //-------------------------------------------- + ModuleBase::GlobalFunc::ZEROS(pre_const, 6); int pre_brav = standard_lat(v1, v2, v3, cel_const, symmetry_prec); @@ -343,7 +343,7 @@ void Symmetry::lattice_type( //now, the highest symmetry of the combination of the shortest vectors has been found //then we compare it with the original symmetry - + bool change_flag=false; for (int i = 0; i < 6; ++i) { if(!equal(cel_const[i], pre_const[i])) @@ -369,24 +369,24 @@ void Symmetry::lattice_type( int at=0; for (int it = 0; it < this->ntype; ++it) { - for (int ia = 0; ia < this->na[it]; ++ia) - { - ModuleBase::Mathzone::Cartesian_to_Direct(atoms[it].tau[ia].x, - atoms[it].tau[ia].y, - atoms[it].tau[ia].z, - q1.x, q1.y, q1.z, - q2.x, q2.y, q2.z, - q3.x, q3.y, q3.z, - newpos[3*at],newpos[3*at+1],newpos[3*at+2]); + for (int ia = 0; ia < this->na[it]; ++ia) + { + ModuleBase::Mathzone::Cartesian_to_Direct(atoms[it].tau[ia].x, + atoms[it].tau[ia].y, + atoms[it].tau[ia].z, + q1.x, q1.y, q1.z, + q2.x, q2.y, q2.z, + q3.x, q3.y, q3.z, + newpos[3*at],newpos[3*at+1],newpos[3*at+2]); - for(int k=0; k<3; ++k) - { - this->check_translation( newpos[at*3+k], -floor(newpos[at*3+k])); - this->check_boundary( newpos[at*3+k] ); - } - ++at; - } - } + for(int k=0; k<3; ++k) + { + this->check_translation( newpos[at*3+k], -floor(newpos[at*3+k])); + this->check_boundary( newpos[at*3+k] ); + } + ++at; + } + } } // return the optimized lattice in v1, v2, v3 v1=q1; @@ -429,7 +429,7 @@ void Symmetry::lattice_type( /* bool flag3; if (pre_brav == temp_brav) - { + { flag3 = 0; if (!equal(temp_const[0], pre_const[0]) || !equal(temp_const[1], pre_const[1]) || @@ -447,8 +447,8 @@ void Symmetry::lattice_type( v1 = s1; v2 = s2; v3 = s3; - change=0; - GlobalV::ofs_running<<" The lattice vectors have been set back!"< mag_istart(mag_type_atoms.size()); std::vector mag_na(mag_type_atoms.size()); std::vector mag_pos; - int mag_itmin_type = 0; - int mag_itmin_start = 0; - for (int mag_it = 0;mag_it < mag_type_atoms.size(); ++mag_it) - { - mag_na[mag_it] = mag_type_atoms.at(mag_it).size(); - if (mag_it > 0) - { - mag_istart[mag_it] = mag_istart[mag_it - 1] + mag_na[mag_it - 1]; - } - if (mag_na[mag_it] < mag_na[itmin_type]) - { - mag_itmin_type = mag_it; - mag_itmin_start = mag_istart[mag_it]; - } - for (auto& mag_iat : mag_type_atoms.at(mag_it)) - { - // this->newpos have been ordered by original structure(ntype, na), it cannot be directly used here. - // we need to reset the calculate again the coordinate of the new structure. - const ModuleBase::Vector3 direct_tmp = atoms[st.iat2it[mag_iat]].tau[st.iat2ia[mag_iat]] * this->optlat.Inverse(); - std::array direct = { direct_tmp.x, direct_tmp.y, direct_tmp.z }; - for (int i = 0; i < 3; ++i) - { - this->check_translation(direct[i], -floor(direct[i])); - this->check_boundary(direct[i]); - mag_pos.push_back(direct[i]); - } - } - } + int mag_itmin_type = 0; + int mag_itmin_start = 0; + for (int mag_it = 0;mag_it < mag_type_atoms.size(); ++mag_it) + { + mag_na[mag_it] = mag_type_atoms.at(mag_it).size(); + if (mag_it > 0) + { + mag_istart[mag_it] = mag_istart[mag_it - 1] + mag_na[mag_it - 1]; + } + if (mag_na[mag_it] < mag_na[itmin_type]) + { + mag_itmin_type = mag_it; + mag_itmin_start = mag_istart[mag_it]; + } + for (auto& mag_iat : mag_type_atoms.at(mag_it)) + { + // this->newpos have been ordered by original structure(ntype, na), it cannot be directly used here. + // we need to reset the calculate again the coordinate of the new structure. + const ModuleBase::Vector3 direct_tmp = atoms[st.iat2it[mag_iat]].tau[st.iat2ia[mag_iat]] * this->optlat.Inverse(); + std::array direct = { direct_tmp.x, direct_tmp.y, direct_tmp.z }; + for (int i = 0; i < 3; ++i) + { + this->check_translation(direct[i], -floor(direct[i])); + this->check_boundary(direct[i]); + mag_pos.push_back(direct[i]); + } + } + } - // 3. analyze the effective structure - this->getgroup(nrot_out, nrotk_out, GlobalV::ofs_running, - this->nop, this->symop, this->gmatrix, - this->gtrans, mag_pos.data(), this->rotpos, - this->index, mag_type_atoms.size(), mag_itmin_type, - mag_itmin_start, mag_istart.data(), mag_na.data()); + // 3. analyze the effective structure + this->getgroup(nrot_out, nrotk_out, GlobalV::ofs_running, + this->nop, this->symop, this->gmatrix, + this->gtrans, mag_pos.data(), this->rotpos, + this->index, mag_type_atoms.size(), mag_itmin_type, + mag_itmin_start, mag_istart.data(), mag_na.data()); } diff --git a/source/source_cell/module_symmetry/symm_other.cpp b/source/source_cell/module_symmetry/symm_other.cpp index 1b7e09c02af..fffe90b812b 100644 --- a/source/source_cell/module_symmetry/symm_other.cpp +++ b/source/source_cell/module_symmetry/symm_other.cpp @@ -4,129 +4,129 @@ namespace ModuleSymmetry { void Symm_Other::print1(const int &ibrav, const double *cel_const, std::ofstream &ofs_running) { - ModuleBase::TITLE("Symm_Other","print1"); + ModuleBase::TITLE("Symm_Other","print1"); - ModuleBase::GlobalFunc::OUT(ofs_running,"IBRAV",ibrav); - if(ibrav==1) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","SIMPLE CUBIC"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - } - else if(ibrav==2) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BODY CENTERED CUBIC"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - } - else if(ibrav==3) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","FACE CENTERED CUBIC"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - } - else if(ibrav==4) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","HEXAGONAL CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - } - else if(ibrav==5) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","SIMPLE TETROGONAL CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - } - else if(ibrav==6) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BODY CENTERED TETROGONAL CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - } - else if(ibrav==7) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","TRIGONAL (RHOMBOEDRIC) CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"COS(ALPHA)",cel_const[3]); - } - else if(ibrav==8) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","SIMPLE ORTHORHOMBIC CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - } - else if(ibrav==9) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BODY CENTERED ORTHORHOMBIC CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - } - else if(ibrav==10) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","FACE CENTERED ORTHORHOMBIC CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - } - else if(ibrav==11) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BASE CENTERED ORTHORHOMBIC CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - } - else if(ibrav==12) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","SIMPLE MONOLINIC CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - ModuleBase::GlobalFunc::OUT(ofs_running,"COS(BETA)",cel_const[4]); - } - else if(ibrav==13) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BASE CENTERED MONOLINIC CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - ModuleBase::GlobalFunc::OUT(ofs_running,"COS(BETA)",cel_const[4]); - } - else if(ibrav==14) - { - ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","TRICLINIC CELL"); - ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); - ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); - ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); - ModuleBase::GlobalFunc::OUT(ofs_running,"COS(ALPHA)",cel_const[3]); - ModuleBase::GlobalFunc::OUT(ofs_running,"COS(BETA)",cel_const[4]); - ModuleBase::GlobalFunc::OUT(ofs_running,"COS(GAMMA)",cel_const[5]); - } - else - { - ModuleBase::WARNING_QUIT("Symm_Other::print1","ibrav is wrong."); - } - return; + ModuleBase::GlobalFunc::OUT(ofs_running,"IBRAV",ibrav); + if(ibrav==1) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","SIMPLE CUBIC"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + } + else if(ibrav==2) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BODY CENTERED CUBIC"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + } + else if(ibrav==3) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","FACE CENTERED CUBIC"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + } + else if(ibrav==4) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","HEXAGONAL CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + } + else if(ibrav==5) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","SIMPLE TETROGONAL CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + } + else if(ibrav==6) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BODY CENTERED TETROGONAL CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + } + else if(ibrav==7) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","TRIGONAL (RHOMBOEDRIC) CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"COS(ALPHA)",cel_const[3]); + } + else if(ibrav==8) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","SIMPLE ORTHORHOMBIC CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + } + else if(ibrav==9) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BODY CENTERED ORTHORHOMBIC CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + } + else if(ibrav==10) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","FACE CENTERED ORTHORHOMBIC CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + } + else if(ibrav==11) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BASE CENTERED ORTHORHOMBIC CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + } + else if(ibrav==12) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","SIMPLE MONOLINIC CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + ModuleBase::GlobalFunc::OUT(ofs_running,"COS(BETA)",cel_const[4]); + } + else if(ibrav==13) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","BASE CENTERED MONOLINIC CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + ModuleBase::GlobalFunc::OUT(ofs_running,"COS(BETA)",cel_const[4]); + } + else if(ibrav==14) + { + ModuleBase::GlobalFunc::OUT(ofs_running,"BRAVAIS","TRICLINIC CELL"); + ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]); + ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]); + ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]); + ModuleBase::GlobalFunc::OUT(ofs_running,"COS(ALPHA)",cel_const[3]); + ModuleBase::GlobalFunc::OUT(ofs_running,"COS(BETA)",cel_const[4]); + ModuleBase::GlobalFunc::OUT(ofs_running,"COS(GAMMA)",cel_const[5]); + } + else + { + ModuleBase::WARNING_QUIT("Symm_Other::print1","ibrav is wrong."); + } + return; } bool Symm_Other::right_hand_sense(ModuleBase::Vector3 &v1,ModuleBase::Vector3 &v2,ModuleBase::Vector3 &v3) { - double volume = Symm_Other::celvol(v1,v2,v3); - //OUT(ofs_running,"volume = ",volume); - if(volume < 0) - { - v1.reverse(); - v2.reverse(); - v3.reverse(); - return false; - } - return true; + double volume = Symm_Other::celvol(v1,v2,v3); + //OUT(ofs_running,"volume = ",volume); + if(volume < 0) + { + v1.reverse(); + v2.reverse(); + v3.reverse(); + return false; + } + return true; } //calculate the volume of the cell spanned by the vectors double Symm_Other::celvol(const ModuleBase::Vector3 &a, const ModuleBase::Vector3 &b, const ModuleBase::Vector3 &c) { - return a.x * ( b.y * c.z - b.z * c.y ) + a.y * ( b.z * c.x - b.x * c.z ) - + a.z * ( b.x * c.y - b.y * c.x ); + return a.x * ( b.y * c.z - b.z * c.y ) + a.y * ( b.z * c.x - b.x * c.z ) + + a.z * ( b.x * c.y - b.y * c.x ); } } diff --git a/source/source_cell/module_symmetry/symm_other.h b/source/source_cell/module_symmetry/symm_other.h index a2295ded183..19ac32a68ed 100644 --- a/source/source_cell/module_symmetry/symm_other.h +++ b/source/source_cell/module_symmetry/symm_other.h @@ -7,12 +7,12 @@ namespace ModuleSymmetry { namespace Symm_Other { - void print1(const int &ibrav, const double *cel_const, std::ofstream &ofs_running); + void print1(const int &ibrav, const double *cel_const, std::ofstream &ofs_running); - bool right_hand_sense(ModuleBase::Vector3 &v1,ModuleBase::Vector3 &v2,ModuleBase::Vector3 &v3); + bool right_hand_sense(ModuleBase::Vector3 &v1,ModuleBase::Vector3 &v2,ModuleBase::Vector3 &v3); - double celvol(const ModuleBase::Vector3 &a, - const ModuleBase::Vector3 &b, const ModuleBase::Vector3 &c); + double celvol(const ModuleBase::Vector3 &a, + const ModuleBase::Vector3 &b, const ModuleBase::Vector3 &c); } diff --git a/source/source_cell/module_symmetry/symm_pricell.cpp b/source/source_cell/module_symmetry/symm_pricell.cpp index ae380201e0c..cd1eb40bad0 100644 --- a/source/source_cell/module_symmetry/symm_pricell.cpp +++ b/source/source_cell/module_symmetry/symm_pricell.cpp @@ -8,10 +8,10 @@ void Symmetry::pricell(double* pos, const Atom* atoms) for (int it = 0; it < ntype; it++) { - //------------------------------------ + //------------------------------------ // impose periodic boundary condition - // 0.5 -> -0.5 - //------------------------------------ + // 0.5 -> -0.5 + //------------------------------------ for (int j = istart[it]; j < istart[it] + na[it]; ++j) { this->check_boundary(pos[j*3+0]); @@ -36,7 +36,7 @@ void Symmetry::pricell(double* pos, const Atom* atoms) ModuleBase::Vector3 diff; double tmp_ptrans[3]; - //--------------------------------------------------------- + //--------------------------------------------------------- // itmin_start = the start atom positions of species itmin //--------------------------------------------------------- // (s)tart (p)osition of atom (t)ype which has (min)inal number. diff --git a/source/source_cell/module_symmetry/symm_rho.cpp b/source/source_cell/module_symmetry/symm_rho.cpp index 2be3ea19c30..45e5620b8df 100644 --- a/source/source_cell/module_symmetry/symm_rho.cpp +++ b/source/source_cell/module_symmetry/symm_rho.cpp @@ -12,7 +12,7 @@ void Symmetry::rho_symmetry( double *rho, assert(nr2>0); assert(nr3>0); - // allocate flag for each FFT grid. + // allocate flag for each FFT grid. bool* symflag = new bool[nr1 * nr2 * nr3]; for (int i=0; i *rhogtot, const int &fftnx, const int &fftny, const int &fftnz, const bool gamma_only_pw) { - ModuleBase::timer::start("Symmetry","rhog_symmetry"); - // ---------------------------------------------------------------------- - // the current way is to cluster the FFT grid points into groups in advance. - // and use OpenMP to realize parallel calculation, one thread works in one group. - // ---------------------------------------------------------------------- + ModuleBase::timer::start("Symmetry","rhog_symmetry"); + // ---------------------------------------------------------------------- + // the current way is to cluster the FFT grid points into groups in advance. + // and use OpenMP to realize parallel calculation, one thread works in one group. + // ---------------------------------------------------------------------- const int nxyz = fftnx*fftny*fftnz; assert(nxyz>0); - // allocate flag for each FFT grid. + // allocate flag for each FFT grid. // which group the grid belongs to - int* symflag = new int[nxyz]; + int* symflag = new int[nxyz]; // which rotration operation the grid corresponds to - int(*isymflag)[48] = new int[nxyz][48]; + int(*isymflag)[48] = new int[nxyz][48]; // group information - int(*table_xyz)[48] = new int[nxyz][48]; + int(*table_xyz)[48] = new int[nxyz][48]; // how many symmetry operations have been covered - int* count_xyz = new int[nxyz]; + int* count_xyz = new int[nxyz]; - for (int i = 0; i < nxyz; i++) - { - symflag[i] = -1; - } - int group_index = 0; + for (int i = 0; i < nxyz; i++) + { + symflag[i] = -1; + } + int group_index = 0; - assert(nrotk >0 ); - assert(nrotk <=48 ); + assert(nrotk >0 ); + assert(nrotk <=48 ); - //map the gmatrix to inv + //map the gmatrix to inv std::vectorinvmap(this->nrotk, -1); this->gmatrix_invmap(kgmatrix, nrotk, invmap.data()); - // ------------------------------------------------------------------------ - // This code defines a lambda function called "rotate_recip" that takes - // a 3x3 matrix and a 3D vector as input. It performs a rotation operation - // on the vector using the matrix and returns the rotated vector. - // Specifically, it calculates the new coordinates of the vector after - // the rotation and applies periodic boundary conditions to ensure that - // the coordinates are within the FFT-grid dimensions. - // The rotated vector is returned by modifying the input vector. - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // This code defines a lambda function called "rotate_recip" that takes + // a 3x3 matrix and a 3D vector as input. It performs a rotation operation + // on the vector using the matrix and returns the rotated vector. + // Specifically, it calculates the new coordinates of the vector after + // the rotation and applies periodic boundary conditions to ensure that + // the coordinates are within the FFT-grid dimensions. + // The rotated vector is returned by modifying the input vector. + // ------------------------------------------------------------------------ //rotate function (different from real space, without scaling gmatrix) auto rotate_recip = [&] (ModuleBase::Matrix3& g, ModuleBase::Vector3& g0, int& ii, int& jj, int& kk) { @@ -135,14 +135,14 @@ void Symmetry::rhog_symmetry(std::complex *rhogtot, return; }; - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ // Trying to group fft grids first. // It iterates over each FFT-grid point and checks if it is within the // PW-sphere. If it is, put all the FFT-grid points connected by the // rotation operation into one group( the index is stored in int(*table_xyz)). // The code marks the point as processed to avoid redundant calculations // by using int* symflag. - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ ModuleBase::timer::start("Symmetry","group_fft_grids"); for (int i = 0; i< fftnx; ++i) @@ -176,7 +176,7 @@ void Symmetry::rhog_symmetry(std::complex *rhogtot, if(!gamma_only_pw) { std::cout << " ROTATE OUT OF FFT-GRID IN RHOG_SYMMETRY !" << std::endl; - ModuleBase::QUIT(); + ModuleBase::QUIT(); } // for gamma_only_pw, just do not consider this rotation. continue; @@ -202,108 +202,108 @@ void Symmetry::rhog_symmetry(std::complex *rhogtot, } ModuleBase::timer::end("Symmetry","group_fft_grids"); - // ------------------------------------------------------------------- - // This code performs symmetry operations on the reciprocal space - // charge density using FFT-grids. It iterates over each FFT-grid - // point in a particular group, applies a phase factor and sums the - // charge density over the symmetry operations, and then divides by - // the number of symmetry operations. Finally, it updates the charge - // density for each FFT-grid point using the calculated sum. - // ------------------------------------------------------------------- + // ------------------------------------------------------------------- + // This code performs symmetry operations on the reciprocal space + // charge density using FFT-grids. It iterates over each FFT-grid + // point in a particular group, applies a phase factor and sums the + // charge density over the symmetry operations, and then divides by + // the number of symmetry operations. Finally, it updates the charge + // density for each FFT-grid point using the calculated sum. + // ------------------------------------------------------------------- #ifdef _OPENMP #pragma omp parallel for schedule(static) #endif - for (int g_index = 0; g_index < group_index; g_index++) - { - // record the index and gphase but not the final gdirect for each symm-opt - int *ipw_record = new int[nrotk]; - int *ixyz_record = new int[nrotk]; - std::complex* gphase_record = new std::complex [nrotk]; - std::complex sum(0, 0); - int rot_count=0; - - for (int c_index = 0; c_index < count_xyz[g_index]; ++c_index) - { - int ixyz0 = table_xyz[g_index][c_index]; - int ipw0 = ixyz2ipw[ixyz0]; - - if (symflag[ixyz0] == g_index) - { - // note : do not use PBC after rotation. - // we need a real gdirect to get the correspoding rhogtot. - int k = ixyz0%fftnz; - int j = ((ixyz0-k)/fftnz)%fftny; - int i = ((ixyz0-k)/fftnz-j)/fftny; - - //fft-grid index to gdirect - ModuleBase::Vector3 tmp_gdirect_double(0.0, 0.0, 0.0); - tmp_gdirect_double.x=static_cast((i>int(nx/2)+1)?(i-nx):i); - tmp_gdirect_double.y=static_cast((j>int(ny/2)+1)?(j-ny):j); - tmp_gdirect_double.z=static_cast((k>int(nz/2)+1)?(k-nz):k); - - //calculate phase factor - tmp_gdirect_double = tmp_gdirect_double * ModuleBase::TWO_PI; - - double cos_arg = 0.0, sin_arg = 0.0; - double arg_gtrans = tmp_gdirect_double * gtrans[isymflag[g_index][c_index]]; - - std::complex phase_gtrans (ModuleBase::libm::cos(arg_gtrans), - ModuleBase::libm::sin(arg_gtrans)); - - // for each pricell in supercell: - for (int ipt = 0;ipt < ((ModuleSymmetry::Symmetry::pricell_loop) ? this->ncell : 1);++ipt) - { - double arg = tmp_gdirect_double * ptrans[ipt]; - double tmp_cos = 0.0, tmp_sin = 0.0; - ModuleBase::libm::sincos(arg, &tmp_sin, &tmp_cos); - cos_arg += tmp_cos; - sin_arg += tmp_sin; - } - - // add nothing to sum, so don't consider this isym into rot_count - cos_arg/=static_cast(ncell); - sin_arg/=static_cast(ncell); - - //deal with double-zero - if (equal(cos_arg, 0.0) && equal(sin_arg, 0.0)) - { - continue; - } - - std::complex gphase(cos_arg, sin_arg); - gphase = phase_gtrans * gphase; - - //deal with small difference from 1 - if (equal(gphase.real(), 1.0) && equal(gphase.imag(), 0)) - { - gphase = std::complex(1.0, 0.0); - } - - gphase_record[rot_count]=gphase; - sum += rhogtot[ipw0]*gphase; - //record - ipw_record[rot_count]=ipw0; - ixyz_record[rot_count]=ixyz0; - ++rot_count; - //assert(rot_count<=nrotk); - }//end if section - }//end c_index loop - if (rot_count!=0) sum/= rot_count; - for (int isym = 0; isym < rot_count; ++isym) - { - rhogtot[ipw_record[isym]] = sum/gphase_record[isym]; - } - - //Clean the records variables for each fft grid point - delete[] ipw_record; - delete[] ixyz_record; - delete[] gphase_record; - }//end g_index loop - - delete[] symflag; - delete[] isymflag; - delete[] table_xyz; - delete[] count_xyz; - ModuleBase::timer::end("Symmetry","rhog_symmetry"); + for (int g_index = 0; g_index < group_index; g_index++) + { + // record the index and gphase but not the final gdirect for each symm-opt + int *ipw_record = new int[nrotk]; + int *ixyz_record = new int[nrotk]; + std::complex* gphase_record = new std::complex [nrotk]; + std::complex sum(0, 0); + int rot_count=0; + + for (int c_index = 0; c_index < count_xyz[g_index]; ++c_index) + { + int ixyz0 = table_xyz[g_index][c_index]; + int ipw0 = ixyz2ipw[ixyz0]; + + if (symflag[ixyz0] == g_index) + { + // note : do not use PBC after rotation. + // we need a real gdirect to get the correspoding rhogtot. + int k = ixyz0%fftnz; + int j = ((ixyz0-k)/fftnz)%fftny; + int i = ((ixyz0-k)/fftnz-j)/fftny; + + //fft-grid index to gdirect + ModuleBase::Vector3 tmp_gdirect_double(0.0, 0.0, 0.0); + tmp_gdirect_double.x=static_cast((i>int(nx/2)+1)?(i-nx):i); + tmp_gdirect_double.y=static_cast((j>int(ny/2)+1)?(j-ny):j); + tmp_gdirect_double.z=static_cast((k>int(nz/2)+1)?(k-nz):k); + + //calculate phase factor + tmp_gdirect_double = tmp_gdirect_double * ModuleBase::TWO_PI; + + double cos_arg = 0.0, sin_arg = 0.0; + double arg_gtrans = tmp_gdirect_double * gtrans[isymflag[g_index][c_index]]; + + std::complex phase_gtrans (ModuleBase::libm::cos(arg_gtrans), + ModuleBase::libm::sin(arg_gtrans)); + + // for each pricell in supercell: + for (int ipt = 0;ipt < ((ModuleSymmetry::Symmetry::pricell_loop) ? this->ncell : 1);++ipt) + { + double arg = tmp_gdirect_double * ptrans[ipt]; + double tmp_cos = 0.0, tmp_sin = 0.0; + ModuleBase::libm::sincos(arg, &tmp_sin, &tmp_cos); + cos_arg += tmp_cos; + sin_arg += tmp_sin; + } + + // add nothing to sum, so don't consider this isym into rot_count + cos_arg/=static_cast(ncell); + sin_arg/=static_cast(ncell); + + //deal with double-zero + if (equal(cos_arg, 0.0) && equal(sin_arg, 0.0)) + { + continue; + } + + std::complex gphase(cos_arg, sin_arg); + gphase = phase_gtrans * gphase; + + //deal with small difference from 1 + if (equal(gphase.real(), 1.0) && equal(gphase.imag(), 0)) + { + gphase = std::complex(1.0, 0.0); + } + + gphase_record[rot_count]=gphase; + sum += rhogtot[ipw0]*gphase; + //record + ipw_record[rot_count]=ipw0; + ixyz_record[rot_count]=ixyz0; + ++rot_count; + //assert(rot_count<=nrotk); + }//end if section + }//end c_index loop + if (rot_count!=0) sum/= rot_count; + for (int isym = 0; isym < rot_count; ++isym) + { + rhogtot[ipw_record[isym]] = sum/gphase_record[isym]; + } + + //Clean the records variables for each fft grid point + delete[] ipw_record; + delete[] ixyz_record; + delete[] gphase_record; + }//end g_index loop + + delete[] symflag; + delete[] isymflag; + delete[] table_xyz; + delete[] count_xyz; + ModuleBase::timer::end("Symmetry","rhog_symmetry"); } diff --git a/source/source_cell/module_symmetry/symmetry.cpp b/source/source_cell/module_symmetry/symmetry.cpp index c63ed4db2ad..e01e9cd97dc 100644 --- a/source/source_cell/module_symmetry/symmetry.cpp +++ b/source/source_cell/module_symmetry/symmetry.cpp @@ -42,21 +42,21 @@ void Symmetry::set_atom_map(const Atom* atoms) { for (int ia = istart[it]; ia < istart[it] + na[it]; ++ia) { - const int xx = ia * 3; - const int yy = ia * 3 + 1; - const int zz = ia * 3 + 2; + const int xx = ia * 3; + const int yy = ia * 3 + 1; + const int zz = ia * 3 + 2; - for (int k = 0;k < this->nrotk;++k) + for (int k = 0;k < this->nrotk;++k) { - rotpos[xx] = pos[xx] * gmatrix[k].e11 - + pos[yy] * gmatrix[k].e21 - + pos[zz] * gmatrix[k].e31 + gtrans[k].x; - rotpos[yy] = pos[xx] * gmatrix[k].e12 - + pos[yy] * gmatrix[k].e22 - + pos[zz] * gmatrix[k].e32 + gtrans[k].y; - rotpos[zz] = pos[xx] * gmatrix[k].e13 - + pos[yy] * gmatrix[k].e23 - + pos[zz] * gmatrix[k].e33 + gtrans[k].z; + rotpos[xx] = pos[xx] * gmatrix[k].e11 + + pos[yy] * gmatrix[k].e21 + + pos[zz] * gmatrix[k].e31 + gtrans[k].x; + rotpos[yy] = pos[xx] * gmatrix[k].e12 + + pos[yy] * gmatrix[k].e22 + + pos[zz] * gmatrix[k].e32 + gtrans[k].y; + rotpos[zz] = pos[xx] * gmatrix[k].e13 + + pos[yy] * gmatrix[k].e23 + + pos[zz] * gmatrix[k].e33 + gtrans[k].z; check_translation(rotpos[xx], -floor(rotpos[xx])); check_boundary(rotpos[xx]); @@ -104,7 +104,7 @@ void Symmetry::symmetrize_vec3_nat(double* v)const // pengfei 2016-12-20 vtot[l*3+2] = vtot[l*3+2] + v[jx] * gmatrix[k].e13 + v[jy] * gmatrix[k].e23 + v[jz] * gmatrix[k].e33; n[l]++; } - } + } for (int j = 0;j < nat; ++j) { v[j * 3] = vtot[j * 3] / n[j]; @@ -113,7 +113,7 @@ void Symmetry::symmetrize_vec3_nat(double* v)const // pengfei 2016-12-20 } delete[] vtot; delete[] n; - return; + return; } void Symmetry::symmetrize_mat3(ModuleBase::matrix& sigma, const Lattice& lat)const //zhengdy added 2017 @@ -129,7 +129,7 @@ void Symmetry::symmetrize_mat3(ModuleBase::matrix& sigma, const Lattice& lat)con * gmatrix[k].Transpose().to_matrix() * invAT; } sigma = tot_sigma * static_cast(1.0 / nrotk); - return; + return; } void Symmetry::gmatrix_convert_int(const ModuleBase::Matrix3* sa, ModuleBase::Matrix3* sb, @@ -282,14 +282,14 @@ void Symmetry::get_optlat(ModuleBase::Vector3 &v1, ModuleBase::Vector3 &v1, ModuleBase::Vector3epsilon = 1e-6; - }; + Symmetry() + { + this->epsilon = 1e-6; + }; ~Symmetry() {}; - //symmetry flag for levels - //-1 : no symmetry at all, k points would be total nks in KPT - //0 : only basic time-reversal symmetry is considered, point k and -k would fold to k - //1 : point group symmetry is considered + //symmetry flag for levels + //-1 : no symmetry at all, k points would be total nks in KPT + //0 : only basic time-reversal symmetry is considered, point k and -k would fold to k + //1 : point group symmetry is considered static int symm_flag; static bool symm_autoclose; // controled by INPUT static bool pricell_loop; ///< whether to loop primitive cell in rhog_symmetry, Only for AFM @@ -39,59 +39,59 @@ class Symmetry : public Symmetry_Basic /// @param nspin number of spin components /// @param calculation calculation type (scf, relax, cell-relax, etc.) /// @param cal_symm_repr control for symmetry representation output [0]=flag, [1]=precision - /// get the symmetry information of the system, gmatries (rotation 3*3 matrixs), gtrans (transfer a collections vector3), etc. + /// get the symmetry information of the system, gmatries (rotation 3*3 matrixs), gtrans (transfer a collections vector3), etc. void analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, std::ofstream& ofs_running, const double symmetry_prec, const int nspin, const std::string& calculation, const int* cal_symm_repr); - ModuleBase::Vector3 s1, s2, s3; - ModuleBase::Vector3 a1, a2, a3; //primitive cell vectors(might be changed during the process of the program) - ModuleBase::Vector3 p1, p2, p3; //primitive cell vectors - - int ntype=0; //the number of atomic species - int nat =0; //the number of all atoms - int *na =nullptr;//number of atoms for each species - int *istart=nullptr; //start number of atom. - int itmin_type=0; //the type has smallest number of atoms - int itmin_start=0; - - // direct coordinates of atoms. - double *newpos=nullptr; - // positions of atoms after rotation. - double *rotpos=nullptr; - - - std::vector> ptrans; // the translation vectors of the primitive cell in the input structure - int ncell=1; //the number of primitive cells within one supercell - int *index=nullptr; - - double cel_const[6]={0.0}; - double pcel_const[6]={0.0}; //cel_const of primitive cell - double pre_const[6]={0.0}; //cel_const of input configuration, first 3 is moduli of a1, a2, a3, last 3 is eular angle - - bool symflag_fft[48]={false}; - int sym_test=0; - int pbrav=0; //ibrav of primitive cell - int real_brav=0; // the real ibrav for the cell pengfei Li 3-15-2022 - std::string ilattname; //the bravais lattice type of the supercell - std::string plattname; //the bravais lattice type of the primitive cell - - ModuleBase::Matrix3 gmatrix[48]; //the rotation matrices for all space group operations - ModuleBase::Matrix3 kgmatrix[48]; //the rotation matrices in reciprocal space - ModuleBase::Vector3 gtrans[48]; - - ModuleBase::Matrix3 symop[48]; //the rotation matrices for the pure bravais lattice - int nop=0; //the number of point group operations of the pure bravais lattice without basis - int nrot=0; //the number of pure point group rotations - int nrotk = -1; //the number of all space group operations, >0 means the nrotk has been analyzed + ModuleBase::Vector3 s1, s2, s3; + ModuleBase::Vector3 a1, a2, a3; //primitive cell vectors(might be changed during the process of the program) + ModuleBase::Vector3 p1, p2, p3; //primitive cell vectors + + int ntype=0; //the number of atomic species + int nat =0; //the number of all atoms + int *na =nullptr;//number of atoms for each species + int *istart=nullptr; //start number of atom. + int itmin_type=0; //the type has smallest number of atoms + int itmin_start=0; + + // direct coordinates of atoms. + double *newpos=nullptr; + // positions of atoms after rotation. + double *rotpos=nullptr; + + + std::vector> ptrans; // the translation vectors of the primitive cell in the input structure + int ncell=1; //the number of primitive cells within one supercell + int *index=nullptr; + + double cel_const[6]={0.0}; + double pcel_const[6]={0.0}; //cel_const of primitive cell + double pre_const[6]={0.0}; //cel_const of input configuration, first 3 is moduli of a1, a2, a3, last 3 is eular angle + + bool symflag_fft[48]={false}; + int sym_test=0; + int pbrav=0; //ibrav of primitive cell + int real_brav=0; // the real ibrav for the cell pengfei Li 3-15-2022 + std::string ilattname; //the bravais lattice type of the supercell + std::string plattname; //the bravais lattice type of the primitive cell + + ModuleBase::Matrix3 gmatrix[48]; //the rotation matrices for all space group operations + ModuleBase::Matrix3 kgmatrix[48]; //the rotation matrices in reciprocal space + ModuleBase::Vector3 gtrans[48]; + + ModuleBase::Matrix3 symop[48]; //the rotation matrices for the pure bravais lattice + int nop=0; //the number of point group operations of the pure bravais lattice without basis + int nrot=0; //the number of pure point group rotations + int nrotk = -1; //the number of all space group operations, >0 means the nrotk has been analyzed int max_nrotk = -1; ///< record the maximum number of symmetry operations during cell-relax - int pgnumber=0; //the serial number of point group - int spgnumber=0; //the serial number of point group in space group - std::string pgname; //the Schoenflies name of the point group R in {R|0} - std::string spgname; //the Schoenflies name of the point group R in the space group {R|t} + int pgnumber=0; //the serial number of point group + int spgnumber=0; //the serial number of point group in space group + std::string pgname; //the Schoenflies name of the point group R in {R|0} + std::string spgname; //the Schoenflies name of the point group R in the space group {R|t} - ModuleBase::Matrix3 optlat; //the optimized-symmetry lattice - ModuleBase::Matrix3 plat; //the primitive lattice + ModuleBase::Matrix3 optlat; //the optimized-symmetry lattice + ModuleBase::Matrix3 plat; //the primitive lattice bool all_mbl = true; ///< whether all the atoms are movable in all the directions @@ -101,49 +101,49 @@ class Symmetry : public Symmetry_Basic double* celconst, const double symmetry_prec)const; - void lattice_type(ModuleBase::Vector3 &v1, + void lattice_type(ModuleBase::Vector3 &v1, ModuleBase::Vector3 &v2, - ModuleBase::Vector3 &v3, - ModuleBase::Vector3 &v01, + ModuleBase::Vector3 &v3, + ModuleBase::Vector3 &v01, ModuleBase::Vector3 &v02, ModuleBase::Vector3 &v03, - double* cel_const, + double* cel_const, double* pre_const, int& real_brav, std::string& bravname, const Atom* atoms, - bool convert_atoms, + bool convert_atoms, double* newpos, const double symmetry_prec)const; - void getgroup(int& nrot, - int& nrotk, - std::ofstream& ofs_running, - const int& nop, - const ModuleBase::Matrix3* symop, - ModuleBase::Matrix3* gmatrix, - ModuleBase::Vector3* gtrans, - double* pos, double* rotpos, int* index, - const int ntype, const int itmin_type, const int itmin_start, - int* istart, int* na)const; - - bool checksym(const ModuleBase::Matrix3 &s, - ModuleBase::Vector3& gtrans, - double* pos, double* rotpos, int* index, - const int itmin_type, const int ntype, const int itmin_start, - int* istart, int* na)const; + void getgroup(int& nrot, + int& nrotk, + std::ofstream& ofs_running, + const int& nop, + const ModuleBase::Matrix3* symop, + ModuleBase::Matrix3* gmatrix, + ModuleBase::Vector3* gtrans, + double* pos, double* rotpos, int* index, + const int ntype, const int itmin_type, const int itmin_start, + int* istart, int* na)const; + + bool checksym(const ModuleBase::Matrix3 &s, + ModuleBase::Vector3& gtrans, + double* pos, double* rotpos, int* index, + const int itmin_type, const int ntype, const int itmin_start, + int* istart, int* na)const; /// @brief primitive cell analysis void pricell(double* pos, const Atom* atoms); - /// ----------------------- - /// Symmetrize the charge density, the forces, and the stress - /// ----------------------- - void rho_symmetry(double *rho, const int &nr1, const int &nr2, const int &nr3); + /// ----------------------- + /// Symmetrize the charge density, the forces, and the stress + /// ----------------------- + void rho_symmetry(double *rho, const int &nr1, const int &nr2, const int &nr3); - void rhog_symmetry(std::complex *rhogtot, int* ixyz2ipw, const int &nx, - const int &ny, const int &nz, const int & fftnx, const int &fftny, const int &fftnz, - const bool gamma_only_pw); + void rhog_symmetry(std::complex *rhogtot, int* ixyz2ipw, const int &nx, + const int &ny, const int &nz, const int & fftnx, const int &fftny, const int &fftnz, + const bool gamma_only_pw); /// symmetrize a vector3 with nat elements, which can be forces or variation of atom positions in relax void symmetrize_vec3_nat(double* v)const; // force @@ -151,20 +151,20 @@ class Symmetry : public Symmetry_Basic /// symmetrize a 3*3 tensor, which can be stress or variation of unitcell in cell-relax void symmetrize_mat3(ModuleBase::matrix& sigma, const Lattice& lat)const; // stress - //convert n rotation-matrices from sa on basis {a1, a2, a3} to sb on basis {b1, b2, b3} - void gmatrix_convert(const ModuleBase::Matrix3* sa, ModuleBase::Matrix3* sb, - const int n, const ModuleBase::Matrix3 &a, const ModuleBase::Matrix3 &b)const; + //convert n rotation-matrices from sa on basis {a1, a2, a3} to sb on basis {b1, b2, b3} + void gmatrix_convert(const ModuleBase::Matrix3* sa, ModuleBase::Matrix3* sb, + const int n, const ModuleBase::Matrix3 &a, const ModuleBase::Matrix3 &b)const; - void gmatrix_convert_int(const ModuleBase::Matrix3* sa, ModuleBase::Matrix3* sb, - const int n, const ModuleBase::Matrix3 &a, const ModuleBase::Matrix3 &b)const; + void gmatrix_convert_int(const ModuleBase::Matrix3* sa, ModuleBase::Matrix3* sb, + const int n, const ModuleBase::Matrix3 &a, const ModuleBase::Matrix3 &b)const; - //convert n translation-vectors from va on basis {a1, a2, a3} to vb on basis {b1, b2, b3} - void gtrans_convert(const ModuleBase::Vector3* va, ModuleBase::Vector3* vb, - const int n, const ModuleBase::Matrix3 &a, const ModuleBase::Matrix3 &b)const; + //convert n translation-vectors from va on basis {a1, a2, a3} to vb on basis {b1, b2, b3} + void gtrans_convert(const ModuleBase::Vector3* va, ModuleBase::Vector3* vb, + const int n, const ModuleBase::Matrix3 &a, const ModuleBase::Matrix3 &b)const; - void gmatrix_invmap(const ModuleBase::Matrix3* s, const int n, int* invmap) const; + void gmatrix_invmap(const ModuleBase::Matrix3* s, const int n, int* invmap) const; - void hermite_normal_form(const ModuleBase::Matrix3 &s, ModuleBase::Matrix3 &H, ModuleBase::Matrix3 &b) const; + void hermite_normal_form(const ModuleBase::Matrix3 &s, ModuleBase::Matrix3 &H, ModuleBase::Matrix3 &b) const; int get_rotated_atom(int isym, int iat)const { @@ -172,7 +172,7 @@ class Symmetry : public Symmetry_Basic else { return -1; } } - private: + private: /// atom-map for each symmetry operation: isym_rotiat[isym][iat]=rotiat std::vector> isym_rotiat_; @@ -184,12 +184,12 @@ class Symmetry : public Symmetry_Basic bool is_all_movable(const Atom* atoms, const Statistics& st)const; // to be called in lattice_type - void get_shortest_latvec(ModuleBase::Vector3 &a1, - ModuleBase::Vector3 &a2, ModuleBase::Vector3 &a3)const; + void get_shortest_latvec(ModuleBase::Vector3 &a1, + ModuleBase::Vector3 &a2, ModuleBase::Vector3 &a3)const; - void get_optlat(ModuleBase::Vector3 &v1, ModuleBase::Vector3 &v2, - ModuleBase::Vector3 &v3, ModuleBase::Vector3 &w1, - ModuleBase::Vector3 &w2, ModuleBase::Vector3 &w3, + void get_optlat(ModuleBase::Vector3 &v1, ModuleBase::Vector3 &v2, + ModuleBase::Vector3 &v3, ModuleBase::Vector3 &w1, + ModuleBase::Vector3 &w2, ModuleBase::Vector3 &w3, int& real_brav, double* cel_const, double* tmp_const, const double symmetry_prec)const; /// Loop the magmom of each atoms in its type when NSPIN>1. diff --git a/source/source_cell/module_symmetry/symmetry_basic.cpp b/source/source_cell/module_symmetry/symmetry_basic.cpp index 09bfc919931..e29e9c71d65 100644 --- a/source/source_cell/module_symmetry/symmetry_basic.cpp +++ b/source/source_cell/module_symmetry/symmetry_basic.cpp @@ -9,313 +9,313 @@ namespace ModuleSymmetry // Find the type of bravais lattice. std::string Symmetry_Basic::get_brav_name(const int ibrav) const { - switch(ibrav) - { - case 1: return "01. Cubic P (simple)"; - case 2: return "02. Cubic I (body-centered)"; - case 3: return "03. Cubic F (face-centered)"; - case 4: return "04. Hexagonal cell"; - case 5: return "05. Tetrogonal P (simple)"; - case 6: return "06. Tetrogonal I (body-centered)"; - case 7: return "07. Rhombohedral (Trigonal) cell"; - case 8: return "08. Orthorhombic P(simple)"; - case 9: return "09. Orthorhombic I (body-centered)"; - case 10: return "10. Orthorhombic F (face-centered)"; - case 11: return "11. Orthorhombic C (base-centered)"; - case 12: return "12. Monoclinic P (simple)"; - case 13: return "13. Monoclinic A (base-center)"; - case 14: return "14. Triclinic cell"; - case 15: return "wrong !! "; - } - // return "Congratulations! You have found a bravais lattice that never existed!"; - return "Unknown Bravais lattice"; + switch(ibrav) + { + case 1: return "01. Cubic P (simple)"; + case 2: return "02. Cubic I (body-centered)"; + case 3: return "03. Cubic F (face-centered)"; + case 4: return "04. Hexagonal cell"; + case 5: return "05. Tetrogonal P (simple)"; + case 6: return "06. Tetrogonal I (body-centered)"; + case 7: return "07. Rhombohedral (Trigonal) cell"; + case 8: return "08. Orthorhombic P(simple)"; + case 9: return "09. Orthorhombic I (body-centered)"; + case 10: return "10. Orthorhombic F (face-centered)"; + case 11: return "11. Orthorhombic C (base-centered)"; + case 12: return "12. Monoclinic P (simple)"; + case 13: return "13. Monoclinic A (base-center)"; + case 14: return "14. Triclinic cell"; + case 15: return "wrong !! "; + } + // return "Congratulations! You have found a bravais lattice that never existed!"; + return "Unknown Bravais lattice"; } // Control the accuracy bool Symmetry_Basic::equal(const double &m, const double &n) const { - //if( fabs(m-n) < 1.0e-5 ) + //if( fabs(m-n) < 1.0e-5 ) if (fabs(m-n) < epsilon) //LiuXh add 2021-08-12, use accuracy for symmetry - { - return true; - } - return false; + { + return true; + } + return false; } // check the boundary condition of atom positions. void Symmetry_Basic::check_boundary(double &x)const { - if(equal(x,-0.5) || equal(x,0.5)) x=-0.5; + if(equal(x,-0.5) || equal(x,0.5)) x=-0.5; } double Symmetry_Basic::get_translation_vector(const double& x1, const double& x2) const { - double t=0.0; // "t"ranslation - t = x2 - x1; - t = fmod(t+100.0, 1.0); - if( fabs(t-1) < epsilon * 0.5) { t = 0.0; } - return t; + double t=0.0; // "t"ranslation + t = x2 - x1; + t = fmod(t+100.0, 1.0); + if( fabs(t-1) < epsilon * 0.5) { t = 0.0; } + return t; } void Symmetry_Basic::check_translation(double &x, const double &t) const { - x += t; - //impose the periodic boundary condition - x = fmod(x + 100.5,1) - 0.5; - return; + x += t; + //impose the periodic boundary condition + x = fmod(x + 100.5,1) - 0.5; + return; } double Symmetry_Basic::check_diff(const double& x1, const double& x2)const { - double diff = x1 - x2; - diff = fmod(diff + 100,1); - //for reasons of safety - if(fabs(diff - 1.0) < epsilon) - { - diff = 0; - } - return diff; + double diff = x1 - x2; + diff = fmod(diff + 100,1); + //for reasons of safety + if(fabs(diff - 1.0) < epsilon) + { + diff = 0; + } + return diff; } void Symmetry_Basic::order_atoms(double* pos, const int& nat, const int* index) const { - double** tmp = new double*[nat]; - for(int ia=0; ia &old1, - const ModuleBase::Vector3 &old2, - const ModuleBase::Vector3 &old3, - const ModuleBase::Vector3 &new1, - const ModuleBase::Vector3 &new2, - const ModuleBase::Vector3 &new3 - ) + double *carpos, + double *rotpos, + const int num, + const ModuleBase::Vector3 &old1, + const ModuleBase::Vector3 &old2, + const ModuleBase::Vector3 &old3, + const ModuleBase::Vector3 &new1, + const ModuleBase::Vector3 &new2, + const ModuleBase::Vector3 &new3 + ) { - GlobalV::ofs_running << "\n old1:" << old1.x << " " << old1.y << " " << old1.z; - GlobalV::ofs_running << "\n old2:" << old2.x << " " << old2.y << " " << old2.z; - GlobalV::ofs_running << "\n old3:" << old3.x << " " << old3.y << " " << old3.z; - - GlobalV::ofs_running << "\n new1:" << new1.x << " " << new1.y << " " << new1.z; - GlobalV::ofs_running << "\n new2:" << new2.x << " " << new2.y << " " << new2.z; - GlobalV::ofs_running << "\n new3:" << new3.x << " " << new3.y << " " << new3.z; - - ModuleBase::Matrix3 oldlat; - oldlat.e11 = old1.x; - oldlat.e12 = old1.y; - oldlat.e13 = old1.z; - oldlat.e21 = old2.x; - oldlat.e22 = old2.y; - oldlat.e23 = old2.z; - oldlat.e31 = old3.x; - oldlat.e32 = old3.y; - oldlat.e33 = old3.z; - - ModuleBase::Matrix3 newlat; - newlat.e11 = new1.x; - newlat.e12 = new1.y; - newlat.e13 = new1.z; - newlat.e21 = new2.x; - newlat.e22 = new2.y; - newlat.e23 = new2.z; - newlat.e31 = new3.x; - newlat.e32 = new3.y; - newlat.e33 = new3.z; - - ModuleBase::Matrix3 GT = newlat.Inverse(); - - ModuleBase::Vector3 car; - ModuleBase::Vector3 direct_old; - ModuleBase::Vector3 direct_new; - - //calculate the reciprocal vectors rb1, rb2, rb3 for the vectors new1, new2, new3 - //this->recip(1.0, new1, new2, new3, rb1, rb2, rb3); - - for(int i = 0; i < num; ++i) - { - direct_old.x = carpos[i * 3 + 0]; - direct_old.y = carpos[i * 3 + 1]; - direct_old.z = carpos[i * 3 + 2]; - - car = direct_old * oldlat; - direct_new = car * GT; - - rotpos[i * 3 + 0] = direct_new.x; - rotpos[i * 3 + 1] = direct_new.y; - rotpos[i * 3 + 2] = direct_new.z; - } - return; + GlobalV::ofs_running << "\n old1:" << old1.x << " " << old1.y << " " << old1.z; + GlobalV::ofs_running << "\n old2:" << old2.x << " " << old2.y << " " << old2.z; + GlobalV::ofs_running << "\n old3:" << old3.x << " " << old3.y << " " << old3.z; + + GlobalV::ofs_running << "\n new1:" << new1.x << " " << new1.y << " " << new1.z; + GlobalV::ofs_running << "\n new2:" << new2.x << " " << new2.y << " " << new2.z; + GlobalV::ofs_running << "\n new3:" << new3.x << " " << new3.y << " " << new3.z; + + ModuleBase::Matrix3 oldlat; + oldlat.e11 = old1.x; + oldlat.e12 = old1.y; + oldlat.e13 = old1.z; + oldlat.e21 = old2.x; + oldlat.e22 = old2.y; + oldlat.e23 = old2.z; + oldlat.e31 = old3.x; + oldlat.e32 = old3.y; + oldlat.e33 = old3.z; + + ModuleBase::Matrix3 newlat; + newlat.e11 = new1.x; + newlat.e12 = new1.y; + newlat.e13 = new1.z; + newlat.e21 = new2.x; + newlat.e22 = new2.y; + newlat.e23 = new2.z; + newlat.e31 = new3.x; + newlat.e32 = new3.y; + newlat.e33 = new3.z; + + ModuleBase::Matrix3 GT = newlat.Inverse(); + + ModuleBase::Vector3 car; + ModuleBase::Vector3 direct_old; + ModuleBase::Vector3 direct_new; + + //calculate the reciprocal vectors rb1, rb2, rb3 for the vectors new1, new2, new3 + //this->recip(1.0, new1, new2, new3, rb1, rb2, rb3); + + for(int i = 0; i < num; ++i) + { + direct_old.x = carpos[i * 3 + 0]; + direct_old.y = carpos[i * 3 + 1]; + direct_old.z = carpos[i * 3 + 2]; + + car = direct_old * oldlat; + direct_new = car * GT; + + rotpos[i * 3 + 0] = direct_new.x; + rotpos[i * 3 + 1] = direct_new.y; + rotpos[i * 3 + 2] = direct_new.z; + } + return; } // generate all point group symmetry operations from the generation group void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, ModuleBase::Matrix3* symop, int &nop) const { - int m1 = 0; + int m1 = 0; int m2 = 0; - int n = 0; - - // allocate memory for the symmetry operations - ModuleBase::Matrix3 iden(1,0,0,0,1,0,0,0,1); - ModuleBase::Matrix3 sig(1,0,0,0,1,0,0,0,1); - ModuleBase::Matrix3 temp1(1,0,0,0,1,0,0,0,1); - ModuleBase::Matrix3 temp2(1,0,0,0,1,0,0,0,1); - - bool flag = false; // mark whether the symmetry operation is a new one - int order = 0; - int now = 0; - - symop[0] = iden; //identity (the trivial element) - nop = 1; // counter of the symmetry operations - - // take all generators - for (int i = 0; i < ngen; ++i) - { - sig = symgen[i]; - flag = true; // assume it is a new symmetry operation - // search if the symmetry operation already exists among the found symmetry operations - // if so, skip it - for (int j = 0; j < nop; ++j) - { - if (symop[j] == sig) - { - flag = 0; // not a new symmetry operation - break; - } - } - if (flag == 0) // if old, return - { - continue; - } - // otherwise - - // determine the order of the operation: by which power will the operation return - // to the identity operation. - temp1 = sig; - for (int j = 1; j < 100; ++j) - { - order = j; - if (temp1 == iden) - { - break; - } - temp1 = sig * temp1; - } - now = nop; - for (int j = 0; j < nop; ++j) - { - temp1 = symop[j]; - for (int k = 1; k < order; ++k) - { - temp1 = sig * temp1; - - for (int l = 0; l < nop; ++l) - { - temp2 = symop[l] * temp1; - flag = 1; - for (int m = 0; m < now; ++m) - { - if (symop[m] == temp2) - { - flag = 0; - break; - } - } - if (flag == 0) - { - continue; //the newly-found element has already existed. - } - - ++now; // the number of elements we found - if (now > 48) // number of symm_op cannot be more than 48 (of O_h point group) - { - std::cout << "\n a: now= "< 48) - { - std::cout << "\n b: now= "< 48) // number of symm_op cannot be more than 48 (of O_h point group) + { + std::cout << "\n a: now= "< 48) + { + std::cout << "\n b: now= "< 1) { - ModuleBase::TITLE("Symmetry_Basic", "setgroup"); - } - ModuleBase::Matrix3 symgen[3]; // the number of generators is up to 3 - - ModuleBase::Matrix3 inv(-1, 0, 0, 0,-1, 0, 0, 0,-1); // (x, y, z) -> (-x, -y, -z) - ModuleBase::Matrix3 r3d( 0, 1, 0, 0, 0, 1, 1, 0, 0); // (x, y, z) -> (y, z, x) - ModuleBase::Matrix3 r6z( 1, 1, 0,-1, 0, 0, 0, 0, 1); // (x, y, z) -> (x+y, -x, z) - ModuleBase::Matrix3 r2hex( 1, 0, 0,-1,-1, 0, 0, 0,-1); // (x, y, z) -> (x, -x-y, -z) - ModuleBase::Matrix3 r2tri(-1, 0, 0, 0, 0,-1, 0,-1, 0); // (x, y, z) -> (-x, -z, -y) - ModuleBase::Matrix3 r4zp( 0, 1, 0,-1, 0, 0, 0, 0, 1); // (x, y, z) -> (y, -x, z) - ModuleBase::Matrix3 r2yp(-1, 0, 0, 0, 1, 0, 0, 0,-1); // (x, y, z) -> (-x, y, -z) - ModuleBase::Matrix3 r4zbc( 0, 0,-1, 1, 1, 1, 0,-1, 0); // (x, y, z) -> (-z, x+y+z, -y) - ModuleBase::Matrix3 r4zfc( 1, 0,-1, 1, 0, 0, 1,-1, 0); // (x, y, z) -> (x-z, x, x-y) - ModuleBase::Matrix3 r2zp(-1, 0, 0, 0,-1, 0, 0, 0, 1); // (x, y, z) -> (-x, -y, z) - ModuleBase::Matrix3 r2ybc( 0, 0, 1,-1,-1,-1, 1, 0, 0); // (x, y, z) -> (z, -x-y-z, x) - ModuleBase::Matrix3 r2zbc( 0, 1, 0, 1, 0, 0,-1,-1,-1); // (x, y, z) -> (y, x, -x-y-z) - ModuleBase::Matrix3 r2ybas( 0,-1, 0,-1, 0, 0, 0, 0,-1); // (x, y, z) -> (-y, -x, -z) - ModuleBase::Matrix3 r2yfc( 0,-1, 1, 0,-1, 0, 1,-1, 0); // (x, y, z) -> (-y+z, -y, x-y) - ModuleBase::Matrix3 r2zfc( 0, 1,-1, 1, 0,-1, 0, 0,-1); // (x, y, z) -> (y-z, x-z, -z) - - //the pure translation lattice (bravais lattice) has some maximum symmetry - //set first up the point group operations for this symmetry. - symgen[0] = inv; - // generate the point group operations for the bravais lattice - // rewrite with switch-case to get better performance and readability - switch (ibrav) { - case 1: - symgen[1] = r3d; - symgen[2] = r4zp; - this->matrigen(symgen, 3, symop, nop); - break; - case 2: - symgen[1] = r3d; - symgen[2] = r4zbc; - this->matrigen(symgen, 3, symop, nop); - break; - case 3: - symgen[1] = r3d; - symgen[2] = r4zfc; - this->matrigen(symgen, 3, symop, nop); - break; - case 4: - symgen[1] = r6z; - symgen[2] = r2hex; - this->matrigen(symgen, 3, symop, nop); - break; - case 5: - symgen[1] = r4zp; - symgen[2] = r2yp; - this->matrigen(symgen, 3, symop, nop); - break; - case 6: - symgen[1] = r4zbc; - symgen[2] = r2ybc; - this->matrigen(symgen, 3, symop, nop); - break; - case 7: - symgen[1] = r2tri; - symgen[2] = r3d; - this->matrigen(symgen, 3, symop, nop); - break; - case 8: - symgen[1] = r2zp; - symgen[2] = r2yp; - this->matrigen(symgen, 3, symop, nop); - break; - case 9: - symgen[1] = r2zbc; - symgen[2] = r2ybc; - this->matrigen(symgen, 3, symop, nop); - break; - case 10: - symgen[1] = r2zfc; - symgen[2] = r2yfc; - this->matrigen(symgen, 3, symop, nop); - break; - case 11: - symgen[1] = r2zp; - symgen[2] = r2ybas; - this->matrigen(symgen, 3, symop, nop); - break; - case 12: - symgen[1] = r2yp; - this->matrigen(symgen, 2, symop, nop); - break; - case 13: - symgen[1] = r2ybas; - this->matrigen(symgen, 2, symop, nop); - break; - case 14: - this->matrigen(symgen, 1, symop, nop); - break; - default: - ModuleBase::WARNING_QUIT("Symmetry_Basic::setgroup", - "ibrav = " + std::to_string(ibrav) + " is not supported."); - break; - } - - // print - if (test_brav) - { - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Number of rotation matrices", nop); - } - - // print the symmetry operations - if (cal_symm_repr != nullptr && cal_symm_repr[0] > 0) - { - GlobalV::ofs_running << std::endl - << " ======================================================================\n" - << " MATRIX REPRESENTATION OF SYMMETRY OPERATION\n" - << " ======================================================================\n" - << " There are " << nop << " symmetry operation representation matrices.\n" - << " For each matrix, the elements are arranged like: \n" - << " [[e11, e12, e13], [e21, e22, e23], [e31, e32, e33]].reshape(3, 3)\n" - << std::endl; - - // control the digits - const int precision = cal_symm_repr[1]; - const int width = precision + 4; - std::string fmtstr = " %" + std::to_string(width) + "." + std::to_string(precision) + "f"; - fmtstr += fmtstr + fmtstr + "\n"; - - // print the symmetry operations - std::string mat; - for (int i = 0; i < nop; ++i) - { - mat = " " + FmtCore::format("No. %3d", i + 1) + "\n" - + FmtCore::format(fmtstr.c_str(), symop[i].e11, symop[i].e12, symop[i].e13) - + FmtCore::format(fmtstr.c_str(), symop[i].e21, symop[i].e22, symop[i].e23) - + FmtCore::format(fmtstr.c_str(), symop[i].e31, symop[i].e32, symop[i].e33); - GlobalV::ofs_running << mat << std::endl; - } - GlobalV::ofs_running << " ======================================================================\n"; - } - - return; + if(cal_symm_repr != nullptr && cal_symm_repr[0] > 1) { + ModuleBase::TITLE("Symmetry_Basic", "setgroup"); + } + ModuleBase::Matrix3 symgen[3]; // the number of generators is up to 3 + + ModuleBase::Matrix3 inv(-1, 0, 0, 0,-1, 0, 0, 0,-1); // (x, y, z) -> (-x, -y, -z) + ModuleBase::Matrix3 r3d( 0, 1, 0, 0, 0, 1, 1, 0, 0); // (x, y, z) -> (y, z, x) + ModuleBase::Matrix3 r6z( 1, 1, 0,-1, 0, 0, 0, 0, 1); // (x, y, z) -> (x+y, -x, z) + ModuleBase::Matrix3 r2hex( 1, 0, 0,-1,-1, 0, 0, 0,-1); // (x, y, z) -> (x, -x-y, -z) + ModuleBase::Matrix3 r2tri(-1, 0, 0, 0, 0,-1, 0,-1, 0); // (x, y, z) -> (-x, -z, -y) + ModuleBase::Matrix3 r4zp( 0, 1, 0,-1, 0, 0, 0, 0, 1); // (x, y, z) -> (y, -x, z) + ModuleBase::Matrix3 r2yp(-1, 0, 0, 0, 1, 0, 0, 0,-1); // (x, y, z) -> (-x, y, -z) + ModuleBase::Matrix3 r4zbc( 0, 0,-1, 1, 1, 1, 0,-1, 0); // (x, y, z) -> (-z, x+y+z, -y) + ModuleBase::Matrix3 r4zfc( 1, 0,-1, 1, 0, 0, 1,-1, 0); // (x, y, z) -> (x-z, x, x-y) + ModuleBase::Matrix3 r2zp(-1, 0, 0, 0,-1, 0, 0, 0, 1); // (x, y, z) -> (-x, -y, z) + ModuleBase::Matrix3 r2ybc( 0, 0, 1,-1,-1,-1, 1, 0, 0); // (x, y, z) -> (z, -x-y-z, x) + ModuleBase::Matrix3 r2zbc( 0, 1, 0, 1, 0, 0,-1,-1,-1); // (x, y, z) -> (y, x, -x-y-z) + ModuleBase::Matrix3 r2ybas( 0,-1, 0,-1, 0, 0, 0, 0,-1); // (x, y, z) -> (-y, -x, -z) + ModuleBase::Matrix3 r2yfc( 0,-1, 1, 0,-1, 0, 1,-1, 0); // (x, y, z) -> (-y+z, -y, x-y) + ModuleBase::Matrix3 r2zfc( 0, 1,-1, 1, 0,-1, 0, 0,-1); // (x, y, z) -> (y-z, x-z, -z) + + //the pure translation lattice (bravais lattice) has some maximum symmetry + //set first up the point group operations for this symmetry. + symgen[0] = inv; + // generate the point group operations for the bravais lattice + // rewrite with switch-case to get better performance and readability + switch (ibrav) { + case 1: + symgen[1] = r3d; + symgen[2] = r4zp; + this->matrigen(symgen, 3, symop, nop); + break; + case 2: + symgen[1] = r3d; + symgen[2] = r4zbc; + this->matrigen(symgen, 3, symop, nop); + break; + case 3: + symgen[1] = r3d; + symgen[2] = r4zfc; + this->matrigen(symgen, 3, symop, nop); + break; + case 4: + symgen[1] = r6z; + symgen[2] = r2hex; + this->matrigen(symgen, 3, symop, nop); + break; + case 5: + symgen[1] = r4zp; + symgen[2] = r2yp; + this->matrigen(symgen, 3, symop, nop); + break; + case 6: + symgen[1] = r4zbc; + symgen[2] = r2ybc; + this->matrigen(symgen, 3, symop, nop); + break; + case 7: + symgen[1] = r2tri; + symgen[2] = r3d; + this->matrigen(symgen, 3, symop, nop); + break; + case 8: + symgen[1] = r2zp; + symgen[2] = r2yp; + this->matrigen(symgen, 3, symop, nop); + break; + case 9: + symgen[1] = r2zbc; + symgen[2] = r2ybc; + this->matrigen(symgen, 3, symop, nop); + break; + case 10: + symgen[1] = r2zfc; + symgen[2] = r2yfc; + this->matrigen(symgen, 3, symop, nop); + break; + case 11: + symgen[1] = r2zp; + symgen[2] = r2ybas; + this->matrigen(symgen, 3, symop, nop); + break; + case 12: + symgen[1] = r2yp; + this->matrigen(symgen, 2, symop, nop); + break; + case 13: + symgen[1] = r2ybas; + this->matrigen(symgen, 2, symop, nop); + break; + case 14: + this->matrigen(symgen, 1, symop, nop); + break; + default: + ModuleBase::WARNING_QUIT("Symmetry_Basic::setgroup", + "ibrav = " + std::to_string(ibrav) + " is not supported."); + break; + } + + // print + if (test_brav) + { + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Number of rotation matrices", nop); + } + + // print the symmetry operations + if (cal_symm_repr != nullptr && cal_symm_repr[0] > 0) + { + GlobalV::ofs_running << std::endl + << " ======================================================================\n" + << " MATRIX REPRESENTATION OF SYMMETRY OPERATION\n" + << " ======================================================================\n" + << " There are " << nop << " symmetry operation representation matrices.\n" + << " For each matrix, the elements are arranged like: \n" + << " [[e11, e12, e13], [e21, e22, e23], [e31, e32, e33]].reshape(3, 3)\n" + << std::endl; + + // control the digits + const int precision = cal_symm_repr[1]; + const int width = precision + 4; + std::string fmtstr = " %" + std::to_string(width) + "." + std::to_string(precision) + "f"; + fmtstr += fmtstr + fmtstr + "\n"; + + // print the symmetry operations + std::string mat; + for (int i = 0; i < nop; ++i) + { + mat = " " + FmtCore::format("No. %3d", i + 1) + "\n" + + FmtCore::format(fmtstr.c_str(), symop[i].e11, symop[i].e12, symop[i].e13) + + FmtCore::format(fmtstr.c_str(), symop[i].e21, symop[i].e22, symop[i].e23) + + FmtCore::format(fmtstr.c_str(), symop[i].e31, symop[i].e32, symop[i].e33); + GlobalV::ofs_running << mat << std::endl; + } + GlobalV::ofs_running << " ======================================================================\n"; + } + + return; } int Symmetry_Basic::subgroup(const int& nrot, const int& ninv, @@ -550,307 +550,307 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, std::string& pgname, const ModuleBase::Matrix3* gmatrix, std::ofstream& ofs_running, const int* cal_symm_repr)const { - //------------------------------------------------------------------------- - //return the name of the point group - //the "name" (Schoenflies mark) of the group defined by following key: - // 1 --> C_1 9 --> C_3 17 --> D_4 25 --> C_6v * - // 2 --> S_2 10 --> S_6 18 --> C_4v 26 --> D_3h * - // 3 --> C_2 11 --> D_3 19 --> D_2d 27 --> D_6h * - // 4 --> C_1h 12 --> C_3v 20 --> D_4h 28 --> T * - // 5 --> C_2h 13 --> D_3d 21 --> C_6 29 --> T_h * - // 6 --> D_2 14 --> C_4 22 --> C_3h 30 --> O * - // 7 --> C_2v 15 --> S_4 23 --> C_6h 31 --> T_d * - // 8 --> D_2h 16 --> C_4h 24 --> D_6 32 --> O_h * - //------------------------------------------------------------------------- - - //there are four trivial cases which could be easily determined - //because the number of their elements are exclusive + //------------------------------------------------------------------------- + //return the name of the point group + //the "name" (Schoenflies mark) of the group defined by following key: + // 1 --> C_1 9 --> C_3 17 --> D_4 25 --> C_6v * + // 2 --> S_2 10 --> S_6 18 --> C_4v 26 --> D_3h * + // 3 --> C_2 11 --> D_3 19 --> D_2d 27 --> D_6h * + // 4 --> C_1h 12 --> C_3v 20 --> D_4h 28 --> T * + // 5 --> C_2h 13 --> D_3d 21 --> C_6 29 --> T_h * + // 6 --> D_2 14 --> C_4 22 --> C_3h 30 --> O * + // 7 --> C_2v 15 --> S_4 23 --> C_6h 31 --> T_d * + // 8 --> D_2h 16 --> C_4h 24 --> D_6 32 --> O_h * + //------------------------------------------------------------------------- + + //there are four trivial cases which could be easily determined + //because the number of their elements are exclusive if (cal_symm_repr != nullptr && cal_symm_repr[0] > 1) { - ModuleBase::TITLE("Symmetry_Basic", "pointgroup"); - } + ModuleBase::TITLE("Symmetry_Basic", "pointgroup"); + } std::vector pgdict = { "none", "C_1", "S_2", "C_2", "C_1h", "C_2h", "D_2", "C_2v", "D_2h", "C_3", "S_6", "D_3", "C_3v", "D_3d", "C_4", "S_4", "C_4h", "D_4", "C_4v", "D_2d", "D_4h", "C_6", "C_3h", "C_6h", "D_6", "C_6v", "D_3h", "D_6h", "T", "T_h", "O", "T_d", "O_h" }; - if(nrot == 1) - { - pgnumber = 1; - pgname="C_1"; + if(nrot == 1) + { + pgnumber = 1; + pgname="C_1"; return true; - } - if(nrot == 3) - { - pgnumber = 9; - pgname="C_3"; + } + if(nrot == 3) + { + pgnumber = 9; + pgname="C_3"; return true; - } - if(nrot == 16) - { - pgnumber = 20; - pgname="D_4h"; + } + if(nrot == 16) + { + pgnumber = 20; + pgname="D_4h"; return true; - } - if(nrot == 48) - { - pgnumber = 32; - pgname="O_h"; + } + if(nrot == 48) + { + pgnumber = 32; + pgname="O_h"; return true; - } - - //------------------------------------------------------------------------------- - //all other groups need further investigations and detailed analysis - //first determine the type of elements and count them - //Possible elements are E, I, C_2, C_3, C_4, C_6 and S_1, S_3, S_4, S_6 (S_1 = m) - //The type of a symmetry operation can be identified simply by - //calculating the trace and the determinant of the rotation matrix. The - //combination of these two quantities is specific for specific elements: - //------------------------------------------------------------------------------- - - // Element: E I C_2 C_3 C_4 C_6 S_1 S_6 S_4 S_3 - // Trace: +3 -3 -1 0 +1 +2 +1 0 -1 -2 - // Determinant: +1 -1 +1 +1 +1 +1 -1 -1 -1 -1 - - int trace = 0; - int det = 0; - int ninv = 0; - - int nc2 = 0; - int nc3 = 0; - int nc4 = 0; - int nc6 = 0; - int ns1 = 0; - int ns3 = 0; //mohan add 2012-01-15 - int ns4 = 0; - int ns6 = 0; //mohan add 2012-01-15 - - for(int i = 0; i < nrot; ++i) - { - //calculate the trace of a matrix - trace = int(gmatrix[i].e11+gmatrix[i].e22+gmatrix[i].e33); - //calculate the determinant of a matrix - det = int(gmatrix[i].Det()); - - if(trace == 3) - { - continue; //found unity operator (trivial) - } - //found inversion - if(trace == -3) - { - ninv = 1; - continue; - } - - if(trace == -1 && det == 1) { ++nc2; } - else if(trace == 0 && det == 1) { ++nc3; } - else if(trace == 1 && det == 1) { ++nc4; } - else if(trace == 2 && det == 1) { ++nc6; } - else if(trace == 1 && det == -1) { ++ns1; } - else if(trace == 0 && det == -1) { ++ns6; } //mohan add 2012-01-15 - else if(trace == -1 && det == -1) { ++ns4; } - else if(trace == -2 && det == -1) { ++ns3; } //mohan add 2012-01-15 - } + } + + //------------------------------------------------------------------------------- + //all other groups need further investigations and detailed analysis + //first determine the type of elements and count them + //Possible elements are E, I, C_2, C_3, C_4, C_6 and S_1, S_3, S_4, S_6 (S_1 = m) + //The type of a symmetry operation can be identified simply by + //calculating the trace and the determinant of the rotation matrix. The + //combination of these two quantities is specific for specific elements: + //------------------------------------------------------------------------------- + + // Element: E I C_2 C_3 C_4 C_6 S_1 S_6 S_4 S_3 + // Trace: +3 -3 -1 0 +1 +2 +1 0 -1 -2 + // Determinant: +1 -1 +1 +1 +1 +1 -1 -1 -1 -1 + + int trace = 0; + int det = 0; + int ninv = 0; + + int nc2 = 0; + int nc3 = 0; + int nc4 = 0; + int nc6 = 0; + int ns1 = 0; + int ns3 = 0; //mohan add 2012-01-15 + int ns4 = 0; + int ns6 = 0; //mohan add 2012-01-15 + + for(int i = 0; i < nrot; ++i) + { + //calculate the trace of a matrix + trace = int(gmatrix[i].e11+gmatrix[i].e22+gmatrix[i].e33); + //calculate the determinant of a matrix + det = int(gmatrix[i].Det()); + + if(trace == 3) + { + continue; //found unity operator (trivial) + } + //found inversion + if(trace == -3) + { + ninv = 1; + continue; + } + + if(trace == -1 && det == 1) { ++nc2; } + else if(trace == 0 && det == 1) { ++nc3; } + else if(trace == 1 && det == 1) { ++nc4; } + else if(trace == 2 && det == 1) { ++nc6; } + else if(trace == 1 && det == -1) { ++ns1; } + else if(trace == 0 && det == -1) { ++ns6; } //mohan add 2012-01-15 + else if(trace == -1 && det == -1) { ++ns4; } + else if(trace == -2 && det == -1) { ++ns3; } //mohan add 2012-01-15 + } if(test_brav) - { - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "C2", nc2); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "C3", nc3); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "C4", nc4); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "C6", nc6); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S1", ns1); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S3", ns3); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S4", ns4); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S6", ns6); - } - - if(nrot == 2) - { - if(ninv == 1) - { - pgnumber = 2; - pgname="S_2"; + { + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "C2", nc2); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "C3", nc3); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "C4", nc4); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "C6", nc6); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S1", ns1); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S3", ns3); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S4", ns4); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S6", ns6); + } + + if(nrot == 2) + { + if(ninv == 1) + { + pgnumber = 2; + pgname="S_2"; return true; - } - if(nc2 == 1) - { - pgnumber = 3; - pgname="C_2"; + } + if(nc2 == 1) + { + pgnumber = 3; + pgname="C_2"; return true; - } - if(ns1 == 1) - { - pgnumber = 4; - pgname="C_1h"; + } + if(ns1 == 1) + { + pgnumber = 4; + pgname="C_1h"; return true; - } - } - if(nrot == 4) - { - if(ninv == 1) - { - pgnumber = 5; - pgname="C_2h"; + } + } + if(nrot == 4) + { + if(ninv == 1) + { + pgnumber = 5; + pgname="C_2h"; return true; - } - if(nc2 == 3) - { - pgnumber = 6; - pgname="D_2"; + } + if(nc2 == 3) + { + pgnumber = 6; + pgname="D_2"; return true; - } - if(ns1 == 2) - { - pgnumber = 7; - pgname="C_2v"; + } + if(ns1 == 2) + { + pgnumber = 7; + pgname="C_2v"; return true; - } - if(nc4 == 2) - { - pgnumber = 14; - pgname="C_4"; + } + if(nc4 == 2) + { + pgnumber = 14; + pgname="C_4"; return true; - } - if(ns4 == 2) - { - pgnumber = 15; - pgname="S_4"; + } + if(ns4 == 2) + { + pgnumber = 15; + pgname="S_4"; return true; - } - } - if(nrot == 6) - { - if(ninv == 1) - { - pgnumber = 10; - pgname="S_6"; + } + } + if(nrot == 6) + { + if(ninv == 1) + { + pgnumber = 10; + pgname="S_6"; return true; - } - if(nc2 == 3) - { - pgnumber = 11; - pgname="D_3"; + } + if(nc2 == 3) + { + pgnumber = 11; + pgname="D_3"; return true; - } - if(ns1 == 3) - { - pgnumber = 12; - pgname="C_3v"; + } + if(ns1 == 3) + { + pgnumber = 12; + pgname="C_3v"; return true; - } - if(nc2 == 1) - { - pgnumber = 21; - pgname="C_6"; + } + if(nc2 == 1) + { + pgnumber = 21; + pgname="C_6"; return true; - } - if(ns1 == 1) - { - pgnumber = 22; - pgname="C_3h"; + } + if(ns1 == 1) + { + pgnumber = 22; + pgname="C_3h"; return true; - } - } - if(nrot == 8) - { - if(ns1 == 3) - { - pgnumber = 8; - pgname="D_2h"; + } + } + if(nrot == 8) + { + if(ns1 == 3) + { + pgnumber = 8; + pgname="D_2h"; return true; - } - if(ns1 == 1) - { - pgnumber = 16; - pgname="C_4h"; + } + if(ns1 == 1) + { + pgnumber = 16; + pgname="C_4h"; return true; - } - if(ns1 == 0) - { - pgnumber = 17; - pgname="D_4"; + } + if(ns1 == 0) + { + pgnumber = 17; + pgname="D_4"; return true; - } - if(ns1 == 4) - { - pgnumber = 18; - pgname="C_4v"; + } + if(ns1 == 4) + { + pgnumber = 18; + pgname="C_4v"; return true; - } - if(ns1 == 2) - { - pgnumber = 19; - pgname="D_2d"; + } + if(ns1 == 2) + { + pgnumber = 19; + pgname="D_2d"; return true; - } - } - if(nrot == 12) - { - if(ns1 == 3) - { - pgnumber = 13; - pgname="D_3d"; + } + } + if(nrot == 12) + { + if(ns1 == 3) + { + pgnumber = 13; + pgname="D_3d"; return true; - } - if(ns1 == 1) - { - pgnumber = 23; - pgname="C_6h"; + } + if(ns1 == 1) + { + pgnumber = 23; + pgname="C_6h"; return true; - } - if(nc2 == 7) - { - pgnumber = 24; - pgname="D_6"; + } + if(nc2 == 7) + { + pgnumber = 24; + pgname="D_6"; return true; - } - if(ns1 == 6) - { - pgnumber = 25; - pgname="C_6v"; + } + if(ns1 == 6) + { + pgnumber = 25; + pgname="C_6v"; return true; - } - if(ns1 == 4) - { - pgnumber = 26; - pgname="D_3h"; + } + if(ns1 == 4) + { + pgnumber = 26; + pgname="D_3h"; return true; - } - if(nc3 == 8) - { - pgnumber = 28; - pgname="T"; + } + if(nc3 == 8) + { + pgnumber = 28; + pgname="T"; return true; - } - } - if(nrot == 24) - { - if(nc6 == 2) - { - pgnumber = 27; - pgname="D_6h"; + } + } + if(nrot == 24) + { + if(nc6 == 2) + { + pgnumber = 27; + pgname="D_6h"; return true; - } - if(ninv == 1) - { - pgnumber = 29; - pgname="T_h"; + } + if(ninv == 1) + { + pgnumber = 29; + pgname="T_h"; return true; - } - if(nc4 == 6) - { - pgnumber = 30; - pgname="O"; + } + if(nc4 == 6) + { + pgnumber = 30; + pgname="O"; return true; - } - if(ns4 == 6) - { - pgnumber = 31; - pgname="T_d"; + } + if(ns4 == 6) + { + pgnumber = 31; + pgname="T_d"; return true; - } - } + } + } GlobalV::ofs_running << "\n WARNING: Symmetry operations cannot completely constitute a point group.\n\ It'll be better to try another `symmetry_prec`.\n Now search the subgroups ..." << std::endl; pgnumber = this->subgroup(nrot, ninv, nc2, nc3, nc4, nc6, ns1, ns3, ns4, ns6); @@ -860,40 +860,40 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3 >rans, - int i, int j, int k, // FFT grid index. - const int nr1, const int nr2, const int nr3, // dimension of FFT grid. - int &ri, int &rj, int &rk) + int i, int j, int k, // FFT grid index. + const int nr1, const int nr2, const int nr3, // dimension of FFT grid. + int &ri, int &rj, int &rk) { - static ModuleBase::Matrix3 g; - g.e11 = gmatrix.e11; - g.e21 = gmatrix.e21 * (double)nr1 / (double)nr2; - g.e31 = gmatrix.e31 * (double)nr1 / (double)nr3; - g.e12 = gmatrix.e12 * (double)nr2 / (double)nr1; - g.e22 = gmatrix.e22; - g.e32 = gmatrix.e32 * (double)nr2 / (double)nr3; - g.e13 = gmatrix.e13 * (double)nr3 / (double)nr1; - g.e23 = gmatrix.e23 * (double)nr3 / (double)nr2; - g.e33 = gmatrix.e33; - - ri = int(g.e11 * i + g.e21 * j + g.e31 * k) + (int)(gtrans.x * nr1); - if (ri < 0) - { - ri += 10 * nr1; - } - ri = ri%nr1; - rj = static_cast(g.e12 * i + g.e22 * j + g.e32 * k) + static_cast(gtrans.y * nr2); - if (rj < 0) - { - rj += 10 * nr2; - } - rj = rj%nr2; - rk = static_cast(g.e13 * i + g.e23 * j + g.e33 * k) + static_cast(gtrans.z * nr3); - if (rk < 0) - { - rk += 10 * nr3; - } - rk = rk%nr3; - return; + static ModuleBase::Matrix3 g; + g.e11 = gmatrix.e11; + g.e21 = gmatrix.e21 * (double)nr1 / (double)nr2; + g.e31 = gmatrix.e31 * (double)nr1 / (double)nr3; + g.e12 = gmatrix.e12 * (double)nr2 / (double)nr1; + g.e22 = gmatrix.e22; + g.e32 = gmatrix.e32 * (double)nr2 / (double)nr3; + g.e13 = gmatrix.e13 * (double)nr3 / (double)nr1; + g.e23 = gmatrix.e23 * (double)nr3 / (double)nr2; + g.e33 = gmatrix.e33; + + ri = int(g.e11 * i + g.e21 * j + g.e31 * k) + (int)(gtrans.x * nr1); + if (ri < 0) + { + ri += 10 * nr1; + } + ri = ri%nr1; + rj = static_cast(g.e12 * i + g.e22 * j + g.e32 * k) + static_cast(gtrans.y * nr2); + if (rj < 0) + { + rj += 10 * nr2; + } + rj = rj%nr2; + rk = static_cast(g.e13 * i + g.e23 * j + g.e33 * k) + static_cast(gtrans.z * nr3); + if (rk < 0) + { + rk += 10 * nr3; + } + rk = rk%nr3; + return; } // atom ordering for each atom type @@ -901,77 +901,77 @@ void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3 tmpx(natom); - std::vector tmpy(natom); - std::vector tmpz(natom); - for(int i=0; iorder_atoms(posi, natom, subindex); - for(int i=0; i1) //need a new sort - { - subindex[0] = 0; - for(int j=0; jorder_atoms(&posi[i*3], nxequal, subindex); - } - i=ix_right; - } - - delete[] weighted_func; - return; + //order the atomic positions inside a supercell by a unique ordering scheme + subindex[0] = 0; + + if(natom == 1) + { + //if there is only one atom, it is not necessary to order + return; + } + + std::vector tmpx(natom); + std::vector tmpy(natom); + std::vector tmpz(natom); + for(int i=0; iorder_atoms(posi, natom, subindex); + for(int i=0; i1) //need a new sort + { + subindex[0] = 0; + for(int j=0; jorder_atoms(&posi[i*3], nxequal, subindex); + } + i=ix_right; + } + + delete[] weighted_func; + return; } void Symmetry_Basic::test_atom_ordering(double *posi, const int natom, int *subindex) const { - //an interface to test a protected function - this->atom_ordering_new(posi, natom, subindex); + //an interface to test a protected function + this->atom_ordering_new(posi, natom, subindex); } } diff --git a/source/source_cell/module_symmetry/symmetry_basic.h b/source/source_cell/module_symmetry/symmetry_basic.h index 8bfed9253fd..196b8c3e57a 100644 --- a/source/source_cell/module_symmetry/symmetry_basic.h +++ b/source/source_cell/module_symmetry/symmetry_basic.h @@ -12,39 +12,39 @@ namespace ModuleSymmetry { class Symmetry_Basic { - public: + public: Symmetry_Basic() {}; ~Symmetry_Basic() {}; - double epsilon; ///< the precision of symmetry operation + double epsilon; ///< the precision of symmetry operation double epsilon_input; ///< the input value of symmetry_prec, should not be changed - // control accuray - bool equal(const double &m, const double &n)const; - void check_boundary(double &x)const; + // control accuray + bool equal(const double &m, const double &n)const; + void check_boundary(double &x)const; double get_translation_vector(const double& x1, const double& x2)const; - void check_translation(double &x, const double &t) const; + void check_translation(double &x, const double &t) const; double check_diff(const double& x1, const double& x2) const; - - void veccon( - double *va, - double *vb, - const int num, - const ModuleBase::Vector3 &aa1, - const ModuleBase::Vector3 &aa2, - const ModuleBase::Vector3 &aa3, - const ModuleBase::Vector3 &bb1, - const ModuleBase::Vector3 &bb2, - const ModuleBase::Vector3 &bb3 - ); - void matrigen(ModuleBase::Matrix3 *symgen, const int ngen, ModuleBase::Matrix3* symop, int &nop) const; - void setgroup(ModuleBase::Matrix3 *symop, int &nop, const int &ibrav, + + void veccon( + double *va, + double *vb, + const int num, + const ModuleBase::Vector3 &aa1, + const ModuleBase::Vector3 &aa2, + const ModuleBase::Vector3 &aa3, + const ModuleBase::Vector3 &bb1, + const ModuleBase::Vector3 &bb2, + const ModuleBase::Vector3 &bb3 + ); + void matrigen(ModuleBase::Matrix3 *symgen, const int ngen, ModuleBase::Matrix3* symop, int &nop) const; + void setgroup(ModuleBase::Matrix3 *symop, int &nop, const int &ibrav, const int* cal_symm_repr) const; - void rotate( - ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3 >rans, - int i, int j, int k, const int, const int, const int, int&, int&, int&); - void test_atom_ordering(double *posi, const int natom, int *subindex) const; + void rotate( + ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3 >rans, + int i, int j, int k, const int, const int, const int, int&, int&, int&); + void test_atom_ordering(double *posi, const int natom, int *subindex) const; /// find out the greatest subgrop according to the number of operations of certain type. /// used to deal with incomplete group due to a subtle`symmetry_prec` @@ -55,14 +55,14 @@ class Symmetry_Basic protected: std::string get_brav_name(const int ibrav) const; - void atom_ordering(double *posi, const int natom, int *subindex); - void atom_ordering_new(double *posi, const int natom, int *subindex) const; + void atom_ordering(double *posi, const int natom, int *subindex); + void atom_ordering_new(double *posi, const int natom, int *subindex) const; - private: + private: - void order_atoms(double* pos, const int &nat, const int *index) const; - void order_y(double *pos, const int &oldpos, const int &newpos); - void order_z(double *pos, const int &oldpos, const int &newpos); + void order_atoms(double* pos, const int &nat, const int *index) const; + void order_y(double *pos, const int &oldpos, const int &newpos); + void order_z(double *pos, const int &oldpos, const int &newpos); }; //for test only diff --git a/source/source_cell/parallel_kpoints.cpp b/source/source_cell/parallel_kpoints.cpp index 2ca14090fba..d52260b3670 100644 --- a/source/source_cell/parallel_kpoints.cpp +++ b/source/source_cell/parallel_kpoints.cpp @@ -211,10 +211,10 @@ void Parallel_Kpoints::pool_collection_aux(T* value, const V& w, const int& dim, T* p = &w.ptr[begin]; // temprary restrict kpar=1 for NSPIN=2 case for generating_orbitals int pool = 0; - if (this->nspin != 2) - { - pool = this->whichpool[ik]; - } + if (this->nspin != 2) + { + pool = this->whichpool[ik]; + } if (this->rank_in_pool == 0) { diff --git a/source/source_cell/print_cell.cpp b/source/source_cell/print_cell.cpp index b9c3abdf211..0c71b8bdbba 100644 --- a/source/source_cell/print_cell.cpp +++ b/source/source_cell/print_cell.cpp @@ -58,17 +58,17 @@ namespace unitcell << std::setw(19) << "vz" << std::endl; - for(int it = 0; it < ntype; it++) - { - for (int ia = 0; ia < atoms[it].na; ia++) - { + for(int it = 0; it < ntype; it++) + { + for (int ia = 0; ia < atoms[it].na; ia++) + { ofs << std::setw(5) << atoms[it].label; ofs << " " << std::setw(18) << atoms[it].vel[ia].x; ofs << " " << std::setw(18) << atoms[it].vel[ia].y; ofs << " " << std::setw(18) << atoms[it].vel[ia].z; ofs << std::endl; - } - } + } + } ofs << std::endl; ofs << std::setprecision(6); // return to 6, as original diff --git a/source/source_cell/pseudo.cpp b/source/source_cell/pseudo.cpp index c9a057e3a71..333d9d59c42 100644 --- a/source/source_cell/pseudo.cpp +++ b/source/source_cell/pseudo.cpp @@ -13,66 +13,66 @@ pseudo::~pseudo() void pseudo::check_betar() { - bool min_flag = false; - for (int ib = 0; ib < nbeta; ib++) - { - for (int ir = 0; ir < mesh; ir++) - { - // Get the bit representation of the double - uint64_t bits = *(uint64_t*)&betar(ib, ir); - // Extract exponent field (bits 52-62) - uint64_t exponent = (bits >> 52) & 0x7FF; - // Define exponent threshold for 1e-30 - // Calculated as: bias + floor(log2(1e-30)) - // Where bias = 1023 and log2(1e-30) ≈ -99.657 - // Thus threshold is approximately 923 - if ((exponent <= 923)) - { - min_flag = true; - betar(ib, ir) = 0.0; - } - } - } - if (min_flag) - { - std::cout << " WARNING: some of potential function is set to zero cause of less than 1e-30.\n"; - } + bool min_flag = false; + for (int ib = 0; ib < nbeta; ib++) + { + for (int ir = 0; ir < mesh; ir++) + { + // Get the bit representation of the double + uint64_t bits = *(uint64_t*)&betar(ib, ir); + // Extract exponent field (bits 52-62) + uint64_t exponent = (bits >> 52) & 0x7FF; + // Define exponent threshold for 1e-30 + // Calculated as: bias + floor(log2(1e-30)) + // Where bias = 1023 and log2(1e-30) ≈ -99.657 + // Thus threshold is approximately 923 + if ((exponent <= 923)) + { + min_flag = true; + betar(ib, ir) = 0.0; + } + } + } + if (min_flag) + { + std::cout << " WARNING: some of potential function is set to zero cause of less than 1e-30.\n"; + } } void pseudo::print_pseudo(std::ofstream& ofs) const { - print_pseudo_vl(ofs); - ofs << "\n pseudo : "; - ofs << "\n kkbeta " << kkbeta; - ofs << "\n nh " << nh; - output::printr1_d(ofs, " lll : ", lll.data(), nbeta); - output::printrm(ofs, " betar : ", betar); - output::printrm(ofs, " dion : ", dion); - ofs << "\n ----------------------"; + print_pseudo_vl(ofs); + ofs << "\n pseudo : "; + ofs << "\n kkbeta " << kkbeta; + ofs << "\n nh " << nh; + output::printr1_d(ofs, " lll : ", lll.data(), nbeta); + output::printrm(ofs, " betar : ", betar); + output::printrm(ofs, " dion : ", dion); + ofs << "\n ----------------------"; } void pseudo::print_pseudo_atom(std::ofstream& ofs) const { - print_pseudo_h(ofs); - ofs << "\n pseudo_atom : "; - ofs << "\n msh " << msh; -// ofs << "\n nchi " << nchi; - output::printr1_d(ofs, " r : ", r.data(), mesh); - output::printr1_d(ofs, " rab : ", rab.data(), mesh); - output::printr1_d(ofs, " rho_atc : ", rho_atc.data(), mesh); - output::printr1_d(ofs, " rho_at : ", rho_at.data(), mesh); - output::printr1_d(ofs," jchi : ", jchi.data(), nchi); - output::printrm(ofs, " chi : ", chi); - ofs << "\n ----------------------"; + print_pseudo_h(ofs); + ofs << "\n pseudo_atom : "; + ofs << "\n msh " << msh; +// ofs << "\n nchi " << nchi; + output::printr1_d(ofs, " r : ", r.data(), mesh); + output::printr1_d(ofs, " rab : ", rab.data(), mesh); + output::printr1_d(ofs, " rho_atc : ", rho_atc.data(), mesh); + output::printr1_d(ofs, " rho_at : ", rho_at.data(), mesh); + output::printr1_d(ofs," jchi : ", jchi.data(), nchi); + output::printrm(ofs, " chi : ", chi); + ofs << "\n ----------------------"; } void pseudo::print_pseudo_vl(std::ofstream& ofs) const { - ofs << "\n pseudo_vl:"; - print_pseudo_atom(ofs); - output::printr1_d(ofs, "vloc_at : ", vloc_at.data(), mesh); - ofs << "\n ----------------------------------- "; + ofs << "\n pseudo_vl:"; + print_pseudo_atom(ofs); + output::printr1_d(ofs, "vloc_at : ", vloc_at.data(), mesh); + ofs << "\n ----------------------------------- "; } void pseudo::print_pseudo_h(std::ofstream& ofs) const diff --git a/source/source_cell/read_orb.cpp b/source/source_cell/read_orb.cpp index 2d0c3da582f..251d94403c5 100644 --- a/source/source_cell/read_orb.cpp +++ b/source/source_cell/read_orb.cpp @@ -65,8 +65,8 @@ namespace unitcell { ifs.close(); if(!atom->nw) { - ModuleBase::WARNING("unitcell::read_orb_file","get nw = 0, check the ORBITAL file"); - return false; + ModuleBase::WARNING("unitcell::read_orb_file","get nw = 0, check the ORBITAL file"); + return false; } return true; } diff --git a/source/source_cell/read_pp.cpp b/source/source_cell/read_pp.cpp index 9732ee196a1..26a471f01b4 100644 --- a/source/source_cell/read_pp.cpp +++ b/source/source_cell/read_pp.cpp @@ -24,40 +24,40 @@ int Pseudopot_upf::init_pseudo_reader(const std::string &fn, std::string &type, // First check if this pseudo-potential has spin-orbit information std::ifstream ifs(fn.c_str(), std::ios::in); - // can't find the file. - if (!ifs) + // can't find the file. + if (!ifs) { return 1; } - if (type == "auto") - { - set_pseudo_type(fn, type); - } - - int info = -1; - if (type == "upf") - { - info = read_pseudo_upf(ifs, pp); - } - else if (type == "vwr") - { - info = read_pseudo_vwr(ifs, pp); - } - else if (type == "upf201") - { - info = read_pseudo_upf201(ifs, pp); - } - else if (type == "blps") - { - info = read_pseudo_blps(ifs, pp); - } + if (type == "auto") + { + set_pseudo_type(fn, type); + } + + int info = -1; + if (type == "upf") + { + info = read_pseudo_upf(ifs, pp); + } + else if (type == "vwr") + { + info = read_pseudo_vwr(ifs, pp); + } + else if (type == "upf201") + { + info = read_pseudo_upf201(ifs, pp); + } + else if (type == "blps") + { + info = read_pseudo_blps(ifs, pp); + } else { return 4; } - return info; + return info; } @@ -68,26 +68,26 @@ int Pseudopot_upf::set_pseudo_type(const std::string &fn, std::string &type) //z { std::ifstream pptype_ifs(fn.c_str(), std::ios::in); std::string dummy; - std::string strversion; - - if (pptype_ifs.good()) - { - getline(pptype_ifs,dummy); - - std::stringstream wdsstream(dummy); - getline(wdsstream,strversion,'"'); - getline(wdsstream,strversion,'"'); - - if ( trim(strversion) == "2.0.1" ) - { - type = "upf201"; - } - else - { - type = "upf"; - } - } - return 0; + std::string strversion; + + if (pptype_ifs.good()) + { + getline(pptype_ifs,dummy); + + std::stringstream wdsstream(dummy); + getline(wdsstream,strversion,'"'); + getline(wdsstream,strversion,'"'); + + if ( trim(strversion) == "2.0.1" ) + { + type = "upf201"; + } + else + { + type = "upf"; + } + } + return 0; } std::string& Pseudopot_upf::trim(std::string &in_str) @@ -95,9 +95,9 @@ std::string& Pseudopot_upf::trim(std::string &in_str) static const std::string deltri = " \t" ; // delete tab or space std::string::size_type position = in_str.find_first_of(deltri, 0); if (position == std::string::npos) - { + { return in_str; - } + } return trim(in_str.erase(position, 1) ); } @@ -138,276 +138,276 @@ int Pseudopot_upf::average_p(const double& lambda, Atom_pseudo& pp, const bool l } //if(std::abs(lambda_)<1.0e-8) - if(!lspinorb_) - { - int new_nbeta = 0; //calculate the new nbeta - for(int nb=0; nb< pp.nbeta; nb++) - { - new_nbeta++; - if(pp.lll[nb] != 0 && std::abs(pp.jjj[nb] - pp.lll[nb] - 0.5) < 1e-6) //two J = l +- 0.5 average to one - { - new_nbeta--; - } - } - - pp.nbeta = new_nbeta; - ModuleBase::matrix dion_new; - dion_new.create(pp.nbeta, pp.nbeta); - - int old_nbeta=-1; - for(int nb=0; nb1e-6) - { - error = 1; - std::cout<<"warning_quit! error beta function 1 !" <1e-6) - { - error = 1; - std::cout<<"warning_quit! error beta function 2 !" <1e-6) - { - error++; - std::cout<<"warning_quit! error chi function 1 !"<1e-6) - { - error++; - std::cout<<"warning_quit! error chi function 2 !"<1e-6) - { - error = 1; - std::cout<<"warning_quit! error beta function 1 !" <1e-6) - { - error = 1; - std::cout<<"warning_quit! error beta function 2 !" <1e-6) - { - error++; - std::cout<<"warning_quit! error chi function 1 !"<1e-6) - { - error++; - std::cout<<"warning_quit! error chi function 2 !"<1e-6) + { + error = 1; + std::cout<<"warning_quit! error beta function 1 !" <1e-6) + { + error = 1; + std::cout<<"warning_quit! error beta function 2 !" <1e-6) + { + error++; + std::cout<<"warning_quit! error chi function 1 !"<1e-6) + { + error++; + std::cout<<"warning_quit! error chi function 2 !"<1e-6) + { + error = 1; + std::cout<<"warning_quit! error beta function 1 !" <1e-6) + { + error = 1; + std::cout<<"warning_quit! error beta function 2 !" <1e-6) + { + error++; + std::cout<<"warning_quit! error chi function 1 !"<1e-6) + { + error++; + std::cout<<"warning_quit! error chi function 2 !"<> temp; - } + if (mesh_changed) + { + double temp = 0.; + ifs >> temp; + } } diff --git a/source/source_cell/read_pp.h b/source/source_cell/read_pp.h index 28e988eba70..31fadae7769 100644 --- a/source/source_cell/read_pp.h +++ b/source/source_cell/read_pp.h @@ -10,18 +10,18 @@ class Pseudopot_upf { public: - //PP_INFO - //PP_HEADER - //PP_MESH - //PP_NLCC - //PP_LOCAL - //PP_NONLOCAL - //PP_PSWFC - //PP_PSRHOATOM - //addinfo - - Pseudopot_upf(); - ~Pseudopot_upf(); + //PP_INFO + //PP_HEADER + //PP_MESH + //PP_NLCC + //PP_LOCAL + //PP_NONLOCAL + //PP_PSWFC + //PP_PSRHOATOM + //addinfo + + Pseudopot_upf(); + ~Pseudopot_upf(); std::string relativistic; // relativistic: no, scalar, full int lmax_rho; // maximum angular momentum component in rho (should be 2*lmax) diff --git a/source/source_cell/read_pp_blps.cpp b/source/source_cell/read_pp_blps.cpp index 5370dbc41b4..5ece8d06d98 100644 --- a/source/source_cell/read_pp_blps.cpp +++ b/source/source_cell/read_pp_blps.cpp @@ -44,10 +44,10 @@ int Pseudopot_upf::read_pseudo_blps(std::ifstream &ifs, Atom_pseudo& pp) ifs >> pspcod >> pspxc >> pp.lmax >> lloc >> pp.mesh >> r2well; this->mesh_changed = false; if (pp.mesh%2 == 0) - { - pp.mesh -= 1; + { + pp.mesh -= 1; this->mesh_changed = true; - } + } if (pspxc == 2) { diff --git a/source/source_cell/read_pp_complete.cpp b/source/source_cell/read_pp_complete.cpp index 86cacb43e68..10899bd0349 100644 --- a/source/source_cell/read_pp_complete.cpp +++ b/source/source_cell/read_pp_complete.cpp @@ -6,159 +6,159 @@ void Pseudopot_upf::complete_default(Atom_pseudo& pp, const double pseudo_rcut) // call subroutines this->complete_default_h(pp); - this->complete_default_atom(pp, pseudo_rcut); - this->complete_default_vl(pp); - - if (pp.nbeta == 0) { - return; - } - - if (pp.lll.empty()) - { - pp.lll = std::vector(pp.nbeta, 0); - } - - pp.nh = 0; - - for (int nb = 0; nb < pp.nbeta;nb++) - { - pp.nh += 2 * pp.lll [nb] + 1; - } - - return; + this->complete_default_atom(pp, pseudo_rcut); + this->complete_default_vl(pp); + + if (pp.nbeta == 0) { + return; + } + + if (pp.lll.empty()) + { + pp.lll = std::vector(pp.nbeta, 0); + } + + pp.nh = 0; + + for (int nb = 0; nb < pp.nbeta;nb++) + { + pp.nh += 2 * pp.lll [nb] + 1; + } + + return; } void Pseudopot_upf::complete_default_h(Atom_pseudo& pp) { - ModuleBase::TITLE("Pseudopot_upf","complete_default_h"); - - // mohan update 2021-02-22 - // max number of points in the atomic radial mesh - int ndmx = 200000; - if (pp.mesh > ndmx) - { - std::cout << "\n complete_default_h, too many grid points,"; - } - - if (pp.els.empty()) - { - pp.els = std::vector(pp.nchi, ""); - } - - if (pp.lchi.empty()) - { - pp.lchi = std::vector(pp.nchi, 0); - } - - if (pp.oc.empty()) - { - pp.oc = std::vector(pp.nchi, 0.0); - } - - if (pp.jjj.empty()) { - pp.jjj = std::vector(pp.nbeta, 0.0); - assert(!pp.has_so or pp.nbeta == 0); - for (int i=0; i(pp.nchi, 0); - assert(!pp.has_so or pp.nchi == 0); - for (int i=0; i(pp.nchi, 0.0); - assert(!pp.has_so or pp.nchi == 0); - for (int i=0; i ndmx) + { + std::cout << "\n complete_default_h, too many grid points,"; + } + + if (pp.els.empty()) + { + pp.els = std::vector(pp.nchi, ""); + } + + if (pp.lchi.empty()) + { + pp.lchi = std::vector(pp.nchi, 0); + } + + if (pp.oc.empty()) + { + pp.oc = std::vector(pp.nchi, 0.0); + } + + if (pp.jjj.empty()) { + pp.jjj = std::vector(pp.nbeta, 0.0); + assert(!pp.has_so or pp.nbeta == 0); + for (int i=0; i(pp.nchi, 0); + assert(!pp.has_so or pp.nchi == 0); + for (int i=0; i(pp.nchi, 0.0); + assert(!pp.has_so or pp.nchi == 0); + for (int i=0; i(pp.mesh, 0.0); - } - - if (pp.rab.empty()) { - pp.rab = std::vector(pp.mesh, 0.0); - } - - if (pp.rho_at.empty()) { - pp.rho_at = std::vector(pp.mesh, 0.0); - } - - if (pp.rho_atc.empty()) { - pp.rho_atc = std::vector(pp.mesh, 0.0); - assert(!pp.nlcc or pp.mesh == 0); - } - - bool br = false; - - pp.msh = 0; - - for (int ir = 0;ir < pp.mesh;ir++) - { - if (pp.r [ir] > pp.rcut) - { - pp.msh = ir + 1; - br = true; - break; - } - } - - if (br) - { - // force msh to be odd for simpson integration - pp.msh = 2 * static_cast((pp.msh + 1) / 2) - 1; // Use static_cast instead of C-style cast for type safety - } - else - { - pp.msh = pp.mesh ; - } - - return; + ModuleBase::TITLE("Pseudopot_upf","complete_default_atom"); + + // mohan 2009-12-15 + // mohan update again 2011-05-23, + // in order to calculate more accurate Vna. + const double pseudo_rcut_ = pseudo_rcut; + pp.rcut = pseudo_rcut_;//(a.u.); + + // remember to update here if you need it. + // rcut = 25.0; + + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"PAO radial cut off (Bohr)", pp.rcut); + if(pp.rcut <= 0.0) + { + ModuleBase::WARNING_QUIT("Pseudopot_upf::complete_default_atom","PAO rcut<=0.0"); + } + + // chi.create(nchi, mesh); + + if (pp.r.empty()) { + pp.r = std::vector(pp.mesh, 0.0); + } + + if (pp.rab.empty()) { + pp.rab = std::vector(pp.mesh, 0.0); + } + + if (pp.rho_at.empty()) { + pp.rho_at = std::vector(pp.mesh, 0.0); + } + + if (pp.rho_atc.empty()) { + pp.rho_atc = std::vector(pp.mesh, 0.0); + assert(!pp.nlcc or pp.mesh == 0); + } + + bool br = false; + + pp.msh = 0; + + for (int ir = 0;ir < pp.mesh;ir++) + { + if (pp.r [ir] > pp.rcut) + { + pp.msh = ir + 1; + br = true; + break; + } + } + + if (br) + { + // force msh to be odd for simpson integration + pp.msh = 2 * static_cast((pp.msh + 1) / 2) - 1; // Use static_cast instead of C-style cast for type safety + } + else + { + pp.msh = pp.mesh ; + } + + return; } void Pseudopot_upf::complete_default_vl(Atom_pseudo& pp) { - ModuleBase::TITLE("Pseudopot_upf","complete_default_vl"); + ModuleBase::TITLE("Pseudopot_upf","complete_default_vl"); - assert(pp.mesh>0);//mohan add 2021-05-01 + assert(pp.mesh>0);//mohan add 2021-05-01 - if (pp.vloc_at.empty()) { - pp.vloc_at = std::vector(pp.mesh, 0.0); - } + if (pp.vloc_at.empty()) { + pp.vloc_at = std::vector(pp.mesh, 0.0); + } - return; + return; } diff --git a/source/source_cell/read_pp_upf100.cpp b/source/source_cell/read_pp_upf100.cpp index 30cc94fa825..5d26764a23d 100644 --- a/source/source_cell/read_pp_upf100.cpp +++ b/source/source_cell/read_pp_upf100.cpp @@ -286,7 +286,7 @@ void Pseudopot_upf::read_pseudo_local(std::ifstream& ifs, Atom_pseudo& pp) void Pseudopot_upf::read_pseudo_nl(std::ifstream& ifs, Atom_pseudo& pp) { - // int nb, mb, n, ir, idum, ldum, lp, i, ikk; + // int nb, mb, n, ir, idum, ldum, lp, i, ikk; int nb = 0; int mb = 0; int ir = 0; diff --git a/source/source_cell/read_pp_upf201.cpp b/source/source_cell/read_pp_upf201.cpp index d02bb8e6d51..39163b799ab 100644 --- a/source/source_cell/read_pp_upf201.cpp +++ b/source/source_cell/read_pp_upf201.cpp @@ -130,11 +130,11 @@ void Pseudopot_upf::getnameval(std::ifstream& ifs, int& n, std::string* name, st while (1) { pos = txt.find("=", pos); - if (pos == std::string::npos) - { - break; - } - pos++; + if (pos == std::string::npos) + { + break; + } + pos++; n++; } @@ -147,10 +147,10 @@ void Pseudopot_upf::getnameval(std::ifstream& ifs, int& n, std::string* name, st pos2 = txt.find("=", pos); for (; pos2 > pos; --pos2) // There may be a space before "="; { - if (txt.substr(pos2 - 1, 1) != " ") - { - break; - } + if (txt.substr(pos2 - 1, 1) != " ") + { + break; + } } ll = pos2 - pos; name[i] = txt.substr(pos, ll); @@ -166,12 +166,12 @@ void Pseudopot_upf::getnameval(std::ifstream& ifs, int& n, std::string* name, st break; } } - if (!findmark) - { - ModuleBase::WARNING_QUIT( - "Pseudopot_upf::getnameval", - "The values are not in \' or \". Please improve the program in read_pp_upf201.cpp"); - } + if (!findmark) + { + ModuleBase::WARNING_QUIT( + "Pseudopot_upf::getnameval", + "The values are not in \' or \". Please improve the program in read_pp_upf201.cpp"); + } pos = pos2; pos2 = txt.find(mark, pos); ll = pos2 - pos; @@ -180,15 +180,15 @@ void Pseudopot_upf::getnameval(std::ifstream& ifs, int& n, std::string* name, st val[i] = tmpval; pos = pos2 + 1; for (int j = 0; j < 100; ++j) - { - if (txt.substr(pos, 1) == " " || txt.substr(pos, 1) == ",") - { - pos++; - } - else - { - break; - } + { + if (txt.substr(pos, 1) == " " || txt.substr(pos, 1) == ",") + { + pos++; + } + else + { + break; + } } //std::cout<> value; length = value.find(","); value.erase(length,1); - pp.mesh = std::atoi( value.c_str() ); - //the mesh should be odd, which is forced in Simpson integration - this->mesh_changed = false; - if(pp.mesh%2==0) - { - pp.mesh=pp.mesh-1; - this->mesh_changed = true; - GlobalV::ofs_running << " Mesh number - 1, we need odd number, \n this may affect some polar atomic orbitals." << std::endl; - } - GlobalV::ofs_running << std::setw(15) << "MESH" << std::setw(15) << pp.mesh << std::endl; - // (2) read in nlcc: nonlinear core correction - ifs >> value; length = value.find(","); value.erase(length,1); - pp.nlcc = std::atoi( value.c_str() ); - GlobalV::ofs_running << std::setw(15) << "NLCC" << std::setw(15) << pp.nlcc << std::endl; - // (3) iatom : index for atom - ifs >> value; length = value.find(","); value.erase(length,1); - pp.psd = value; - GlobalV::ofs_running << std::setw(15) << "ATOM" << std::setw(15) << pp.psd << std::endl; - // (4) valence electron number - ifs >> value; length = value.find(","); value.erase(length,1); - pp.zv = std::stod( value ); - GlobalV::ofs_running << std::setw(15) << "Z(VALENCE)" << std::setw(15) << pp.zv << std::endl; - // (5) spd_loc, which local pseudopotential should I choose - ifs >> value; length = value.find(","); value.erase(length,1); - spd_loc = std::atoi( value.c_str() ); - GlobalV::ofs_running << std::setw(15) << "LOC(spd)" << std::setw(15) << spd_loc << std::endl; - // (6) read in the occupations - std::vector tmp_oc(3, 0.0); - ifs >> value; length = value.find(","); value.erase(length,1); - tmp_oc[0]= std::atoi( value.c_str() ); - ifs >> value; length = value.find(","); value.erase(length,1); - tmp_oc[1]= std::atoi( value.c_str() ); - ifs >> value; length = value.find(","); value.erase(length,1); - tmp_oc[2]= std::atoi( value.c_str() ); - GlobalV::ofs_running << std::setw(15) << "OCCUPATION" << std::setw(15) << tmp_oc[0] - << std::setw(15) << tmp_oc[1] << std::setw(15) << tmp_oc[2] << std::endl; - // (7) spin orbital - ifs >> pp.has_so; + std::string value; + size_t length=0; + ifs >> value; length = value.find(","); value.erase(length,1); + pp.mesh = std::atoi( value.c_str() ); + //the mesh should be odd, which is forced in Simpson integration + this->mesh_changed = false; + if(pp.mesh%2==0) + { + pp.mesh=pp.mesh-1; + this->mesh_changed = true; + GlobalV::ofs_running << " Mesh number - 1, we need odd number, \n this may affect some polar atomic orbitals." << std::endl; + } + GlobalV::ofs_running << std::setw(15) << "MESH" << std::setw(15) << pp.mesh << std::endl; + // (2) read in nlcc: nonlinear core correction + ifs >> value; length = value.find(","); value.erase(length,1); + pp.nlcc = std::atoi( value.c_str() ); + GlobalV::ofs_running << std::setw(15) << "NLCC" << std::setw(15) << pp.nlcc << std::endl; + // (3) iatom : index for atom + ifs >> value; length = value.find(","); value.erase(length,1); + pp.psd = value; + GlobalV::ofs_running << std::setw(15) << "ATOM" << std::setw(15) << pp.psd << std::endl; + // (4) valence electron number + ifs >> value; length = value.find(","); value.erase(length,1); + pp.zv = std::stod( value ); + GlobalV::ofs_running << std::setw(15) << "Z(VALENCE)" << std::setw(15) << pp.zv << std::endl; + // (5) spd_loc, which local pseudopotential should I choose + ifs >> value; length = value.find(","); value.erase(length,1); + spd_loc = std::atoi( value.c_str() ); + GlobalV::ofs_running << std::setw(15) << "LOC(spd)" << std::setw(15) << spd_loc << std::endl; + // (6) read in the occupations + std::vector tmp_oc(3, 0.0); + ifs >> value; length = value.find(","); value.erase(length,1); + tmp_oc[0]= std::atoi( value.c_str() ); + ifs >> value; length = value.find(","); value.erase(length,1); + tmp_oc[1]= std::atoi( value.c_str() ); + ifs >> value; length = value.find(","); value.erase(length,1); + tmp_oc[2]= std::atoi( value.c_str() ); + GlobalV::ofs_running << std::setw(15) << "OCCUPATION" << std::setw(15) << tmp_oc[0] + << std::setw(15) << tmp_oc[1] << std::setw(15) << tmp_oc[2] << std::endl; + // (7) spin orbital + ifs >> pp.has_so; - // label to count the projector or atomic wave functions - getline(ifs,value); - int iref_s, iref_p, iref_d; - ifs >> iref_s >> iref_p >> iref_d; - GlobalV::ofs_running << std::setw(15) << "Vnl_USED" << std::setw(15) << iref_s - << std::setw(15) << iref_p << std::setw(15) << iref_d << std::endl; - if(spd_loc==1) { iref_s=0; - } else if(spd_loc==2) { iref_p=0; - } else if(spd_loc==3) { iref_d=0; + // label to count the projector or atomic wave functions + getline(ifs,value); + int iref_s, iref_p, iref_d; + ifs >> iref_s >> iref_p >> iref_d; + GlobalV::ofs_running << std::setw(15) << "Vnl_USED" << std::setw(15) << iref_s + << std::setw(15) << iref_p << std::setw(15) << iref_d << std::endl; + if(spd_loc==1) { iref_s=0; + } else if(spd_loc==2) { iref_p=0; + } else if(spd_loc==3) { iref_d=0; } - ifs >> iTB_s >> iTB_p >> iTB_d; - GlobalV::ofs_running << std::setw(15) << "Orb_USED" << std::setw(15) << iTB_s - << std::setw(15) << iTB_p << std::setw(15) << iTB_d << std::endl; - - - // calculate the number of wave functions - pp.nchi = 0; - if(iTB_s) { ++pp.nchi; + ifs >> iTB_s >> iTB_p >> iTB_d; + GlobalV::ofs_running << std::setw(15) << "Orb_USED" << std::setw(15) << iTB_s + << std::setw(15) << iTB_p << std::setw(15) << iTB_d << std::endl; + + + // calculate the number of wave functions + pp.nchi = 0; + if(iTB_s) { ++pp.nchi; } - if(iTB_p) { ++pp.nchi; + if(iTB_p) { ++pp.nchi; } - if(iTB_d) { ++pp.nchi; + if(iTB_d) { ++pp.nchi; } - GlobalV::ofs_running << std::setw(15) << "NWFC" << std::setw(15) << pp.nchi << std::endl; - // allocate occupation number array for wave functions - pp.oc = std::vector(pp.nchi, 0.0); - pp.els = std::vector(pp.nchi, ""); - // set the value of occupations - pp.lchi = std::vector(pp.nchi, 0); - int iwfc=0; - if(iTB_s){pp.oc[iwfc]=tmp_oc[0];pp.lchi[iwfc]=0;pp.els[iwfc]="S";++iwfc;} - if(iTB_p){pp.oc[iwfc]=tmp_oc[1];pp.lchi[iwfc]=1;pp.els[iwfc]="P";++iwfc;} - if(iTB_d){pp.oc[iwfc]=tmp_oc[2];pp.lchi[iwfc]=2;pp.els[iwfc]="D";++iwfc;} - getline(ifs,value); + GlobalV::ofs_running << std::setw(15) << "NWFC" << std::setw(15) << pp.nchi << std::endl; + // allocate occupation number array for wave functions + pp.oc = std::vector(pp.nchi, 0.0); + pp.els = std::vector(pp.nchi, ""); + // set the value of occupations + pp.lchi = std::vector(pp.nchi, 0); + int iwfc=0; + if(iTB_s){pp.oc[iwfc]=tmp_oc[0];pp.lchi[iwfc]=0;pp.els[iwfc]="S";++iwfc;} + if(iTB_p){pp.oc[iwfc]=tmp_oc[1];pp.lchi[iwfc]=1;pp.els[iwfc]="P";++iwfc;} + if(iTB_d){pp.oc[iwfc]=tmp_oc[2];pp.lchi[iwfc]=2;pp.els[iwfc]="D";++iwfc;} + getline(ifs,value); - // global variables that will be used - // in other classes. - pp.r = std::vector(pp.mesh, 0.0); - pp.rab = std::vector(pp.mesh, 0.0); - pp.vloc_at = std::vector(pp.mesh, 0.0); - pp.rho_at = std::vector(pp.mesh, 0.0); - pp.rho_atc = std::vector(pp.mesh, 0.0); - // local variables in this function + // global variables that will be used + // in other classes. + pp.r = std::vector(pp.mesh, 0.0); + pp.rab = std::vector(pp.mesh, 0.0); + pp.vloc_at = std::vector(pp.mesh, 0.0); + pp.rho_at = std::vector(pp.mesh, 0.0); + pp.rho_atc = std::vector(pp.mesh, 0.0); + // local variables in this function std::vector vs = std::vector(pp.mesh, 0.0); // local pseudopotential for s, unit is Hartree std::vector vp = std::vector(pp.mesh, 0.0); // local pseudopotential for p std::vector vd = std::vector(pp.mesh, 0.0); // local pseudopotential for d std::vector ws = std::vector(pp.mesh, 0.0); // wave function for s std::vector wp = std::vector(pp.mesh, 0.0); // wave function for p std::vector wd = std::vector(pp.mesh, 0.0); // wave function for d - std::string line; - if(spd_loc>0 && pp.nlcc==0) - { - for(int ir=0; ir> pp.r[ir] >> vs[ir] >> vp[ir] >> vd[ir] - >> ws[ir] >> wp[ir] >> wd[ir]; - getline(ifs, line); - } - } - else if(spd_loc==0 && pp.nlcc==0) - { - for(int ir=0; ir> pp.r[ir] >> vs[ir] >> vp[ir] >> vd[ir] - >> ws[ir] >> wp[ir] >> wd[ir] >> pp.vloc_at[ir]; - getline(ifs, line); - } - } - else if(spd_loc>0 && pp.nlcc==1) - { - for(int ir=0; ir> pp.r[ir] >> vs[ir] >> vp[ir] >> vd[ir] - >> ws[ir] >> wp[ir] >> wd[ir] >> pp.rho_atc[ir]; - getline(ifs, line); - } - } - else if(spd_loc==0 && pp.nlcc==1) - { - for(int ir=0; ir> pp.r[ir] >> vs[ir] >> vp[ir] >> vd[ir] - >> ws[ir] >> wp[ir] >> wd[ir] >> pp.vloc_at[ir] >> pp.rho_atc[ir]; - getline(ifs, line); - } - } - // Hartree to Rydberg - for(int ir=0; ir0 && pp.nlcc==0) + { + for(int ir=0; ir> pp.r[ir] >> vs[ir] >> vp[ir] >> vd[ir] + >> ws[ir] >> wp[ir] >> wd[ir]; + getline(ifs, line); + } + } + else if(spd_loc==0 && pp.nlcc==0) + { + for(int ir=0; ir> pp.r[ir] >> vs[ir] >> vp[ir] >> vd[ir] + >> ws[ir] >> wp[ir] >> wd[ir] >> pp.vloc_at[ir]; + getline(ifs, line); + } + } + else if(spd_loc>0 && pp.nlcc==1) + { + for(int ir=0; ir> pp.r[ir] >> vs[ir] >> vp[ir] >> vd[ir] + >> ws[ir] >> wp[ir] >> wd[ir] >> pp.rho_atc[ir]; + getline(ifs, line); + } + } + else if(spd_loc==0 && pp.nlcc==1) + { + for(int ir=0; ir> pp.r[ir] >> vs[ir] >> vp[ir] >> vd[ir] + >> ws[ir] >> wp[ir] >> wd[ir] >> pp.vloc_at[ir] >> pp.rho_atc[ir]; + getline(ifs, line); + } + } + // Hartree to Rydberg + for(int ir=0; ir 0.2 && (iTB_s==1 || iref_s==1)) {return 3;} - if( std::abs(unitp-1.0) > 0.2 && (iTB_p==1 || iref_p==1)) {return 3;} - if( std::abs(unitd-1.0) > 0.2 && (iTB_d==1 || iref_d==1)) {return 3;} + // because only the rank=0 procesor read the pseudopotential + // information, in order to make all the processors to stop + // the job, we need to return the error information first. + // we need to choose a threshold for the deviation of the + // norm of pseudo atomic orbitals, I set 0.2 + // mohan 2013-06-28 + if( std::abs(units-1.0) > 0.2 && (iTB_s==1 || iref_s==1)) {return 3;} + if( std::abs(unitp-1.0) > 0.2 && (iTB_p==1 || iref_p==1)) {return 3;} + if( std::abs(unitd-1.0) > 0.2 && (iTB_d==1 || iref_d==1)) {return 3;} - // calculate the phi*r*sqrt(4pi) - pp.chi.create(pp.nchi,pp.mesh); - for(int ir=0; irnd = pp.nbeta; - GlobalV::ofs_running << std::setw(15) << "N-Dij" << std::setw(15) << nd << std::endl; - // calculate the angular momentum for each pp.betar - pp.lll = std::vector(pp.nbeta, 0); - int icount=0; - if(iref_s==1) {pp.lll[icount]=0; ++icount;}// s projector - if(iref_p==1) {pp.lll[icount]=1; ++icount;}// p projector - if(iref_d==1) {pp.lll[icount]=2; ++icount;}// p projector - for(int i=0; ind = pp.nbeta; + GlobalV::ofs_running << std::setw(15) << "N-Dij" << std::setw(15) << nd << std::endl; + // calculate the angular momentum for each pp.betar + pp.lll = std::vector(pp.nbeta, 0); + int icount=0; + if(iref_s==1) {pp.lll[icount]=0; ++icount;}// s projector + if(iref_p==1) {pp.lll[icount]=1; ++icount;}// p projector + if(iref_d==1) {pp.lll[icount]=2; ++icount;}// p projector + for(int i=0; i + std::vector func = std::vector(pp.mesh, 0.0); + // tmp value (vs, vp or vd) + std::vector vl = std::vector(pp.mesh, 0.0); + // tmp wave function (ws, wp or wd with r) + std::vector wlr = std::vector(pp.mesh, 0.0); + double rcut = 5.0/1.03; + GlobalV::ofs_running << std::setw(15) << "RCUT_NL" << std::setw(15) << rcut << std::endl; + for(int ib=0; ib integration must have 4pi, - // this 4pi is also needed in < phi | phi > = 1 integration. - // However, this phi has sqrt(sphi) already because I - // found < phi | phi > = 1 directly. - GlobalV::ofs_running << " Projector index = " << ib+1 << ", L = " << lnow << std::endl; - for(int ir=2; ir integration must have 4pi, + // this 4pi is also needed in < phi | phi > = 1 integration. + // However, this phi has sqrt(sphi) already because I + // found < phi | phi > = 1 directly. + GlobalV::ofs_running << " Projector index = " << ib+1 << ", L = " << lnow << std::endl; + for(int ir=2; ir=0.0) { pp.dion(ib,ib) = 1.0; } - //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - // suppose wave function have sqrt(4pi) already - //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // suppose wave function have sqrt(4pi) already + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! coef=1.0/sqrt(std::abs(coef)); - GlobalV::ofs_running << std::setw(25) << "1/sqrt()" << std::setw(15) << coef << std::endl; - for(int ir=0; ir2) - { -// pp.betar(ib,ir) *= 0.0; // for test, disable Non-local - } - // --------- FOR TEST --------- - } - - } + GlobalV::ofs_running << std::setw(25) << "1/sqrt()" << std::setw(15) << coef << std::endl; + for(int ir=0; ir2) + { +// pp.betar(ib,ir) *= 0.0; // for test, disable Non-local + } + // --------- FOR TEST --------- + } + + } - // print out the projector. - /* - GlobalV::ofs_running << " Nonlocal projector : " << std::endl; - for(int ir=0; ir diff = 0.0; - double norm = 0.0; - double tolerence_bohr = 1.0e-3; + ModuleBase::Vector3 diff = 0.0; + double norm = 0.0; + double tolerence_bohr = 1.0e-3; - for(int T1=0; T1< ntype; T1++) - { - for(int I1=0; I1< atoms[T1].na; I1++) - { - double shortest_norm = 10000.0; // a large number - for(int T2=0; T2 norm ) - { - shortest_norm = norm; - } - if( norm < tolerence_bohr ) // unit is Bohr - { - GlobalV::ofs_warning << " two atoms are too close!" << std::endl; - GlobalV::ofs_warning << " type:" << atoms[T1].label << " atom " << I1 + 1 << std::endl; - GlobalV::ofs_warning << " type:" << atoms[T2].label << " atom " << I2 + 1 << std::endl; - GlobalV::ofs_warning << " distance = " << norm << " Bohr" << std::endl; - ModuleBase::timer::end("UnitCell","check_tau"); - return false; - } - } - } - } - } - } - ModuleBase::timer::end("UnitCell","check_tau"); - return true; + for(int T1=0; T1< ntype; T1++) + { + for(int I1=0; I1< atoms[T1].na; I1++) + { + double shortest_norm = 10000.0; // a large number + for(int T2=0; T2 norm ) + { + shortest_norm = norm; + } + if( norm < tolerence_bohr ) // unit is Bohr + { + GlobalV::ofs_warning << " two atoms are too close!" << std::endl; + GlobalV::ofs_warning << " type:" << atoms[T1].label << " atom " << I1 + 1 << std::endl; + GlobalV::ofs_warning << " type:" << atoms[T2].label << " atom " << I2 + 1 << std::endl; + GlobalV::ofs_warning << " distance = " << norm << " Bohr" << std::endl; + ModuleBase::timer::end("UnitCell","check_tau"); + return false; + } + } + } + } + } + } + ModuleBase::timer::end("UnitCell","check_tau"); + return true; } void unitcell::check_dtau(Atom* atoms, - const int& ntype, - const double& lat0, - ModuleBase::Matrix3& latvec) + const int& ntype, + const double& lat0, + ModuleBase::Matrix3& latvec) { - for(int it=0; ittaud[ia].x=fmod(atom1->taud[ia].x + 10000,1.0); - atom1->taud[ia].y=fmod(atom1->taud[ia].y + 10000,1.0); - atom1->taud[ia].z=fmod(atom1->taud[ia].z + 10000,1.0); + for(int it=0; ittaud[ia].x=fmod(atom1->taud[ia].x + 10000,1.0); + atom1->taud[ia].y=fmod(atom1->taud[ia].y + 10000,1.0); + atom1->taud[ia].z=fmod(atom1->taud[ia].z + 10000,1.0); - double cx2=0.0; - double cy2=0.0; - double cz2=0.0; + double cx2=0.0; + double cy2=0.0; + double cz2=0.0; - ModuleBase::Mathzone::Direct_to_Cartesian( - atom1->taud[ia].x, atom1->taud[ia].y, atom1->taud[ia].z, - latvec.e11, latvec.e12, latvec.e13, - latvec.e21, latvec.e22, latvec.e23, - latvec.e31, latvec.e32, latvec.e33, - cx2, cy2, cz2); + ModuleBase::Mathzone::Direct_to_Cartesian( + atom1->taud[ia].x, atom1->taud[ia].y, atom1->taud[ia].z, + latvec.e11, latvec.e12, latvec.e13, + latvec.e21, latvec.e22, latvec.e23, + latvec.e31, latvec.e32, latvec.e33, + cx2, cy2, cz2); - atom1->tau[ia].x = cx2; - atom1->tau[ia].y = cy2; - atom1->tau[ia].z = cz2; + atom1->tau[ia].x = cx2; + atom1->tau[ia].y = cy2; + atom1->tau[ia].z = cz2; - } - } - return; + } + } + return; } diff --git a/source/source_cell/test/atom_pseudo_test.cpp b/source/source_cell/test/atom_pseudo_test.cpp index 51ad878362c..9386b223f81 100644 --- a/source/source_cell/test/atom_pseudo_test.cpp +++ b/source/source_cell/test/atom_pseudo_test.cpp @@ -30,75 +30,75 @@ class AtomPseudoTest : public testing::Test { protected: - std::unique_ptr upf{new Pseudopot_upf}; - std::unique_ptr atom_pseudo{new Atom_pseudo}; + std::unique_ptr upf{new Pseudopot_upf}; + std::unique_ptr atom_pseudo{new Atom_pseudo}; }; TEST_F(AtomPseudoTest, SetDSo) { #ifdef __MPI - if(GlobalV::MY_RANK==0) - { + if(GlobalV::MY_RANK==0) + { #endif - std::ifstream ifs; - ifs.open("./support/C.upf"); - const double pseudo_rcut = 15.0; - upf->read_pseudo_upf201(ifs, *atom_pseudo); - upf->complete_default(*atom_pseudo, pseudo_rcut); - ifs.close(); - EXPECT_EQ(atom_pseudo->nh,14); - EXPECT_TRUE(atom_pseudo->has_so); - ModuleBase::ComplexMatrix d_so_in(atom_pseudo->nh*2,atom_pseudo->nh*2); - int nproj = 6; - int nproj_soc = 4; - bool has_so = true; - const bool lspinorb = false; - const int nspin = 4; - atom_pseudo->set_d_so(d_so_in, nproj, nproj_soc, has_so, lspinorb, nspin); - EXPECT_NEAR(atom_pseudo->d_so(0,0,0).real(),1e-8,1e-7); - EXPECT_NEAR(atom_pseudo->d_so(0,0,0).imag(),1e-8,1e-7); - const bool lspinorb_true = true; - const int nspin_4 = 4; - atom_pseudo->set_d_so(d_so_in, nproj, nproj_soc, has_so, lspinorb_true, nspin_4); - EXPECT_NEAR(atom_pseudo->d_so(0,0,0).real(),1e-8,1e-7); - EXPECT_NEAR(atom_pseudo->d_so(0,0,0).imag(),1e-8,1e-7); + std::ifstream ifs; + ifs.open("./support/C.upf"); + const double pseudo_rcut = 15.0; + upf->read_pseudo_upf201(ifs, *atom_pseudo); + upf->complete_default(*atom_pseudo, pseudo_rcut); + ifs.close(); + EXPECT_EQ(atom_pseudo->nh,14); + EXPECT_TRUE(atom_pseudo->has_so); + ModuleBase::ComplexMatrix d_so_in(atom_pseudo->nh*2,atom_pseudo->nh*2); + int nproj = 6; + int nproj_soc = 4; + bool has_so = true; + const bool lspinorb = false; + const int nspin = 4; + atom_pseudo->set_d_so(d_so_in, nproj, nproj_soc, has_so, lspinorb, nspin); + EXPECT_NEAR(atom_pseudo->d_so(0,0,0).real(),1e-8,1e-7); + EXPECT_NEAR(atom_pseudo->d_so(0,0,0).imag(),1e-8,1e-7); + const bool lspinorb_true = true; + const int nspin_4 = 4; + atom_pseudo->set_d_so(d_so_in, nproj, nproj_soc, has_so, lspinorb_true, nspin_4); + EXPECT_NEAR(atom_pseudo->d_so(0,0,0).real(),1e-8,1e-7); + EXPECT_NEAR(atom_pseudo->d_so(0,0,0).imag(),1e-8,1e-7); #ifdef __MPI - } + } #endif } #ifdef __MPI TEST_F(AtomPseudoTest, BcastAtomPseudo) { - if(GlobalV::MY_RANK==0) - { - std::ifstream ifs; - ifs.open("./support/C.upf"); - const double pseudo_rcut = 15.0; - upf->read_pseudo_upf201(ifs, *atom_pseudo); - upf->complete_default(*atom_pseudo, pseudo_rcut); - ifs.close(); - } - atom_pseudo->bcast_atom_pseudo(); - if(GlobalV::MY_RANK!=0) - { - EXPECT_EQ(atom_pseudo->nbeta,6); - EXPECT_EQ(atom_pseudo->nchi,3); - EXPECT_DOUBLE_EQ(atom_pseudo->rho_atc[0],8.7234550809E-01); - } + if(GlobalV::MY_RANK==0) + { + std::ifstream ifs; + ifs.open("./support/C.upf"); + const double pseudo_rcut = 15.0; + upf->read_pseudo_upf201(ifs, *atom_pseudo); + upf->complete_default(*atom_pseudo, pseudo_rcut); + ifs.close(); + } + atom_pseudo->bcast_atom_pseudo(); + if(GlobalV::MY_RANK!=0) + { + EXPECT_EQ(atom_pseudo->nbeta,6); + EXPECT_EQ(atom_pseudo->nchi,3); + EXPECT_DOUBLE_EQ(atom_pseudo->rho_atc[0],8.7234550809E-01); + } } int main(int argc, char **argv) { - MPI_Init(&argc, &argv); - testing::InitGoogleTest(&argc, argv); + MPI_Init(&argc, &argv); + testing::InitGoogleTest(&argc, argv); - MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC); - MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK); - int result = RUN_ALL_TESTS(); - - MPI_Finalize(); - - return result; + MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC); + MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK); + int result = RUN_ALL_TESTS(); + + MPI_Finalize(); + + return result; } #endif diff --git a/source/source_cell/test/atom_spec_test.cpp b/source/source_cell/test/atom_spec_test.cpp index fe28aaafd19..7f5a0a50cb7 100644 --- a/source/source_cell/test/atom_spec_test.cpp +++ b/source/source_cell/test/atom_spec_test.cpp @@ -35,179 +35,179 @@ class AtomSpecTest : public testing::Test { protected: - Atom atom; - Pseudopot_upf upf; - std::ofstream ofs; - std::ifstream ifs; + Atom atom; + Pseudopot_upf upf; + std::ofstream ofs; + std::ifstream ifs; }; TEST_F(AtomSpecTest, PrintAtom) { #ifdef __MPI - if(GlobalV::MY_RANK==0) - { + if(GlobalV::MY_RANK==0) + { #endif - ofs.open("tmp_atom_info"); - atom.label = "C"; - atom.type = 1; - atom.na = 2; - atom.nwl = 2; - atom.Rcut = 1.1; - atom.nw = 14; - atom.stapos_wf = 0; - atom.mass = 12.0; - atom.tau.resize(atom.na); - atom.tau[0].x = 0.2; - atom.tau[0].y = 0.2; - atom.tau[0].z = 0.2; - atom.tau[1].x = 0.4; - atom.tau[1].y = 0.4; - atom.tau[1].z = 0.4; - atom.print_Atom(ofs); - ofs.close(); - ifs.open("tmp_atom_info"); - std::string str((std::istreambuf_iterator(ifs)),std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("label = C")); - EXPECT_THAT(str, testing::HasSubstr("type = 1")); - EXPECT_THAT(str, testing::HasSubstr("na = 2")); - EXPECT_THAT(str, testing::HasSubstr("nwl = 2")); - EXPECT_THAT(str, testing::HasSubstr("Rcut = 1.1")); - EXPECT_THAT(str, testing::HasSubstr("nw = 14")); - EXPECT_THAT(str, testing::HasSubstr("stapos_wf = 0")); - EXPECT_THAT(str, testing::HasSubstr("mass = 12")); - EXPECT_THAT(str, testing::HasSubstr("atom_position(cartesian) Dimension = 2")); - ifs.close(); - remove("tmp_atom_info"); + ofs.open("tmp_atom_info"); + atom.label = "C"; + atom.type = 1; + atom.na = 2; + atom.nwl = 2; + atom.Rcut = 1.1; + atom.nw = 14; + atom.stapos_wf = 0; + atom.mass = 12.0; + atom.tau.resize(atom.na); + atom.tau[0].x = 0.2; + atom.tau[0].y = 0.2; + atom.tau[0].z = 0.2; + atom.tau[1].x = 0.4; + atom.tau[1].y = 0.4; + atom.tau[1].z = 0.4; + atom.print_Atom(ofs); + ofs.close(); + ifs.open("tmp_atom_info"); + std::string str((std::istreambuf_iterator(ifs)),std::istreambuf_iterator()); + EXPECT_THAT(str, testing::HasSubstr("label = C")); + EXPECT_THAT(str, testing::HasSubstr("type = 1")); + EXPECT_THAT(str, testing::HasSubstr("na = 2")); + EXPECT_THAT(str, testing::HasSubstr("nwl = 2")); + EXPECT_THAT(str, testing::HasSubstr("Rcut = 1.1")); + EXPECT_THAT(str, testing::HasSubstr("nw = 14")); + EXPECT_THAT(str, testing::HasSubstr("stapos_wf = 0")); + EXPECT_THAT(str, testing::HasSubstr("mass = 12")); + EXPECT_THAT(str, testing::HasSubstr("atom_position(cartesian) Dimension = 2")); + ifs.close(); + remove("tmp_atom_info"); #ifdef __MPI - } + } #endif } TEST_F(AtomSpecTest, SetIndex) { #ifdef __MPI - if(GlobalV::MY_RANK==0) - { + if(GlobalV::MY_RANK==0) + { #endif - atom.nw = 0; - atom.nwl = 1; - atom.l_nchi.resize(atom.nwl+1); - atom.l_nchi[0] = 2; // l:0, N:2 (arbitrary) - atom.nw += 1*atom.l_nchi[0]; // m = 2*0+1 = 1 - atom.l_nchi[1] = 4; // l:1, N:4 (arbitrary) - atom.nw += 3*atom.l_nchi[1]; // m = 2*1+1 = 3 - atom.set_index(); - EXPECT_EQ(atom.iw2l[13],1); - EXPECT_EQ(atom.iw2n[13],3); - EXPECT_EQ(atom.iw2m[13],2); - EXPECT_EQ(atom.iw2_ylm[13],3); - EXPECT_TRUE(atom.iw2_new[11]); - // here is the table: - // nw = 2 + 3*4 = 14 - // L N m L*L+m - // 0 0 0 0 0 - // 1 0 1 0 0 - // 2 1 0 0 1 - // 3 1 0 1 2 - // 4 1 0 2 3 - // 5 1 1 0 1 - // 6 1 1 1 2 - // 7 1 1 2 3 - // 8 1 2 0 1 - // 9 1 2 1 2 - // 10 1 2 2 3 - // 11 1 3 0 1 - // 12 1 3 1 2 - // 13 1 3 2 3 + atom.nw = 0; + atom.nwl = 1; + atom.l_nchi.resize(atom.nwl+1); + atom.l_nchi[0] = 2; // l:0, N:2 (arbitrary) + atom.nw += 1*atom.l_nchi[0]; // m = 2*0+1 = 1 + atom.l_nchi[1] = 4; // l:1, N:4 (arbitrary) + atom.nw += 3*atom.l_nchi[1]; // m = 2*1+1 = 3 + atom.set_index(); + EXPECT_EQ(atom.iw2l[13],1); + EXPECT_EQ(atom.iw2n[13],3); + EXPECT_EQ(atom.iw2m[13],2); + EXPECT_EQ(atom.iw2_ylm[13],3); + EXPECT_TRUE(atom.iw2_new[11]); + // here is the table: + // nw = 2 + 3*4 = 14 + // L N m L*L+m + // 0 0 0 0 0 + // 1 0 1 0 0 + // 2 1 0 0 1 + // 3 1 0 1 2 + // 4 1 0 2 3 + // 5 1 1 0 1 + // 6 1 1 1 2 + // 7 1 1 2 3 + // 8 1 2 0 1 + // 9 1 2 1 2 + // 10 1 2 2 3 + // 11 1 3 0 1 + // 12 1 3 1 2 + // 13 1 3 2 3 #ifdef __MPI - } + } #endif } #ifdef __MPI TEST_F(AtomSpecTest, BcastAtom) { - if(GlobalV::MY_RANK==0) - { - atom.label = "C"; - atom.type = 1; - atom.na = 2; - atom.nw = 0; - atom.nwl = 1; - atom.Rcut = 1.1; - atom.l_nchi.resize(atom.nwl+1); - atom.l_nchi[0] = 2; - atom.nw += atom.l_nchi[0]; - atom.l_nchi[1] = 4; - atom.nw += 3*atom.l_nchi[1]; - atom.stapos_wf = 0; - atom.mass = 12.0; - atom.tau.resize(atom.na); - atom.taud.resize(atom.na); - atom.dis.resize(atom.na); - atom.vel.resize(atom.na); - atom.mag.resize(atom.na); - atom.angle1.resize(atom.na); - atom.angle2.resize(atom.na); - atom.m_loc_.resize(atom.na); - atom.mbl.resize(atom.na); - atom.lambda.resize(atom.na); - atom.constrain.resize(atom.na); - atom.tau[0].x = 0.2; - atom.tau[0].y = 0.2; - atom.tau[0].z = 0.2; - atom.tau[1].x = 0.4; - atom.tau[1].y = 0.4; - atom.tau[1].z = 0.4; - } - atom.bcast_atom(); - if(GlobalV::MY_RANK!=0) - { - EXPECT_EQ(atom.label,"C"); - EXPECT_EQ(atom.type,1); - EXPECT_EQ(atom.na,2); - EXPECT_EQ(atom.nwl,1); - EXPECT_DOUBLE_EQ(atom.Rcut,1.1); - EXPECT_EQ(atom.nw,14); - EXPECT_EQ(atom.stapos_wf,0); - EXPECT_DOUBLE_EQ(atom.mass,12.0); - EXPECT_DOUBLE_EQ(atom.tau[0].x,0.2); - EXPECT_DOUBLE_EQ(atom.tau[1].z,0.4); - } + if(GlobalV::MY_RANK==0) + { + atom.label = "C"; + atom.type = 1; + atom.na = 2; + atom.nw = 0; + atom.nwl = 1; + atom.Rcut = 1.1; + atom.l_nchi.resize(atom.nwl+1); + atom.l_nchi[0] = 2; + atom.nw += atom.l_nchi[0]; + atom.l_nchi[1] = 4; + atom.nw += 3*atom.l_nchi[1]; + atom.stapos_wf = 0; + atom.mass = 12.0; + atom.tau.resize(atom.na); + atom.taud.resize(atom.na); + atom.dis.resize(atom.na); + atom.vel.resize(atom.na); + atom.mag.resize(atom.na); + atom.angle1.resize(atom.na); + atom.angle2.resize(atom.na); + atom.m_loc_.resize(atom.na); + atom.mbl.resize(atom.na); + atom.lambda.resize(atom.na); + atom.constrain.resize(atom.na); + atom.tau[0].x = 0.2; + atom.tau[0].y = 0.2; + atom.tau[0].z = 0.2; + atom.tau[1].x = 0.4; + atom.tau[1].y = 0.4; + atom.tau[1].z = 0.4; + } + atom.bcast_atom(); + if(GlobalV::MY_RANK!=0) + { + EXPECT_EQ(atom.label,"C"); + EXPECT_EQ(atom.type,1); + EXPECT_EQ(atom.na,2); + EXPECT_EQ(atom.nwl,1); + EXPECT_DOUBLE_EQ(atom.Rcut,1.1); + EXPECT_EQ(atom.nw,14); + EXPECT_EQ(atom.stapos_wf,0); + EXPECT_DOUBLE_EQ(atom.mass,12.0); + EXPECT_DOUBLE_EQ(atom.tau[0].x,0.2); + EXPECT_DOUBLE_EQ(atom.tau[1].z,0.4); + } } TEST_F(AtomSpecTest, BcastAtom2) { - if(GlobalV::MY_RANK==0) - { - ifs.open("./support/C.upf"); - const double pseudo_rcut = 15.0; - upf.read_pseudo_upf201(ifs, atom.ncpp); - upf.complete_default(atom.ncpp, pseudo_rcut); - ifs.close(); - EXPECT_TRUE(atom.ncpp.has_so); - } - atom.bcast_atom2(); - if(GlobalV::MY_RANK!=0) - { - EXPECT_EQ(atom.ncpp.nbeta,6); - EXPECT_EQ(atom.ncpp.nchi,3); - EXPECT_DOUBLE_EQ(atom.ncpp.rho_atc[0],8.7234550809E-01); - } + if(GlobalV::MY_RANK==0) + { + ifs.open("./support/C.upf"); + const double pseudo_rcut = 15.0; + upf.read_pseudo_upf201(ifs, atom.ncpp); + upf.complete_default(atom.ncpp, pseudo_rcut); + ifs.close(); + EXPECT_TRUE(atom.ncpp.has_so); + } + atom.bcast_atom2(); + if(GlobalV::MY_RANK!=0) + { + EXPECT_EQ(atom.ncpp.nbeta,6); + EXPECT_EQ(atom.ncpp.nchi,3); + EXPECT_DOUBLE_EQ(atom.ncpp.rho_atc[0],8.7234550809E-01); + } } int main(int argc, char **argv) { - MPI_Init(&argc, &argv); - testing::InitGoogleTest(&argc, argv); + MPI_Init(&argc, &argv); + testing::InitGoogleTest(&argc, argv); - MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC); - MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK); - int result = RUN_ALL_TESTS(); - - MPI_Finalize(); - - return result; + MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC); + MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK); + int result = RUN_ALL_TESTS(); + + MPI_Finalize(); + + return result; } #endif diff --git a/source/source_cell/test/magnetism_test.cpp b/source/source_cell/test/magnetism_test.cpp index e95afac9dc2..fdfe2d55042 100644 --- a/source/source_cell/test/magnetism_test.cpp +++ b/source/source_cell/test/magnetism_test.cpp @@ -63,72 +63,72 @@ TEST_F(MagnetismTest, JudgeParallel) TEST_F(MagnetismTest, ComputeMagnetizationS2) { - const int nspin = 2; - const bool two_fermi = false; - const double nelec = 10.0; - - Charge* chr = new Charge; - chr->nrxx = 100; - chr->nxyz = 1000; - chr->rho = new double*[nspin]; - for (int i=0; i< nspin; i++) - { - chr->rho[i] = new double[chr->nrxx]; - } - for (int ir=0; ir< chr->nrxx; ir++) - { - chr->rho[0][ir] = 1.00; - chr->rho[1][ir] = 1.01; - } - double* nelec_spin = new double[2]; - magnetism->compute_mag(500.0,chr->nrxx, chr->nxyz, chr->rho, - nspin, two_fermi, nelec, nelec_spin); - EXPECT_DOUBLE_EQ(-0.5, magnetism->tot_mag); - EXPECT_DOUBLE_EQ(0.5, magnetism->abs_mag); - EXPECT_DOUBLE_EQ(4.75, nelec_spin[0]); - EXPECT_DOUBLE_EQ(5.25, nelec_spin[1]); - delete[] nelec_spin; - for (int i=0; i< nspin; i++) - { - delete[] chr->rho[i]; - } - delete[] chr->rho; - delete chr; + const int nspin = 2; + const bool two_fermi = false; + const double nelec = 10.0; + + Charge* chr = new Charge; + chr->nrxx = 100; + chr->nxyz = 1000; + chr->rho = new double*[nspin]; + for (int i=0; i< nspin; i++) + { + chr->rho[i] = new double[chr->nrxx]; + } + for (int ir=0; ir< chr->nrxx; ir++) + { + chr->rho[0][ir] = 1.00; + chr->rho[1][ir] = 1.01; + } + double* nelec_spin = new double[2]; + magnetism->compute_mag(500.0,chr->nrxx, chr->nxyz, chr->rho, + nspin, two_fermi, nelec, nelec_spin); + EXPECT_DOUBLE_EQ(-0.5, magnetism->tot_mag); + EXPECT_DOUBLE_EQ(0.5, magnetism->abs_mag); + EXPECT_DOUBLE_EQ(4.75, nelec_spin[0]); + EXPECT_DOUBLE_EQ(5.25, nelec_spin[1]); + delete[] nelec_spin; + for (int i=0; i< nspin; i++) + { + delete[] chr->rho[i]; + } + delete[] chr->rho; + delete chr; } TEST_F(MagnetismTest, ComputeMagnetizationS4) { - const int nspin = 4; - - Charge* chr = new Charge; - chr->rho = new double*[nspin]; - chr->nrxx = 100; - chr->nxyz = 1000; - for (int i=0; i< nspin; i++) - { - chr->rho[i] = new double[chr->nrxx]; - } - for (int ir=0; ir< chr->nrxx; ir++) - { - chr->rho[0][ir] = 1.00; - chr->rho[1][ir] = std::sqrt(2.0); - chr->rho[2][ir] = 1.00; - chr->rho[3][ir] = 1.00; - } - double* nelec_spin = new double[4]; - magnetism->compute_mag(500.0,chr->nrxx, chr->nxyz, chr->rho, - nspin, false, 0.0, nelec_spin); - EXPECT_DOUBLE_EQ(100.0, magnetism->abs_mag); - EXPECT_DOUBLE_EQ(50.0*std::sqrt(2.0), magnetism->tot_mag_nc[0]); - EXPECT_DOUBLE_EQ(50.0, magnetism->tot_mag_nc[1]); - EXPECT_DOUBLE_EQ(50.0, magnetism->tot_mag_nc[2]); - delete[] nelec_spin; - for (int i=0; i< nspin; i++) - { - delete[] chr->rho[i]; - } - delete[] chr->rho; - delete chr; + const int nspin = 4; + + Charge* chr = new Charge; + chr->rho = new double*[nspin]; + chr->nrxx = 100; + chr->nxyz = 1000; + for (int i=0; i< nspin; i++) + { + chr->rho[i] = new double[chr->nrxx]; + } + for (int ir=0; ir< chr->nrxx; ir++) + { + chr->rho[0][ir] = 1.00; + chr->rho[1][ir] = std::sqrt(2.0); + chr->rho[2][ir] = 1.00; + chr->rho[3][ir] = 1.00; + } + double* nelec_spin = new double[4]; + magnetism->compute_mag(500.0,chr->nrxx, chr->nxyz, chr->rho, + nspin, false, 0.0, nelec_spin); + EXPECT_DOUBLE_EQ(100.0, magnetism->abs_mag); + EXPECT_DOUBLE_EQ(50.0*std::sqrt(2.0), magnetism->tot_mag_nc[0]); + EXPECT_DOUBLE_EQ(50.0, magnetism->tot_mag_nc[1]); + EXPECT_DOUBLE_EQ(50.0, magnetism->tot_mag_nc[2]); + delete[] nelec_spin; + for (int i=0; i< nspin; i++) + { + delete[] chr->rho[i]; + } + delete[] chr->rho; + delete chr; } #ifdef __MPI diff --git a/source/source_cell/test/prepare_unitcell.h b/source/source_cell/test/prepare_unitcell.h index abfc9cf8def..00e2c080191 100644 --- a/source/source_cell/test/prepare_unitcell.h +++ b/source/source_cell/test/prepare_unitcell.h @@ -6,476 +6,476 @@ class UcellTestPrepare { public: - 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 latvec_in, - std::vector elements_in, - std::vector pp_files_in, - std::vector pp_types_in, - std::vector orb_files_in, - std::valarray natom_in, - std::vector atomic_mass_in, - std::string coor_type_in, - std::valarray coordinates_in); - 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 latvec_in, - std::vector elements_in, - std::vector pp_files_in, - std::vector pp_types_in, - std::vector orb_files_in, - std::valarray natom_in, - std::vector atomic_mass_in, - std::string coor_type_in, - std::valarray coordinates_in, - std::valarray mbl_in, - std::valarray velocity_in); - UcellTestPrepare(const UcellTestPrepare &utp); + 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 latvec_in, + std::vector elements_in, + std::vector pp_files_in, + std::vector pp_types_in, + std::vector orb_files_in, + std::valarray natom_in, + std::vector atomic_mass_in, + std::string coor_type_in, + std::valarray coordinates_in); + 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 latvec_in, + std::vector elements_in, + std::vector pp_files_in, + std::vector pp_types_in, + std::vector orb_files_in, + std::valarray natom_in, + std::vector atomic_mass_in, + std::string coor_type_in, + std::valarray coordinates_in, + std::valarray mbl_in, + std::valarray velocity_in); + UcellTestPrepare(const UcellTestPrepare &utp); - std::string latname; - int lmaxmax; - bool init_vel; - bool selective_dynamics; - bool relax_new; - std::string fixed_axes; - double lat0; - std::valarray latvec; - std::vector elements; - std::vector pp_files; - std::vector pp_types; - std::vector orb_files; - std::valarray natom; - std::vector atomic_mass; - std::string coor_type; - std::valarray coordinates; - std::valarray mbl; - std::valarray velocity; - // ntype - int ntype; - int atomic_index; + std::string latname; + int lmaxmax; + bool init_vel; + bool selective_dynamics; + bool relax_new; + std::string fixed_axes; + double lat0; + std::valarray latvec; + std::vector elements; + std::vector pp_files; + std::vector pp_types; + std::vector orb_files; + std::valarray natom; + std::vector atomic_mass; + std::string coor_type; + std::valarray coordinates; + std::valarray mbl; + std::valarray velocity; + // ntype + int ntype; + int atomic_index; - std::unique_ptr SetUcellInfo() - { - //basic info - this->ntype = this->elements.size(); - std::unique_ptr ucell(new UnitCell); - ucell->setup(this->latname, - this->ntype, - this->lmaxmax, - this->init_vel, - this->fixed_axes); - - ucell->atom_label.resize(ucell->ntype); - ucell->atom_mass.resize(ucell->ntype); - ucell->pseudo_fn.resize(ucell->ntype); - ucell->pseudo_type.resize(ucell->ntype); - ucell->orbital_fn.resize(ucell->ntype); - ucell->magnet.ux_[0] = 0.0; // ux_ set here - ucell->magnet.ux_[1] = 0.0; - ucell->magnet.ux_[2] = 0.0; - for(int it=0;itntype;++it) - { - ucell->atom_label[it] = this->elements[it]; - ucell->atom_mass[it] = this->atomic_mass[it]; - ucell->pseudo_fn[it] = this->pp_files[it]; - ucell->pseudo_type[it] = this->pp_types[it]; - ucell->orbital_fn[it] = this->orb_files[it]; - } - //lattice info - ucell->lat0 = this->lat0; - ucell->lat0_angstrom = ucell->lat0 * ModuleBase::BOHR_TO_A; - ucell->tpiba = ModuleBase::TWO_PI/ucell->lat0; - ucell->tpiba2 = ucell->tpiba * ucell->tpiba; - ucell->latvec.e11 = this->latvec[0]; - ucell->latvec.e12 = this->latvec[1]; - ucell->latvec.e13 = this->latvec[2]; - ucell->latvec.e21 = this->latvec[3]; - ucell->latvec.e22 = this->latvec[4]; - ucell->latvec.e23 = this->latvec[5]; - ucell->latvec.e31 = this->latvec[6]; - ucell->latvec.e32 = this->latvec[7]; - ucell->latvec.e33 = this->latvec[8]; - ucell->a1.x = ucell->latvec.e11; - ucell->a1.y = ucell->latvec.e12; - ucell->a1.z = ucell->latvec.e13; - ucell->a2.x = ucell->latvec.e21; - ucell->a2.y = ucell->latvec.e22; - ucell->a2.z = ucell->latvec.e23; - ucell->a3.x = ucell->latvec.e31; - ucell->a3.y = ucell->latvec.e32; - ucell->a3.z = ucell->latvec.e33; - ucell->GT = ucell->latvec.Inverse(); - ucell->G = ucell->GT.Transpose(); - ucell->GGT = ucell->G*ucell->GT; - ucell->invGGT = ucell->GGT.Inverse(); - ucell->omega = std::abs(ucell->latvec.Det())*(ucell->lat0)*(ucell->lat0)*(ucell->lat0); - //atomic info - ucell->Coordinate = this->coor_type; - ucell->atoms = new Atom[ucell->ntype]; - ucell->set_atom_flag = true; - this->atomic_index = 0; - for(int it=0;itntype;++it) - { - ucell->atoms[it].label = this->elements[it]; - ucell->atoms[it].nw = 0; - ucell->atoms[it].nwl = 2; - ucell->atoms[it].l_nchi.resize(ucell->atoms[it].nwl+1); - for(int L=0; Latoms[it].nwl+1; L++) - { - ucell->atoms[it].l_nchi[L] = 1; - ucell->atoms[it].nw += (2*L + 1) * ucell->atoms[it].l_nchi[L]; - } - ucell->atoms[it].na = this->natom[it]; - //coordinates and related physical quantities - ucell->atoms[it].tau.resize(ucell->atoms[it].na); - ucell->atoms[it].dis.resize(ucell->atoms[it].na); - ucell->atoms[it].taud.resize(ucell->atoms[it].na); - ucell->atoms[it].vel.resize(ucell->atoms[it].na); - ucell->atoms[it].mag.resize(ucell->atoms[it].na); - ucell->atoms[it].angle1.resize(ucell->atoms[it].na); - ucell->atoms[it].angle2.resize(ucell->atoms[it].na); - ucell->atoms[it].m_loc_.resize(ucell->atoms[it].na); - ucell->atoms[it].mbl.resize(ucell->atoms[it].na); - ucell->atoms[it].lambda.resize(ucell->atoms[it].na); - ucell->atoms[it].constrain.resize(ucell->atoms[it].na); - ucell->atoms[it].mass = ucell->atom_mass[it]; // mass set here - for(int ia=0; iaatoms[it].na; ++ia) - { - if (ucell->Coordinate == "Direct") - { - ucell->atoms[it].taud[ia].x = this->coordinates[this->atomic_index*3+0]; - ucell->atoms[it].taud[ia].y = this->coordinates[this->atomic_index*3+1]; - ucell->atoms[it].taud[ia].z = this->coordinates[this->atomic_index*3+2]; - ucell->atoms[it].tau[ia] = ucell->atoms[it].taud[ia]*ucell->latvec; - } - else if (ucell->Coordinate == "Cartesian") - { - ucell->atoms[it].tau[ia].x = this->coordinates[this->atomic_index*3+0]; - ucell->atoms[it].tau[ia].y = this->coordinates[this->atomic_index*3+1]; - ucell->atoms[it].tau[ia].z = this->coordinates[this->atomic_index*3+2]; - ModuleBase::Mathzone::Cartesian_to_Direct( - ucell->atoms[it].tau[ia].x, ucell->atoms[it].tau[ia].y, ucell->atoms[it].tau[ia].z, - ucell->latvec.e11, ucell->latvec.e12, ucell->latvec.e13, - ucell->latvec.e21, ucell->latvec.e22, ucell->latvec.e23, - ucell->latvec.e31, ucell->latvec.e32, ucell->latvec.e33, - ucell->atoms[it].taud[ia].x, ucell->atoms[it].taud[ia].y, ucell->atoms[it].taud[ia].z); - } + std::unique_ptr SetUcellInfo() + { + //basic info + this->ntype = this->elements.size(); + std::unique_ptr ucell(new UnitCell); + ucell->setup(this->latname, + this->ntype, + this->lmaxmax, + this->init_vel, + this->fixed_axes); + + ucell->atom_label.resize(ucell->ntype); + ucell->atom_mass.resize(ucell->ntype); + ucell->pseudo_fn.resize(ucell->ntype); + ucell->pseudo_type.resize(ucell->ntype); + ucell->orbital_fn.resize(ucell->ntype); + ucell->magnet.ux_[0] = 0.0; // ux_ set here + ucell->magnet.ux_[1] = 0.0; + ucell->magnet.ux_[2] = 0.0; + for(int it=0;itntype;++it) + { + ucell->atom_label[it] = this->elements[it]; + ucell->atom_mass[it] = this->atomic_mass[it]; + ucell->pseudo_fn[it] = this->pp_files[it]; + ucell->pseudo_type[it] = this->pp_types[it]; + ucell->orbital_fn[it] = this->orb_files[it]; + } + //lattice info + ucell->lat0 = this->lat0; + ucell->lat0_angstrom = ucell->lat0 * ModuleBase::BOHR_TO_A; + ucell->tpiba = ModuleBase::TWO_PI/ucell->lat0; + ucell->tpiba2 = ucell->tpiba * ucell->tpiba; + ucell->latvec.e11 = this->latvec[0]; + ucell->latvec.e12 = this->latvec[1]; + ucell->latvec.e13 = this->latvec[2]; + ucell->latvec.e21 = this->latvec[3]; + ucell->latvec.e22 = this->latvec[4]; + ucell->latvec.e23 = this->latvec[5]; + ucell->latvec.e31 = this->latvec[6]; + ucell->latvec.e32 = this->latvec[7]; + ucell->latvec.e33 = this->latvec[8]; + ucell->a1.x = ucell->latvec.e11; + ucell->a1.y = ucell->latvec.e12; + ucell->a1.z = ucell->latvec.e13; + ucell->a2.x = ucell->latvec.e21; + ucell->a2.y = ucell->latvec.e22; + ucell->a2.z = ucell->latvec.e23; + ucell->a3.x = ucell->latvec.e31; + ucell->a3.y = ucell->latvec.e32; + ucell->a3.z = ucell->latvec.e33; + ucell->GT = ucell->latvec.Inverse(); + ucell->G = ucell->GT.Transpose(); + ucell->GGT = ucell->G*ucell->GT; + ucell->invGGT = ucell->GGT.Inverse(); + ucell->omega = std::abs(ucell->latvec.Det())*(ucell->lat0)*(ucell->lat0)*(ucell->lat0); + //atomic info + ucell->Coordinate = this->coor_type; + ucell->atoms = new Atom[ucell->ntype]; + ucell->set_atom_flag = true; + this->atomic_index = 0; + for(int it=0;itntype;++it) + { + ucell->atoms[it].label = this->elements[it]; + ucell->atoms[it].nw = 0; + ucell->atoms[it].nwl = 2; + ucell->atoms[it].l_nchi.resize(ucell->atoms[it].nwl+1); + for(int L=0; Latoms[it].nwl+1; L++) + { + ucell->atoms[it].l_nchi[L] = 1; + ucell->atoms[it].nw += (2*L + 1) * ucell->atoms[it].l_nchi[L]; + } + ucell->atoms[it].na = this->natom[it]; + //coordinates and related physical quantities + ucell->atoms[it].tau.resize(ucell->atoms[it].na); + ucell->atoms[it].dis.resize(ucell->atoms[it].na); + ucell->atoms[it].taud.resize(ucell->atoms[it].na); + ucell->atoms[it].vel.resize(ucell->atoms[it].na); + ucell->atoms[it].mag.resize(ucell->atoms[it].na); + ucell->atoms[it].angle1.resize(ucell->atoms[it].na); + ucell->atoms[it].angle2.resize(ucell->atoms[it].na); + ucell->atoms[it].m_loc_.resize(ucell->atoms[it].na); + ucell->atoms[it].mbl.resize(ucell->atoms[it].na); + ucell->atoms[it].lambda.resize(ucell->atoms[it].na); + ucell->atoms[it].constrain.resize(ucell->atoms[it].na); + ucell->atoms[it].mass = ucell->atom_mass[it]; // mass set here + for(int ia=0; iaatoms[it].na; ++ia) + { + if (ucell->Coordinate == "Direct") + { + ucell->atoms[it].taud[ia].x = this->coordinates[this->atomic_index*3+0]; + ucell->atoms[it].taud[ia].y = this->coordinates[this->atomic_index*3+1]; + ucell->atoms[it].taud[ia].z = this->coordinates[this->atomic_index*3+2]; + ucell->atoms[it].tau[ia] = ucell->atoms[it].taud[ia]*ucell->latvec; + } + else if (ucell->Coordinate == "Cartesian") + { + ucell->atoms[it].tau[ia].x = this->coordinates[this->atomic_index*3+0]; + ucell->atoms[it].tau[ia].y = this->coordinates[this->atomic_index*3+1]; + ucell->atoms[it].tau[ia].z = this->coordinates[this->atomic_index*3+2]; + ModuleBase::Mathzone::Cartesian_to_Direct( + ucell->atoms[it].tau[ia].x, ucell->atoms[it].tau[ia].y, ucell->atoms[it].tau[ia].z, + ucell->latvec.e11, ucell->latvec.e12, ucell->latvec.e13, + ucell->latvec.e21, ucell->latvec.e22, ucell->latvec.e23, + ucell->latvec.e31, ucell->latvec.e32, ucell->latvec.e33, + ucell->atoms[it].taud[ia].x, ucell->atoms[it].taud[ia].y, ucell->atoms[it].taud[ia].z); + } ucell->atoms[it].dis[ia].set(0, 0, 0); - if(this->init_vel) - { - ucell->atoms[it].vel[ia].x = this->velocity[this->atomic_index*3+0]; - ucell->atoms[it].vel[ia].y = this->velocity[this->atomic_index*3+1]; - ucell->atoms[it].vel[ia].z = this->velocity[this->atomic_index*3+2]; - } - else - { - ucell->atoms[it].vel[ia].set(0,0,0); - } - ucell->atoms[it].m_loc_[ia].set(0,0,0); - ucell->atoms[it].angle1[ia] = 0; - ucell->atoms[it].angle2[ia] = 0; - if(this->selective_dynamics) - { - ucell->atoms[it].mbl[ia].x = this->mbl[this->atomic_index*3+0]; - ucell->atoms[it].mbl[ia].y = this->mbl[this->atomic_index*3+1]; - ucell->atoms[it].mbl[ia].z = this->mbl[this->atomic_index*3+2]; - } - else - { - ucell->atoms[it].mbl[ia] = {1,1,1}; - } - ++(this->atomic_index); - } - } - ucell->nat = this->natom.sum(); - return ucell; - } + if(this->init_vel) + { + ucell->atoms[it].vel[ia].x = this->velocity[this->atomic_index*3+0]; + ucell->atoms[it].vel[ia].y = this->velocity[this->atomic_index*3+1]; + ucell->atoms[it].vel[ia].z = this->velocity[this->atomic_index*3+2]; + } + else + { + ucell->atoms[it].vel[ia].set(0,0,0); + } + ucell->atoms[it].m_loc_[ia].set(0,0,0); + ucell->atoms[it].angle1[ia] = 0; + ucell->atoms[it].angle2[ia] = 0; + if(this->selective_dynamics) + { + ucell->atoms[it].mbl[ia].x = this->mbl[this->atomic_index*3+0]; + ucell->atoms[it].mbl[ia].y = this->mbl[this->atomic_index*3+1]; + ucell->atoms[it].mbl[ia].z = this->mbl[this->atomic_index*3+2]; + } + else + { + ucell->atoms[it].mbl[ia] = {1,1,1}; + } + ++(this->atomic_index); + } + } + ucell->nat = this->natom.sum(); + return ucell; + } }; UcellTestPrepare::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 latvec_in, - std::vector elements_in, - std::vector pp_files_in, - std::vector pp_types_in, - std::vector orb_files_in, - std::valarray natom_in, - std::vector atomic_mass_in, - std::string coor_type_in, - std::valarray coordinates_in): - latname(latname_in), - lmaxmax(lmaxmax_in), - init_vel(init_vel_in), - selective_dynamics(selective_dynamics_in), - relax_new(relax_new_in), - fixed_axes(fixed_axes_in), - lat0(lat0_in), - latvec(latvec_in), - elements(elements_in), - pp_files(pp_files_in), - pp_types(pp_types_in), - orb_files(orb_files_in), - natom(natom_in), - atomic_mass(atomic_mass_in), - coor_type(coor_type_in), - coordinates(coordinates_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 latvec_in, + std::vector elements_in, + std::vector pp_files_in, + std::vector pp_types_in, + std::vector orb_files_in, + std::valarray natom_in, + std::vector atomic_mass_in, + std::string coor_type_in, + std::valarray coordinates_in): + latname(latname_in), + lmaxmax(lmaxmax_in), + init_vel(init_vel_in), + selective_dynamics(selective_dynamics_in), + relax_new(relax_new_in), + fixed_axes(fixed_axes_in), + lat0(lat0_in), + latvec(latvec_in), + elements(elements_in), + pp_files(pp_files_in), + pp_types(pp_types_in), + orb_files(orb_files_in), + natom(natom_in), + atomic_mass(atomic_mass_in), + coor_type(coor_type_in), + coordinates(coordinates_in) { - mbl = std::valarray(0.0, coordinates_in.size()); - velocity = std::valarray(0.0, coordinates_in.size()); + mbl = std::valarray(0.0, coordinates_in.size()); + velocity = std::valarray(0.0, coordinates_in.size()); } UcellTestPrepare::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 latvec_in, - std::vector elements_in, - std::vector pp_files_in, - std::vector pp_types_in, - std::vector orb_files_in, - std::valarray natom_in, - std::vector atomic_mass_in, - std::string coor_type_in, - std::valarray coordinates_in, - std::valarray mbl_in, - std::valarray velocity_in): - latname(latname_in), - lmaxmax(lmaxmax_in), - init_vel(init_vel_in), - selective_dynamics(selective_dynamics_in), - relax_new(relax_new_in), - fixed_axes(fixed_axes_in), - lat0(lat0_in), - latvec(latvec_in), - elements(elements_in), - pp_files(pp_files_in), - pp_types(pp_types_in), - orb_files(orb_files_in), - natom(natom_in), - atomic_mass(atomic_mass_in), - coor_type(coor_type_in), - coordinates(coordinates_in), - mbl(mbl_in), - velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file() + 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 latvec_in, + std::vector elements_in, + std::vector pp_files_in, + std::vector pp_types_in, + std::vector orb_files_in, + std::valarray natom_in, + std::vector atomic_mass_in, + std::string coor_type_in, + std::valarray coordinates_in, + std::valarray mbl_in, + std::valarray velocity_in): + latname(latname_in), + lmaxmax(lmaxmax_in), + init_vel(init_vel_in), + selective_dynamics(selective_dynamics_in), + relax_new(relax_new_in), + fixed_axes(fixed_axes_in), + lat0(lat0_in), + latvec(latvec_in), + elements(elements_in), + pp_files(pp_files_in), + pp_types(pp_types_in), + orb_files(orb_files_in), + natom(natom_in), + atomic_mass(atomic_mass_in), + coor_type(coor_type_in), + coordinates(coordinates_in), + mbl(mbl_in), + velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file() {} UcellTestPrepare::UcellTestPrepare(const UcellTestPrepare &utp): - latname(utp.latname), - lmaxmax(utp.lmaxmax), - init_vel(utp.init_vel), - selective_dynamics(utp.selective_dynamics), - relax_new(utp.relax_new), - fixed_axes(utp.fixed_axes), - lat0(utp.lat0), - latvec(utp.latvec), - elements(utp.elements), - pp_files(utp.pp_files), - pp_types(utp.pp_types), - orb_files(utp.orb_files), - natom(utp.natom), - atomic_mass(utp.atomic_mass), - coor_type(utp.coor_type), - coordinates(utp.coordinates), - mbl(utp.mbl), - velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file() + latname(utp.latname), + lmaxmax(utp.lmaxmax), + init_vel(utp.init_vel), + selective_dynamics(utp.selective_dynamics), + relax_new(utp.relax_new), + fixed_axes(utp.fixed_axes), + lat0(utp.lat0), + latvec(utp.latvec), + elements(utp.elements), + pp_files(utp.pp_files), + pp_types(utp.pp_types), + orb_files(utp.orb_files), + natom(utp.natom), + atomic_mass(utp.atomic_mass), + coor_type(utp.coor_type), + coordinates(utp.coordinates), + mbl(utp.mbl), + velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file() {} std::map UcellTestLib { - {"C1H2-Index", UcellTestPrepare( - "bcc", //latname - 2, //lmaxmax - true, //init_vel - true, //selective_dyanmics - true, //relax_new - "volume", //fixed_axes - 1.8897261254578281, //lat0 - {10.0,0.0,0.0, //latvec - 0.0,10.0,0.0, - 0.0,0.0,10.0}, - {"C","H"}, //elements - {"C.upf","H.upf"}, //upf file - {"upf201","upf201"}, //upf types - {"C.orb","H.orb"}, //orb file - {1,2}, //number of each elements - {12.0,1.0}, //atomic mass - "Direct", //coordination type - {0.1,0.1,0.1, //atomic coordinates - 0.15,0.15,0.15, - 0.05,0.05,0.05}, - {1,1,1, //if atom can move: mbl - 0,0,0, - 0,0,1}, - {0.1,0.1,0.1, //velocity: vel - 0.1,0.1,0.1, - 0.1,0.1,0.1})}, - {"C1H2-Cartesian", UcellTestPrepare( - "bcc", //latname - 2, //lmaxmax - true, //init_vel - true, //selective_dyanmics - true, //relax_new - "volume", //fixed_axes - 1.8897261254578281, //lat0 - {10.0,0.0,0.0, //latvec - 0.0,10.0,0.0, - 0.0,0.0,10.0}, - {"C","H"}, //elements - {"C.upf","H.upf"}, //upf file - {"upf201","upf201"}, //upf types - {"C.orb","H.orb"}, //orb file - {1,2}, //number of each elements - {12.0,1.0}, //atomic mass - "Cartesian", //coordination type - {1,1,1, //atomic coordinates - 1.5,1.5,1.5, - 0.5,0.5,0.5})}, - {"C1H2-CheckDTau", UcellTestPrepare( - "bcc", //latname - 2, //lmaxmax - false, //init_vel - false, //selective_dyanmics - true, //relax_new - "volume", //fixed_axes - 1.8897261254578281, //lat0 - {0.1,0.1,0.1, //latvec - 0.15,0.15,0.15, - 0.05,0.05,0.05}, - {"C","H"}, //elements - {"C.upf","H.upf"}, //upf file - {"upf201","upf201"}, //upf types - {"C.orb","H.orb"}, //orb file - {1,2}, //number of each elements - {12.0,1.0}, //atomic mass - "Direct", //coordination type - {1.6,2.5,3.8, //atomic coordinates - -0.15,1.0,-0.15, - -3.05,-2.8,0.0})}, - {"C1H2-CheckTau", UcellTestPrepare( - "bcc", //latname - 2, //lmaxmax - false, //init_vel - false, //selective_dyanmics - true, //relax_new - "volume", //fixed_axes - 1.8897261254578281, //lat0 - {0.1,0.1,0.1, //latvec - 0.15,0.15,0.15, - 0.05,0.05,0.05}, - {"C","H"}, //elements - {"C.upf","H.upf"}, //upf file - {"upf201","upf201"}, //upf types - {"C.orb","H.orb"}, //orb file - {1,2}, //number of each elements - {12.0,1.0}, //atomic mass - "Direct", //coordination type - {0.0,0.0,0.0, //atomic coordinates - 0.00001,0.00001,0.00001, - -3.05,-2.8,0.0})}, - {"C1H2-SD", UcellTestPrepare( - "bcc", //latname - 2, //lmaxmax - false, //init_vel - false, //selective_dyanmics - true, //relax_new - "volume", //fixed_axes - 1.8897261254578281, //lat0 - {0.1,0.1,0.1, //latvec - 0.15,0.15,0.15, - 0.05,0.05,0.05}, - {"C","H"}, //elements - {"C.upf","H.upf"}, //upf file - {"upf201","upf201"}, //upf types - {"C.orb","H.orb"}, //orb file - {1,2}, //number of each elements - {12.0,1.0}, //atomic mass - "Direct", //coordination type - {0.1,0.1,0.1, //atomic coordinates - 0.15,0.15,0.15, - 0.05,0.05,0.05})}, - {"C1H2-PBA", UcellTestPrepare( - "bcc", //latname - 2, //lmaxmax - false, //init_vel - false, //selective_dyanmics - true, //relax_new - "volume", //fixed_axes - 1.8897261254578281, //lat0 - {0.1,0.1,0.1, //latvec - 0.15,0.15,0.15, - 0.05,0.05,0.05}, - {"C","H"}, //elements - {"C.upf","H.upf"}, //upf file - {"upf201","upf201"}, //upf types - {"C.orb","H.orb"}, //orb file - {1,2}, //number of each elements - {12.0,1.0}, //atomic mass - "Direct", //coordination type - {-0.1,-0.1,-0.1, //atomic coordinates - 1.2,1.2,1.2, - -3.05,-2.8,0.0})}, - {"C1H2-Read", UcellTestPrepare( - "bcc", //latname - 2, //lmaxmax - true, //init_vel - true, //selective_dyanmics - true, //relax_new - "volume", //fixed_axes - 1.8897261254578281, //lat0 - {10.0,0.0,0.0, //latvec - 0.0,10.0,0.0, - 0.0,0.0,10.0}, - {"C","H"}, //elements - {"C.upf","H.upf"}, //upf file - {"upf201","upf201"}, //upf types - {"C.orb","H.orb"}, //orb file - {1,2}, //number of each elements - {12.0,1.0}, //atomic mass - "Direct", //coordination type - {0.1,0.1,0.1, //atomic coordinates - 0.12,0.12,0.12, - 0.08,0.08,0.08})}, - {"flz-Read", UcellTestPrepare( - "bcc", //latname - 2, //lmaxmax - false, //init_vel - false, //selective_dyanmics - false, //relax_new - "volume", //fixed_axes - 1.8897261254578281, //lat0 - {10.0,0.0,0.0, //latvec - 0.0,10.0,0.0, - 0.0,0.0,10.0}, - {"C","H"}, //elements - {"C.upf","H.upf"}, //upf file - {"upf201","upf201"}, //upf types - {"C_gga_8au_100Ry_2s2p1d.orb","H_gga_8au_100Ry_2s1p.orb"}, //orb file - {1,2}, //number of each elements - {12.0,1.0}, //atomic mass - "Direct", //coordination type - {0.1,0.1,0.1, //atomic coordinates - 0.12,0.12,0.12, - 0.08,0.08,0.08} - ) - } + {"C1H2-Index", UcellTestPrepare( + "bcc", //latname + 2, //lmaxmax + true, //init_vel + true, //selective_dyanmics + true, //relax_new + "volume", //fixed_axes + 1.8897261254578281, //lat0 + {10.0,0.0,0.0, //latvec + 0.0,10.0,0.0, + 0.0,0.0,10.0}, + {"C","H"}, //elements + {"C.upf","H.upf"}, //upf file + {"upf201","upf201"}, //upf types + {"C.orb","H.orb"}, //orb file + {1,2}, //number of each elements + {12.0,1.0}, //atomic mass + "Direct", //coordination type + {0.1,0.1,0.1, //atomic coordinates + 0.15,0.15,0.15, + 0.05,0.05,0.05}, + {1,1,1, //if atom can move: mbl + 0,0,0, + 0,0,1}, + {0.1,0.1,0.1, //velocity: vel + 0.1,0.1,0.1, + 0.1,0.1,0.1})}, + {"C1H2-Cartesian", UcellTestPrepare( + "bcc", //latname + 2, //lmaxmax + true, //init_vel + true, //selective_dyanmics + true, //relax_new + "volume", //fixed_axes + 1.8897261254578281, //lat0 + {10.0,0.0,0.0, //latvec + 0.0,10.0,0.0, + 0.0,0.0,10.0}, + {"C","H"}, //elements + {"C.upf","H.upf"}, //upf file + {"upf201","upf201"}, //upf types + {"C.orb","H.orb"}, //orb file + {1,2}, //number of each elements + {12.0,1.0}, //atomic mass + "Cartesian", //coordination type + {1,1,1, //atomic coordinates + 1.5,1.5,1.5, + 0.5,0.5,0.5})}, + {"C1H2-CheckDTau", UcellTestPrepare( + "bcc", //latname + 2, //lmaxmax + false, //init_vel + false, //selective_dyanmics + true, //relax_new + "volume", //fixed_axes + 1.8897261254578281, //lat0 + {0.1,0.1,0.1, //latvec + 0.15,0.15,0.15, + 0.05,0.05,0.05}, + {"C","H"}, //elements + {"C.upf","H.upf"}, //upf file + {"upf201","upf201"}, //upf types + {"C.orb","H.orb"}, //orb file + {1,2}, //number of each elements + {12.0,1.0}, //atomic mass + "Direct", //coordination type + {1.6,2.5,3.8, //atomic coordinates + -0.15,1.0,-0.15, + -3.05,-2.8,0.0})}, + {"C1H2-CheckTau", UcellTestPrepare( + "bcc", //latname + 2, //lmaxmax + false, //init_vel + false, //selective_dyanmics + true, //relax_new + "volume", //fixed_axes + 1.8897261254578281, //lat0 + {0.1,0.1,0.1, //latvec + 0.15,0.15,0.15, + 0.05,0.05,0.05}, + {"C","H"}, //elements + {"C.upf","H.upf"}, //upf file + {"upf201","upf201"}, //upf types + {"C.orb","H.orb"}, //orb file + {1,2}, //number of each elements + {12.0,1.0}, //atomic mass + "Direct", //coordination type + {0.0,0.0,0.0, //atomic coordinates + 0.00001,0.00001,0.00001, + -3.05,-2.8,0.0})}, + {"C1H2-SD", UcellTestPrepare( + "bcc", //latname + 2, //lmaxmax + false, //init_vel + false, //selective_dyanmics + true, //relax_new + "volume", //fixed_axes + 1.8897261254578281, //lat0 + {0.1,0.1,0.1, //latvec + 0.15,0.15,0.15, + 0.05,0.05,0.05}, + {"C","H"}, //elements + {"C.upf","H.upf"}, //upf file + {"upf201","upf201"}, //upf types + {"C.orb","H.orb"}, //orb file + {1,2}, //number of each elements + {12.0,1.0}, //atomic mass + "Direct", //coordination type + {0.1,0.1,0.1, //atomic coordinates + 0.15,0.15,0.15, + 0.05,0.05,0.05})}, + {"C1H2-PBA", UcellTestPrepare( + "bcc", //latname + 2, //lmaxmax + false, //init_vel + false, //selective_dyanmics + true, //relax_new + "volume", //fixed_axes + 1.8897261254578281, //lat0 + {0.1,0.1,0.1, //latvec + 0.15,0.15,0.15, + 0.05,0.05,0.05}, + {"C","H"}, //elements + {"C.upf","H.upf"}, //upf file + {"upf201","upf201"}, //upf types + {"C.orb","H.orb"}, //orb file + {1,2}, //number of each elements + {12.0,1.0}, //atomic mass + "Direct", //coordination type + {-0.1,-0.1,-0.1, //atomic coordinates + 1.2,1.2,1.2, + -3.05,-2.8,0.0})}, + {"C1H2-Read", UcellTestPrepare( + "bcc", //latname + 2, //lmaxmax + true, //init_vel + true, //selective_dyanmics + true, //relax_new + "volume", //fixed_axes + 1.8897261254578281, //lat0 + {10.0,0.0,0.0, //latvec + 0.0,10.0,0.0, + 0.0,0.0,10.0}, + {"C","H"}, //elements + {"C.upf","H.upf"}, //upf file + {"upf201","upf201"}, //upf types + {"C.orb","H.orb"}, //orb file + {1,2}, //number of each elements + {12.0,1.0}, //atomic mass + "Direct", //coordination type + {0.1,0.1,0.1, //atomic coordinates + 0.12,0.12,0.12, + 0.08,0.08,0.08})}, + {"flz-Read", UcellTestPrepare( + "bcc", //latname + 2, //lmaxmax + false, //init_vel + false, //selective_dyanmics + false, //relax_new + "volume", //fixed_axes + 1.8897261254578281, //lat0 + {10.0,0.0,0.0, //latvec + 0.0,10.0,0.0, + 0.0,0.0,10.0}, + {"C","H"}, //elements + {"C.upf","H.upf"}, //upf file + {"upf201","upf201"}, //upf types + {"C_gga_8au_100Ry_2s2p1d.orb","H_gga_8au_100Ry_2s1p.orb"}, //orb file + {1,2}, //number of each elements + {12.0,1.0}, //atomic mass + "Direct", //coordination type + {0.1,0.1,0.1, //atomic coordinates + 0.12,0.12,0.12, + 0.08,0.08,0.08} + ) + } }; #endif diff --git a/source/source_cell/test/pseudo_nc_test.cpp b/source/source_cell/test/pseudo_nc_test.cpp index 0da34fe2c2e..c5b0b636bc4 100644 --- a/source/source_cell/test/pseudo_nc_test.cpp +++ b/source/source_cell/test/pseudo_nc_test.cpp @@ -28,101 +28,101 @@ class NCPPTest : public testing::Test { protected: - std::unique_ptr upf{new Pseudopot_upf}; - std::unique_ptr ncpp{new Atom_pseudo}; + std::unique_ptr upf{new Pseudopot_upf}; + std::unique_ptr ncpp{new Atom_pseudo}; }; TEST_F(NCPPTest, SetPseudoH) { - std::ifstream ifs; - //set - ifs.open("./support/C.upf"); - upf->read_pseudo_upf201(ifs, *ncpp); - //set_pseudo_h - upf->complete_default_h(*ncpp); + std::ifstream ifs; + //set + ifs.open("./support/C.upf"); + upf->read_pseudo_upf201(ifs, *ncpp); + //set_pseudo_h + upf->complete_default_h(*ncpp); - if(!ncpp->has_so) - { - for (int i=0;inchi;i++) - { - EXPECT_EQ(ncpp->nn[i],0); - EXPECT_EQ(ncpp->jchi[i],0); - } - for (int i=0;inbeta;i++) - { - EXPECT_EQ(ncpp->jjj[i],0); - } - } - ifs.close(); + if(!ncpp->has_so) + { + for (int i=0;inchi;i++) + { + EXPECT_EQ(ncpp->nn[i],0); + EXPECT_EQ(ncpp->jchi[i],0); + } + for (int i=0;inbeta;i++) + { + EXPECT_EQ(ncpp->jjj[i],0); + } + } + ifs.close(); } TEST_F(NCPPTest, SetPseudoAtom) { - std::ifstream ifs; - //set - ifs.open("./support/C.upf"); - const double pseudo_rcut = 15.0; - upf->read_pseudo_upf201(ifs, *ncpp); - //set_pseudo_atom - upf->complete_default_h(*ncpp); - upf->complete_default_atom(*ncpp, pseudo_rcut); - EXPECT_EQ(ncpp->rcut,pseudo_rcut); + std::ifstream ifs; + //set + ifs.open("./support/C.upf"); + const double pseudo_rcut = 15.0; + upf->read_pseudo_upf201(ifs, *ncpp); + //set_pseudo_atom + upf->complete_default_h(*ncpp); + upf->complete_default_atom(*ncpp, pseudo_rcut); + EXPECT_EQ(ncpp->rcut,pseudo_rcut); - if(!ncpp->nlcc) - { - for(int i=0;imesh;i++) - { - EXPECT_EQ(ncpp->rho_atc[i],0.0); - } - } - EXPECT_EQ(ncpp->msh,ncpp->mesh); - ifs.close(); + if(!ncpp->nlcc) + { + for(int i=0;imesh;i++) + { + EXPECT_EQ(ncpp->rho_atc[i],0.0); + } + } + EXPECT_EQ(ncpp->msh,ncpp->mesh); + ifs.close(); } TEST_F(NCPPTest, SetPseudoNC) { - std::ifstream ifs; - //set - ifs.open("./support/C.upf"); - const double pseudo_rcut = 15.0; - // set pseudo nbeta = 0 - upf->read_pseudo_upf201(ifs, *ncpp); - ncpp->nbeta = 0; - upf->complete_default(*ncpp, pseudo_rcut); - EXPECT_EQ(ncpp->nh,0); + std::ifstream ifs; + //set + ifs.open("./support/C.upf"); + const double pseudo_rcut = 15.0; + // set pseudo nbeta = 0 + upf->read_pseudo_upf201(ifs, *ncpp); + ncpp->nbeta = 0; + upf->complete_default(*ncpp, pseudo_rcut); + EXPECT_EQ(ncpp->nh,0); // set pseudo nbeta > 0 - upf->read_pseudo_upf201(ifs, *ncpp); + upf->read_pseudo_upf201(ifs, *ncpp); upf->complete_default(*ncpp, pseudo_rcut); - EXPECT_EQ(ncpp->nh,14); - EXPECT_EQ(ncpp->kkbeta,132); - ifs.close(); - + EXPECT_EQ(ncpp->nh,14); + EXPECT_EQ(ncpp->kkbeta,132); + ifs.close(); + } TEST_F(NCPPTest, PrintNC) { - std::ifstream ifs; - //set - ifs.open("./support/C.upf"); - const double pseudo_rcut = 15.0; - upf->read_pseudo_upf201(ifs, *ncpp); + std::ifstream ifs; + //set + ifs.open("./support/C.upf"); + const double pseudo_rcut = 15.0; + upf->read_pseudo_upf201(ifs, *ncpp); upf->complete_default(*ncpp, pseudo_rcut); ifs.close(); - //print - std::ofstream ofs; - ofs.open("./tmp_log"); - ncpp->print_pseudo(ofs); - ofs.close(); - ifs.open("./tmp_log"); - std::string str((std::istreambuf_iterator(ifs)),std::istreambuf_iterator()); - EXPECT_THAT(str,testing::HasSubstr("psd C")); - EXPECT_THAT(str,testing::HasSubstr("pp_type NC")); - EXPECT_THAT(str,testing::HasSubstr("dft PBE")); - EXPECT_THAT(str,testing::HasSubstr("zv 4")); - EXPECT_THAT(str,testing::HasSubstr("nchi 3")); - EXPECT_THAT(str,testing::HasSubstr("nbeta 6")); - EXPECT_THAT(str,testing::HasSubstr("dion : nr=6 nc=6")); - EXPECT_THAT(str,testing::HasSubstr("msh\t1247")); - ifs.close(); - remove("./tmp_log"); + //print + std::ofstream ofs; + ofs.open("./tmp_log"); + ncpp->print_pseudo(ofs); + ofs.close(); + ifs.open("./tmp_log"); + std::string str((std::istreambuf_iterator(ifs)),std::istreambuf_iterator()); + EXPECT_THAT(str,testing::HasSubstr("psd C")); + EXPECT_THAT(str,testing::HasSubstr("pp_type NC")); + EXPECT_THAT(str,testing::HasSubstr("dft PBE")); + EXPECT_THAT(str,testing::HasSubstr("zv 4")); + EXPECT_THAT(str,testing::HasSubstr("nchi 3")); + EXPECT_THAT(str,testing::HasSubstr("nbeta 6")); + EXPECT_THAT(str,testing::HasSubstr("dion : nr=6 nc=6")); + EXPECT_THAT(str,testing::HasSubstr("msh\t1247")); + ifs.close(); + remove("./tmp_log"); } diff --git a/source/source_cell/test/read_pp_test.cpp b/source/source_cell/test/read_pp_test.cpp index 74b2a2ad59d..66e3db009e1 100644 --- a/source/source_cell/test/read_pp_test.cpp +++ b/source/source_cell/test/read_pp_test.cpp @@ -66,61 +66,61 @@ class ReadPPTest : public testing::Test { protected: - std::string output; - std::unique_ptr read_pp{new Pseudopot_upf}; - std::unique_ptr upf{new Atom_pseudo}; + std::string output; + std::unique_ptr read_pp{new Pseudopot_upf}; + std::unique_ptr upf{new Atom_pseudo}; }; TEST_F(ReadPPTest, ReadUPF100_Coulomb) { - std::ifstream ifs; - ifs.open("./support/Te.pbe-coulomb.UPF"); - read_pp->read_pseudo_upf(ifs, *upf); - EXPECT_TRUE(upf->vloc_at.empty()); - EXPECT_EQ(read_pp->coulomb_potential, true); - EXPECT_EQ(upf->tvanp, false); - EXPECT_EQ(upf->nbeta, 0); - EXPECT_EQ(upf->lmax, 0); - EXPECT_EQ(read_pp->lloc, 0); - ifs.close(); + std::ifstream ifs; + ifs.open("./support/Te.pbe-coulomb.UPF"); + read_pp->read_pseudo_upf(ifs, *upf); + EXPECT_TRUE(upf->vloc_at.empty()); + EXPECT_EQ(read_pp->coulomb_potential, true); + EXPECT_EQ(upf->tvanp, false); + EXPECT_EQ(upf->nbeta, 0); + EXPECT_EQ(upf->lmax, 0); + EXPECT_EQ(read_pp->lloc, 0); + ifs.close(); } TEST_F(ReadPPTest, ReadUPF100) { - std::ifstream ifs; - ifs.open("./support/Te.pbe-rrkj.UPF"); - read_pp->read_pseudo_upf(ifs, *upf); - EXPECT_FALSE(upf->has_so); // no soc info - EXPECT_EQ(upf->nv,0); // number of version - EXPECT_EQ(upf->psd,"Te"); // element label - EXPECT_EQ(upf->pp_type,"NC"); // pp_type - EXPECT_FALSE(upf->tvanp); // not ultrasoft - EXPECT_FALSE(upf->nlcc); // no Nonlinear core correction - EXPECT_EQ(upf->xc_func,"PBE"); // Exchange-Correlation functional - EXPECT_EQ(upf->zv,6); // Z valence - EXPECT_DOUBLE_EQ(upf->etotps,-15.54533017755); // total energy - EXPECT_DOUBLE_EQ(upf->ecutwfc,0.0); // suggested cutoff for wfc - EXPECT_DOUBLE_EQ(upf->ecutrho,0.0); // suggested cutoff for rho - EXPECT_EQ(upf->lmax,2); // max angular momentum component - EXPECT_EQ(upf->mesh,1191); // Number of points in mesh - EXPECT_EQ(upf->nchi,3); // Number of wavefunctions - EXPECT_EQ(upf->nbeta,3); // Number of projectors - EXPECT_EQ(upf->els[0],"5S"); // label for i-th atomic orbital - EXPECT_EQ(upf->els[1],"5P"); // label for i-th atomic orbital - EXPECT_EQ(upf->els[2],"5D"); // label for i-th atomic orbital - EXPECT_EQ(upf->lchi[0],0); // angluar momentum of each atomic orbital - EXPECT_EQ(upf->lchi[1],1); // angluar momentum of each atomic orbital - EXPECT_EQ(upf->lchi[2],2); // angluar momentum of each atomic orbital - EXPECT_DOUBLE_EQ(upf->oc[0],2.0); // occupation of each atomic orbital - EXPECT_DOUBLE_EQ(upf->oc[1],3.0); // occupation of each atomic orbital - EXPECT_DOUBLE_EQ(upf->oc[2],1.0); // occupation of each atomic orbital - EXPECT_DOUBLE_EQ(upf->r[0],1.75361916453E-05); // r - EXPECT_DOUBLE_EQ(upf->r[upf->mesh-1],5.05901190442E+01); // r - EXPECT_DOUBLE_EQ(upf->rab[0],2.19202395566E-07); // rab - EXPECT_DOUBLE_EQ(upf->rab[upf->mesh-1],6.32376488053E-01); // rab - EXPECT_DOUBLE_EQ(upf->vloc_at[0],-5.00890143222E+00); // vloc - EXPECT_DOUBLE_EQ(upf->vloc_at[upf->mesh-1],-2.37200471955E-01); // vloc - EXPECT_EQ(upf->lll[0],0); // BETA + std::ifstream ifs; + ifs.open("./support/Te.pbe-rrkj.UPF"); + read_pp->read_pseudo_upf(ifs, *upf); + EXPECT_FALSE(upf->has_so); // no soc info + EXPECT_EQ(upf->nv,0); // number of version + EXPECT_EQ(upf->psd,"Te"); // element label + EXPECT_EQ(upf->pp_type,"NC"); // pp_type + EXPECT_FALSE(upf->tvanp); // not ultrasoft + EXPECT_FALSE(upf->nlcc); // no Nonlinear core correction + EXPECT_EQ(upf->xc_func,"PBE"); // Exchange-Correlation functional + EXPECT_EQ(upf->zv,6); // Z valence + EXPECT_DOUBLE_EQ(upf->etotps,-15.54533017755); // total energy + EXPECT_DOUBLE_EQ(upf->ecutwfc,0.0); // suggested cutoff for wfc + EXPECT_DOUBLE_EQ(upf->ecutrho,0.0); // suggested cutoff for rho + EXPECT_EQ(upf->lmax,2); // max angular momentum component + EXPECT_EQ(upf->mesh,1191); // Number of points in mesh + EXPECT_EQ(upf->nchi,3); // Number of wavefunctions + EXPECT_EQ(upf->nbeta,3); // Number of projectors + EXPECT_EQ(upf->els[0],"5S"); // label for i-th atomic orbital + EXPECT_EQ(upf->els[1],"5P"); // label for i-th atomic orbital + EXPECT_EQ(upf->els[2],"5D"); // label for i-th atomic orbital + EXPECT_EQ(upf->lchi[0],0); // angluar momentum of each atomic orbital + EXPECT_EQ(upf->lchi[1],1); // angluar momentum of each atomic orbital + EXPECT_EQ(upf->lchi[2],2); // angluar momentum of each atomic orbital + EXPECT_DOUBLE_EQ(upf->oc[0],2.0); // occupation of each atomic orbital + EXPECT_DOUBLE_EQ(upf->oc[1],3.0); // occupation of each atomic orbital + EXPECT_DOUBLE_EQ(upf->oc[2],1.0); // occupation of each atomic orbital + EXPECT_DOUBLE_EQ(upf->r[0],1.75361916453E-05); // r + EXPECT_DOUBLE_EQ(upf->r[upf->mesh-1],5.05901190442E+01); // r + EXPECT_DOUBLE_EQ(upf->rab[0],2.19202395566E-07); // rab + EXPECT_DOUBLE_EQ(upf->rab[upf->mesh-1],6.32376488053E-01); // rab + EXPECT_DOUBLE_EQ(upf->vloc_at[0],-5.00890143222E+00); // vloc + EXPECT_DOUBLE_EQ(upf->vloc_at[upf->mesh-1],-2.37200471955E-01); // vloc + EXPECT_EQ(upf->lll[0],0); // BETA EXPECT_EQ(read_pp->kbeta[0], 957); EXPECT_DOUBLE_EQ(upf->betar(0, 0), -1.82560984478E-03); EXPECT_DOUBLE_EQ(upf->betar(0, read_pp->kbeta[0] - 1), -1.61398366674E-03); @@ -133,44 +133,44 @@ TEST_F(ReadPPTest, ReadUPF100) EXPECT_DOUBLE_EQ(upf->betar(2, 0), -3.10582746893E-13); EXPECT_DOUBLE_EQ(upf->betar(2, read_pp->kbeta[2] - 1), -4.17131335030E-04); EXPECT_EQ(read_pp->nd,4); // DIJ - EXPECT_DOUBLE_EQ(upf->dion(0,0),-1.70394647943E-01); - EXPECT_DOUBLE_EQ(upf->dion(0,1),-1.76521654672E-01); - EXPECT_DOUBLE_EQ(upf->dion(1,1),-1.80323263809E-01); - EXPECT_DOUBLE_EQ(upf->dion(2,2),1.16612440320E-02); - EXPECT_DOUBLE_EQ(upf->chi(0,0),1.40252610787E-06); // PSWFC - EXPECT_DOUBLE_EQ(upf->chi(0,upf->mesh-1),6.15962544650E-25); - EXPECT_DOUBLE_EQ(upf->chi(1,0),7.65306256201E-11); - EXPECT_DOUBLE_EQ(upf->chi(1,upf->mesh-1),1.44320361049E-17); - EXPECT_DOUBLE_EQ(upf->chi(2,0),4.37015997370E-16); - EXPECT_DOUBLE_EQ(upf->chi(2,upf->mesh-1),6.20093850585E-05); - EXPECT_DOUBLE_EQ(upf->rho_at[0],3.93415898407E-12); // RhoAtom - EXPECT_DOUBLE_EQ(upf->rho_at[upf->mesh-1],3.84516383534E-09); - EXPECT_EQ(upf->nn[0],1); // nn - EXPECT_EQ(upf->nn[1],2); - EXPECT_EQ(upf->nn[2],3); - EXPECT_DOUBLE_EQ(upf->jchi[0],0.0); // jchi - EXPECT_DOUBLE_EQ(upf->jchi[1],0.0); - EXPECT_DOUBLE_EQ(upf->jchi[2],0.0); - EXPECT_DOUBLE_EQ(upf->jjj[0],0.0); // jjj - EXPECT_DOUBLE_EQ(upf->jjj[1],0.0); - EXPECT_DOUBLE_EQ(upf->jjj[2],0.0); - //EXPECT_EQ - ifs.close(); - std::ofstream ofs; - ofs.open("tmp"); - read_pp->print_pseudo_upf(ofs, *upf); - ofs.close(); - ifs.open("tmp"); - getline(ifs, output); - EXPECT_THAT(output, testing::HasSubstr("==== read_pseudo_upf ===")); - ifs.close(); + EXPECT_DOUBLE_EQ(upf->dion(0,0),-1.70394647943E-01); + EXPECT_DOUBLE_EQ(upf->dion(0,1),-1.76521654672E-01); + EXPECT_DOUBLE_EQ(upf->dion(1,1),-1.80323263809E-01); + EXPECT_DOUBLE_EQ(upf->dion(2,2),1.16612440320E-02); + EXPECT_DOUBLE_EQ(upf->chi(0,0),1.40252610787E-06); // PSWFC + EXPECT_DOUBLE_EQ(upf->chi(0,upf->mesh-1),6.15962544650E-25); + EXPECT_DOUBLE_EQ(upf->chi(1,0),7.65306256201E-11); + EXPECT_DOUBLE_EQ(upf->chi(1,upf->mesh-1),1.44320361049E-17); + EXPECT_DOUBLE_EQ(upf->chi(2,0),4.37015997370E-16); + EXPECT_DOUBLE_EQ(upf->chi(2,upf->mesh-1),6.20093850585E-05); + EXPECT_DOUBLE_EQ(upf->rho_at[0],3.93415898407E-12); // RhoAtom + EXPECT_DOUBLE_EQ(upf->rho_at[upf->mesh-1],3.84516383534E-09); + EXPECT_EQ(upf->nn[0],1); // nn + EXPECT_EQ(upf->nn[1],2); + EXPECT_EQ(upf->nn[2],3); + EXPECT_DOUBLE_EQ(upf->jchi[0],0.0); // jchi + EXPECT_DOUBLE_EQ(upf->jchi[1],0.0); + EXPECT_DOUBLE_EQ(upf->jchi[2],0.0); + EXPECT_DOUBLE_EQ(upf->jjj[0],0.0); // jjj + EXPECT_DOUBLE_EQ(upf->jjj[1],0.0); + EXPECT_DOUBLE_EQ(upf->jjj[2],0.0); + //EXPECT_EQ + ifs.close(); + std::ofstream ofs; + ofs.open("tmp"); + read_pp->print_pseudo_upf(ofs, *upf); + ofs.close(); + ifs.open("tmp"); + getline(ifs, output); + EXPECT_THAT(output, testing::HasSubstr("==== read_pseudo_upf ===")); + ifs.close(); } TEST_F(ReadPPTest, ReadUPF100USPP) { std::ifstream ifs; ifs.open("./support/fe_pbe_v1.5.uspp.F.UPF"); - read_pp->read_pseudo_upf(ifs, *upf); + read_pp->read_pseudo_upf(ifs, *upf); EXPECT_FALSE(upf->has_so); // has soc info EXPECT_FALSE(read_pp->q_with_l); // q_with_l EXPECT_EQ(upf->nv, 0); // number of version @@ -284,68 +284,68 @@ TEST_F(ReadPPTest, ReadUPF100USPP) TEST_F(ReadPPTest, ReadUPF201_Coulomb) { - std::ifstream ifs; - ifs.open("./support/Al.pbe-coulomb.UPF"); - read_pp->read_pseudo_upf201(ifs, *upf); - EXPECT_TRUE(upf->vloc_at.empty()); - EXPECT_EQ(read_pp->coulomb_potential, true); - EXPECT_EQ(upf->nbeta, 0); - EXPECT_EQ(upf->lmax, 0); - EXPECT_EQ(read_pp->lloc, 0); - ifs.close(); + std::ifstream ifs; + ifs.open("./support/Al.pbe-coulomb.UPF"); + read_pp->read_pseudo_upf201(ifs, *upf); + EXPECT_TRUE(upf->vloc_at.empty()); + EXPECT_EQ(read_pp->coulomb_potential, true); + EXPECT_EQ(upf->nbeta, 0); + EXPECT_EQ(upf->lmax, 0); + EXPECT_EQ(read_pp->lloc, 0); + ifs.close(); } TEST_F(ReadPPTest, ReadUPF201) { - std::ifstream ifs; - ifs.open("./support/Cu_ONCV_PBE-1.0.upf"); - read_pp->read_pseudo_upf201(ifs, *upf); - EXPECT_EQ(upf->psd,"Cu"); - EXPECT_EQ(upf->pp_type,"NC"); - EXPECT_FALSE(upf->has_so); - EXPECT_FALSE(upf->nlcc); - EXPECT_EQ(upf->xc_func,"PBE"); - EXPECT_EQ(upf->zv,19); - EXPECT_DOUBLE_EQ(upf->etotps,-1.82394100797E+02); - EXPECT_EQ(upf->lmax,2); - EXPECT_EQ(upf->mesh,601); // mesh -= 1 at line 388 (why? Let's see) - EXPECT_EQ(upf->nchi,0); - EXPECT_EQ(upf->nbeta,6); - EXPECT_DOUBLE_EQ(upf->r[0],0.0); - EXPECT_DOUBLE_EQ(upf->r[600],6.00); - EXPECT_DOUBLE_EQ(upf->rab[0],0.01); - EXPECT_DOUBLE_EQ(upf->rab[600],0.01); - EXPECT_DOUBLE_EQ(upf->vloc_at[0],-5.3426582174E+01); - EXPECT_DOUBLE_EQ(upf->vloc_at[600],-6.3333339776E+00); - EXPECT_EQ(upf->lll[0],0); + std::ifstream ifs; + ifs.open("./support/Cu_ONCV_PBE-1.0.upf"); + read_pp->read_pseudo_upf201(ifs, *upf); + EXPECT_EQ(upf->psd,"Cu"); + EXPECT_EQ(upf->pp_type,"NC"); + EXPECT_FALSE(upf->has_so); + EXPECT_FALSE(upf->nlcc); + EXPECT_EQ(upf->xc_func,"PBE"); + EXPECT_EQ(upf->zv,19); + EXPECT_DOUBLE_EQ(upf->etotps,-1.82394100797E+02); + EXPECT_EQ(upf->lmax,2); + EXPECT_EQ(upf->mesh,601); // mesh -= 1 at line 388 (why? Let's see) + EXPECT_EQ(upf->nchi,0); + EXPECT_EQ(upf->nbeta,6); + EXPECT_DOUBLE_EQ(upf->r[0],0.0); + EXPECT_DOUBLE_EQ(upf->r[600],6.00); + EXPECT_DOUBLE_EQ(upf->rab[0],0.01); + EXPECT_DOUBLE_EQ(upf->rab[600],0.01); + EXPECT_DOUBLE_EQ(upf->vloc_at[0],-5.3426582174E+01); + EXPECT_DOUBLE_EQ(upf->vloc_at[600],-6.3333339776E+00); + EXPECT_EQ(upf->lll[0],0); EXPECT_EQ(read_pp->kbeta[0], 196); EXPECT_DOUBLE_EQ(upf->betar(0,0),0.0); - EXPECT_DOUBLE_EQ(upf->betar(0,600),0.0); - EXPECT_EQ(upf->lll[1],0); + EXPECT_DOUBLE_EQ(upf->betar(0,600),0.0); + EXPECT_EQ(upf->lll[1],0); EXPECT_EQ(read_pp->kbeta[1], 196); EXPECT_DOUBLE_EQ(upf->betar(1,0),0.0); - EXPECT_DOUBLE_EQ(upf->betar(1,600),0.0); - EXPECT_EQ(upf->lll[2],1); + EXPECT_DOUBLE_EQ(upf->betar(1,600),0.0); + EXPECT_EQ(upf->lll[2],1); EXPECT_EQ(read_pp->kbeta[2], 196); EXPECT_DOUBLE_EQ(upf->betar(2,0),0.0); - EXPECT_DOUBLE_EQ(upf->betar(2,600),0.0); - EXPECT_EQ(upf->lll[3],1); + EXPECT_DOUBLE_EQ(upf->betar(2,600),0.0); + EXPECT_EQ(upf->lll[3],1); EXPECT_EQ(read_pp->kbeta[3], 196); EXPECT_DOUBLE_EQ(upf->betar(3,0),0.0); - EXPECT_DOUBLE_EQ(upf->betar(3,600),0.0); - EXPECT_EQ(upf->lll[4],2); + EXPECT_DOUBLE_EQ(upf->betar(3,600),0.0); + EXPECT_EQ(upf->lll[4],2); EXPECT_EQ(read_pp->kbeta[4], 196); EXPECT_DOUBLE_EQ(upf->betar(4,0),0.0); - EXPECT_DOUBLE_EQ(upf->betar(4,600),0.0); - EXPECT_EQ(upf->lll[5],2); + EXPECT_DOUBLE_EQ(upf->betar(4,600),0.0); + EXPECT_EQ(upf->lll[5],2); EXPECT_EQ(read_pp->kbeta[5], 196); EXPECT_DOUBLE_EQ(upf->betar(5,0),0.0); - EXPECT_DOUBLE_EQ(upf->betar(5,600),0.0); - EXPECT_DOUBLE_EQ(upf->dion(0,0),-6.6178420255E+00); - EXPECT_DOUBLE_EQ(upf->dion(5,5),-7.0938557228E+00); - EXPECT_DOUBLE_EQ(upf->rho_at[0],0.0); - EXPECT_DOUBLE_EQ(upf->rho_at[600],3.2115793029E-02); - ifs.close(); + EXPECT_DOUBLE_EQ(upf->betar(5,600),0.0); + EXPECT_DOUBLE_EQ(upf->dion(0,0),-6.6178420255E+00); + EXPECT_DOUBLE_EQ(upf->dion(5,5),-7.0938557228E+00); + EXPECT_DOUBLE_EQ(upf->rho_at[0],0.0); + EXPECT_DOUBLE_EQ(upf->rho_at[600],3.2115793029E-02); + ifs.close(); } TEST_F(ReadPPTest, ReadUSPPUPF201) @@ -383,7 +383,7 @@ TEST_F(ReadPPTest, ReadUSPPUPF201) EXPECT_DOUBLE_EQ(upf->rab[892], 3.344685763390000e0); EXPECT_DOUBLE_EQ(upf->vloc_at[0], 3.456089057550000e0); EXPECT_DOUBLE_EQ(upf->vloc_at[892], -1.096266796840000e-1); - EXPECT_TRUE(upf->rho_atc.empty()); + EXPECT_TRUE(upf->rho_atc.empty()); EXPECT_EQ(upf->lll[0], 0); EXPECT_EQ(read_pp->kbeta[0], 617); EXPECT_EQ(read_pp->els_beta[0], "2S"); @@ -420,49 +420,49 @@ TEST_F(ReadPPTest, ReadUSPPUPF201) EXPECT_DOUBLE_EQ(upf->rho_at[0], 0.0); EXPECT_DOUBLE_EQ(upf->rho_at[892], 0.0); EXPECT_TRUE(upf->jchi.empty()); - EXPECT_TRUE(upf->jjj.empty()); - EXPECT_TRUE(upf->nn.empty()); + EXPECT_TRUE(upf->jjj.empty()); + EXPECT_TRUE(upf->nn.empty()); ifs.close(); } TEST_F(ReadPPTest, HeaderErr2011) { - std::ifstream ifs; - // 1st - ifs.open("./support/HeaderError1"); - //read_pp->read_pseudo_upf201(ifs, *upf); - testing::internal::CaptureStdout(); - EXPECT_EXIT(read_pp->read_pseudo_upf201(ifs, *upf), - ::testing::ExitedWithCode(1),""); - output = testing::internal::GetCapturedStdout(); + std::ifstream ifs; + // 1st + ifs.open("./support/HeaderError1"); + //read_pp->read_pseudo_upf201(ifs, *upf); + testing::internal::CaptureStdout(); + EXPECT_EXIT(read_pp->read_pseudo_upf201(ifs, *upf), + ::testing::ExitedWithCode(1),""); + output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("Found no PP_HEADER")); ifs.close(); } TEST_F(ReadPPTest, HeaderErr2012) { - std::ifstream ifs; - // 2nd - ifs.open("./support/HeaderError2"); - //read_pp->read_pseudo_upf201(ifs, *upf); - testing::internal::CaptureStdout(); - EXPECT_EXIT(read_pp->read_pseudo_upf201(ifs, *upf), - ::testing::ExitedWithCode(1),""); - output = testing::internal::GetCapturedStdout(); + std::ifstream ifs; + // 2nd + ifs.open("./support/HeaderError2"); + //read_pp->read_pseudo_upf201(ifs, *upf); + testing::internal::CaptureStdout(); + EXPECT_EXIT(read_pp->read_pseudo_upf201(ifs, *upf), + ::testing::ExitedWithCode(1),""); + output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("SEMI-LOCAL PSEUDOPOTENTIAL IS NOT SUPPORTED")); ifs.close(); } TEST_F(ReadPPTest, HeaderErr2013) { - std::ifstream ifs; - // 3rd - ifs.open("./support/HeaderError3"); - //read_pp->read_pseudo_upf201(ifs, *upf); - testing::internal::CaptureStdout(); - EXPECT_EXIT(read_pp->read_pseudo_upf201(ifs, *upf), - ::testing::ExitedWithCode(1),""); - output = testing::internal::GetCapturedStdout(); + std::ifstream ifs; + // 3rd + ifs.open("./support/HeaderError3"); + //read_pp->read_pseudo_upf201(ifs, *upf); + testing::internal::CaptureStdout(); + EXPECT_EXIT(read_pp->read_pseudo_upf201(ifs, *upf), + ::testing::ExitedWithCode(1),""); + output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("PAW POTENTIAL IS NOT SUPPORTED")); ifs.close(); } @@ -473,7 +473,7 @@ TEST_F(ReadPPTest, HeaderErr2015) // 4th GlobalV::ofs_warning.open("warning.log"); ifs.open("./support/HeaderError5"); - upf->mesh = 1; // avoid assert(pp.mesh > 0) in line 406 of read_pp_upf201.cpp + upf->mesh = 1; // avoid assert(pp.mesh > 0) in line 406 of read_pp_upf201.cpp read_pp->read_pseudo_upf201(ifs, *upf); GlobalV::ofs_warning.close(); ifs.close(); @@ -488,167 +488,167 @@ TEST_F(ReadPPTest, HeaderErr2015) TEST_F(ReadPPTest, ReadUPF201FR) { - std::ifstream ifs; - // this is a dojo full-relativisitic pp - ifs.open("./support/C.upf"); - read_pp->read_pseudo_upf201(ifs, *upf); - EXPECT_EQ(upf->psd,"C"); - EXPECT_TRUE(upf->has_so); - EXPECT_TRUE(upf->nlcc); - EXPECT_EQ(upf->mesh,1247); - //RELBETA - EXPECT_EQ(upf->nbeta,6); - EXPECT_EQ(upf->lll[0],0); - EXPECT_EQ(upf->lll[1],0); - EXPECT_EQ(upf->lll[2],1); - EXPECT_EQ(upf->lll[3],1); - EXPECT_EQ(upf->lll[4],1); - EXPECT_EQ(upf->lll[5],1); - EXPECT_DOUBLE_EQ(upf->jjj[0],0.5); - EXPECT_DOUBLE_EQ(upf->jjj[1],0.5); - EXPECT_DOUBLE_EQ(upf->jjj[2],0.5); - EXPECT_DOUBLE_EQ(upf->jjj[3],1.5); - EXPECT_DOUBLE_EQ(upf->jjj[4],0.5); - EXPECT_DOUBLE_EQ(upf->jjj[5],1.5); - //RELWFC - EXPECT_EQ(upf->nchi,3); - EXPECT_EQ(upf->nn[0],1); - EXPECT_EQ(upf->nn[1],2); - EXPECT_EQ(upf->nn[2],2); - EXPECT_EQ(upf->lchi[0],0); - EXPECT_EQ(upf->lchi[1],1); - EXPECT_EQ(upf->lchi[2],1); - EXPECT_DOUBLE_EQ(upf->jchi[0],0.5); - EXPECT_DOUBLE_EQ(upf->jchi[1],1.5); - EXPECT_DOUBLE_EQ(upf->jchi[2],0.5); - //PSWFC - EXPECT_EQ(upf->els[0],"2S"); - EXPECT_EQ(upf->lchi[0],0); - EXPECT_DOUBLE_EQ(upf->oc[0],2.0); - EXPECT_EQ(upf->els[1],"2P"); - EXPECT_EQ(upf->lchi[1],1); - EXPECT_DOUBLE_EQ(upf->oc[1],1.333); - EXPECT_EQ(upf->els[2],"2P"); - EXPECT_EQ(upf->lchi[2],1); - EXPECT_DOUBLE_EQ(upf->oc[2],0.667); - EXPECT_DOUBLE_EQ(upf->chi(0,0),2.0715339166E-12); - EXPECT_DOUBLE_EQ(upf->chi(2,upf->mesh-1),1.1201306967E-03); - //NLCC - EXPECT_DOUBLE_EQ(upf->rho_atc[0],8.7234550809E-01); - EXPECT_DOUBLE_EQ(upf->rho_atc[upf->mesh-1],0.0); - ifs.close(); + std::ifstream ifs; + // this is a dojo full-relativisitic pp + ifs.open("./support/C.upf"); + read_pp->read_pseudo_upf201(ifs, *upf); + EXPECT_EQ(upf->psd,"C"); + EXPECT_TRUE(upf->has_so); + EXPECT_TRUE(upf->nlcc); + EXPECT_EQ(upf->mesh,1247); + //RELBETA + EXPECT_EQ(upf->nbeta,6); + EXPECT_EQ(upf->lll[0],0); + EXPECT_EQ(upf->lll[1],0); + EXPECT_EQ(upf->lll[2],1); + EXPECT_EQ(upf->lll[3],1); + EXPECT_EQ(upf->lll[4],1); + EXPECT_EQ(upf->lll[5],1); + EXPECT_DOUBLE_EQ(upf->jjj[0],0.5); + EXPECT_DOUBLE_EQ(upf->jjj[1],0.5); + EXPECT_DOUBLE_EQ(upf->jjj[2],0.5); + EXPECT_DOUBLE_EQ(upf->jjj[3],1.5); + EXPECT_DOUBLE_EQ(upf->jjj[4],0.5); + EXPECT_DOUBLE_EQ(upf->jjj[5],1.5); + //RELWFC + EXPECT_EQ(upf->nchi,3); + EXPECT_EQ(upf->nn[0],1); + EXPECT_EQ(upf->nn[1],2); + EXPECT_EQ(upf->nn[2],2); + EXPECT_EQ(upf->lchi[0],0); + EXPECT_EQ(upf->lchi[1],1); + EXPECT_EQ(upf->lchi[2],1); + EXPECT_DOUBLE_EQ(upf->jchi[0],0.5); + EXPECT_DOUBLE_EQ(upf->jchi[1],1.5); + EXPECT_DOUBLE_EQ(upf->jchi[2],0.5); + //PSWFC + EXPECT_EQ(upf->els[0],"2S"); + EXPECT_EQ(upf->lchi[0],0); + EXPECT_DOUBLE_EQ(upf->oc[0],2.0); + EXPECT_EQ(upf->els[1],"2P"); + EXPECT_EQ(upf->lchi[1],1); + EXPECT_DOUBLE_EQ(upf->oc[1],1.333); + EXPECT_EQ(upf->els[2],"2P"); + EXPECT_EQ(upf->lchi[2],1); + EXPECT_DOUBLE_EQ(upf->oc[2],0.667); + EXPECT_DOUBLE_EQ(upf->chi(0,0),2.0715339166E-12); + EXPECT_DOUBLE_EQ(upf->chi(2,upf->mesh-1),1.1201306967E-03); + //NLCC + EXPECT_DOUBLE_EQ(upf->rho_atc[0],8.7234550809E-01); + EXPECT_DOUBLE_EQ(upf->rho_atc[upf->mesh-1],0.0); + ifs.close(); } TEST_F(ReadPPTest, ReadUPF201MESH2) { - std::ifstream ifs; - // this pp file has gipaw, thus a different header - ifs.open("./support/Fe.pbe-sp-mt_gipaw.UPF"); - read_pp->read_pseudo_upf201(ifs, *upf); - EXPECT_EQ(upf->psd,"Fe"); - ifs.close(); + std::ifstream ifs; + // this pp file has gipaw, thus a different header + ifs.open("./support/Fe.pbe-sp-mt_gipaw.UPF"); + read_pp->read_pseudo_upf201(ifs, *upf); + EXPECT_EQ(upf->psd,"Fe"); + ifs.close(); } TEST_F(ReadPPTest, VWR) { - std::ifstream ifs; - // this pp file is a vwr type of pp - ifs.open("./support/vwr.Si"); - read_pp->read_pseudo_vwr(ifs, *upf); - EXPECT_EQ(upf->xc_func,"PZ"); - EXPECT_EQ(upf->pp_type,"NC"); - EXPECT_FALSE(upf->tvanp); - EXPECT_EQ(upf->mesh,1073); - EXPECT_FALSE(upf->nlcc); - EXPECT_EQ(upf->psd,"14"); - EXPECT_EQ(upf->zv,4); - EXPECT_EQ(read_pp->spd_loc,2); - EXPECT_FALSE(upf->has_so); - EXPECT_EQ(read_pp->iTB_s,1); - EXPECT_EQ(read_pp->iTB_p,1); - EXPECT_EQ(read_pp->iTB_d,0); - EXPECT_EQ(upf->nchi,2); - EXPECT_DOUBLE_EQ(upf->oc[0],2); - EXPECT_DOUBLE_EQ(upf->oc[1],2); - EXPECT_EQ(upf->lchi[0],0); - EXPECT_EQ(upf->lchi[1],1); - EXPECT_EQ(upf->els[0],"S"); - EXPECT_EQ(upf->els[1],"P"); - EXPECT_DOUBLE_EQ(upf->r[0],.22270617E-05); - EXPECT_DOUBLE_EQ(upf->r[upf->mesh-1],.11832572E+03); - EXPECT_NEAR(upf->rho_at[0],6.18479e-13,1.0e-17); - EXPECT_NEAR(upf->rho_at[upf->mesh-1],3.46232e-56,1.0e-60); - EXPECT_EQ(upf->nbeta,1); - EXPECT_NEAR(upf->betar(0,2),2.67501e-05,1.0e-9); - EXPECT_EQ(upf->lll[0],0); - ifs.close(); + std::ifstream ifs; + // this pp file is a vwr type of pp + ifs.open("./support/vwr.Si"); + read_pp->read_pseudo_vwr(ifs, *upf); + EXPECT_EQ(upf->xc_func,"PZ"); + EXPECT_EQ(upf->pp_type,"NC"); + EXPECT_FALSE(upf->tvanp); + EXPECT_EQ(upf->mesh,1073); + EXPECT_FALSE(upf->nlcc); + EXPECT_EQ(upf->psd,"14"); + EXPECT_EQ(upf->zv,4); + EXPECT_EQ(read_pp->spd_loc,2); + EXPECT_FALSE(upf->has_so); + EXPECT_EQ(read_pp->iTB_s,1); + EXPECT_EQ(read_pp->iTB_p,1); + EXPECT_EQ(read_pp->iTB_d,0); + EXPECT_EQ(upf->nchi,2); + EXPECT_DOUBLE_EQ(upf->oc[0],2); + EXPECT_DOUBLE_EQ(upf->oc[1],2); + EXPECT_EQ(upf->lchi[0],0); + EXPECT_EQ(upf->lchi[1],1); + EXPECT_EQ(upf->els[0],"S"); + EXPECT_EQ(upf->els[1],"P"); + EXPECT_DOUBLE_EQ(upf->r[0],.22270617E-05); + EXPECT_DOUBLE_EQ(upf->r[upf->mesh-1],.11832572E+03); + EXPECT_NEAR(upf->rho_at[0],6.18479e-13,1.0e-17); + EXPECT_NEAR(upf->rho_at[upf->mesh-1],3.46232e-56,1.0e-60); + EXPECT_EQ(upf->nbeta,1); + EXPECT_NEAR(upf->betar(0,2),2.67501e-05,1.0e-9); + EXPECT_EQ(upf->lll[0],0); + ifs.close(); } TEST_F(ReadPPTest, BLPS) { - std::ifstream ifs; - // this pp file is a vwr type of pp - ifs.open("./support/si.lda.lps"); - read_pp->read_pseudo_blps(ifs, *upf); - EXPECT_FALSE(upf->nlcc); - EXPECT_FALSE(upf->tvanp); - EXPECT_FALSE(upf->has_so); - EXPECT_EQ(upf->nbeta,0); - EXPECT_EQ(upf->psd,"Si"); - EXPECT_EQ(upf->zv,4); - EXPECT_EQ(upf->lmax,0); - EXPECT_EQ(upf->mesh,1601); - EXPECT_EQ(upf->xc_func,"PZ"); - EXPECT_DOUBLE_EQ(upf->r[0],0.0); - EXPECT_DOUBLE_EQ(upf->r[upf->mesh-1],16.0); - EXPECT_DOUBLE_EQ(upf->vloc_at[0],2.4189229665506291*2.0); - EXPECT_DOUBLE_EQ(upf->vloc_at[upf->mesh-1],-0.25*2.0); - EXPECT_DOUBLE_EQ(upf->rho_at[0],0.25); - EXPECT_DOUBLE_EQ(upf->rho_at[upf->mesh-1],0.25); - ifs.close(); + std::ifstream ifs; + // this pp file is a vwr type of pp + ifs.open("./support/si.lda.lps"); + read_pp->read_pseudo_blps(ifs, *upf); + EXPECT_FALSE(upf->nlcc); + EXPECT_FALSE(upf->tvanp); + EXPECT_FALSE(upf->has_so); + EXPECT_EQ(upf->nbeta,0); + EXPECT_EQ(upf->psd,"Si"); + EXPECT_EQ(upf->zv,4); + EXPECT_EQ(upf->lmax,0); + EXPECT_EQ(upf->mesh,1601); + EXPECT_EQ(upf->xc_func,"PZ"); + EXPECT_DOUBLE_EQ(upf->r[0],0.0); + EXPECT_DOUBLE_EQ(upf->r[upf->mesh-1],16.0); + EXPECT_DOUBLE_EQ(upf->vloc_at[0],2.4189229665506291*2.0); + EXPECT_DOUBLE_EQ(upf->vloc_at[upf->mesh-1],-0.25*2.0); + EXPECT_DOUBLE_EQ(upf->rho_at[0],0.25); + EXPECT_DOUBLE_EQ(upf->rho_at[upf->mesh-1],0.25); + ifs.close(); } TEST_F(ReadPPTest, SetPseudoType) { - std::string pp_address = "./support/Cu_ONCV_PBE-1.0.upf"; - std::string type = "auto"; - read_pp->set_pseudo_type(pp_address,type); - EXPECT_EQ(type,"upf201"); - pp_address = "./support/Te.pbe-rrkj.UPF"; - read_pp->set_pseudo_type(pp_address,type); - EXPECT_EQ(type,"upf"); + std::string pp_address = "./support/Cu_ONCV_PBE-1.0.upf"; + std::string type = "auto"; + read_pp->set_pseudo_type(pp_address,type); + EXPECT_EQ(type,"upf201"); + pp_address = "./support/Te.pbe-rrkj.UPF"; + read_pp->set_pseudo_type(pp_address,type); + EXPECT_EQ(type,"upf"); } TEST_F(ReadPPTest, Trim) { - std::string tmp_string = " aaa \t bbb\t "; - output = read_pp->trim(tmp_string); - EXPECT_EQ(output,"aaabbb"); - tmp_string = " \taaa\tbbb\t "; - output = read_pp->trimend(tmp_string); - EXPECT_EQ(output,"aaa\tbbb"); + std::string tmp_string = " aaa \t bbb\t "; + output = read_pp->trim(tmp_string); + EXPECT_EQ(output,"aaabbb"); + tmp_string = " \taaa\tbbb\t "; + output = read_pp->trimend(tmp_string); + EXPECT_EQ(output,"aaa\tbbb"); } TEST_F(ReadPPTest, SetEmptyElement) { - upf->mesh = 10; - upf->nbeta = 10; - upf->vloc_at = std::vector(upf->mesh, 0.0); - upf->rho_at = std::vector(upf->mesh, 0.0); - upf->dion.create(upf->nbeta,upf->nbeta); - read_pp->set_empty_element(*upf); - for(int ir=0;irmesh;++ir) - { - EXPECT_DOUBLE_EQ(upf->vloc_at[ir],0.0); - EXPECT_DOUBLE_EQ(upf->rho_at[ir],0.0); - } - for(int i=0;inbeta;++i) - { - for(int j=0;jnbeta;++j) - { - EXPECT_DOUBLE_EQ(upf->dion(i,j),0.0); - } - } + upf->mesh = 10; + upf->nbeta = 10; + upf->vloc_at = std::vector(upf->mesh, 0.0); + upf->rho_at = std::vector(upf->mesh, 0.0); + upf->dion.create(upf->nbeta,upf->nbeta); + read_pp->set_empty_element(*upf); + for(int ir=0;irmesh;++ir) + { + EXPECT_DOUBLE_EQ(upf->vloc_at[ir],0.0); + EXPECT_DOUBLE_EQ(upf->rho_at[ir],0.0); + } + for(int i=0;inbeta;++i) + { + for(int j=0;jnbeta;++j) + { + EXPECT_DOUBLE_EQ(upf->dion(i,j),0.0); + } + } } TEST_F(ReadPPTest, SetUpfQ) @@ -709,45 +709,45 @@ TEST_F(ReadPPTest, SetQfNew) TEST_F(ReadPPTest, InitReader) { - std::string pp_file = "arbitrary"; - std::string type = "auto"; - int info = read_pp->init_pseudo_reader(pp_file,type,*upf); - EXPECT_EQ(info,1); - pp_file = "./support/Te.pbe-rrkj.UPF"; - info = read_pp->init_pseudo_reader(pp_file,type,*upf); - EXPECT_EQ(type,"upf"); - EXPECT_EQ(info,0); - pp_file = "./support/Cu_ONCV_PBE-1.0.upf"; - info = read_pp->init_pseudo_reader(pp_file,type,*upf); - EXPECT_EQ(info,2); - pp_file = "./support/Cu_ONCV_PBE-1.0.upf"; - type = "auto"; - info = read_pp->init_pseudo_reader(pp_file,type,*upf); - EXPECT_EQ(type,"upf201"); - EXPECT_EQ(info,0); - pp_file = "./support/vwr.Si"; - type = "vwr"; - info = read_pp->init_pseudo_reader(pp_file,type,*upf); - EXPECT_EQ(info,0); - pp_file = "./support/si.lda.lps"; - type = "blps"; - info = read_pp->init_pseudo_reader(pp_file,type,*upf); - EXPECT_EQ(info,0); + std::string pp_file = "arbitrary"; + std::string type = "auto"; + int info = read_pp->init_pseudo_reader(pp_file,type,*upf); + EXPECT_EQ(info,1); + pp_file = "./support/Te.pbe-rrkj.UPF"; + info = read_pp->init_pseudo_reader(pp_file,type,*upf); + EXPECT_EQ(type,"upf"); + EXPECT_EQ(info,0); + pp_file = "./support/Cu_ONCV_PBE-1.0.upf"; + info = read_pp->init_pseudo_reader(pp_file,type,*upf); + EXPECT_EQ(info,2); + pp_file = "./support/Cu_ONCV_PBE-1.0.upf"; + type = "auto"; + info = read_pp->init_pseudo_reader(pp_file,type,*upf); + EXPECT_EQ(type,"upf201"); + EXPECT_EQ(info,0); + pp_file = "./support/vwr.Si"; + type = "vwr"; + info = read_pp->init_pseudo_reader(pp_file,type,*upf); + EXPECT_EQ(info,0); + pp_file = "./support/si.lda.lps"; + type = "blps"; + info = read_pp->init_pseudo_reader(pp_file,type,*upf); + EXPECT_EQ(info,0); } TEST_F(ReadPPTest, AverageSimpleReturns) { - int ierr; - double lambda = 1.0; - // first return - const bool lspinorb_1 = true; - upf->has_so = 0; - ierr = read_pp->average_p(lambda, *upf, lspinorb_1); - EXPECT_EQ(ierr,1); - // second return - upf->has_so = 1; - ierr = read_pp->average_p(lambda, *upf, lspinorb_1); - EXPECT_EQ(ierr,0); + int ierr; + double lambda = 1.0; + // first return + const bool lspinorb_1 = true; + upf->has_so = 0; + ierr = read_pp->average_p(lambda, *upf, lspinorb_1); + EXPECT_EQ(ierr,1); + // second return + upf->has_so = 1; + ierr = read_pp->average_p(lambda, *upf, lspinorb_1); + EXPECT_EQ(ierr,0); upf->has_so = 1; upf->tvanp = 1; ierr = read_pp->average_p(lambda, *upf, lspinorb_1); @@ -756,54 +756,54 @@ TEST_F(ReadPPTest, AverageSimpleReturns) TEST_F(ReadPPTest, AverageErrReturns) { - int ierr; - double lambda = 1.0; - // LSPINORB = 0 - std::ifstream ifs; - ifs.open("./support/Si.rel-pbe-rrkj.UPF"); - read_pp->read_pseudo_upf(ifs, *upf); - EXPECT_TRUE(upf->has_so); // has soc info - const bool lspinorb_0 = false; - ierr = read_pp->average_p(lambda, *upf, lspinorb_0); - EXPECT_EQ(upf->nbeta,2); - EXPECT_EQ(ierr,0); - // LSPINORB = 1, should return error because has_so was set to false after average_p with lspinorb=false - const bool lspinorb_1 = true; - ierr = read_pp->average_p(lambda, *upf, lspinorb_1); - EXPECT_EQ(ierr,1); - ifs.close(); + int ierr; + double lambda = 1.0; + // LSPINORB = 0 + std::ifstream ifs; + ifs.open("./support/Si.rel-pbe-rrkj.UPF"); + read_pp->read_pseudo_upf(ifs, *upf); + EXPECT_TRUE(upf->has_so); // has soc info + const bool lspinorb_0 = false; + ierr = read_pp->average_p(lambda, *upf, lspinorb_0); + EXPECT_EQ(upf->nbeta,2); + EXPECT_EQ(ierr,0); + // LSPINORB = 1, should return error because has_so was set to false after average_p with lspinorb=false + const bool lspinorb_1 = true; + ierr = read_pp->average_p(lambda, *upf, lspinorb_1); + EXPECT_EQ(ierr,1); + ifs.close(); } TEST_F(ReadPPTest, AverageLSPINORB0) { - std::ifstream ifs; - // this is a dojo full-relativisitic pp - ifs.open("./support/C.upf"); - read_pp->read_pseudo_upf201(ifs, *upf); - EXPECT_TRUE(upf->has_so); // has soc info - int ierr; - double lambda = 1.0; - // LSPINORB = 0 - const bool lspinorb_0 = false; - ierr = read_pp->average_p(lambda, *upf, lspinorb_0); - EXPECT_EQ(ierr,0); - EXPECT_EQ(upf->nbeta,4); - EXPECT_FALSE(upf->has_so); // has not soc info,why? + std::ifstream ifs; + // this is a dojo full-relativisitic pp + ifs.open("./support/C.upf"); + read_pp->read_pseudo_upf201(ifs, *upf); + EXPECT_TRUE(upf->has_so); // has soc info + int ierr; + double lambda = 1.0; + // LSPINORB = 0 + const bool lspinorb_0 = false; + ierr = read_pp->average_p(lambda, *upf, lspinorb_0); + EXPECT_EQ(ierr,0); + EXPECT_EQ(upf->nbeta,4); + EXPECT_FALSE(upf->has_so); // has not soc info,why? } TEST_F(ReadPPTest, AverageLSPINORB1) { - std::ifstream ifs; - // this is a dojo full-relativisitic pp - ifs.open("./support/C.upf"); - read_pp->read_pseudo_upf201(ifs, *upf); - EXPECT_TRUE(upf->has_so); // has soc info - int ierr; - double lambda = 1.1; - // LSPINORB = 1 - const bool lspinorb_1 = true; - ierr = read_pp->average_p(lambda, *upf, lspinorb_1); - EXPECT_EQ(ierr,0); - EXPECT_EQ(upf->nbeta,6); - EXPECT_TRUE(upf->has_so); // has soc info + std::ifstream ifs; + // this is a dojo full-relativisitic pp + ifs.open("./support/C.upf"); + read_pp->read_pseudo_upf201(ifs, *upf); + EXPECT_TRUE(upf->has_so); // has soc info + int ierr; + double lambda = 1.1; + // LSPINORB = 1 + const bool lspinorb_1 = true; + ierr = read_pp->average_p(lambda, *upf, lspinorb_1); + EXPECT_EQ(ierr,0); + EXPECT_EQ(upf->nbeta,6); + EXPECT_TRUE(upf->has_so); // has soc info } diff --git a/source/source_cell/test/unitcell_test.cpp b/source/source_cell/test/unitcell_test.cpp index 5f354d046d9..a87100f741e 100644 --- a/source/source_cell/test/unitcell_test.cpp +++ b/source/source_cell/test/unitcell_test.cpp @@ -1055,9 +1055,9 @@ class UcellTestReadStru : public ::testing::Test protected: std::unique_ptr ucell{new UnitCell}; std::string output; - void SetUp() override + void SetUp() override { - ucell->ntype = 2; + ucell->ntype = 2; ucell->atom_mass.resize(ucell->ntype); ucell->atom_label.resize(ucell->ntype); ucell->pseudo_fn.resize(ucell->ntype); diff --git a/source/source_cell/test/unitcell_test_setupcell.cpp b/source/source_cell/test/unitcell_test_setupcell.cpp index 15dcc678f9d..799581bde25 100644 --- a/source/source_cell/test/unitcell_test_setupcell.cpp +++ b/source/source_cell/test/unitcell_test_setupcell.cpp @@ -14,8 +14,8 @@ Magnetism::Magnetism() { - this->tot_mag = 0.0; - this->abs_mag = 0.0; + this->tot_mag = 0.0; + this->abs_mag = 0.0; } Magnetism::~Magnetism() { @@ -44,27 +44,27 @@ Magnetism::~Magnetism() class UcellTest : public ::testing::Test { protected: - std::unique_ptr ucell{new UnitCell}; - std::string output; - - const double symmetry_prec = 1e-5; - const int dfthalf_type = 0; - const std::string pseudo_dir = "./support"; - const std::string basis_type = "pw"; - const std::string orbital_dir = "./"; - const std::string init_wfc = "atomic"; - const double onsite_radius = 0.0; - const bool deepks_setorb = false; - const bool rpa = false; - const bool fixed_atoms = false; - const bool noncolin = false; - const std::string calculation = "scf"; - const std::string esolver_type = "cg"; - - void SetUp() + std::unique_ptr ucell{new UnitCell}; + std::string output; + + const double symmetry_prec = 1e-5; + const int dfthalf_type = 0; + const std::string pseudo_dir = "./support"; + const std::string basis_type = "pw"; + const std::string orbital_dir = "./"; + const std::string init_wfc = "atomic"; + const double onsite_radius = 0.0; + const bool deepks_setorb = false; + const bool rpa = false; + const bool fixed_atoms = false; + const bool noncolin = false; + const std::string calculation = "scf"; + const std::string esolver_type = "cg"; + + void SetUp() { - ucell->lmaxmax = 2; - ucell->ntype = 2; + ucell->lmaxmax = 2; + ucell->ntype = 2; ucell->atom_mass.resize(ucell->ntype); ucell->atom_label.resize(ucell->ntype); ucell->pseudo_fn.resize(ucell->ntype); @@ -77,130 +77,130 @@ using UcellDeathTest = UcellTest; TEST_F(UcellTest,SetupCellS1) { - std::string fn = "./support/STRU_MgO"; - std::ofstream ofs_running; - ofs_running.open("setup_cell.tmp"); - const int nspin = 1; - - ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, + std::string fn = "./support/STRU_MgO"; + std::ofstream ofs_running; + ofs_running.open("setup_cell.tmp"); + const int nspin = 1; + + ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa, fixed_atoms, noncolin, calculation, esolver_type); - ofs_running.close(); - remove("setup_cell.tmp"); + ofs_running.close(); + remove("setup_cell.tmp"); } TEST_F(UcellTest,SetupCellS2) { - std::string fn = "./support/STRU_MgO"; - std::ofstream ofs_running; - ofs_running.open("setup_cell.tmp"); - const int nspin = 2; - - ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, + std::string fn = "./support/STRU_MgO"; + std::ofstream ofs_running; + ofs_running.open("setup_cell.tmp"); + const int nspin = 2; + + ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa, fixed_atoms, noncolin, calculation, esolver_type); - ofs_running.close(); - remove("setup_cell.tmp"); + ofs_running.close(); + remove("setup_cell.tmp"); } TEST_F(UcellTest,SetupCellS4) { - std::string fn = "./support/STRU_MgO"; - std::ofstream ofs_running; - ofs_running.open("setup_cell.tmp"); - const int nspin = 4; - - ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, + std::string fn = "./support/STRU_MgO"; + std::ofstream ofs_running; + ofs_running.open("setup_cell.tmp"); + const int nspin = 4; + + ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa, fixed_atoms, noncolin, calculation, esolver_type); - ofs_running.close(); - remove("setup_cell.tmp"); + ofs_running.close(); + remove("setup_cell.tmp"); } TEST_F(UcellDeathTest,SetupCellWarning1) { - std::string fn = "./STRU_MgO"; - std::ofstream ofs_running; - ofs_running.open("setup_cell.tmp"); - - testing::internal::CaptureStdout(); - const int nspin = 1; - EXPECT_EXIT(ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, + std::string fn = "./STRU_MgO"; + std::ofstream ofs_running; + ofs_running.open("setup_cell.tmp"); + + testing::internal::CaptureStdout(); + const int nspin = 1; + EXPECT_EXIT(ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa, fixed_atoms, noncolin, calculation, esolver_type), ::testing::ExitedWithCode(1), ""); - output = testing::internal::GetCapturedStdout(); - EXPECT_THAT(output,testing::HasSubstr("Can not find the file containing atom positions.!")); - ofs_running.close(); - remove("setup_cell.tmp"); + output = testing::internal::GetCapturedStdout(); + EXPECT_THAT(output,testing::HasSubstr("Can not find the file containing atom positions.!")); + ofs_running.close(); + remove("setup_cell.tmp"); } TEST_F(UcellDeathTest,SetupCellWarning2) { - std::string fn = "./support/STRU_MgO_WarningC2"; - std::ofstream ofs_running; - ofs_running.open("setup_cell.tmp"); - - testing::internal::CaptureStdout(); - const int nspin = 1; - EXPECT_EXIT(ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, + std::string fn = "./support/STRU_MgO_WarningC2"; + std::ofstream ofs_running; + ofs_running.open("setup_cell.tmp"); + + testing::internal::CaptureStdout(); + const int nspin = 1; + EXPECT_EXIT(ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa, fixed_atoms, noncolin, calculation, esolver_type), ::testing::ExitedWithCode(1), ""); - output = testing::internal::GetCapturedStdout(); - EXPECT_THAT(output,testing::HasSubstr("Something wrong during read_atom_positions")); - ofs_running.close(); - remove("setup_cell.tmp"); + output = testing::internal::GetCapturedStdout(); + EXPECT_THAT(output,testing::HasSubstr("Something wrong during read_atom_positions")); + ofs_running.close(); + remove("setup_cell.tmp"); } TEST_F(UcellTest,SetupCellAfterVC) { - std::string fn = "./support/STRU_MgO"; - std::ofstream ofs_running; - ofs_running.open("setup_cell.tmp"); - const int nspin = 1; + std::string fn = "./support/STRU_MgO"; + std::ofstream ofs_running; + ofs_running.open("setup_cell.tmp"); + const int nspin = 1; - ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, + ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa, fixed_atoms, noncolin, calculation, esolver_type); - ucell->lat0 = 1.0; - ucell->latvec.Zero(); - ucell->latvec.e11 = 10.0; - ucell->latvec.e22 = 10.0; - ucell->latvec.e33 = 10.0; - for (int i =0;intype;i++) - { - ucell->atoms[i].na = 1; - ucell->atoms[i].taud.resize(ucell->atoms[i].na); - ucell->atoms[i].tau.resize(ucell->atoms[i].na); - ucell->atoms[i].taud[0].x = 0.1; - ucell->atoms[i].taud[0].y = 0.1; - ucell->atoms[i].taud[0].z = 0.1; - } - - unitcell::setup_cell_after_vc(*ucell,ofs_running, nspin); - EXPECT_EQ(ucell->lat0_angstrom,0.529177); - EXPECT_EQ(ucell->tpiba,ModuleBase::TWO_PI); - EXPECT_EQ(ucell->tpiba2,ModuleBase::TWO_PI*ModuleBase::TWO_PI); - EXPECT_EQ(ucell->a1.x ,10.0); - EXPECT_EQ(ucell->a2.y ,10.0); - EXPECT_EQ(ucell->a3.z ,10.0); - EXPECT_EQ(ucell->omega,1000.0); - EXPECT_EQ(ucell->GT.e11,0.1); - EXPECT_EQ(ucell->GT.e22,0.1); - EXPECT_EQ(ucell->GT.e33,0.1); - EXPECT_EQ(ucell->G.e11,0.1); - EXPECT_EQ(ucell->G.e22,0.1); - EXPECT_EQ(ucell->G.e33,0.1); - - for (int it = 0; it < ucell->ntype; it++) { + ucell->lat0 = 1.0; + ucell->latvec.Zero(); + ucell->latvec.e11 = 10.0; + ucell->latvec.e22 = 10.0; + ucell->latvec.e33 = 10.0; + for (int i =0;intype;i++) + { + ucell->atoms[i].na = 1; + ucell->atoms[i].taud.resize(ucell->atoms[i].na); + ucell->atoms[i].tau.resize(ucell->atoms[i].na); + ucell->atoms[i].taud[0].x = 0.1; + ucell->atoms[i].taud[0].y = 0.1; + ucell->atoms[i].taud[0].z = 0.1; + } + + unitcell::setup_cell_after_vc(*ucell,ofs_running, nspin); + EXPECT_EQ(ucell->lat0_angstrom,0.529177); + EXPECT_EQ(ucell->tpiba,ModuleBase::TWO_PI); + EXPECT_EQ(ucell->tpiba2,ModuleBase::TWO_PI*ModuleBase::TWO_PI); + EXPECT_EQ(ucell->a1.x ,10.0); + EXPECT_EQ(ucell->a2.y ,10.0); + EXPECT_EQ(ucell->a3.z ,10.0); + EXPECT_EQ(ucell->omega,1000.0); + EXPECT_EQ(ucell->GT.e11,0.1); + EXPECT_EQ(ucell->GT.e22,0.1); + EXPECT_EQ(ucell->GT.e33,0.1); + EXPECT_EQ(ucell->G.e11,0.1); + EXPECT_EQ(ucell->G.e22,0.1); + EXPECT_EQ(ucell->G.e33,0.1); + + for (int it = 0; it < ucell->ntype; it++) { Atom* atom = &ucell->atoms[it]; for (int ia = 0; ia < atom->na; ia++) { EXPECT_EQ(atom->tau[ia].x,1); - EXPECT_EQ(atom->tau[ia].y,1); - EXPECT_EQ(atom->tau[ia].z,1); + EXPECT_EQ(atom->tau[ia].y,1); + EXPECT_EQ(atom->tau[ia].z,1); } } - ofs_running.close(); - remove("setup_cell.tmp"); + ofs_running.close(); + remove("setup_cell.tmp"); } @@ -208,14 +208,14 @@ TEST_F(UcellTest,SetupCellAfterVC) #include "mpi.h" int main(int argc, char **argv) { - MPI_Init(&argc, &argv); - testing::InitGoogleTest(&argc, argv); + MPI_Init(&argc, &argv); + testing::InitGoogleTest(&argc, argv); - MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC); - MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK); + MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC); + MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK); - int result = RUN_ALL_TESTS(); - MPI_Finalize(); - return result; + int result = RUN_ALL_TESTS(); + MPI_Finalize(); + return result; } #endif diff --git a/source/source_cell/test_pw/unitcell_test_pw.cpp b/source/source_cell/test_pw/unitcell_test_pw.cpp index 89a46833665..cdcdc53368b 100644 --- a/source/source_cell/test_pw/unitcell_test_pw.cpp +++ b/source/source_cell/test_pw/unitcell_test_pw.cpp @@ -12,8 +12,8 @@ Magnetism::Magnetism() { - this->tot_mag = 0.0; - this->abs_mag = 0.0; + this->tot_mag = 0.0; + this->abs_mag = 0.0; } Magnetism::~Magnetism() { @@ -36,26 +36,26 @@ Magnetism::~Magnetism() class UcellTest : public ::testing::Test { protected: - std::unique_ptr ucell{new UnitCell}; - std::string output; + std::unique_ptr ucell{new UnitCell}; + std::string output; - const double symmetry_prec = 1e-5; - const int dfthalf_type = 0; - const std::string pseudo_dir = "./support"; - const std::string basis_type = "pw"; - const std::string orbital_dir = "./"; - const std::string init_wfc = "atomic"; - const double onsite_radius = 0.0; - const bool deepks_setorb = false; - const bool rpa = false; - const bool fixed_atoms = false; - const bool noncolin = false; - const std::string calculation = "scf"; - const std::string esolver_type = "cg"; + const double symmetry_prec = 1e-5; + const int dfthalf_type = 0; + const std::string pseudo_dir = "./support"; + const std::string basis_type = "pw"; + const std::string orbital_dir = "./"; + const std::string init_wfc = "atomic"; + const double onsite_radius = 0.0; + const bool deepks_setorb = false; + const bool rpa = false; + const bool fixed_atoms = false; + const bool noncolin = false; + const std::string calculation = "scf"; + const std::string esolver_type = "cg"; - void SetUp() + void SetUp() { - ucell->lmaxmax = 2; + ucell->lmaxmax = 2; ucell->ntype = 2; ucell->atom_mass.resize(ucell->ntype); ucell->atom_label.resize(ucell->ntype); @@ -71,21 +71,21 @@ TEST_F(UcellTest,ReadAtomSpecies) if(GlobalV::MY_RANK==0) { #endif - std::string fn = "./support/STRU_MgO"; - std::ifstream ifa(fn.c_str()); - std::ofstream ofs_running; - ofs_running.open("read_atom_species.tmp"); - ucell->atoms = new Atom[ucell->ntype]; - ucell->set_atom_flag = true; - EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running, *ucell, + std::string fn = "./support/STRU_MgO"; + std::ifstream ifa(fn.c_str()); + std::ofstream ofs_running; + ofs_running.open("read_atom_species.tmp"); + ucell->atoms = new Atom[ucell->ntype]; + ucell->set_atom_flag = true; + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running, *ucell, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa)); - EXPECT_NO_THROW(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat)); - EXPECT_DOUBLE_EQ(ucell->latvec.e11,4.27957); - EXPECT_DOUBLE_EQ(ucell->latvec.e22,4.27957); - EXPECT_DOUBLE_EQ(ucell->latvec.e33,4.27957); - ofs_running.close(); - ifa.close(); - remove("read_atom_species.tmp"); + EXPECT_NO_THROW(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat)); + EXPECT_DOUBLE_EQ(ucell->latvec.e11,4.27957); + EXPECT_DOUBLE_EQ(ucell->latvec.e22,4.27957); + EXPECT_DOUBLE_EQ(ucell->latvec.e33,4.27957); + ofs_running.close(); + ifa.close(); + remove("read_atom_species.tmp"); #ifdef __MPI } #endif @@ -97,31 +97,31 @@ TEST_F(UcellTest,ReadAtomPositions) if(GlobalV::MY_RANK==0) { #endif - std::string fn = "./support/STRU_MgO"; - std::ifstream ifa(fn.c_str()); - std::ofstream ofs_running; - std::ofstream ofs_warning; - ofs_running.open("read_atom_species.tmp"); - ofs_warning.open("read_atom_species.warn"); - ucell->atoms = new Atom[ucell->ntype]; - ucell->set_atom_flag = true; - const int nspin = 1; - //call read_atom_species - EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running, *ucell, + std::string fn = "./support/STRU_MgO"; + std::ifstream ifa(fn.c_str()); + std::ofstream ofs_running; + std::ofstream ofs_warning; + ofs_running.open("read_atom_species.tmp"); + ofs_warning.open("read_atom_species.warn"); + ucell->atoms = new Atom[ucell->ntype]; + ucell->set_atom_flag = true; + const int nspin = 1; + //call read_atom_species + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running, *ucell, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa)); - EXPECT_NO_THROW(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat)); - EXPECT_DOUBLE_EQ(ucell->latvec.e11,4.27957); - EXPECT_DOUBLE_EQ(ucell->latvec.e22,4.27957); - EXPECT_DOUBLE_EQ(ucell->latvec.e33,4.27957); - //call read_atom_positions - EXPECT_NO_THROW(unitcell::read_atom_positions(*ucell, ifa, ofs_running, ofs_warning, nspin, + EXPECT_NO_THROW(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat)); + EXPECT_DOUBLE_EQ(ucell->latvec.e11,4.27957); + EXPECT_DOUBLE_EQ(ucell->latvec.e22,4.27957); + EXPECT_DOUBLE_EQ(ucell->latvec.e33,4.27957); + //call read_atom_positions + EXPECT_NO_THROW(unitcell::read_atom_positions(*ucell, ifa, ofs_running, ofs_warning, nspin, basis_type, orbital_dir, init_wfc, onsite_radius, fixed_atoms, noncolin, calculation, esolver_type)); - ofs_running.close(); - ofs_warning.close(); - ifa.close(); - remove("read_atom_species.tmp"); - remove("read_atom_species.warn"); + ofs_running.close(); + ofs_warning.close(); + ifa.close(); + remove("read_atom_species.tmp"); + remove("read_atom_species.warn"); #ifdef __MPI } #endif @@ -129,29 +129,29 @@ if(GlobalV::MY_RANK==0) TEST_F(UcellTest,SetupCell) { - std::string fn = "./support/STRU_MgO"; - std::ofstream ofs_running; - ofs_running.open("setup_cell.tmp"); - const int nspin = 1; - ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, + std::string fn = "./support/STRU_MgO"; + std::ofstream ofs_running; + ofs_running.open("setup_cell.tmp"); + const int nspin = 1; + ucell->setup_cell(fn, ofs_running, symmetry_prec, dfthalf_type, pseudo_dir, nspin, basis_type, orbital_dir, init_wfc, onsite_radius, deepks_setorb, rpa, fixed_atoms, noncolin, calculation, esolver_type); - ofs_running.close(); - remove("setup_cell.tmp"); + ofs_running.close(); + remove("setup_cell.tmp"); } #ifdef __MPI #include "mpi.h" int main(int argc, char **argv) { - MPI_Init(&argc, &argv); - testing::InitGoogleTest(&argc, argv); + MPI_Init(&argc, &argv); + testing::InitGoogleTest(&argc, argv); - MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC); - MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK); + MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC); + MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK); - int result = RUN_ALL_TESTS(); - MPI_Finalize(); - return result; + int result = RUN_ALL_TESTS(); + MPI_Finalize(); + return result; } #endif diff --git a/source/source_cell/unitcell.cpp b/source/source_cell/unitcell.cpp index 43fac8a18cc..950524d314f 100644 --- a/source/source_cell/unitcell.cpp +++ b/source/source_cell/unitcell.cpp @@ -136,44 +136,44 @@ std::vector> UnitCell::get_lnchiCounts() const { std::vector> UnitCell::get_target_mag() const { - std::vector> target_mag(this->nat); - for (int it = 0; it < this->ntype; it++) - { - for (int ia = 0; ia < this->atoms[it].na; ia++) - { - int iat = itia2iat(it, ia); - target_mag[iat] = this->atoms[it].m_loc_[ia]; - } - } - return target_mag; + std::vector> target_mag(this->nat); + for (int it = 0; it < this->ntype; it++) + { + for (int ia = 0; ia < this->atoms[it].na; ia++) + { + int iat = itia2iat(it, ia); + target_mag[iat] = this->atoms[it].m_loc_[ia]; + } + } + return target_mag; } std::vector> UnitCell::get_lambda() const { - std::vector> lambda(this->nat); - for (int it = 0; it < this->ntype; it++) - { - for (int ia = 0; ia < this->atoms[it].na; ia++) - { - int iat = itia2iat(it, ia); - lambda[iat] = this->atoms[it].lambda[ia]; - } - } - return lambda; + std::vector> lambda(this->nat); + for (int it = 0; it < this->ntype; it++) + { + for (int ia = 0; ia < this->atoms[it].na; ia++) + { + int iat = itia2iat(it, ia); + lambda[iat] = this->atoms[it].lambda[ia]; + } + } + return lambda; } std::vector> UnitCell::get_constrain() const { - std::vector> constrain(this->nat); - for (int it = 0; it < this->ntype; it++) - { - for (int ia = 0; ia < this->atoms[it].na; ia++) - { - int iat = itia2iat(it, ia); - constrain[iat] = this->atoms[it].constrain[ia]; - } - } - return constrain; + std::vector> constrain(this->nat); + for (int it = 0; it < this->ntype; it++) + { + for (int ia = 0; ia < this->atoms[it].na; ia++) + { + int iat = itia2iat(it, ia); + constrain[iat] = this->atoms[it].constrain[ia]; + } + } + return constrain; } //============================================================== @@ -382,26 +382,26 @@ bool UnitCell::if_atoms_can_move() const for (int it = 0; it < this->ntype; it++) { Atom* atom = &atoms[it]; - for (int ia = 0; ia < atom->na; ia++) - { - if (atom->mbl[ia].x || atom->mbl[ia].y || atom->mbl[ia].z) - { - return true; - } - } - } + for (int ia = 0; ia < atom->na; ia++) + { + if (atom->mbl[ia].x || atom->mbl[ia].y || atom->mbl[ia].z) + { + return true; + } + } + } return false; } // check if lattice vector can be changed bool UnitCell::if_cell_can_change() const { - // need to be fixed next - if (this->lat_axis_free[0] || this->lat_axis_free[1] || this->lat_axis_free[2]) - { - return true; - } - return false; + // need to be fixed next + if (this->lat_axis_free[0] || this->lat_axis_free[1] || this->lat_axis_free[2]) + { + return true; + } + return false; } void UnitCell::setup(const std::string& latname_in, @@ -482,30 +482,30 @@ void UnitCell::compare_atom_labels(const std::string& label1, const std::string& { std::string stru_label = ""; std::string psuedo_label = ""; - for (int ip = 0; ip < label1.length(); ip++) - { - if (!(isdigit(label1[ip]) || label1[ip] == '_')) - { - stru_label += label1[ip]; - } - else - { - break; - } - } - stru_label[0] = toupper(stru_label[0]); - - for (int ip = 0; ip < label2.length(); ip++) - { - if (!(isdigit(label2[ip]) || label2[ip] == '_')) - { - psuedo_label += label2[ip]; - } - else - { - break; - } - } + for (int ip = 0; ip < label1.length(); ip++) + { + if (!(isdigit(label1[ip]) || label1[ip] == '_')) + { + stru_label += label1[ip]; + } + else + { + break; + } + } + stru_label[0] = toupper(stru_label[0]); + + for (int ip = 0; ip < label2.length(); ip++) + { + if (!(isdigit(label2[ip]) || label2[ip] == '_')) + { + psuedo_label += label2[ip]; + } + else + { + break; + } + } psuedo_label[0] = toupper(psuedo_label[0]); if (!(stru_label == psuedo_label diff --git a/source/source_cell/unitcell.h b/source/source_cell/unitcell.h index ecd97431b13..41347a8c2df 100644 --- a/source/source_cell/unitcell.h +++ b/source/source_cell/unitcell.h @@ -257,7 +257,7 @@ class UnitCell : public AtomProvider { //================================================================ // cal_natomwfc : calculate total number of atomic wavefunctions // cal_nwfc : calculate total number of local basis and lmax - // cal_meshx : calculate max number of mesh points in pp file + // cal_meshx : calculate max number of mesh points in pp file //================================================================ bool if_atoms_can_move() const; bool if_cell_can_change() const; diff --git a/source/source_cell/update_cell.cpp b/source/source_cell/update_cell.cpp index e5103a7a26c..b7370e4ca1f 100644 --- a/source/source_cell/update_cell.cpp +++ b/source/source_cell/update_cell.cpp @@ -18,288 +18,288 @@ void remake_cell(Lattice& lat) if (latName == "user_defined_lattice") { - ModuleBase::WARNING_QUIT("UnitCell", "to use fixed_ibrav, latname must be provided"); + ModuleBase::WARNING_QUIT("UnitCell", "to use fixed_ibrav, latname must be provided"); } else if (latName == "sc") // ibrav = 1 { - double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)); + double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)); - latvec.Zero(); - latvec.e11 = latvec.e22 = latvec.e33 = celldm; + latvec.Zero(); + latvec.e11 = latvec.e22 = latvec.e33 = celldm; } else if (latName == "fcc") // ibrav = 2 { - double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)) / std::sqrt(2.0); - - latvec.e11 = -celldm; - latvec.e12 = 0.0; - latvec.e13 = celldm; - latvec.e21 = 0.0; - latvec.e22 = celldm; - latvec.e23 = celldm; - latvec.e31 = -celldm; - latvec.e32 = celldm; - latvec.e33 = 0.0; + double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)) / std::sqrt(2.0); + + latvec.e11 = -celldm; + latvec.e12 = 0.0; + latvec.e13 = celldm; + latvec.e21 = 0.0; + latvec.e22 = celldm; + latvec.e23 = celldm; + latvec.e31 = -celldm; + latvec.e32 = celldm; + latvec.e33 = 0.0; } else if (latName == "bcc") // ibrav = 3 { - double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)) - / std::sqrt(3.0); - - latvec.e11 = celldm; - latvec.e12 = celldm; - latvec.e13 = celldm; - latvec.e21 = -celldm; - latvec.e22 = celldm; - latvec.e23 = celldm; - latvec.e31 = -celldm; - latvec.e32 = -celldm; - latvec.e33 = celldm; + double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)) + / std::sqrt(3.0); + + latvec.e11 = celldm; + latvec.e12 = celldm; + latvec.e13 = celldm; + latvec.e21 = -celldm; + latvec.e22 = celldm; + latvec.e23 = celldm; + latvec.e31 = -celldm; + latvec.e32 = -celldm; + latvec.e33 = celldm; } else if (latName == "hexagonal") // ibrav = 4 { - double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)); - double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) - + pow(latvec.e33, 2)); - double e22 = sqrt(3.0) / 2.0; - - latvec.e11 = celldm1; - latvec.e12 = 0.0; - latvec.e13 = 0.0; - latvec.e21 = -0.5 * celldm1; - latvec.e22 = celldm1 * e22; - latvec.e23 = 0.0; - latvec.e31 = 0.0; - latvec.e32 = 0.0; - latvec.e33 = celldm3; + double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)); + double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) + + pow(latvec.e33, 2)); + double e22 = sqrt(3.0) / 2.0; + + latvec.e11 = celldm1; + latvec.e12 = 0.0; + latvec.e13 = 0.0; + latvec.e21 = -0.5 * celldm1; + latvec.e22 = celldm1 * e22; + latvec.e23 = 0.0; + latvec.e31 = 0.0; + latvec.e32 = 0.0; + latvec.e33 = celldm3; } else if (latName == "trigonal") // ibrav = 5 { - double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)); - double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) - + pow(latvec.e23, 2)); - double celldm12 = (latvec.e11 * latvec.e21 + latvec.e12 * latvec.e22 - + latvec.e13 * latvec.e23); - double cos12 = celldm12 / celldm1 / celldm2; - - if (cos12 <= -0.5 || cos12 >= 1.0) - { - ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!"); - } - double t1 = sqrt(1.0 + 2.0 * cos12); - double t2 = sqrt(1.0 - cos12); - - double e11 = celldm1 * t2 / sqrt(2.0); - double e12 = -celldm1 * t2 / sqrt(6.0); - double e13 = celldm1 * t1 / sqrt(3.0); - double e22 = celldm1 * sqrt(2.0) * t2 / sqrt(3.0); - - latvec.e11 = e11; - latvec.e12 = e12; - latvec.e13 = e13; - latvec.e21 = 0.0; - latvec.e22 = e22; - latvec.e23 = e13; - latvec.e31 = -e11; - latvec.e32 = e12; - latvec.e33 = e13; + double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)); + double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) + + pow(latvec.e23, 2)); + double celldm12 = (latvec.e11 * latvec.e21 + latvec.e12 * latvec.e22 + + latvec.e13 * latvec.e23); + double cos12 = celldm12 / celldm1 / celldm2; + + if (cos12 <= -0.5 || cos12 >= 1.0) + { + ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!"); + } + double t1 = sqrt(1.0 + 2.0 * cos12); + double t2 = sqrt(1.0 - cos12); + + double e11 = celldm1 * t2 / sqrt(2.0); + double e12 = -celldm1 * t2 / sqrt(6.0); + double e13 = celldm1 * t1 / sqrt(3.0); + double e22 = celldm1 * sqrt(2.0) * t2 / sqrt(3.0); + + latvec.e11 = e11; + latvec.e12 = e12; + latvec.e13 = e13; + latvec.e21 = 0.0; + latvec.e22 = e22; + latvec.e23 = e13; + latvec.e31 = -e11; + latvec.e32 = e12; + latvec.e33 = e13; } else if (latName == "st") // ibrav = 6 { - double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)); - double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) - + pow(latvec.e33, 2)); - latvec.e11 = celldm1; - latvec.e12 = 0.0; - latvec.e13 = 0.0; - latvec.e21 = 0.0; - latvec.e22 = celldm1; - latvec.e23 = 0.0; - latvec.e31 = 0.0; - latvec.e32 = 0.0; - latvec.e33 = celldm3; + double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)); + double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) + + pow(latvec.e33, 2)); + latvec.e11 = celldm1; + latvec.e12 = 0.0; + latvec.e13 = 0.0; + latvec.e21 = 0.0; + latvec.e22 = celldm1; + latvec.e23 = 0.0; + latvec.e31 = 0.0; + latvec.e32 = 0.0; + latvec.e33 = celldm3; } else if (latName == "bct") // ibrav = 7 { - double celldm1 = std::abs(latvec.e11); - double celldm2 = std::abs(latvec.e13); - - latvec.e11 = celldm1; - latvec.e12 = -celldm1; - latvec.e13 = celldm2; - latvec.e21 = celldm1; - latvec.e22 = celldm1; - latvec.e23 = celldm2; - latvec.e31 = -celldm1; - latvec.e32 = -celldm1; - latvec.e33 = celldm2; + double celldm1 = std::abs(latvec.e11); + double celldm2 = std::abs(latvec.e13); + + latvec.e11 = celldm1; + latvec.e12 = -celldm1; + latvec.e13 = celldm2; + latvec.e21 = celldm1; + latvec.e22 = celldm1; + latvec.e23 = celldm2; + latvec.e31 = -celldm1; + latvec.e32 = -celldm1; + latvec.e33 = celldm2; } else if (latName == "so") // ibrav = 8 { - double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)); - double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) - + pow(latvec.e23, 2)); - double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) - + pow(latvec.e33, 2)); - - latvec.e11 = celldm1; - latvec.e12 = 0.0; - latvec.e13 = 0.0; - latvec.e21 = 0.0; - latvec.e22 = celldm2; - latvec.e23 = 0.0; - latvec.e31 = 0.0; - latvec.e32 = 0.0; - latvec.e33 = celldm3; + double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)); + double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) + + pow(latvec.e23, 2)); + double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) + + pow(latvec.e33, 2)); + + latvec.e11 = celldm1; + latvec.e12 = 0.0; + latvec.e13 = 0.0; + latvec.e21 = 0.0; + latvec.e22 = celldm2; + latvec.e23 = 0.0; + latvec.e31 = 0.0; + latvec.e32 = 0.0; + latvec.e33 = celldm3; } else if (latName == "baco") // ibrav = 9 { - double celldm1 = std::abs(latvec.e11); - double celldm2 = std::abs(latvec.e22); - double celldm3 = std::abs(latvec.e33); - - latvec.e11 = celldm1; - latvec.e12 = celldm2; - latvec.e13 = 0.0; - latvec.e21 = -celldm1; - latvec.e22 = celldm2; - latvec.e23 = 0.0; - latvec.e31 = 0.0; - latvec.e32 = 0.0; - latvec.e33 = celldm3; + double celldm1 = std::abs(latvec.e11); + double celldm2 = std::abs(latvec.e22); + double celldm3 = std::abs(latvec.e33); + + latvec.e11 = celldm1; + latvec.e12 = celldm2; + latvec.e13 = 0.0; + latvec.e21 = -celldm1; + latvec.e22 = celldm2; + latvec.e23 = 0.0; + latvec.e31 = 0.0; + latvec.e32 = 0.0; + latvec.e33 = celldm3; } else if (latName == "fco") // ibrav = 10 { - double celldm1 = std::abs(latvec.e11); - double celldm2 = std::abs(latvec.e22); - double celldm3 = std::abs(latvec.e33); - - latvec.e11 = celldm1; - latvec.e12 = 0.0; - latvec.e13 = celldm3; - latvec.e21 = celldm1; - latvec.e22 = celldm2; - latvec.e23 = 0.0; - latvec.e31 = 0.0; - latvec.e32 = celldm2; - latvec.e33 = celldm3; + double celldm1 = std::abs(latvec.e11); + double celldm2 = std::abs(latvec.e22); + double celldm3 = std::abs(latvec.e33); + + latvec.e11 = celldm1; + latvec.e12 = 0.0; + latvec.e13 = celldm3; + latvec.e21 = celldm1; + latvec.e22 = celldm2; + latvec.e23 = 0.0; + latvec.e31 = 0.0; + latvec.e32 = celldm2; + latvec.e33 = celldm3; } else if (latName == "bco") // ibrav = 11 { - double celldm1 = std::abs(latvec.e11); - double celldm2 = std::abs(latvec.e12); - double celldm3 = std::abs(latvec.e13); - - latvec.e11 = celldm1; - latvec.e12 = celldm2; - latvec.e13 = celldm3; - latvec.e21 = -celldm1; - latvec.e22 = celldm2; - latvec.e23 = celldm3; - latvec.e31 = -celldm1; - latvec.e32 = -celldm2; - latvec.e33 = celldm3; + double celldm1 = std::abs(latvec.e11); + double celldm2 = std::abs(latvec.e12); + double celldm3 = std::abs(latvec.e13); + + latvec.e11 = celldm1; + latvec.e12 = celldm2; + latvec.e13 = celldm3; + latvec.e21 = -celldm1; + latvec.e22 = celldm2; + latvec.e23 = celldm3; + latvec.e31 = -celldm1; + latvec.e32 = -celldm2; + latvec.e33 = celldm3; } else if (latName == "sm") // ibrav = 12 { - double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)); - double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) - + pow(latvec.e23, 2)); - double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) - + pow(latvec.e33, 2)); - double celldm12 = (latvec.e11 * latvec.e21 + latvec.e12 * latvec.e22 - + latvec.e13 * latvec.e23); - double cos12 = celldm12 / celldm1 / celldm2; - - double e21 = celldm2 * cos12; - double e22 = celldm2 * std::sqrt(1.0 - cos12 * cos12); - - latvec.e11 = celldm1; - latvec.e12 = 0.0; - latvec.e13 = 0.0; - latvec.e21 = e21; - latvec.e22 = e22; - latvec.e23 = 0.0; - latvec.e31 = 0.0; - latvec.e32 = 0.0; - latvec.e33 = celldm3; + double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)); + double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) + + pow(latvec.e23, 2)); + double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) + + pow(latvec.e33, 2)); + double celldm12 = (latvec.e11 * latvec.e21 + latvec.e12 * latvec.e22 + + latvec.e13 * latvec.e23); + double cos12 = celldm12 / celldm1 / celldm2; + + double e21 = celldm2 * cos12; + double e22 = celldm2 * std::sqrt(1.0 - cos12 * cos12); + + latvec.e11 = celldm1; + latvec.e12 = 0.0; + latvec.e13 = 0.0; + latvec.e21 = e21; + latvec.e22 = e22; + latvec.e23 = 0.0; + latvec.e31 = 0.0; + latvec.e32 = 0.0; + latvec.e33 = celldm3; } else if (latName == "bacm") // ibrav = 13 { - double celldm1 = std::abs(latvec.e11); - double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) - + pow(latvec.e23, 2)); - double celldm3 = std::abs(latvec.e13); - - double cos12 = latvec.e21 / celldm2; - if (cos12 >= 1.0) - { - ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!"); - } - - double e21 = celldm2 * cos12; - double e22 = celldm2 * std::sqrt(1.0 - cos12 * cos12); - - latvec.e11 = celldm1; - latvec.e12 = 0.0; - latvec.e13 = -celldm3; - latvec.e21 = e21; - latvec.e22 = e22; - latvec.e23 = 0.0; - latvec.e31 = celldm1; - latvec.e32 = 0.0; - latvec.e33 = celldm3; + double celldm1 = std::abs(latvec.e11); + double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) + + pow(latvec.e23, 2)); + double celldm3 = std::abs(latvec.e13); + + double cos12 = latvec.e21 / celldm2; + if (cos12 >= 1.0) + { + ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!"); + } + + double e21 = celldm2 * cos12; + double e22 = celldm2 * std::sqrt(1.0 - cos12 * cos12); + + latvec.e11 = celldm1; + latvec.e12 = 0.0; + latvec.e13 = -celldm3; + latvec.e21 = e21; + latvec.e22 = e22; + latvec.e23 = 0.0; + latvec.e31 = celldm1; + latvec.e32 = 0.0; + latvec.e33 = celldm3; } else if (latName == "triclinic") // ibrav = 14 { - double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) - + pow(latvec.e13, 2)); - double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) - + pow(latvec.e23, 2)); - double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) - + pow(latvec.e33, 2)); - double celldm12 = (latvec.e11 * latvec.e21 + latvec.e12 * latvec.e22 - + latvec.e13 * latvec.e23); - double cos12 = celldm12 / celldm1 / celldm2; - double celldm13 = (latvec.e11 * latvec.e31 + latvec.e12 * latvec.e32 - + latvec.e13 * latvec.e33); - double cos13 = celldm13 / celldm1 / celldm3; - double celldm23 = (latvec.e21 * latvec.e31 + latvec.e22 * latvec.e32 - + latvec.e23 * latvec.e33); - double cos23 = celldm23 / celldm2 / celldm3; - - double sin12 = std::sqrt(1.0 - cos12 * cos12); - if (cos12 >= 1.0) - { - ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!"); - } - - latvec.e11 = celldm1; - latvec.e12 = 0.0; - latvec.e13 = 0.0; - latvec.e21 = celldm2 * cos12; - latvec.e22 = celldm2 * sin12; - latvec.e23 = 0.0; - latvec.e31 = celldm3 * cos13; - latvec.e32 = celldm3 * (cos23 - cos13 * cos12) / sin12; - double term = 1.0 + 2.0 * cos12 * cos13 * cos23 - cos12 * cos12 - - cos13 * cos13 - cos23 * cos23; - term = sqrt(term) / sin12; - latvec.e33 = celldm3 * term; + double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2) + + pow(latvec.e13, 2)); + double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2) + + pow(latvec.e23, 2)); + double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2) + + pow(latvec.e33, 2)); + double celldm12 = (latvec.e11 * latvec.e21 + latvec.e12 * latvec.e22 + + latvec.e13 * latvec.e23); + double cos12 = celldm12 / celldm1 / celldm2; + double celldm13 = (latvec.e11 * latvec.e31 + latvec.e12 * latvec.e32 + + latvec.e13 * latvec.e33); + double cos13 = celldm13 / celldm1 / celldm3; + double celldm23 = (latvec.e21 * latvec.e31 + latvec.e22 * latvec.e32 + + latvec.e23 * latvec.e33); + double cos23 = celldm23 / celldm2 / celldm3; + + double sin12 = std::sqrt(1.0 - cos12 * cos12); + if (cos12 >= 1.0) + { + ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!"); + } + + latvec.e11 = celldm1; + latvec.e12 = 0.0; + latvec.e13 = 0.0; + latvec.e21 = celldm2 * cos12; + latvec.e22 = celldm2 * sin12; + latvec.e23 = 0.0; + latvec.e31 = celldm3 * cos13; + latvec.e32 = celldm3 * (cos23 - cos13 * cos12) / sin12; + double term = 1.0 + 2.0 * cos12 * cos13 * cos23 - cos12 * cos12 + - cos13 * cos13 - cos23 * cos23; + term = sqrt(term) / sin12; + latvec.e33 = celldm3 * term; } else { - std::cout << "latname is : " << latName << std::endl; - ModuleBase::WARNING_QUIT("unitcell::remake_cell", - "latname type not supported!"); + std::cout << "latname is : " << latName << std::endl; + ModuleBase::WARNING_QUIT("unitcell::remake_cell", + "latname type not supported!"); } } @@ -346,11 +346,11 @@ void setup_cell_after_vc(UnitCell& ucell, std::ofstream& log, const int nspin) ucell.GGT = ucell.G * ucell.GT; ucell.invGGT = ucell.GGT.Inverse(); - for (int it = 0; it < ucell.ntype; it++) - { - Atom* atom = &ucell.atoms[it]; - for (int ia = 0; ia < atom->na; ia++) - { + for (int it = 0; it < ucell.ntype; it++) + { + Atom* atom = &ucell.atoms[it]; + for (int ia = 0; ia < atom->na; ia++) + { atom->tau[ia] = atom->taud[ia] * ucell.latvec; } } @@ -377,13 +377,13 @@ void update_pos_tau(const Lattice& lat, Atom* atoms) { int iat = 0; - for (int it = 0; it < ntype; it++) - { - Atom* atom = &atoms[it]; - for (int ia = 0; ia < atom->na; ia++) - { - for (int ik = 0; ik < 3; ++ik) - { + for (int it = 0; it < ntype; it++) + { + Atom* atom = &atoms[it]; + for (int ia = 0; ia < atom->na; ia++) + { + for (int ik = 0; ik < 3; ++ik) + { if (atom->mbl[ia][ik]) { atom->dis[ia][ik] = pos[3 * iat + ik] / lat.lat0 - atom->tau[ia][ik]; @@ -480,12 +480,12 @@ void periodic_boundary_adjustment(Atom* atoms, // first adjust direct coordinates, // then update them into cartesian coordinates, //---------------------------------------------- - for (int it = 0; it < ntype; it++) - { - Atom* atom = &atoms[it]; + for (int it = 0; it < ntype; it++) + { + Atom* atom = &atoms[it]; atom->boundary_shift.assign(atom->na, {0,0,0}); - for (int ia = 0; ia < atom->na; ia++) - { + for (int ia = 0; ia < atom->na; ia++) + { // mohan update 2011-03-21 for (int ik = 0; ik < 3; ik++) { From 07f4d45b853ce1c5a23f6f5fc8c029cf40f69aa9 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Wed, 22 Jul 2026 22:07:01 +0800 Subject: [PATCH 2/3] fix bug --- source/source_cell/pseudo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/source_cell/pseudo.cpp b/source/source_cell/pseudo.cpp index 333d9d59c42..0bb32b27933 100644 --- a/source/source_cell/pseudo.cpp +++ b/source/source_cell/pseudo.cpp @@ -55,7 +55,7 @@ void pseudo::print_pseudo_atom(std::ofstream& ofs) const { print_pseudo_h(ofs); ofs << "\n pseudo_atom : "; - ofs << "\n msh " << msh; + ofs << "\n msh\t" << msh; // ofs << "\n nchi " << nchi; output::printr1_d(ofs, " r : ", r.data(), mesh); output::printr1_d(ofs, " rab : ", rab.data(), mesh); From 2116c89044acadb951b2d8525435c35adfd26657 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Thu, 23 Jul 2026 16:56:51 +0800 Subject: [PATCH 3/3] fix --- source/source_cell/pseudo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/source_cell/pseudo.cpp b/source/source_cell/pseudo.cpp index 0bb32b27933..c4321e1bef4 100644 --- a/source/source_cell/pseudo.cpp +++ b/source/source_cell/pseudo.cpp @@ -43,7 +43,7 @@ void pseudo::print_pseudo(std::ofstream& ofs) const { print_pseudo_vl(ofs); ofs << "\n pseudo : "; - ofs << "\n kkbeta " << kkbeta; + ofs << "\n kkbeta\t" << kkbeta; ofs << "\n nh " << nh; output::printr1_d(ofs, " lll : ", lll.data(), nbeta); output::printrm(ofs, " betar : ", betar);