From beeb2565e379e53f49a09040f0e613cae6017ebb Mon Sep 17 00:00:00 2001 From: liiutao <74701833+A-006@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:41:46 +0800 Subject: [PATCH] Refactor:Remove the read_atom_species and add read_lattice_constant (#5828) * modify cheack_tau * change the cheak_tau * modify the read_atom_species * upadte the file * fix unittest bug * add objs * modify the atom_label and atom_mass * modify compile bug * modify the reszie of the atom_mass * fix compile bug * [pre-commit.ci lite] apply automatic fixes * Revert "fix compile bug" This reverts commit 9a51ca36193624144c45c510a9d04a6f241d28d5. * Revert "modify the reszie of the atom_mass" This reverts commit f9cc2b947c45cc26a50cad48fcabb0af9be48fad. * update the resize * fix unitest bug * change the compile bug --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- source/Makefile.Objects | 2 + source/module_cell/CMakeLists.txt | 2 + .../module_neighbor/test/prepare_unitcell.h | 12 +- source/module_cell/read_atom_species.cpp | 386 +++++++++++++++ source/module_cell/read_atoms.cpp | 438 +----------------- source/module_cell/read_stru.cpp | 55 +++ source/module_cell/read_stru.h | 20 + source/module_cell/test/CMakeLists.txt | 2 + source/module_cell/test/prepare_unitcell.h | 12 +- .../test/support/mock_unitcell.cpp | 9 - source/module_cell/test/unitcell_test.cpp | 86 ++-- .../test/unitcell_test_setupcell.cpp | 18 +- source/module_cell/test_pw/CMakeLists.txt | 1 + .../module_cell/test_pw/unitcell_test_pw.cpp | 16 +- source/module_cell/unitcell.cpp | 26 +- source/module_cell/unitcell.h | 15 +- source/module_cell/update_cell.cpp | 6 +- .../module_dm/test/prepare_unitcell.h | 13 +- .../module_elecstate/test/prepare_unitcell.h | 13 +- .../module_esolver/test/esolver_dp_test.cpp | 3 +- source/module_esolver/test/for_test.h | 2 +- .../module_deepks/test/CMakeLists.txt | 4 +- .../module_deltaspin/test/prepare_unitcell.h | 13 +- .../module_hcontainer/test/prepare_unitcell.h | 13 +- source/module_io/json_output/init_info.cpp | 4 +- .../json_output/test/para_json_test.cpp | 4 +- source/module_io/test/prepare_unitcell.h | 13 +- source/module_io/test/to_qo_test.cpp | 32 +- .../module_io/test_serial/prepare_unitcell.h | 13 +- source/module_io/to_qo_kernel.cpp | 2 +- source/module_md/test/CMakeLists.txt | 2 + source/module_md/test/setcell.h | 8 +- .../test/psi_initializer_unit_test.cpp | 9 +- source/module_relax/relax_old/test/for_test.h | 8 +- 34 files changed, 652 insertions(+), 610 deletions(-) create mode 100644 source/module_cell/read_atom_species.cpp create mode 100644 source/module_cell/read_stru.cpp create mode 100644 source/module_cell/read_stru.h diff --git a/source/Makefile.Objects b/source/Makefile.Objects index 058aff4f36..ec7764b5e9 100644 --- a/source/Makefile.Objects +++ b/source/Makefile.Objects @@ -189,6 +189,8 @@ OBJS_CELL=atom_pseudo.o\ check_atomic_stru.o\ update_cell.o\ bcast_cell.o\ + read_stru.o\ + read_atom_species.o\ OBJS_DEEPKS=LCAO_deepks.o\ deepks_force.o\ diff --git a/source/module_cell/CMakeLists.txt b/source/module_cell/CMakeLists.txt index 230a6ae2dd..1b94549f0c 100644 --- a/source/module_cell/CMakeLists.txt +++ b/source/module_cell/CMakeLists.txt @@ -25,6 +25,8 @@ add_library( check_atomic_stru.cpp update_cell.cpp bcast_cell.cpp + read_stru.cpp + read_atom_species.cpp ) if(ENABLE_COVERAGE) diff --git a/source/module_cell/module_neighbor/test/prepare_unitcell.h b/source/module_cell/module_neighbor/test/prepare_unitcell.h index e29339ed1a..8fa4aa947f 100644 --- a/source/module_cell/module_neighbor/test/prepare_unitcell.h +++ b/source/module_cell/module_neighbor/test/prepare_unitcell.h @@ -76,16 +76,12 @@ class UcellTestPrepare this->lmaxmax, this->init_vel, this->fixed_axes); - delete[] ucell->atom_label; - delete[] ucell->atom_mass; - delete[] ucell->pseudo_fn; - delete[] ucell->pseudo_type; delete[] ucell->magnet.start_magnetization; //mag set here - ucell->atom_label = new std::string[ucell->ntype]; - ucell->atom_mass = new double[ucell->ntype]; - ucell->pseudo_fn = new std::string[ucell->ntype]; - ucell->pseudo_type = new std::string[ucell->ntype]; + 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.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp new file mode 100644 index 0000000000..a50d4ee6d1 --- /dev/null +++ b/source/module_cell/read_atom_species.cpp @@ -0,0 +1,386 @@ +#include "read_stru.h" + +#include "module_parameter/parameter.h" +#include "module_base/tool_title.h" +#ifdef __EXX +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_ri/serialization_cereal.h" +#endif +namespace unitcell +{ +bool read_atom_species(std::ifstream& ifa, + std::ofstream& ofs_running, + UnitCell& ucell) +{ + ModuleBase::TITLE("UnitCell","read_atom_species"); + const int ntype = ucell.ntype; + std::string word; + + //========================================== + // read in information of each type of atom + //========================================== + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "ATOMIC_SPECIES") ) + { + ifa.ignore(300, '\n'); + ModuleBase::GlobalFunc::OUT(ofs_running,"ntype",ntype); + for (int i = 0;i < ntype;i++) + { + std::string one_line; + std::string one_string; + std::getline(ifa, one_line); + std::stringstream ss; + ss << one_line; + ss >> ucell.atom_label[i] >> ucell.atom_mass[i]; + ucell.pseudo_fn[i] = "auto"; + ucell.pseudo_type[i] = "auto"; + + if(!PARAM.inp.use_paw) + { + bool end = false; + if (ss >> one_string) + { + if (one_string[0] != '#') + { + ucell.pseudo_fn[i] = one_string; + } + else + { + end = true; + } + } + + if (!end && ss >> one_string && one_string[0] != '#') + { + if (one_string == "auto" || one_string == "upf" || one_string == "vwr" || one_string == "upf201" || one_string == "blps") + { + ucell.pseudo_type[i] = one_string; + } + else if (one_string == "1/r") + { + ucell.atoms[i].coulomb_potential = true; + } + else + { + GlobalV::ofs_warning << "unrecongnized pseudopotential type: " << one_string << ", check your STRU file." << std::endl; + ModuleBase::WARNING_QUIT("read_atom_species", "unrecongnized pseudo type."); + } + } + + // Peize Lin test for bsse 2021.04.07 + const std::string bsse_label = "empty"; + ucell.atoms[i].flag_empty_element = + (search( ucell.atom_label[i].begin(), ucell.atom_label[i].end(), bsse_label.begin(), bsse_label.end() ) != ucell.atom_label[i].end()) + ? true : false; + } + } + } + + if((PARAM.inp.basis_type == "lcao") + ||(PARAM.inp.basis_type == "lcao_in_pw") + ||((PARAM.inp.basis_type == "pw")&&(PARAM.inp.init_wfc.substr(0, 3) == "nao")) + || PARAM.inp.onsite_radius > 0.0) + { + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "NUMERICAL_ORBITAL") ) + { + for(int i=0; i> ucell.orbital_fn[i]; + } + } + // caoyu add 2021-03-16 + if(PARAM.globalv.deepks_setorb) + { + if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "NUMERICAL_DESCRIPTOR")) { + ifa >> ucell.descriptor_file; + } + } + else + { + ucell.descriptor_file = PARAM.inp.orbital_dir + ucell.orbital_fn[0]; + } + } +#ifdef __LCAO + // Peize Lin add 2016-09-23 +#ifdef __MPI +#ifdef __EXX + if( GlobalC::exx_info.info_global.cal_exx || PARAM.inp.rpa ) + { + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "ABFS_ORBITAL") ) + { + for(int i=0; i> ofile; + GlobalC::exx_info.info_ri.files_abfs.push_back(ofile); + } + } + } + +#endif // __EXX +#endif // __MPI +#endif // __LCAO + return true; +} + +bool read_lattice_constant(std::ifstream& ifa, + std::ofstream& ofs_running, + Lattice& lat) +{ + //========================== + // read in lattice constant + //========================== + double& lat0 = lat.lat0; + double& lat0_angstrom =lat.lat0_angstrom; + std::string& latName = lat.latName; + ModuleBase::Matrix3& latvec = lat.latvec; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_CONSTANT") ) + { + ModuleBase::GlobalFunc::READ_VALUE(ifa, lat0); + if(lat0<=0.0) + { + ModuleBase::WARNING_QUIT("read_atom_species","lat0<=0.0"); + } + lat0_angstrom = lat0 * 0.529177; + ModuleBase::GlobalFunc::OUT(ofs_running,"lattice constant (Bohr)",lat0); + ModuleBase::GlobalFunc::OUT(ofs_running,"lattice constant (Angstrom)",lat0_angstrom); + lat.tpiba = ModuleBase::TWO_PI / lat0; + lat.tpiba2 = lat.tpiba * lat.tpiba; + } + + //=========================== + // Read in latticies vector + //=========================== + + if(latName=="none") + { + if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, + "LATTICE_PARAMETERS", + true, + false)) + { + ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant","do not use LATTICE_PARAMETERS without explicit specification of lattice type"); + } + if( !ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_VECTORS") ) + { + ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant","Please set LATTICE_VECTORS in STRU file"); + } + else if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_VECTORS") ) + { + // Reading lattice vectors. notice + // here that only one cpu read these + // parameters. + ifa >> latvec.e11 >> latvec.e12; + ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e13); + ifa >> latvec.e21 >> latvec.e22; + ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e23); + ifa >> latvec.e31 >> latvec.e32; + ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); + } + }//supply lattice vectors + else + { + if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, + "LATTICE_VECTORS", + true, + false)) + { + ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant","do not use LATTICE_VECTORS along with explicit specification of lattice type"); + } + if(latName=="sc") + {//simple-cubic, ibrav = 1 + latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; + latvec.e21 = 0.0; latvec.e22 = 1.0; latvec.e23 = 0.0; + latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 1.0; + } + else if(latName=="fcc") + {//face-centered cubic, ibrav = 2 + latvec.e11 =-0.5; latvec.e12 = 0.0; latvec.e13 = 0.5; + latvec.e21 = 0.0; latvec.e22 = 0.5; latvec.e23 = 0.5; + latvec.e31 =-0.5; latvec.e32 = 0.5; latvec.e33 = 0.0; + } + else if(latName=="bcc") + {//body-centered cubic, ibrav = 3 + latvec.e11 = 0.5; latvec.e12 = 0.5; latvec.e13 = 0.5; + latvec.e21 =-0.5; latvec.e22 = 0.5; latvec.e23 = 0.5; + latvec.e31 =-0.5; latvec.e32 =-0.5; latvec.e33 = 0.5; + } + else if(latName=="hexagonal") + {//hexagonal, ibrav = 4 + double e22 = sqrt(3.0) / 2.0; + latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; + latvec.e21 =-0.5; latvec.e22 = e22; latvec.e23 = 0.0; + latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); + } + } + else if(latName=="trigonal") + {//trigonal, ibrav = 5 + double t1 = 0.0; + double t2 = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + double cosab=0.0; + ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab); + t1 = sqrt(1.0 + 2.0*cosab); + t2 = sqrt(1.0 - cosab); + } + double e11 = t2 / sqrt(2.0); + double e12 = -t2 / sqrt(6.0); + double e13 = t1 / sqrt(3.0); + double e22 = 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") + {//simple tetragonal, ibrav= 6 + latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; + latvec.e21 = 0.0; latvec.e22 = 1.0; latvec.e23 = 0.0; + latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); + } + } + else if(latName=="bct") + {//body-centered tetragonal, ibrav = 7 + double cba = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ModuleBase::GlobalFunc::READ_VALUE(ifa, cba); + cba = cba / 2.0; + } + latvec.e11 = 0.5; latvec.e12 =-0.5; latvec.e13 = cba; + latvec.e21 = 0.5; latvec.e22 = 0.5; latvec.e23 = cba; + latvec.e31 =-0.5; latvec.e32 =-0.5; latvec.e33 = cba; + } + else if(latName=="so") + {//simple orthorhombic, ibrav = 8 + latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; + latvec.e21 = 0.0; latvec.e22 = 0.0; latvec.e23 = 0.0; + latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ifa >> latvec.e22; + ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); + } + } + else if(latName=="baco") + {//base-centered orthorhombic, ibrav = 9 + latvec.e11 = 0.5; latvec.e12 = 0.0; latvec.e13 = 0.0; + latvec.e21 =-0.5; latvec.e22 = 0.0; latvec.e23 = 0.0; + latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ifa >> latvec.e12; + latvec.e12 = latvec.e12 / 2.0; + latvec.e22 = latvec.e12; + ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); + } + } + else if(latName=="fco") + {//face-centered orthorhombic, ibrav = 10 + double bba = 0.0; double cba = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ifa >> bba; + ModuleBase::GlobalFunc::READ_VALUE(ifa, cba); + bba = bba / 2.0; cba = cba / 2.0; + } + latvec.e11 = 0.5; latvec.e12 = 0.0; latvec.e13 = cba; + latvec.e21 = 0.5; latvec.e22 = bba; latvec.e23 = 0.0; + latvec.e31 = 0.0; latvec.e32 = bba; latvec.e33 = cba; + } + else if(latName=="bco") + {//body-centered orthorhombic, ibrav = 11 + double bba = 0.0; double cba = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ifa >> bba; + ModuleBase::GlobalFunc::READ_VALUE(ifa, cba); + bba = bba / 2.0; cba = cba / 2.0; + } + latvec.e11 = 0.5; latvec.e12 = bba; latvec.e13 = cba; + latvec.e21 =-0.5; latvec.e22 = bba; latvec.e23 = cba; + latvec.e31 =-0.5; latvec.e32 =-bba; latvec.e33 = cba; + } + else if(latName=="sm") + {//simple monoclinic, ibrav = 12 + double bba = 0.0; double cba = 0.0; + double cosab = 0.0; + double e21 = 0.0; double e22 = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ifa >> bba >> cba; + ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab); + e21 = bba * cosab; + e22 = bba * sqrt(1.0-cosab*cosab); + } + latvec.e11 = 1.0; 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 = cba; + } + else if(latName=="bacm") + {//base-centered monoclinic, ibrav = 13 + double bba = 0.0; double cba = 0.0; + double cosab = 0.0; + double e21 = 0.0; double e22 = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ifa >> bba >> cba; + ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab); + e21 = bba * cosab; + e22 = bba * sqrt(1.0-cosab*cosab); + cba = cba / 2.0; + } + latvec.e11 = 0.5; latvec.e12 = 0.0; latvec.e13 =-cba; + latvec.e21 = e21; latvec.e22 = e22; latvec.e23 = 0.0; + latvec.e31 = 0.5; latvec.e32 = 0.0; latvec.e33 = cba; + } + else if(latName=="triclinic") + {//triclinic, ibrav = 14 + double bba = 0.0; + double cba = 0.0; + double cosab = 0.0; + double cosac = 0.0; + double cosbc = 0.0; + double sinab = 0.0; + double term = 0.0; + if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) + { + ifa >> bba >> cba >> cosab >> cosac; + ModuleBase::GlobalFunc::READ_VALUE(ifa, cosbc); + sinab = sqrt(1.0-cosab*cosab); + } + latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; + latvec.e21 = bba * cosab; latvec.e22 = bba * sinab; latvec.e23 = 0.0; + latvec.e31 = cba * cosac; latvec.e32 = cba * (cosbc - cosac*cosab) / sinab; + term = 1.0 + 2.0 * cosab*cosac*cosbc - cosab*cosab - cosac*cosac - cosbc*cosbc; + term = sqrt(term)/sinab; + latvec.e33 = cba * term; + } + else + { + std::cout << "latname is : " << latName << std::endl; + ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant","latname not supported!"); + } + } + + // lattice vectors in another form. + lat.a1.x = latvec.e11; + lat.a1.y = latvec.e12; + lat.a1.z = latvec.e13; + + lat.a2.x = latvec.e21; + lat.a2.y = latvec.e22; + lat.a2.z = latvec.e23; + + lat.a3.x = latvec.e31; + lat.a3.y = latvec.e32; + lat.a3.z = latvec.e33; + return true; +} + +} \ No newline at end of file diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 26f9d86789..f1031b2a2e 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -1,5 +1,6 @@ #include "unitcell.h" #include "module_parameter/parameter.h" +#include "read_stru.h" #ifdef __LCAO #include "../module_basis/module_ao/ORB_read.h" // to use 'ORB' -- mohan 2021-01-30 #endif @@ -10,369 +11,6 @@ #include // Peize Lin fix bug about strcmp 2016-08-02 #include #include -int UnitCell::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running) -{ - ModuleBase::TITLE("UnitCell","read_atom_species"); - - int error = 0;//0 for correct, >0 for warning and quit - - delete[] atom_label; - delete[] atom_mass; - delete[] pseudo_fn; - delete[] pseudo_type; - this->atom_mass = new double[ntype]; //atom masses - this->atom_label = new std::string[ntype]; //atom labels - this->pseudo_fn = new std::string[ntype]; //file name of pseudopotential - this->pseudo_type = new std::string[ntype]; // type of pseudopotential - - std::string word; - //========================================== - // read in information of each type of atom - //========================================== - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "ATOMIC_SPECIES") ) - { - ifa.ignore(300, '\n'); - ModuleBase::GlobalFunc::OUT(ofs_running,"ntype",ntype); - for (int i = 0;i < ntype;i++) - { - std::string one_line, one_string; - std::getline(ifa, one_line); - std::stringstream ss; - ss << one_line; - ss >> atom_label[i] >> atom_mass[i]; - pseudo_fn[i] = "auto"; - pseudo_type[i] = "auto"; - - if(!PARAM.inp.use_paw) - { - bool end = false; - if (ss >> one_string) - { - if (one_string[0] != '#') - { - pseudo_fn[i] = one_string; - } - else - { - end = true; - } - } - - if (!end && ss >> one_string && one_string[0] != '#') - { - if (one_string == "auto" || one_string == "upf" || one_string == "vwr" || one_string == "upf201" || one_string == "blps") - { - pseudo_type[i] = one_string; - } - else if (one_string == "1/r") - { - atoms[i].coulomb_potential = true; - } - else - { - GlobalV::ofs_warning << "unrecongnized pseudopotential type: " << one_string << ", check your STRU file." << std::endl; - ModuleBase::WARNING_QUIT("read_atom_species", "unrecongnized pseudo type."); - } - } - - if(PARAM.inp.test_pseudo_cell==2) - { - ofs_running << "\n" << std::setw(6) << atom_label[i] - << std::setw(12) << atom_mass[i] - << std::setw(18) << pseudo_fn[i] - << std::setw(18) << pseudo_type[i]; - } - - // Peize Lin test for bsse 2021.04.07 - const std::string bsse_label = "empty"; - this->atoms[i].flag_empty_element = - (search( atom_label[i].begin(), atom_label[i].end(), bsse_label.begin(), bsse_label.end() ) != atom_label[i].end()) - ? true : false; - } - } - } - - if( - (PARAM.inp.basis_type == "lcao") - ||(PARAM.inp.basis_type == "lcao_in_pw") - ||( - (PARAM.inp.basis_type == "pw") - &&(PARAM.inp.init_wfc.substr(0, 3) == "nao") - ) - || PARAM.inp.onsite_radius > 0.0 - ) - { - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "NUMERICAL_ORBITAL") ) - { - for(int i=0; i> orbital_fn[i]; - } - } - // caoyu add 2021-03-16 - if(PARAM.globalv.deepks_setorb) - { - if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "NUMERICAL_DESCRIPTOR")) { - ifa >> descriptor_file; - } - } - else{ - descriptor_file = PARAM.inp.orbital_dir + orbital_fn[0]; - } - } -#ifdef __LCAO - // Peize Lin add 2016-09-23 -#ifdef __MPI -#ifdef __EXX - if( GlobalC::exx_info.info_global.cal_exx || PARAM.inp.rpa ) - { - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "ABFS_ORBITAL") ) - { - for(int i=0; i> ofile; - GlobalC::exx_info.info_ri.files_abfs.push_back(ofile); - } - } - } - -#endif // __EXX -#endif // __MPI -#endif // __LCAO - //========================== - // read in lattice constant - //========================== - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_CONSTANT") ) - { - ModuleBase::GlobalFunc::READ_VALUE(ifa, lat0); - if(lat0<=0.0) - { - ModuleBase::WARNING_QUIT("read_atom_species","lat0<=0.0"); - } - lat0_angstrom = lat0 * 0.529177 ; - ModuleBase::GlobalFunc::OUT(ofs_running,"lattice constant (Bohr)",lat0); - ModuleBase::GlobalFunc::OUT(ofs_running,"lattice constant (Angstrom)",lat0_angstrom); - this->tpiba = ModuleBase::TWO_PI / lat0; - this->tpiba2 = tpiba * tpiba; - } - - //=========================== - // Read in latticies vector - //=========================== - if(latName=="none"){ - if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, - "LATTICE_PARAMETERS", - true, - false)) { - ModuleBase::WARNING_QUIT("UnitCell::read_atom_species","do not use LATTICE_PARAMETERS without explicit specification of lattice type"); - } - if( !ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_VECTORS") ) - { - ModuleBase::WARNING_QUIT("UnitCell::read_atom_species","Please set LATTICE_VECTORS in STRU file"); - } - else if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_VECTORS") ) - { - // Reading lattice vectors. notice - // here that only one cpu read these - // parameters. - ifa >> latvec.e11 >> latvec.e12; - ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e13); - ifa >> latvec.e21 >> latvec.e22; - ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e23); - ifa >> latvec.e31 >> latvec.e32; - ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); - } - }//supply lattice vectors - else{ - if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, - "LATTICE_VECTORS", - true, - false)) { - ModuleBase::WARNING_QUIT("UnitCell::read_atom_species","do not use LATTICE_VECTORS along with explicit specification of lattice type"); - } - if(latName=="sc"){//simple-cubic, ibrav = 1 - latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; - latvec.e21 = 0.0; latvec.e22 = 1.0; latvec.e23 = 0.0; - latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 1.0; - } - else if(latName=="fcc"){//face-centered cubic, ibrav = 2 - latvec.e11 =-0.5; latvec.e12 = 0.0; latvec.e13 = 0.5; - latvec.e21 = 0.0; latvec.e22 = 0.5; latvec.e23 = 0.5; - latvec.e31 =-0.5; latvec.e32 = 0.5; latvec.e33 = 0.0; - } - else if(latName=="bcc"){//body-centered cubic, ibrav = 3 - latvec.e11 = 0.5; latvec.e12 = 0.5; latvec.e13 = 0.5; - latvec.e21 =-0.5; latvec.e22 = 0.5; latvec.e23 = 0.5; - latvec.e31 =-0.5; latvec.e32 =-0.5; latvec.e33 = 0.5; - } - else if(latName=="hexagonal"){//hexagonal, ibrav = 4 - double e22 = sqrt(3.0) / 2.0; - latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; - latvec.e21 =-0.5; latvec.e22 = e22; latvec.e23 = 0.0; - latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); - } - } - else if(latName=="trigonal"){//trigonal, ibrav = 5 - double t1 = 0.0; - double t2 = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - double cosab=0.0; - ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab); - t1 = sqrt(1.0 + 2.0*cosab); - t2 = sqrt(1.0 - cosab); - } - double e11 = t2 / sqrt(2.0); - double e12 = -t2 / sqrt(6.0); - double e13 = t1 / sqrt(3.0); - double e22 = 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"){//simple tetragonal, ibrav= 6 - latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; - latvec.e21 = 0.0; latvec.e22 = 1.0; latvec.e23 = 0.0; - latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); - } - } - else if(latName=="bct"){//body-centered tetragonal, ibrav = 7 - double cba = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ModuleBase::GlobalFunc::READ_VALUE(ifa, cba); - cba = cba / 2.0; - } - latvec.e11 = 0.5; latvec.e12 =-0.5; latvec.e13 = cba; - latvec.e21 = 0.5; latvec.e22 = 0.5; latvec.e23 = cba; - latvec.e31 =-0.5; latvec.e32 =-0.5; latvec.e33 = cba; - } - else if(latName=="so"){//simple orthorhombic, ibrav = 8 - latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; - latvec.e21 = 0.0; latvec.e22 = 0.0; latvec.e23 = 0.0; - latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ifa >> latvec.e22; - ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); - } - } - else if(latName=="baco"){//base-centered orthorhombic, ibrav = 9 - latvec.e11 = 0.5; latvec.e12 = 0.0; latvec.e13 = 0.0; - latvec.e21 =-0.5; latvec.e22 = 0.0; latvec.e23 = 0.0; - latvec.e31 = 0.0; latvec.e32 = 0.0; latvec.e33 = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ifa >> latvec.e12; - latvec.e12 = latvec.e12 / 2.0; - latvec.e22 = latvec.e12; - ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); - } - } - else if(latName=="fco"){//face-centered orthorhombic, ibrav = 10 - double bba = 0.0; double cba = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ifa >> bba; - ModuleBase::GlobalFunc::READ_VALUE(ifa, cba); - bba = bba / 2.0; cba = cba / 2.0; - } - latvec.e11 = 0.5; latvec.e12 = 0.0; latvec.e13 = cba; - latvec.e21 = 0.5; latvec.e22 = bba; latvec.e23 = 0.0; - latvec.e31 = 0.0; latvec.e32 = bba; latvec.e33 = cba; - } - else if(latName=="bco"){//body-centered orthorhombic, ibrav = 11 - double bba = 0.0; double cba = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ifa >> bba; - ModuleBase::GlobalFunc::READ_VALUE(ifa, cba); - bba = bba / 2.0; cba = cba / 2.0; - } - latvec.e11 = 0.5; latvec.e12 = bba; latvec.e13 = cba; - latvec.e21 =-0.5; latvec.e22 = bba; latvec.e23 = cba; - latvec.e31 =-0.5; latvec.e32 =-bba; latvec.e33 = cba; - } - else if(latName=="sm"){//simple monoclinic, ibrav = 12 - double bba = 0.0; double cba = 0.0; - double cosab = 0.0; - double e21 = 0.0; double e22 = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ifa >> bba >> cba; - ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab); - e21 = bba * cosab; - e22 = bba * sqrt(1.0-cosab*cosab); - } - latvec.e11 = 1.0; 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 = cba; - } - else if(latName=="bacm"){//base-centered monoclinic, ibrav = 13 - double bba = 0.0; double cba = 0.0; - double cosab = 0.0; - double e21 = 0.0; double e22 = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ifa >> bba >> cba; - ModuleBase::GlobalFunc::READ_VALUE(ifa, cosab); - e21 = bba * cosab; - e22 = bba * sqrt(1.0-cosab*cosab); - cba = cba / 2.0; - } - latvec.e11 = 0.5; latvec.e12 = 0.0; latvec.e13 =-cba; - latvec.e21 = e21; latvec.e22 = e22; latvec.e23 = 0.0; - latvec.e31 = 0.5; latvec.e32 = 0.0; latvec.e33 = cba; - } - else if(latName=="triclinic"){//triclinic, ibrav = 14 - double bba = 0.0; double cba = 0.0; - double cosab = 0.0; double cosac = 0.0; - double cosbc = 0.0; double sinab = 0.0; - double term = 0.0; - if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) - { - ifa >> bba >> cba >> cosab >> cosac; - ModuleBase::GlobalFunc::READ_VALUE(ifa, cosbc); - sinab = sqrt(1.0-cosab*cosab); - } - latvec.e11 = 1.0; latvec.e12 = 0.0; latvec.e13 = 0.0; - latvec.e21 = bba * cosab; - latvec.e22 = bba * sinab; - latvec.e23 = 0.0; - latvec.e31 = cba * cosac; - latvec.e32 = cba * (cosbc - cosac*cosab) / sinab; - term = 1.0 + 2.0 * cosab*cosac*cosbc - cosab*cosab - cosac*cosac - cosbc*cosbc; - term = sqrt(term)/sinab; - latvec.e33 = cba * term; - } - else{ - std::cout << "latname is : " << latName << std::endl; - ModuleBase::WARNING_QUIT("UnitCell::read_atom_species","latname not supported!"); - } - } - - // lattice vectors in another form. - a1.x = latvec.e11; - a1.y = latvec.e12; - a1.z = latvec.e13; - - a2.x = latvec.e21; - a2.y = latvec.e22; - a2.z = latvec.e23; - - a3.x = latvec.e31; - a3.y = latvec.e32; - a3.z = latvec.e33; - return 0; -} #include "../module_base/mathzone.h" // Read atomic positions @@ -912,81 +550,17 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn //this->print_cell_xyz("STRU_READIN.xyz"); this->check_dtau(); - if ( this->check_tau() ) - { - - } - else + if (unitcell::check_tau(this->atoms, this->ntype, this->lat0)) { - return false; - } - this->print_tau(); + this->print_tau(); //xiaohui modify 2015-03-15, cancel outputfile "STRU_READIN.xyz" //this->print_cell_xyz("STRU_READIN_ADJUST.xyz"); + return true; + } + return false; - return true; }//end read_atom_positions -bool UnitCell::check_tau() const { - ModuleBase::TITLE("UnitCell","check_tau"); - ModuleBase::timer::tick("UnitCell","check_tau"); - - ModuleBase::Vector3 diff = 0.0; - double norm = 0.0; - double tolerence_bohr = 1.0e-3; - - //GlobalV::ofs_running << "\n Output nearest atom not considering periodic boundary condition" << std::endl; - //GlobalV::ofs_running << " " << std::setw(5) << "TYPE" << std::setw(6) << "INDEX" - //<< std::setw(20) << "NEAREST(Bohr)" - //<< std::setw(20) << "NEAREST(Angstrom)" << std::endl; - for(int T1=0; T1< this->ntype; T1++) - { - for(int I1=0; I1< this->atoms[T1].na; I1++) - { - double shortest_norm = 10000.0; // a large number - //int nearest_atom_type = 0; - //int nearest_atom_index = 0; - for(int T2=0; T2ntype; T2++) - { - for(int I2=0; I2atoms[T2].na; I2++) - { - if(T1==T2 && I1==I2) - { - shortest_norm = 0.0; - //nearest_atom_type = T1; - //nearest_atom_index = I2; - // self atom - } - else - { - diff = atoms[T1].tau[I1] - atoms[T2].tau[I2]; - norm = diff.norm() * lat0; - if( shortest_norm > norm ) - { - shortest_norm = norm; - //nearest_atom_type = T2; - //nearest_atom_index = I2; - } - if( norm < tolerence_bohr ) // unit is Bohr - { - GlobalV::ofs_warning << " two atoms are too close!" << std::endl; - GlobalV::ofs_warning << " type:" << this->atoms[T1].label << " atom " << I1 + 1 << std::endl; - GlobalV::ofs_warning << " type:" << this->atoms[T2].label << " atom " << I2 + 1 << std::endl; - GlobalV::ofs_warning << " distance = " << norm << " Bohr" << std::endl; - return false; - } - } - } - } - //GlobalV::ofs_running << " " << std::setw(5) << atoms[T1].label << std::setw(6) << I1+1 - //<< std::setw(20) << shortest_norm - //<< std::setw(20) << shortest_norm * ModuleBase::BOHR_TO_A << std::endl; - } - } - - ModuleBase::timer::tick("UnitCell","check_tau"); - return true; -} void UnitCell::print_stru_file(const std::string& fn, const int& nspin, diff --git a/source/module_cell/read_stru.cpp b/source/module_cell/read_stru.cpp new file mode 100644 index 0000000000..51af080611 --- /dev/null +++ b/source/module_cell/read_stru.cpp @@ -0,0 +1,55 @@ +#include "read_stru.h" +#include "module_base/timer.h" +#include "module_base/vector3.h" + +namespace unitcell +{ + bool check_tau(const Atom* atoms, + const int ntype, + const int lat0) + { + ModuleBase::TITLE("UnitCell","check_tau"); + ModuleBase::timer::tick("UnitCell","check_tau"); + + 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; + return false; + } + } + } + } + } + } + ModuleBase::timer::tick("UnitCell","check_tau"); + return true; + } +} \ No newline at end of file diff --git a/source/module_cell/read_stru.h b/source/module_cell/read_stru.h new file mode 100644 index 0000000000..3827666966 --- /dev/null +++ b/source/module_cell/read_stru.h @@ -0,0 +1,20 @@ +#ifndef READ_STRU_H +#define READ_STRU_H + +#include "atom_spec.h" +#include "module_cell/unitcell.h" +namespace unitcell +{ + bool check_tau(const Atom* atoms, + const int ntype, + const int lat0); + + bool read_atom_species(std::ifstream& ifa, + std::ofstream& ofs_running, + UnitCell& ucell); // read in the atom information for each type of atom + + bool read_lattice_constant(std::ifstream& ifa, + std::ofstream& ofs_running, + Lattice& lat); +} +#endif // READ_STRU_H \ No newline at end of file diff --git a/source/module_cell/test/CMakeLists.txt b/source/module_cell/test/CMakeLists.txt index 0d2a90db42..9020cf3c67 100644 --- a/source/module_cell/test/CMakeLists.txt +++ b/source/module_cell/test/CMakeLists.txt @@ -16,6 +16,8 @@ list(APPEND cell_simple_srcs ../unitcell.cpp ../update_cell.cpp ../bcast_cell.cpp + ../read_stru.cpp + ../read_atom_species.cpp ../read_atoms.cpp ../atom_spec.cpp ../atom_pseudo.cpp diff --git a/source/module_cell/test/prepare_unitcell.h b/source/module_cell/test/prepare_unitcell.h index 173537ffdc..d3f7ec6a3b 100644 --- a/source/module_cell/test/prepare_unitcell.h +++ b/source/module_cell/test/prepare_unitcell.h @@ -75,16 +75,12 @@ class UcellTestPrepare this->lmaxmax, this->init_vel, this->fixed_axes); - delete[] ucell->atom_label; - delete[] ucell->atom_mass; - delete[] ucell->pseudo_fn; - delete[] ucell->pseudo_type; delete[] ucell->magnet.start_magnetization; //mag set here - ucell->atom_label = new std::string[ucell->ntype]; - ucell->atom_mass = new double[ucell->ntype]; - ucell->pseudo_fn = new std::string[ucell->ntype]; - ucell->pseudo_type = new std::string[ucell->ntype]; + 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.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here diff --git a/source/module_cell/test/support/mock_unitcell.cpp b/source/module_cell/test/support/mock_unitcell.cpp index d944dc7868..353bb62687 100644 --- a/source/module_cell/test/support/mock_unitcell.cpp +++ b/source/module_cell/test/support/mock_unitcell.cpp @@ -13,20 +13,12 @@ UnitCell::UnitCell() { itia2iat.create(1, 1); } UnitCell::~UnitCell() { - delete[] atom_label; - delete[] atom_mass; - delete[] pseudo_fn; - delete[] pseudo_type; if (set_atom_flag) { delete[] atoms; } } void UnitCell::print_cell(std::ofstream& ofs) const {} void UnitCell::print_cell_xyz(const std::string& fn) const {} -int UnitCell::read_atom_species(std::ifstream& ifa, - std::ofstream& ofs_running) { - return 0; -} bool UnitCell::read_atom_positions(std::ifstream& ifpos, std::ofstream& ofs_running, std::ofstream& ofs_warning) { @@ -56,7 +48,6 @@ void UnitCell::check_dtau() {} void UnitCell::cal_nwfc(std::ofstream& log) {} void UnitCell::cal_meshx() {} void UnitCell::cal_natomwfc(std::ofstream& log) {} -bool UnitCell::check_tau() const { return true; } bool UnitCell::if_atoms_can_move() const { return true; } bool UnitCell::if_cell_can_change() const { return true; } void UnitCell::setup(const std::string& latname_in, diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 30b0c299c9..2a783630dc 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -5,8 +5,9 @@ #undef private #include "module_elecstate/cal_ux.h" #include "module_elecstate/read_pseudo.h" - +#include "module_cell/read_stru.h" #include "memory" +#include "module_cell/read_stru.h" #include "module_base/global_variable.h" #include "module_base/mathzone.h" #include "prepare_unitcell.h" @@ -185,7 +186,6 @@ TEST_F(UcellTest, Constructor) EXPECT_DOUBLE_EQ(ucell->tpiba, 0.0); EXPECT_DOUBLE_EQ(ucell->tpiba2, 0.0); EXPECT_DOUBLE_EQ(ucell->omega, 0.0); - EXPECT_EQ(ucell->atom_mass, nullptr); EXPECT_FALSE(ucell->set_atom_flag); } @@ -759,7 +759,7 @@ TEST_F(UcellTest, CheckTau) PARAM.input.relax_new = utp.relax_new; ucell = utp.SetUcellInfo(); GlobalV::ofs_warning.open("checktau_warning"); - ucell->check_tau(); + unitcell::check_tau(ucell->atoms ,ucell->ntype, ucell->lat0); GlobalV::ofs_warning.close(); std::ifstream ifs; ifs.open("checktau_warning"); @@ -1102,6 +1102,10 @@ class UcellTestReadStru : public ::testing::Test void SetUp() override { ucell->ntype = 2; + ucell->atom_mass.resize(ucell->ntype); + ucell->atom_label.resize(ucell->ntype); + ucell->pseudo_fn.resize(ucell->ntype); + ucell->pseudo_type.resize(ucell->ntype); ucell->orbital_fn.resize(ucell->ntype); } void TearDown() override @@ -1122,7 +1126,8 @@ TEST_F(UcellTestReadStru, ReadAtomSpecies) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1131,7 +1136,7 @@ TEST_F(UcellTestReadStru, ReadAtomSpecies) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadAtomSpeciesWarning1) +TEST_F(UcellTestReadStru, ReadAtomSpeciesWarning1) { std::string fn = "./support/STRU_MgO_Warning1"; std::ifstream ifa(fn.c_str()); @@ -1141,7 +1146,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning1) ucell->atoms = new Atom[ucell->ntype]; ucell->set_atom_flag = true; testing::internal::CaptureStdout(); - EXPECT_EXIT(ucell->read_atom_species(ifa, ofs_running), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(unitcell::read_atom_species(ifa, ofs_running,*ucell), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("unrecongnized pseudo type.")); ofs_running.close(); @@ -1149,7 +1154,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning1) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadAtomSpeciesWarning2) +TEST_F(UcellTestReadStru, ReadLatticeConstantWarning1) { std::string fn = "./support/STRU_MgO_Warning2"; std::ifstream ifa(fn.c_str()); @@ -1159,7 +1164,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning2) ucell->atoms = new Atom[ucell->ntype]; ucell->set_atom_flag = true; testing::internal::CaptureStdout(); - EXPECT_EXIT(ucell->read_atom_species(ifa, ofs_running), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("lat0<=0.0")); ofs_running.close(); @@ -1167,7 +1172,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning2) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadAtomSpeciesWarning3) +TEST_F(UcellTestReadStru, ReadLatticeConstantWarning2) { std::string fn = "./support/STRU_MgO_Warning3"; std::ifstream ifa(fn.c_str()); @@ -1177,7 +1182,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning3) ucell->atoms = new Atom[ucell->ntype]; ucell->set_atom_flag = true; testing::internal::CaptureStdout(); - EXPECT_EXIT(ucell->read_atom_species(ifa, ofs_running), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("do not use LATTICE_PARAMETERS without explicit specification of lattice type")); @@ -1186,7 +1191,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning3) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadAtomSpeciesWarning4) +TEST_F(UcellTestReadStru, ReadLatticeConstantWarning3) { std::string fn = "./support/STRU_MgO_Warning4"; std::ifstream ifa(fn.c_str()); @@ -1197,7 +1202,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning4) ucell->set_atom_flag = true; ucell->latName = "bcc"; testing::internal::CaptureStdout(); - EXPECT_EXIT(ucell->read_atom_species(ifa, ofs_running), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("do not use LATTICE_VECTORS along with explicit specification of lattice type")); @@ -1232,7 +1237,7 @@ TEST_F(UcellTestReadStru, ReadAtomSpeciesLatName) std::ofstream ofs_running; ofs_running.open("read_atom_species.tmp"); ucell->latName = latName_in[i]; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat)); if (ucell->latName == "sc") { EXPECT_DOUBLE_EQ(ucell->latvec.e11, 1.0); @@ -1256,7 +1261,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning5) ucell->set_atom_flag = true; ucell->latName = "arbitrary"; testing::internal::CaptureStdout(); - EXPECT_EXIT(ucell->read_atom_species(ifa, ofs_running), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("latname not supported")); ofs_running.close(); @@ -1280,7 +1285,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsS1) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1311,7 +1317,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsS2) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 2; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1343,7 +1350,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsS4Noncolin) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 4; PARAM.input.noncolin = true; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1375,7 +1383,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsS4Colin) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 4; PARAM.input.noncolin = false; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1406,7 +1415,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsC) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1437,7 +1447,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsCA) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1468,7 +1479,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsCACXY) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1499,7 +1511,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsCACXZ) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1530,7 +1543,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsCACYZ) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1561,7 +1575,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsCACXYZ) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1593,7 +1608,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsCAU) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; PARAM.input.fixed_atoms = true; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1624,7 +1640,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsAutosetMag) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 2; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1677,7 +1694,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsWarning1) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1720,7 +1738,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsWarning2) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1756,7 +1775,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsWarning3) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1777,7 +1797,7 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsWarning3) remove("read_atom_positions.warn"); } -TEST_F(UcellDeathTest, ReadAtomPositionsWarning4) +TEST_F(UcellTestReadStru, ReadAtomPositionsWarning4) { std::string fn = "./support/STRU_MgO_WarningC4"; std::ifstream ifa(fn.c_str()); @@ -1793,7 +1813,8 @@ TEST_F(UcellDeathTest, ReadAtomPositionsWarning4) PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -1827,7 +1848,8 @@ TEST_F(UcellTestReadStru, ReadAtomPositionsWarning5) PARAM.sys.deepks_setorb = true; PARAM.input.calculation = "md"; PARAM.input.esolver_type = "arbitrary"; - EXPECT_NO_THROW(ucell->read_atom_species(ifa, ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); diff --git a/source/module_cell/test/unitcell_test_setupcell.cpp b/source/module_cell/test/unitcell_test_setupcell.cpp index 7e832c2d99..39d2bd9064 100644 --- a/source/module_cell/test/unitcell_test_setupcell.cpp +++ b/source/module_cell/test/unitcell_test_setupcell.cpp @@ -67,6 +67,12 @@ class UcellTest : public ::testing::Test void SetUp() { ucell->lmaxmax = 2; + ucell->ntype = 2; + ucell->atom_mass.resize(ucell->ntype); + ucell->atom_label.resize(ucell->ntype); + ucell->pseudo_fn.resize(ucell->ntype); + ucell->pseudo_type.resize(ucell->ntype); + ucell->orbital_fn.resize(ucell->ntype); } }; @@ -78,7 +84,7 @@ TEST_F(UcellTest,SetupCellS1) std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); PARAM.input.nspin = 1; - ucell->ntype = 2; + ucell->setup_cell(fn,ofs_running); ofs_running.close(); remove("setup_cell.tmp"); @@ -90,7 +96,7 @@ TEST_F(UcellTest,SetupCellS2) std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); PARAM.input.nspin = 2; - ucell->ntype = 2; + ucell->setup_cell(fn,ofs_running); ofs_running.close(); remove("setup_cell.tmp"); @@ -102,7 +108,7 @@ TEST_F(UcellTest,SetupCellS4) std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); PARAM.input.nspin = 4; - ucell->ntype = 2; + ucell->setup_cell(fn,ofs_running); ofs_running.close(); remove("setup_cell.tmp"); @@ -113,7 +119,7 @@ TEST_F(UcellDeathTest,SetupCellWarning1) std::string fn = "./STRU_MgO"; std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); - ucell->ntype = 2; + testing::internal::CaptureStdout(); EXPECT_EXIT(ucell->setup_cell(fn,ofs_running),::testing::ExitedWithCode(1),""); output = testing::internal::GetCapturedStdout(); @@ -127,7 +133,7 @@ TEST_F(UcellDeathTest,SetupCellWarning2) std::string fn = "./support/STRU_MgO_WarningC2"; std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); - ucell->ntype = 2; + testing::internal::CaptureStdout(); EXPECT_EXIT(ucell->setup_cell(fn,ofs_running),::testing::ExitedWithCode(1),""); output = testing::internal::GetCapturedStdout(); @@ -142,7 +148,7 @@ TEST_F(UcellTest,SetupCellAfterVC) std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); PARAM.input.nspin = 1; - ucell->ntype = 2; + delete[] ucell->magnet.start_magnetization; ucell->magnet.start_magnetization = new double[ucell->ntype]; diff --git a/source/module_cell/test_pw/CMakeLists.txt b/source/module_cell/test_pw/CMakeLists.txt index 4a087c29c7..4f1446e514 100644 --- a/source/module_cell/test_pw/CMakeLists.txt +++ b/source/module_cell/test_pw/CMakeLists.txt @@ -13,6 +13,7 @@ AddTest( LIBS parameter ${math_libs} base device SOURCES unitcell_test_pw.cpp ../unitcell.cpp ../read_atoms.cpp ../atom_spec.cpp ../update_cell.cpp ../bcast_cell.cpp ../atom_pseudo.cpp ../pseudo.cpp ../read_pp.cpp ../read_pp_complete.cpp ../read_pp_upf201.cpp ../read_pp_upf100.cpp + ../read_stru.cpp ../read_atom_species.cpp ../read_pp_vwr.cpp ../read_pp_blps.cpp ../../module_io/output.cpp ../../module_elecstate/read_pseudo.cpp ../../module_elecstate/cal_nelec_nband.cpp ) diff --git a/source/module_cell/test_pw/unitcell_test_pw.cpp b/source/module_cell/test_pw/unitcell_test_pw.cpp index 4adf86b6ad..2e41265090 100644 --- a/source/module_cell/test_pw/unitcell_test_pw.cpp +++ b/source/module_cell/test_pw/unitcell_test_pw.cpp @@ -7,6 +7,7 @@ #include "module_base/mathzone.h" #include "module_base/global_variable.h" #include "module_cell/unitcell.h" +#include "module_cell/read_stru.h" #include #include @@ -43,6 +44,12 @@ class UcellTest : public ::testing::Test void SetUp() { ucell->lmaxmax = 2; + ucell->ntype = 2; + ucell->atom_mass.resize(ucell->ntype); + ucell->atom_label.resize(ucell->ntype); + ucell->pseudo_fn.resize(ucell->ntype); + ucell->pseudo_type.resize(ucell->ntype); + ucell->orbital_fn.resize(ucell->ntype); } }; @@ -56,11 +63,11 @@ if(GlobalV::MY_RANK==0) std::ifstream ifa(fn.c_str()); std::ofstream ofs_running; ofs_running.open("read_atom_species.tmp"); - ucell->ntype = 2; ucell->atoms = new Atom[ucell->ntype]; ucell->set_atom_flag = true; PARAM.input.test_pseudo_cell = 2; - EXPECT_NO_THROW(ucell->read_atom_species(ifa,ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -84,13 +91,13 @@ if(GlobalV::MY_RANK==0) std::ofstream ofs_warning; ofs_running.open("read_atom_species.tmp"); ofs_warning.open("read_atom_species.warn"); - ucell->ntype = 2; ucell->atoms = new Atom[ucell->ntype]; ucell->set_atom_flag = true; PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "pw"; //call read_atom_species - EXPECT_NO_THROW(ucell->read_atom_species(ifa,ofs_running)); + EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + 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); @@ -115,7 +122,6 @@ TEST_F(UcellTest,SetupCell) std::ofstream ofs_running; ofs_running.open("setup_cell.tmp"); PARAM.input.nspin = 1; - ucell->ntype = 2; ucell->setup_cell(fn,ofs_running); ofs_running.close(); remove("setup_cell.tmp"); diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index 4aa7f868ba..c889799463 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -9,7 +9,7 @@ #include "unitcell.h" #include "bcast_cell.h" #include "module_parameter/parameter.h" - +#include "read_stru.h" #ifdef __LCAO #include "../module_basis/module_ao/ORB_read.h" // to use 'ORB' -- mohan 2021-01-30 #endif @@ -31,10 +31,6 @@ UnitCell::UnitCell() { } UnitCell::~UnitCell() { - delete[] atom_label; - delete[] atom_mass; - delete[] pseudo_fn; - delete[] pseudo_type; if (set_atom_flag) { delete[] atoms; } @@ -232,17 +228,22 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { bool ok2 = true; // (3) read in atom information - orbital_fn.resize(ntype); + this->atom_mass.resize(ntype); + this->atom_label.resize(ntype); + this->pseudo_fn.resize(ntype); + this->pseudo_type.resize(ntype); + this->orbital_fn.resize(ntype); if (GlobalV::MY_RANK == 0) { // open "atom_unitcell" file. std::ifstream ifa(fn.c_str(), std::ios::in); - if (!ifa) { + if (!ifa) + { GlobalV::ofs_warning << fn; ok = false; } - if (ok) { - + if (ok) + { log << "\n\n\n\n"; log << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>>>>>>>>>" @@ -289,8 +290,11 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { //======================== // call read_atom_species //======================== - const int error = this->read_atom_species(ifa, log); - + const bool read_atom_species = unitcell::read_atom_species(ifa, log ,*this); + //======================== + // call read_lattice_constant + //======================== + const bool read_lattice_constant = unitcell::read_lattice_constant(ifa, log ,this->lat); //========================== // call read_atom_positions //========================== diff --git a/source/module_cell/unitcell.h b/source/module_cell/unitcell.h index 0132f29360..f62b20edb2 100644 --- a/source/module_cell/unitcell.h +++ b/source/module_cell/unitcell.h @@ -204,11 +204,11 @@ class UnitCell { void update_stress(ModuleBase::matrix& scs); // updates stress void update_force(ModuleBase::matrix& fcs); // updates force in Atom - double* atom_mass = nullptr; - std::string* atom_label = new std::string[1]; - std::string* pseudo_fn = new std::string[1]; - std::string* pseudo_type = new std::string[1]; // pseudopotential types for each elements, - // sunliang added 2022-09-15. + std::vector atom_mass; + std::vector atom_label; + std::vector pseudo_fn; + std::vector pseudo_type; + std::vector orbital_fn; // filenames of orbitals, liuyu add 2022-10-19 std::string descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06 @@ -230,10 +230,6 @@ class UnitCell { std::string& orb_file, std::ofstream& ofs_running, Atom* atom); - int read_atom_species( - std::ifstream& ifa, - std::ofstream& - ofs_running); // read in the atom information for each type of atom bool read_atom_positions( std::ifstream& ifpos, std::ofstream& ofs_running, @@ -275,7 +271,6 @@ class UnitCell { void cal_nwfc(std::ofstream& log); void cal_meshx(); void cal_natomwfc(std::ofstream& log); - bool check_tau() const; // mohan add 2011-03-03 bool if_atoms_can_move() const; bool if_cell_can_change() const; void setup(const std::string& latname_in, diff --git a/source/module_cell/update_cell.cpp b/source/module_cell/update_cell.cpp index 69cad55823..cf4380a79a 100644 --- a/source/module_cell/update_cell.cpp +++ b/source/module_cell/update_cell.cpp @@ -274,9 +274,11 @@ void remake_cell(Lattice& lat) - cos13 * cos13 - cos23 * cos23; term = sqrt(term) / sin12; latvec.e33 = celldm3 * term; - } else { + } + else + { std::cout << "latname is : " << latName << std::endl; - ModuleBase::WARNING_QUIT("UnitCell::read_atom_species", + ModuleBase::WARNING_QUIT("UnitCell::remake_cell", "latname not supported!"); } } diff --git a/source/module_elecstate/module_dm/test/prepare_unitcell.h b/source/module_elecstate/module_dm/test/prepare_unitcell.h index e4bee46903..8dfd0c3ada 100644 --- a/source/module_elecstate/module_dm/test/prepare_unitcell.h +++ b/source/module_elecstate/module_dm/test/prepare_unitcell.h @@ -73,16 +73,13 @@ class UcellTestPrepare this->ntype = this->elements.size(); static UnitCell ucell; ucell.setup(this->latname, this->ntype, this->lmaxmax, this->init_vel, this->fixed_axes); - delete[] ucell.atom_label; - delete[] ucell.atom_mass; - delete[] ucell.pseudo_fn; - delete[] ucell.pseudo_type; delete[] ucell.magnet.start_magnetization; // mag set here - ucell.atom_label = new std::string[ucell.ntype]; - ucell.atom_mass = new double[ucell.ntype]; - ucell.pseudo_fn = new std::string[ucell.ntype]; - ucell.pseudo_type = new std::string[ucell.ntype]; + + 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.start_magnetization = new double[ucell.ntype]; // mag set here ucell.magnet.ux_[0] = 0.0; // ux_ set here diff --git a/source/module_elecstate/test/prepare_unitcell.h b/source/module_elecstate/test/prepare_unitcell.h index 6bf9357f55..8d485cc16b 100644 --- a/source/module_elecstate/test/prepare_unitcell.h +++ b/source/module_elecstate/test/prepare_unitcell.h @@ -60,15 +60,12 @@ class UcellTestPrepare this->lmaxmax, this->init_vel, this->fixed_axes); - delete[] ucell->atom_label; - delete[] ucell->atom_mass; - delete[] ucell->pseudo_fn; - delete[] ucell->pseudo_type; delete[] ucell->magnet.start_magnetization; //mag set here - ucell->atom_label = new std::string[ucell->ntype]; - ucell->atom_mass = new double[ucell->ntype]; - ucell->pseudo_fn = new std::string[ucell->ntype]; - ucell->pseudo_type = new std::string[ucell->ntype]; + + 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.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here diff --git a/source/module_esolver/test/esolver_dp_test.cpp b/source/module_esolver/test/esolver_dp_test.cpp index 6925eae6f8..ab9ef17331 100644 --- a/source/module_esolver/test/esolver_dp_test.cpp +++ b/source/module_esolver/test/esolver_dp_test.cpp @@ -55,7 +55,7 @@ class ESolverDPTest : public ::testing::Test ucell.atoms[0].taud.resize(1, ModuleBase::Vector3(0.0, 0.0, 0.0)); ucell.atoms[1].taud.resize(1, ModuleBase::Vector3(0.0, 0.0, 0.0)); - ucell.atom_label = new std::string[2]; + ucell.atom_label.resize(ucell.ntype); ucell.atom_label[0] = "Cu"; ucell.atom_label[1] = "Al"; esolver->before_all_runners(ucell, inp); @@ -66,7 +66,6 @@ class ESolverDPTest : public ::testing::Test // Clean up after each test delete esolver; delete[] ucell.atoms; - delete[] ucell.atom_label; } ModuleESolver::ESolver_DP* esolver; diff --git a/source/module_esolver/test/for_test.h b/source/module_esolver/test/for_test.h index 36bff1de56..0437d7f2dc 100644 --- a/source/module_esolver/test/for_test.h +++ b/source/module_esolver/test/for_test.h @@ -22,7 +22,7 @@ UnitCell::UnitCell() ntype = 2; nat = 2; - atom_label = new std::string[ntype]; + atom_label.resize(ntype); atom_label[0] = "Al"; atom_label[1] = "Cu"; diff --git a/source/module_hamilt_lcao/module_deepks/test/CMakeLists.txt b/source/module_hamilt_lcao/module_deepks/test/CMakeLists.txt index fb8c89a6ef..aaa7fa281f 100644 --- a/source/module_hamilt_lcao/module_deepks/test/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_deepks/test/CMakeLists.txt @@ -8,6 +8,8 @@ add_executable( ../../../module_cell/atom_spec.cpp ../../../module_cell/atom_pseudo.cpp ../../../module_cell/read_atoms.cpp + ../../../module_cell/read_stru.cpp + ../../../module_cell/read_atom_species.cpp ../../../module_cell/setup_nonlocal.cpp ../../../module_cell/pseudo.cpp ../../../module_cell/read_pp.cpp @@ -35,7 +37,7 @@ add_executable( target_link_libraries( test_deepks - base device parameter deepks psi planewave neighbor container + base device parameter deepks psi planewave neighbor container orb gint numerical_atomic_orbitals ${math_libs} ) diff --git a/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h b/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h index bbfbcc924f..9f94cbfd86 100644 --- a/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h +++ b/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h @@ -72,16 +72,13 @@ class UcellTestPrepare this->ntype = this->elements.size(); static UnitCell ucell; ucell.setup(this->latname, this->ntype, this->lmaxmax, this->init_vel, this->fixed_axes); - delete[] ucell.atom_label; - delete[] ucell.atom_mass; - delete[] ucell.pseudo_fn; - delete[] ucell.pseudo_type; delete[] ucell.orbital_fn; delete[] ucell.magnet.start_magnetization; // mag set here - ucell.atom_label = new std::string[ucell.ntype]; - ucell.atom_mass = new double[ucell.ntype]; - ucell.pseudo_fn = new std::string[ucell.ntype]; - ucell.pseudo_type = new std::string[ucell.ntype]; + 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.start_magnetization = new double[ucell.ntype]; // mag set here ucell.magnet.ux_[0] = 0.0; // ux_ set here diff --git a/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h b/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h index 913f0d910f..6dee43ef9c 100644 --- a/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h +++ b/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h @@ -72,15 +72,12 @@ class UcellTestPrepare this->ntype = this->elements.size(); static UnitCell ucell; ucell.setup(this->latname, this->ntype, this->lmaxmax, this->init_vel, this->fixed_axes); - delete[] ucell.atom_label; - delete[] ucell.atom_mass; - delete[] ucell.pseudo_fn; - delete[] ucell.pseudo_type; delete[] ucell.magnet.start_magnetization; // mag set here - ucell.atom_label = new std::string[ucell.ntype]; - ucell.atom_mass = new double[ucell.ntype]; - ucell.pseudo_fn = new std::string[ucell.ntype]; - ucell.pseudo_type = new std::string[ucell.ntype]; + 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.start_magnetization = new double[ucell.ntype]; // mag set here ucell.magnet.ux_[0] = 0.0; // ux_ set here diff --git a/source/module_io/json_output/init_info.cpp b/source/module_io/json_output/init_info.cpp index b967b157d6..0b35642248 100644 --- a/source/module_io/json_output/init_info.cpp +++ b/source/module_io/json_output/init_info.cpp @@ -63,7 +63,7 @@ void gen_stru(UnitCell* ucell) int ntype = ucell->ntype; // array of pseudopotential file - std::string* pseudo_fn = ucell->pseudo_fn; + std::string* pseudo_fn = ucell->pseudo_fn.data(); // array of orbital file std::string* orbital_fn = ucell->orbital_fn.data(); @@ -99,7 +99,7 @@ void gen_stru(UnitCell* ucell) // atom coordinate, mag and label double lat0 = ucell->lat0; - std::string* label = ucell->atom_label; + std::string* label = ucell->atom_label.data(); for (int i = 0; i < ntype; i++) { ModuleBase::Vector3* tau = ucell->atoms[i].tau.data(); diff --git a/source/module_io/json_output/test/para_json_test.cpp b/source/module_io/json_output/test/para_json_test.cpp index 92675f8698..0d4e4a0332 100644 --- a/source/module_io/json_output/test/para_json_test.cpp +++ b/source/module_io/json_output/test/para_json_test.cpp @@ -337,10 +337,10 @@ TEST(AbacusJsonTest, Init_stru_test) double lat0 = 10.0; ucell.ntype = 1; - ucell.pseudo_fn = new std::string[1]; + ucell.pseudo_fn.resize(1); ucell.orbital_fn.resize(1); ucell.atoms = atomlist; - ucell.atom_label = new std::string[1]; + ucell.atom_label.resize(1); ucell.lat0 = lat0; ModuleBase::Vector3 tau[2]; diff --git a/source/module_io/test/prepare_unitcell.h b/source/module_io/test/prepare_unitcell.h index d03ff49eac..c0b394d1fc 100644 --- a/source/module_io/test/prepare_unitcell.h +++ b/source/module_io/test/prepare_unitcell.h @@ -76,15 +76,12 @@ class UcellTestPrepare this->lmaxmax, this->init_vel, this->fixed_axes); - delete[] ucell->atom_label; - delete[] ucell->atom_mass; - delete[] ucell->pseudo_fn; - delete[] ucell->pseudo_type; delete[] ucell->magnet.start_magnetization; //mag set here - ucell->atom_label = new std::string[ucell->ntype]; - ucell->atom_mass = new double[ucell->ntype]; - ucell->pseudo_fn = new std::string[ucell->ntype]; - ucell->pseudo_type = new std::string[ucell->ntype]; + 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.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here diff --git a/source/module_io/test/to_qo_test.cpp b/source/module_io/test/to_qo_test.cpp index e05d7fc76c..c1d00714b4 100644 --- a/source/module_io/test/to_qo_test.cpp +++ b/source/module_io/test/to_qo_test.cpp @@ -52,7 +52,7 @@ void define_fcc_cell(UnitCell& ucell) ucell.orbital_fn.resize(2); ucell.orbital_fn[0] = "../../../../tests/PP_ORB/Si_gga_8au_100Ry_2s2p1d.orb"; ucell.orbital_fn[1] = "../../../../tests/PP_ORB/C_gga_8au_100Ry_2s2p1d.orb"; - ucell.pseudo_fn = new std::string[2]; + ucell.pseudo_fn.resize(2); ucell.pseudo_fn[0] = "../../../../tests/PP_ORB/Si_dojo_soc.upf"; ucell.pseudo_fn[1] = "../../../../tests/PP_ORB/C.LDA.UPF"; @@ -88,7 +88,7 @@ void define_sc_cell(UnitCell& ucell) ucell.GGT = ucell.G * ucell.GT; ucell.orbital_fn.resize(1); ucell.orbital_fn[0] = "../../../../tests/PP_ORB/Si_gga_8au_100Ry_2s2p1d.orb"; - ucell.pseudo_fn = new std::string[1]; + ucell.pseudo_fn.resize(1); ucell.pseudo_fn[0] = "../../../../tests/PP_ORB/Si_dojo_soc.upf"; PARAM.sys.global_out_dir = "./"; @@ -309,7 +309,7 @@ TEST_F(toQOTest, RadialCollectionIndexing) tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), {}, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -363,7 +363,7 @@ TEST_F(toQOTest, BuildHydrogenMinimal) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), {}, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -416,7 +416,7 @@ TEST_F(toQOTest, ScanSupercellForAtom) } tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), {}, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -465,7 +465,7 @@ TEST_F(toQOTest, ScanSupercellFCC) 0); tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), {}, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -491,7 +491,7 @@ TEST_F(toQOTest, ScanSupercellSC1) PARAM.input.qo_thr = 1e-6; tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), {}, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -521,7 +521,7 @@ TEST_F(toQOTest, AllocateOvlpMinimal) } tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), {}, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -874,7 +874,7 @@ TEST_F(toQOTest, BuildHydrogenFull) PARAM.input.qo_thr = 1e-10; tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), {}, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -1061,7 +1061,7 @@ TEST_F(toQOTest, BuildPswfcPartial1) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), PARAM.input.qo_screening_coeff, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -1081,7 +1081,7 @@ TEST_F(toQOTest, BuildPswfcPartial2) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), PARAM.input.qo_screening_coeff, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -1101,7 +1101,7 @@ TEST_F(toQOTest, BuildPswfcPartial3) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), PARAM.input.qo_screening_coeff, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -1122,7 +1122,7 @@ TEST_F(toQOTest, BuildPswfcAll) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), PARAM.input.qo_screening_coeff, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -1149,7 +1149,7 @@ TEST_F(toQOTest, ScanSupercellSC2) PARAM.input.qo_thr = 1e-6; tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), PARAM.input.qo_screening_coeff, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -1175,7 +1175,7 @@ TEST_F(toQOTest, ScanSupercellSC3) PARAM.input.qo_thr = 1e-6; tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), PARAM.input.qo_screening_coeff, PARAM.input.qo_thr, GlobalV::ofs_running, @@ -1202,7 +1202,7 @@ TEST_F(toQOTest, ScanSupercellSC4) PARAM.input.qo_thr = 1e-6; tqo.build_ao(ucell.ntype, "./", - ucell.pseudo_fn, + ucell.pseudo_fn.data(), PARAM.input.qo_screening_coeff, PARAM.input.qo_thr, GlobalV::ofs_running, diff --git a/source/module_io/test_serial/prepare_unitcell.h b/source/module_io/test_serial/prepare_unitcell.h index 6dd2fa7e4c..2fb2e48ea3 100644 --- a/source/module_io/test_serial/prepare_unitcell.h +++ b/source/module_io/test_serial/prepare_unitcell.h @@ -76,15 +76,12 @@ class UcellTestPrepare this->lmaxmax, this->init_vel, this->fixed_axes); - delete[] ucell->atom_label; - delete[] ucell->atom_mass; - delete[] ucell->pseudo_fn; - delete[] ucell->pseudo_type; delete[] ucell->magnet.start_magnetization; //mag set here - ucell->atom_label = new std::string[ucell->ntype]; - ucell->atom_mass = new double[ucell->ntype]; - ucell->pseudo_fn = new std::string[ucell->ntype]; - ucell->pseudo_type = new std::string[ucell->ntype]; + 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.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here diff --git a/source/module_io/to_qo_kernel.cpp b/source/module_io/to_qo_kernel.cpp index 77e1d029f1..0b4008bc09 100644 --- a/source/module_io/to_qo_kernel.cpp +++ b/source/module_io/to_qo_kernel.cpp @@ -83,7 +83,7 @@ void toQO::initialize(const std::string& out_dir, // build the numerical atomic orbital basis build_nao(ntype_, orbital_dir_, p_ucell_->orbital_fn.data(), iproc_); // build another atomic orbital - build_ao(ntype_, pseudo_dir_, p_ucell_->pseudo_fn, screening_coeffs_, qo_thr_, ofs_running, iproc_); + build_ao(ntype_, pseudo_dir_, p_ucell_->pseudo_fn.data(), screening_coeffs_, qo_thr_, ofs_running, iproc_); // neighbor list search, based on built RadialCollection(s) scan_supercell(iproc_, nprocs_); diff --git a/source/module_md/test/CMakeLists.txt b/source/module_md/test/CMakeLists.txt index ec8bb0bf8c..39f30baa94 100644 --- a/source/module_md/test/CMakeLists.txt +++ b/source/module_md/test/CMakeLists.txt @@ -8,6 +8,8 @@ list(APPEND depend_files ../../module_cell/update_cell.cpp ../../module_cell/bcast_cell.cpp ../../module_cell/atom_spec.cpp + ../../module_cell/read_stru.cpp + ../../module_cell/read_atom_species.cpp ../../module_cell/atom_pseudo.cpp ../../module_cell/read_atoms.cpp ../../module_cell/pseudo.cpp diff --git a/source/module_md/test/setcell.h b/source/module_md/test/setcell.h index 1f97b4e0f4..fedb2478e0 100644 --- a/source/module_md/test/setcell.h +++ b/source/module_md/test/setcell.h @@ -43,11 +43,9 @@ class Setcell ucell.atoms = new Atom[ucell.ntype]; ucell.set_atom_flag = true; - - delete[] ucell.atom_label; - delete[] ucell.atom_mass; - ucell.atom_mass = new double[ucell.ntype]; - ucell.atom_label = new std::string[ucell.ntype]; + + ucell.atom_mass.resize(ucell.ntype); + ucell.atom_label.resize(ucell.ntype); ucell.atom_mass[0] = 39.948; ucell.atom_label[0] = "Ar"; diff --git a/source/module_psi/test/psi_initializer_unit_test.cpp b/source/module_psi/test/psi_initializer_unit_test.cpp index 0cf1f6060f..d4e30234c9 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -142,8 +142,8 @@ class PsiIntializerUnitTest : public ::testing::Test { this->p_ucell->tpiba = 2.0 * M_PI / this->p_ucell->lat0; this->p_ucell->tpiba2 = this->p_ucell->tpiba * this->p_ucell->tpiba; // atom - delete[] this->p_ucell->atom_label; - this->p_ucell->atom_label = new std::string[1]; + this->p_ucell->atom_label.shrink_to_fit(); + this->p_ucell->atom_label.resize(1); this->p_ucell->atom_label[0] = "Si"; // atom properties this->p_ucell->nat = 1; @@ -160,9 +160,8 @@ class PsiIntializerUnitTest : public ::testing::Test { this->p_ucell->atoms[0].taud.resize(1, {0.25, 0.25, 0.25}); this->p_ucell->atoms[0].mbl.resize(1, {0, 0, 0}); // atom pseudopotential - if(this->p_ucell->pseudo_fn != nullptr) { delete[] this->p_ucell->pseudo_fn; -} - this->p_ucell->pseudo_fn = new std::string[1]; + this->p_ucell->pseudo_fn.shrink_to_fit(); + this->p_ucell->pseudo_fn.resize(1); this->p_ucell->pseudo_fn[0] = "Si_NCSR_ONCVPSP_v0.5_dojo.upf"; this->p_ucell->natomwfc = 4; this->p_ucell->atoms[0].ncpp.nchi = 2; diff --git a/source/module_relax/relax_old/test/for_test.h b/source/module_relax/relax_old/test/for_test.h index be61eb9ea2..6968132d96 100644 --- a/source/module_relax/relax_old/test/for_test.h +++ b/source/module_relax/relax_old/test/for_test.h @@ -43,10 +43,10 @@ UnitCell::UnitCell() tpiba2 = 0.0; omega = 0.0; - atom_label = new std::string[1]; - atom_mass = nullptr; - pseudo_fn = new std::string[1]; - pseudo_type = new std::string[1]; + atom_mass.shrink_to_fit(); + atom_label.resize(1); + pseudo_fn.resize(1); + pseudo_type.resize(1); orbital_fn.resize(1); atoms = new Atom[ntype];