From ec41a02eb856404141d8d78fbc24402113f2af0e Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Sat, 4 Jan 2025 20:56:01 +0800 Subject: [PATCH 01/16] modify cheack_tau --- source/module_cell/CMakeLists.txt | 1 + source/module_cell/read_atoms.cpp | 74 ++----------------- source/module_cell/read_stru.cpp | 69 +++++++++++++++++ source/module_cell/read_stru.h | 10 +++ .../test/support/mock_unitcell.cpp | 1 - source/module_cell/test/unitcell_test.cpp | 2 +- source/module_cell/unitcell.h | 1 - 7 files changed, 86 insertions(+), 72 deletions(-) create mode 100644 source/module_cell/read_stru.cpp create mode 100644 source/module_cell/read_stru.h diff --git a/source/module_cell/CMakeLists.txt b/source/module_cell/CMakeLists.txt index 230a6ae2dd..2307eb2dc1 100644 --- a/source/module_cell/CMakeLists.txt +++ b/source/module_cell/CMakeLists.txt @@ -25,6 +25,7 @@ add_library( check_atomic_stru.cpp update_cell.cpp bcast_cell.cpp + read_stru.cpp ) if(ENABLE_COVERAGE) diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 736a0aec06..5a4e504db0 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -915,81 +915,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() ) + if (unitcell::check_tau(this->atoms, this->ntype)) { - - } - else - { - 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..6d18101b0c --- /dev/null +++ b/source/module_cell/read_stru.cpp @@ -0,0 +1,69 @@ +#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) + { + 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< ntype; T1++) + { + for(int I1=0; I1< 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; T2 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:" << 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; + } + } + } + } + //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; + } +} \ 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..ddc550bf5c --- /dev/null +++ b/source/module_cell/read_stru.h @@ -0,0 +1,10 @@ +#ifndef READ_STRU_H +#define READ_STRU_H + +#include "atom_sepc.h" +namespace unitcell +{ + bool check_tau(const Atom* atoms, + const int ntype); +} +#endif // READ_STRU_H \ No newline at end of file diff --git a/source/module_cell/test/support/mock_unitcell.cpp b/source/module_cell/test/support/mock_unitcell.cpp index c335a181a9..a60a22f8f5 100644 --- a/source/module_cell/test/support/mock_unitcell.cpp +++ b/source/module_cell/test/support/mock_unitcell.cpp @@ -64,7 +64,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 90925df62d..4c315604df 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -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(); + check_tau(ucell->atoms ,ucell->ntype); GlobalV::ofs_warning.close(); std::ifstream ifs; ifs.open("checktau_warning"); diff --git a/source/module_cell/unitcell.h b/source/module_cell/unitcell.h index e6f2fa96f0..6fbbaa9988 100644 --- a/source/module_cell/unitcell.h +++ b/source/module_cell/unitcell.h @@ -286,7 +286,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, From a3c7da65605c33f46130e764b00f045c1d318870 Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Mon, 6 Jan 2025 11:20:11 +0800 Subject: [PATCH 02/16] change the cheak_tau --- source/module_cell/read_atoms.cpp | 3 ++- source/module_cell/read_stru.cpp | 3 ++- source/module_cell/read_stru.h | 5 +++-- source/module_cell/test/CMakeLists.txt | 1 + source/module_cell/test/unitcell_test.cpp | 3 ++- source/module_cell/test_pw/CMakeLists.txt | 1 + source/module_md/test/CMakeLists.txt | 1 + 7 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 5a4e504db0..3acbb6e2d2 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 @@ -915,7 +916,7 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn //this->print_cell_xyz("STRU_READIN.xyz"); this->check_dtau(); - if (unitcell::check_tau(this->atoms, this->ntype)) + if (unitcell::check_tau(this->atoms, this->ntype, this->lat0)) { this->print_tau(); //xiaohui modify 2015-03-15, cancel outputfile "STRU_READIN.xyz" diff --git a/source/module_cell/read_stru.cpp b/source/module_cell/read_stru.cpp index 6d18101b0c..bc1eaee7f5 100644 --- a/source/module_cell/read_stru.cpp +++ b/source/module_cell/read_stru.cpp @@ -5,7 +5,8 @@ namespace unitcell { bool check_tau(const Atom* atoms, - const int ntype) + const int ntype, + const int lat0) { ModuleBase::TITLE("UnitCell","check_tau"); ModuleBase::timer::tick("UnitCell","check_tau"); diff --git a/source/module_cell/read_stru.h b/source/module_cell/read_stru.h index ddc550bf5c..90c8d90f55 100644 --- a/source/module_cell/read_stru.h +++ b/source/module_cell/read_stru.h @@ -1,10 +1,11 @@ #ifndef READ_STRU_H #define READ_STRU_H -#include "atom_sepc.h" +#include "atom_spec.h" namespace unitcell { bool check_tau(const Atom* atoms, - const int ntype); + const int ntype, + const int lat0); } #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..ea46838e05 100644 --- a/source/module_cell/test/CMakeLists.txt +++ b/source/module_cell/test/CMakeLists.txt @@ -16,6 +16,7 @@ list(APPEND cell_simple_srcs ../unitcell.cpp ../update_cell.cpp ../bcast_cell.cpp + ../read_stru.cpp ../read_atoms.cpp ../atom_spec.cpp ../atom_pseudo.cpp diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 4c315604df..029ea13fde 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -7,6 +7,7 @@ #include "module_elecstate/read_pseudo.h" #include "memory" +#include "module_cell/read_stru.h" #include "module_base/global_variable.h" #include "module_base/mathzone.h" #include "prepare_unitcell.h" @@ -759,7 +760,7 @@ TEST_F(UcellTest, CheckTau) PARAM.input.relax_new = utp.relax_new; ucell = utp.SetUcellInfo(); GlobalV::ofs_warning.open("checktau_warning"); - check_tau(ucell->atoms ,ucell->ntype); + unitcell::check_tau(ucell->atoms ,ucell->ntype, ucell->lat0); GlobalV::ofs_warning.close(); std::ifstream ifs; ifs.open("checktau_warning"); diff --git a/source/module_cell/test_pw/CMakeLists.txt b/source/module_cell/test_pw/CMakeLists.txt index 4a087c29c7..0cbea0cfda 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_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_md/test/CMakeLists.txt b/source/module_md/test/CMakeLists.txt index ec8bb0bf8c..dff555ea36 100644 --- a/source/module_md/test/CMakeLists.txt +++ b/source/module_md/test/CMakeLists.txt @@ -8,6 +8,7 @@ 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/atom_pseudo.cpp ../../module_cell/read_atoms.cpp ../../module_cell/pseudo.cpp From 22c69c7f2f35e1cd6b2ec3c04eaa186ecd9d156a Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Mon, 6 Jan 2025 15:11:25 +0800 Subject: [PATCH 03/16] modify the read_atom_species --- source/module_cell/CMakeLists.txt | 1 + source/module_cell/read_atom_species.cpp | 370 ++++++++++++++++++ source/module_cell/read_atoms.cpp | 366 ----------------- source/module_cell/read_stru.cpp | 15 - source/module_cell/read_stru.h | 6 + source/module_cell/test/CMakeLists.txt | 1 + .../test/support/mock_unitcell.cpp | 4 - source/module_cell/test/unitcell_test.cpp | 50 +-- source/module_cell/test_pw/CMakeLists.txt | 2 +- .../module_cell/test_pw/unitcell_test_pw.cpp | 5 +- source/module_cell/unitcell.cpp | 8 +- source/module_cell/unitcell.h | 4 - source/module_cell/update_cell.cpp | 6 +- source/module_md/test/CMakeLists.txt | 1 + 14 files changed, 416 insertions(+), 423 deletions(-) create mode 100644 source/module_cell/read_atom_species.cpp diff --git a/source/module_cell/CMakeLists.txt b/source/module_cell/CMakeLists.txt index 2307eb2dc1..1b94549f0c 100644 --- a/source/module_cell/CMakeLists.txt +++ b/source/module_cell/CMakeLists.txt @@ -26,6 +26,7 @@ add_library( update_cell.cpp bcast_cell.cpp read_stru.cpp + read_atom_species.cpp ) if(ENABLE_COVERAGE) diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp new file mode 100644 index 0000000000..427f69b51c --- /dev/null +++ b/source/module_cell/read_atom_species.cpp @@ -0,0 +1,370 @@ +#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 +{ +int read_atom_species(std::ifstream& ifa, + std::ofstream& ofs_running, + UnitCell& ucell) +{ + ModuleBase::TITLE("UnitCell","read_atom_species"); + const int ntype = ucell.ntype; + + delete[] ucell.atom_label; + delete[] ucell.atom_mass; + delete[] ucell.pseudo_fn; + delete[] ucell.pseudo_type; + delete[] ucell.orbital_fn; + ucell.atom_mass = new double[ntype]; //atom masses + ucell.atom_label = new std::string[ntype]; //atom labels + ucell.pseudo_fn = new std::string[ntype]; //file name of pseudopotential + ucell.pseudo_type = new std::string[ntype]; // type of pseudopotential + ucell.orbital_fn = new std::string[ntype]; // filename of orbitals + 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 >> 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.psi_initializer)&&(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 + //========================== + // read in lattice constant + //========================== + double& lat0 = ucell.lat0; + double& lat0_angstrom =ucell.lat0_angstrom; + std::string& latName = ucell.latName; + ModuleBase::Matrix3& latvec = ucell.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); + ucell.tpiba = ModuleBase::TWO_PI / lat0; + ucell.tpiba2 = ucell.tpiba * ucell.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. + ucell.a1.x = latvec.e11; + ucell.a1.y = latvec.e12; + ucell.a1.z = latvec.e13; + + ucell.a2.x = latvec.e21; + ucell.a2.y = latvec.e22; + ucell.a2.z = latvec.e23; + + ucell.a3.x = latvec.e31; + ucell.a3.y = latvec.e32; + ucell.a3.z = latvec.e33; + return 0; +} + +} \ No newline at end of file diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 3acbb6e2d2..8ebcfa5e1d 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -11,372 +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; - delete[] orbital_fn; - 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 - this->orbital_fn = new std::string[ntype]; // filename of orbitals - - 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.psi_initializer) - &&(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 diff --git a/source/module_cell/read_stru.cpp b/source/module_cell/read_stru.cpp index bc1eaee7f5..51af080611 100644 --- a/source/module_cell/read_stru.cpp +++ b/source/module_cell/read_stru.cpp @@ -15,17 +15,11 @@ namespace unitcell 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< ntype; T1++) { for(int I1=0; I1< 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; T2 norm ) { shortest_norm = norm; - //nearest_atom_type = T2; - //nearest_atom_index = I2; } if( norm < tolerence_bohr ) // unit is Bohr { @@ -58,12 +47,8 @@ namespace unitcell } } } - //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; } diff --git a/source/module_cell/read_stru.h b/source/module_cell/read_stru.h index 90c8d90f55..7f32115cd3 100644 --- a/source/module_cell/read_stru.h +++ b/source/module_cell/read_stru.h @@ -2,10 +2,16 @@ #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); + + int read_atom_species(std::ifstream& ifa, + std::ofstream& ofs_running, + UnitCell& ucell); // read in the atom information for each type of atom + } #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 ea46838e05..9020cf3c67 100644 --- a/source/module_cell/test/CMakeLists.txt +++ b/source/module_cell/test/CMakeLists.txt @@ -17,6 +17,7 @@ list(APPEND cell_simple_srcs ../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/support/mock_unitcell.cpp b/source/module_cell/test/support/mock_unitcell.cpp index a60a22f8f5..d48aade920 100644 --- a/source/module_cell/test/support/mock_unitcell.cpp +++ b/source/module_cell/test/support/mock_unitcell.cpp @@ -24,10 +24,6 @@ UnitCell::~UnitCell() { } 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) { diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 029ea13fde..5e36ebfc4e 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -5,7 +5,7 @@ #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" @@ -1108,7 +1108,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1127,7 +1127,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(); @@ -1145,7 +1145,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_atom_species(ifa, ofs_running,*ucell), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("lat0<=0.0")); ofs_running.close(); @@ -1163,7 +1163,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_atom_species(ifa, ofs_running,*ucell), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("do not use LATTICE_PARAMETERS without explicit specification of lattice type")); @@ -1183,7 +1183,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_atom_species(ifa, ofs_running,*ucell), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("do not use LATTICE_VECTORS along with explicit specification of lattice type")); @@ -1218,7 +1218,7 @@ TEST_F(UcellTest, 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_atom_species(ifa, ofs_running,*ucell)); if (ucell->latName == "sc") { EXPECT_DOUBLE_EQ(ucell->latvec.e11, 1.0); @@ -1242,7 +1242,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_atom_species(ifa, ofs_running,*ucell), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("latname not supported")); ofs_running.close(); @@ -1266,7 +1266,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1297,7 +1297,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1329,7 +1329,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1361,7 +1361,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1392,7 +1392,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1423,7 +1423,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1454,7 +1454,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1485,7 +1485,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1516,7 +1516,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1547,7 +1547,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1579,7 +1579,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1610,7 +1610,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1663,7 +1663,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1706,7 +1706,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1742,7 +1742,7 @@ TEST_F(UcellTest, 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1778,7 +1778,7 @@ 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_DOUBLE_EQ(ucell->latvec.e11, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22, 4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33, 4.27957); @@ -1812,7 +1812,7 @@ TEST_F(UcellTest, 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_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_pw/CMakeLists.txt b/source/module_cell/test_pw/CMakeLists.txt index 0cbea0cfda..4f1446e514 100644 --- a/source/module_cell/test_pw/CMakeLists.txt +++ b/source/module_cell/test_pw/CMakeLists.txt @@ -13,7 +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_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..82b266f4b0 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 @@ -60,7 +61,7 @@ if(GlobalV::MY_RANK==0) 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_DOUBLE_EQ(ucell->latvec.e11,4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e22,4.27957); EXPECT_DOUBLE_EQ(ucell->latvec.e33,4.27957); @@ -90,7 +91,7 @@ if(GlobalV::MY_RANK==0) 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_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/unitcell.cpp b/source/module_cell/unitcell.cpp index 69ca76df23..f2cbc6d20e 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -8,7 +8,7 @@ #include "module_base/global_variable.h" #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 @@ -397,13 +397,13 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { 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) { - log << "\n\n\n\n"; log << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>>>>>>>>>" @@ -450,7 +450,7 @@ 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 int error = unitcell::read_atom_species(ifa, log ,*this); //========================== // call read_atom_positions diff --git a/source/module_cell/unitcell.h b/source/module_cell/unitcell.h index 6fbbaa9988..3f0c8d47c5 100644 --- a/source/module_cell/unitcell.h +++ b/source/module_cell/unitcell.h @@ -241,10 +241,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, diff --git a/source/module_cell/update_cell.cpp b/source/module_cell/update_cell.cpp index c4c324ce45..40bc6b57b9 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_md/test/CMakeLists.txt b/source/module_md/test/CMakeLists.txt index dff555ea36..39f30baa94 100644 --- a/source/module_md/test/CMakeLists.txt +++ b/source/module_md/test/CMakeLists.txt @@ -9,6 +9,7 @@ list(APPEND depend_files ../../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 From 7152471424cade4e93d53d8b7d5c669b652faa16 Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Mon, 6 Jan 2025 15:58:51 +0800 Subject: [PATCH 04/16] upadte the file --- source/module_cell/read_atom_species.cpp | 177 +++++++++++++---------- source/module_cell/read_stru.h | 7 +- source/module_cell/unitcell.cpp | 10 +- 3 files changed, 114 insertions(+), 80 deletions(-) diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp index 427f69b51c..40672b00df 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -8,7 +8,7 @@ #endif namespace unitcell { -int read_atom_species(std::ifstream& ifa, +bool read_atom_species(std::ifstream& ifa, std::ofstream& ofs_running, UnitCell& ucell) { @@ -36,7 +36,8 @@ int read_atom_species(std::ifstream& ifa, ModuleBase::GlobalFunc::OUT(ofs_running,"ntype",ntype); for (int i = 0;i < ntype;i++) { - std::string one_line, one_string; + std::string one_line; + std::string one_string; std::getline(ifa, one_line); std::stringstream ss; ss << one_line; @@ -104,7 +105,8 @@ int read_atom_species(std::ifstream& ifa, ifa >> ucell.descriptor_file; } } - else{ + else + { ucell.descriptor_file = PARAM.inp.orbital_dir + ucell.orbital_fn[0]; } } @@ -128,13 +130,20 @@ int read_atom_species(std::ifstream& ifa, #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 = ucell.lat0; - double& lat0_angstrom =ucell.lat0_angstrom; - std::string& latName = ucell.latName; - ModuleBase::Matrix3& latvec = ucell.latvec; + 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); @@ -145,24 +154,26 @@ int read_atom_species(std::ifstream& ifa, lat0_angstrom = lat0 * 0.529177 ; ModuleBase::GlobalFunc::OUT(ofs_running,"lattice constant (Bohr)",lat0); ModuleBase::GlobalFunc::OUT(ofs_running,"lattice constant (Angstrom)",lat0_angstrom); - ucell.tpiba = ModuleBase::TWO_PI / lat0; - ucell.tpiba2 = ucell.tpiba * ucell.tpiba; + lat.tpiba = ModuleBase::TWO_PI / lat0; + lat.tpiba2 = lat.tpiba * lat.tpiba; } //=========================== // Read in latticies vector //=========================== - if(latName=="none"){ + 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"); + 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_atom_species","Please set LATTICE_VECTORS in STRU file"); + ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant","Please set LATTICE_VECTORS in STRU file"); } else if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_VECTORS") ) { @@ -177,39 +188,46 @@ int read_atom_species(std::ifstream& ifa, ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); } }//supply lattice vectors - else{ + 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"); + 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 + 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; + 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 + 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; + 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 + 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; + 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 + 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; + 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 + else if(latName=="trigonal") + {//trigonal, ibrav = 5 double t1 = 0.0; double t2 = 0.0; if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) @@ -223,21 +241,22 @@ int read_atom_species(std::ifstream& ifa, 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; + 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 + 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; + 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 + else if(latName=="bct") + {//body-centered tetragonal, ibrav = 7 double cba = 0.0; if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "LATTICE_PARAMETERS") ) { @@ -246,22 +265,24 @@ int read_atom_species(std::ifstream& ifa, } 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; + latvec.e31 =-0.5; latvec.e32 =-0.5; latvec.e33 = cba; } - else if(latName=="so"){//simple orthorhombic, ibrav = 8 + 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; + 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 + 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; + 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; @@ -270,7 +291,8 @@ int read_atom_species(std::ifstream& ifa, ModuleBase::GlobalFunc::READ_VALUE(ifa, latvec.e33); } } - else if(latName=="fco"){//face-centered orthorhombic, ibrav = 10 + 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") ) { @@ -279,10 +301,11 @@ int read_atom_species(std::ifstream& ifa, 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; + 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 + 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") ) { @@ -291,10 +314,11 @@ int read_atom_species(std::ifstream& ifa, 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; + 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 + 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; @@ -306,10 +330,11 @@ int read_atom_species(std::ifstream& ifa, 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; + 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 + 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; @@ -322,13 +347,17 @@ int read_atom_species(std::ifstream& ifa, 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; + 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; + 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") ) { @@ -336,35 +365,33 @@ int read_atom_species(std::ifstream& ifa, 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; + 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{ + else + { std::cout << "latname is : " << latName << std::endl; - ModuleBase::WARNING_QUIT("UnitCell::read_atom_species","latname not supported!"); + ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant","latname not supported!"); } } // lattice vectors in another form. - ucell.a1.x = latvec.e11; - ucell.a1.y = latvec.e12; - ucell.a1.z = latvec.e13; + lat.a1.x = latvec.e11; + lat.a1.y = latvec.e12; + lat.a1.z = latvec.e13; - ucell.a2.x = latvec.e21; - ucell.a2.y = latvec.e22; - ucell.a2.z = latvec.e23; + lat.a2.x = latvec.e21; + lat.a2.y = latvec.e22; + lat.a2.z = latvec.e23; - ucell.a3.x = latvec.e31; - ucell.a3.y = latvec.e32; - ucell.a3.z = latvec.e33; - return 0; + 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_stru.h b/source/module_cell/read_stru.h index 7f32115cd3..3827666966 100644 --- a/source/module_cell/read_stru.h +++ b/source/module_cell/read_stru.h @@ -9,9 +9,12 @@ namespace unitcell const int ntype, const int lat0); - int read_atom_species(std::ifstream& ifa, + 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/unitcell.cpp b/source/module_cell/unitcell.cpp index f2cbc6d20e..5178e1a225 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -403,7 +403,8 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { ok = false; } - if (ok) { + if (ok) + { log << "\n\n\n\n"; log << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>>>>>>>>>" @@ -450,8 +451,11 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { //======================== // call read_atom_species //======================== - const int error = unitcell::read_atom_species(ifa, log ,*this); - + 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 //========================== From 551e4870d1934ba8f9885e589c4d4d52085a35bd Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Mon, 6 Jan 2025 17:16:30 +0800 Subject: [PATCH 05/16] fix unittest bug --- source/module_cell/test/unitcell_test.cpp | 34 +++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 5e36ebfc4e..a3caff68b6 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -1109,6 +1109,7 @@ TEST_F(UcellTest, ReadAtomSpecies) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; 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); @@ -1135,7 +1136,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning1) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadAtomSpeciesWarning2) +TEST_F(UcellDeathTest, ReadLatticeConstantWarning1) { std::string fn = "./support/STRU_MgO_Warning2"; std::ifstream ifa(fn.c_str()); @@ -1145,7 +1146,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning2) ucell->atoms = new Atom[ucell->ntype]; ucell->set_atom_flag = true; testing::internal::CaptureStdout(); - EXPECT_EXIT(unitcell::read_atom_species(ifa, ofs_running,*ucell), ::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(); @@ -1153,7 +1154,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning2) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadAtomSpeciesWarning3) +TEST_F(UcellDeathTest, ReadLatticeConstantWarning2) { std::string fn = "./support/STRU_MgO_Warning3"; std::ifstream ifa(fn.c_str()); @@ -1163,7 +1164,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning3) ucell->atoms = new Atom[ucell->ntype]; ucell->set_atom_flag = true; testing::internal::CaptureStdout(); - EXPECT_EXIT(unitcell::read_atom_species(ifa, ofs_running,*ucell), ::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")); @@ -1172,7 +1173,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning3) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadAtomSpeciesWarning4) +TEST_F(UcellDeathTest, ReadLatticeConstantWarning3) { std::string fn = "./support/STRU_MgO_Warning4"; std::ifstream ifa(fn.c_str()); @@ -1183,7 +1184,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning4) ucell->set_atom_flag = true; ucell->latName = "bcc"; testing::internal::CaptureStdout(); - EXPECT_EXIT(unitcell::read_atom_species(ifa, ofs_running,*ucell), ::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")); @@ -1218,7 +1219,7 @@ TEST_F(UcellTest, ReadAtomSpeciesLatName) std::ofstream ofs_running; ofs_running.open("read_atom_species.tmp"); ucell->latName = latName_in[i]; - EXPECT_NO_THROW(unitcell::read_atom_species(ifa, ofs_running,*ucell)); + EXPECT_NO_THROW(unitcell::read_lattice_constant(ifa, ofs_running,ucell->lat)); if (ucell->latName == "sc") { EXPECT_DOUBLE_EQ(ucell->latvec.e11, 1.0); @@ -1242,7 +1243,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning5) ucell->set_atom_flag = true; ucell->latName = "arbitrary"; testing::internal::CaptureStdout(); - EXPECT_EXIT(unitcell::read_atom_species(ifa, ofs_running,*ucell), ::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(); @@ -1267,6 +1268,7 @@ TEST_F(UcellTest, ReadAtomPositionsS1) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; 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); @@ -1298,6 +1300,7 @@ TEST_F(UcellTest, ReadAtomPositionsS2) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 2; 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); @@ -1330,6 +1333,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Noncolin) PARAM.input.nspin = 4; PARAM.input.noncolin = true; 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); @@ -1362,6 +1366,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Colin) PARAM.input.nspin = 4; PARAM.input.noncolin = false; 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); @@ -1393,6 +1398,7 @@ TEST_F(UcellTest, ReadAtomPositionsC) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; 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); @@ -1424,6 +1430,7 @@ TEST_F(UcellTest, ReadAtomPositionsCA) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; 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); @@ -1455,6 +1462,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXY) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; 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); @@ -1486,6 +1494,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXZ) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; 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); @@ -1517,6 +1526,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACYZ) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; 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); @@ -1548,6 +1558,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXYZ) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 1; 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); @@ -1580,6 +1591,7 @@ TEST_F(UcellTest, ReadAtomPositionsCAU) PARAM.input.nspin = 1; PARAM.input.fixed_atoms = true; 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); @@ -1611,6 +1623,7 @@ TEST_F(UcellTest, ReadAtomPositionsAutosetMag) PARAM.sys.deepks_setorb = true; PARAM.input.nspin = 2; 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); @@ -1664,6 +1677,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning1) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; 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); @@ -1707,6 +1721,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning2) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; 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); @@ -1743,6 +1758,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning3) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; 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); @@ -1779,6 +1795,7 @@ TEST_F(UcellDeathTest, ReadAtomPositionsWarning4) PARAM.input.basis_type = "lcao"; PARAM.sys.deepks_setorb = true; 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); @@ -1813,6 +1830,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning5) PARAM.input.calculation = "md"; PARAM.input.esolver_type = "arbitrary"; 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); From 7b66f986cb8e556de8ebe7137e7177a67447e75f Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Mon, 6 Jan 2025 17:22:06 +0800 Subject: [PATCH 06/16] add objs --- source/Makefile.Objects | 2 ++ source/module_cell/read_atom_species.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/source/Makefile.Objects b/source/Makefile.Objects index f209a16513..e7c8081857 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/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp index 40672b00df..493585123d 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -151,7 +151,7 @@ bool read_lattice_constant(std::ifstream& ifa, { ModuleBase::WARNING_QUIT("read_atom_species","lat0<=0.0"); } - lat0_angstrom = lat0 * 0.529177 ; + 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; From c586e9fdc4ef44b230d6193cb1060bf83bd78bd3 Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Tue, 7 Jan 2025 10:13:54 +0800 Subject: [PATCH 07/16] modify the atom_label and atom_mass --- .../module_neighbor/test/prepare_unitcell.h | 12 ++++-------- source/module_cell/read_atom_species.cpp | 8 -------- source/module_cell/test/prepare_unitcell.h | 12 ++++-------- source/module_cell/test/support/mock_unitcell.cpp | 4 ---- source/module_cell/test/unitcell_test.cpp | 1 - source/module_cell/unitcell.cpp | 4 ---- source/module_cell/unitcell.h | 10 +++++----- .../module_dm/test/prepare_unitcell.h | 13 +++++-------- source/module_elecstate/test/prepare_unitcell.h | 13 +++++-------- source/module_esolver/test/esolver_dp_test.cpp | 3 +-- .../module_deltaspin/test/prepare_unitcell.h | 13 +++++-------- .../module_hcontainer/test/prepare_unitcell.h | 13 +++++-------- source/module_io/test/prepare_unitcell.h | 13 +++++-------- source/module_io/test_serial/prepare_unitcell.h | 13 +++++-------- source/module_md/test/setcell.h | 8 +++----- .../module_psi/test/psi_initializer_unit_test.cpp | 5 ++--- source/module_relax/relax_old/test/for_test.h | 2 +- 17 files changed, 50 insertions(+), 97 deletions(-) diff --git a/source/module_cell/module_neighbor/test/prepare_unitcell.h b/source/module_cell/module_neighbor/test/prepare_unitcell.h index e3a2e80e04..42da528182 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->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 = new std::string[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 index 493585123d..9cfb8c636e 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -15,15 +15,7 @@ bool read_atom_species(std::ifstream& ifa, ModuleBase::TITLE("UnitCell","read_atom_species"); const int ntype = ucell.ntype; - delete[] ucell.atom_label; - delete[] ucell.atom_mass; - delete[] ucell.pseudo_fn; - delete[] ucell.pseudo_type; delete[] ucell.orbital_fn; - ucell.atom_mass = new double[ntype]; //atom masses - ucell.atom_label = new std::string[ntype]; //atom labels - ucell.pseudo_fn = new std::string[ntype]; //file name of pseudopotential - ucell.pseudo_type = new std::string[ntype]; // type of pseudopotential ucell.orbital_fn = new std::string[ntype]; // filename of orbitals std::string word; diff --git a/source/module_cell/test/prepare_unitcell.h b/source/module_cell/test/prepare_unitcell.h index 3890670e18..0551733580 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->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 = new std::string[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 d48aade920..6543b0b18e 100644 --- a/source/module_cell/test/support/mock_unitcell.cpp +++ b/source/module_cell/test/support/mock_unitcell.cpp @@ -13,10 +13,6 @@ UnitCell::UnitCell() { itia2iat.create(1, 1); } UnitCell::~UnitCell() { - delete[] atom_label; - delete[] atom_mass; - delete[] pseudo_fn; - delete[] pseudo_type; delete[] orbital_fn; if (set_atom_flag) { delete[] atoms; diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index a3caff68b6..8aa06402a6 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -186,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); } diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index 5178e1a225..064881c2db 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -37,10 +37,6 @@ UnitCell::UnitCell() { } UnitCell::~UnitCell() { - delete[] atom_label; - delete[] atom_mass; - delete[] pseudo_fn; - delete[] pseudo_type; delete[] orbital_fn; if (set_atom_flag) { delete[] atoms; diff --git a/source/module_cell/unitcell.h b/source/module_cell/unitcell.h index 3f0c8d47c5..bbdb3dd901 100644 --- a/source/module_cell/unitcell.h +++ b/source/module_cell/unitcell.h @@ -209,11 +209,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::string* orbital_fn = nullptr; // filenames of orbitals, liuyu add 2022-10-19 std::string descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06 diff --git a/source/module_elecstate/module_dm/test/prepare_unitcell.h b/source/module_elecstate/module_dm/test/prepare_unitcell.h index fcc98db9fa..e731178f35 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.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 = new std::string[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 f7bfc924e5..59c5726d85 100644 --- a/source/module_elecstate/test/prepare_unitcell.h +++ b/source/module_elecstate/test/prepare_unitcell.h @@ -60,16 +60,13 @@ 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->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 = new std::string[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_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h b/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h index aa8221a8fe..24634aa15a 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 = new std::string[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 dd4d27e2eb..b18a0a79ae 100644 --- a/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h +++ b/source/module_hamilt_lcao/module_hcontainer/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 = new std::string[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/prepare_unitcell.h b/source/module_io/test/prepare_unitcell.h index a7c070ebe7..512d590811 100644 --- a/source/module_io/test/prepare_unitcell.h +++ b/source/module_io/test/prepare_unitcell.h @@ -76,16 +76,13 @@ 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->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 = new std::string[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_serial/prepare_unitcell.h b/source/module_io/test_serial/prepare_unitcell.h index 13b96cce5c..64870fdf03 100644 --- a/source/module_io/test_serial/prepare_unitcell.h +++ b/source/module_io/test_serial/prepare_unitcell.h @@ -76,16 +76,13 @@ 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->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 = new std::string[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_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 3f74fdc44d..fb2830be2b 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -139,9 +139,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 - if(this->p_ucell->atom_label != nullptr) { 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; diff --git a/source/module_relax/relax_old/test/for_test.h b/source/module_relax/relax_old/test/for_test.h index 10ee140b79..6429e7fcf9 100644 --- a/source/module_relax/relax_old/test/for_test.h +++ b/source/module_relax/relax_old/test/for_test.h @@ -44,7 +44,7 @@ UnitCell::UnitCell() omega = 0.0; atom_label = new std::string[1]; - atom_mass = nullptr; + atom_mass.shrink_to_fit(); pseudo_fn = new std::string[1]; pseudo_type = new std::string[1]; orbital_fn = new std::string[1]; From 0d90ec11c00f00d822f146384ef5b55b729a58b1 Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Tue, 7 Jan 2025 11:31:45 +0800 Subject: [PATCH 08/16] modify compile bug --- .../module_dm/test/prepare_unitcell.h | 8 ++--- source/module_esolver/test/for_test.h | 2 +- .../module_deepks/test/CMakeLists.txt | 4 ++- .../module_hcontainer/test/prepare_unitcell.h | 10 +++--- source/module_io/json_output/init_info.cpp | 4 +-- .../json_output/test/para_json_test.cpp | 4 +-- source/module_io/test/to_qo_test.cpp | 32 +++++++++---------- source/module_io/to_qo_kernel.cpp | 2 +- .../test/psi_initializer_unit_test.cpp | 7 ++-- source/module_relax/relax_old/test/for_test.h | 6 ++-- 10 files changed, 40 insertions(+), 39 deletions(-) diff --git a/source/module_elecstate/module_dm/test/prepare_unitcell.h b/source/module_elecstate/module_dm/test/prepare_unitcell.h index e731178f35..4adc2f0f62 100644 --- a/source/module_elecstate/module_dm/test/prepare_unitcell.h +++ b/source/module_elecstate/module_dm/test/prepare_unitcell.h @@ -76,10 +76,10 @@ class UcellTestPrepare delete[] ucell.orbital_fn; delete[] ucell.magnet.start_magnetization; // mag set here - 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.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 = new std::string[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/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 fd4de98d76..27dacaaa0f 100644 --- a/source/module_hamilt_lcao/module_deepks/test/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_deepks/test/CMakeLists.txt @@ -7,6 +7,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 @@ -34,7 +36,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 paw ${math_libs} ) 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 b18a0a79ae..fd168c7ef3 100644 --- a/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h +++ b/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h @@ -74,11 +74,11 @@ class UcellTestPrepare ucell.setup(this->latname, this->ntype, this->lmaxmax, this->init_vel, this->fixed_axes); delete[] ucell.orbital_fn; delete[] ucell.magnet.start_magnetization; // mag set here - 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.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 = new std::string[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 f9ce429568..9bd8c0740f 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; @@ -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 cc529ce4a3..a72bccb80a 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 = new std::string[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/to_qo_test.cpp b/source/module_io/test/to_qo_test.cpp index 1013ad93cf..24a3b03302 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 = new std::string[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 = new std::string[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/to_qo_kernel.cpp b/source/module_io/to_qo_kernel.cpp index 13f5b7c06b..b691b22316 100644 --- a/source/module_io/to_qo_kernel.cpp +++ b/source/module_io/to_qo_kernel.cpp @@ -82,7 +82,7 @@ void toQO::initialize(const std::string& out_dir, // build the numerical atomic orbital basis build_nao(ntype_, orbital_dir_, p_ucell_->orbital_fn, 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_psi/test/psi_initializer_unit_test.cpp b/source/module_psi/test/psi_initializer_unit_test.cpp index fb2830be2b..3ad0e7a0a7 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -139,7 +139,7 @@ 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 - this->p_ucell->atom_label.shrink_to_fit() + this->p_ucell->atom_label.shrink_to_fit(); this->p_ucell->atom_label.resize(1); this->p_ucell->atom_label[0] = "Si"; // atom properties @@ -156,9 +156,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 6429e7fcf9..8ef5d2ac05 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.shrink_to_fit(); - pseudo_fn = new std::string[1]; - pseudo_type = new std::string[1]; + atom_label.resize(1); + pseudo_fn.resize(1); + pseudo_type.resize(1); orbital_fn = new std::string[1]; atoms = new Atom[ntype]; From f9cc2b947c45cc26a50cad48fcabb0af9be48fad Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Tue, 7 Jan 2025 12:11:02 +0800 Subject: [PATCH 09/16] modify the reszie of the atom_mass --- source/module_cell/read_atom_species.cpp | 30 +++++++++++------------- source/module_cell/unitcell.cpp | 4 ++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp index 9cfb8c636e..4fa309bdd9 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -18,6 +18,9 @@ bool read_atom_species(std::ifstream& ifa, delete[] ucell.orbital_fn; ucell.orbital_fn = new std::string[ntype]; // filename of orbitals std::string word; + std::string one_line; + std::string one_string; + std::stringstream ss; //========================================== // read in information of each type of atom @@ -28,12 +31,10 @@ bool read_atom_species(std::ifstream& ifa, 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]; + ss >> ucell.atom_label[i] + ss >> ucell.atom_mass[i]; ucell.pseudo_fn[i] = "auto"; ucell.pseudo_type[i] = "auto"; @@ -102,10 +103,8 @@ bool read_atom_species(std::ifstream& ifa, ucell.descriptor_file = PARAM.inp.orbital_dir + ucell.orbital_fn[0]; } } -#ifdef __LCAO +#ifdef (__LCAO) && (__MPI) && (__EXX) // 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") ) @@ -118,9 +117,6 @@ bool read_atom_species(std::ifstream& ifa, } } } - -#endif // __EXX -#endif // __MPI #endif // __LCAO return true; } @@ -141,19 +137,19 @@ bool read_lattice_constant(std::ifstream& ifa, ModuleBase::GlobalFunc::READ_VALUE(ifa, lat0); if(lat0<=0.0) { - ModuleBase::WARNING_QUIT("read_atom_species","lat0<=0.0"); + ModuleBase::WARNING_QUIT("read_lattice_constant","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; + ModuleBase::GlobalFunc::OUT(ofs_running,"lattice constant (Bohr)",lat0); + ModuleBase::GlobalFunc::OUT(ofs_running,"lattice constant (Angstrom)",lat0_angstrom); + } //=========================== // Read in latticies vector //=========================== - if(latName=="none") { if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, @@ -161,7 +157,8 @@ bool read_lattice_constant(std::ifstream& ifa, true, false)) { - ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant","do not use LATTICE_PARAMETERS without explicit specification of lattice type"); + 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") ) { @@ -187,7 +184,8 @@ bool read_lattice_constant(std::ifstream& ifa, true, false)) { - ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant","do not use LATTICE_VECTORS along with explicit specification of lattice type"); + 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 diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index 6f40994422..2d90750464 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -331,6 +331,10 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { bool ok2 = true; // (3) read in atom information + this->atom_mass.resize(ntype); + this->atom_label.resize(ntype); + this->pseudo_fn.resize(ntype); + this->pseudo_type.resize(ntype); if (GlobalV::MY_RANK == 0) { // open "atom_unitcell" file. std::ifstream ifa(fn.c_str(), std::ios::in); From 9a51ca36193624144c45c510a9d04a6f241d28d5 Mon Sep 17 00:00:00 2001 From: liiutao <3158793232@qq.com> Date: Tue, 7 Jan 2025 12:18:26 +0800 Subject: [PATCH 10/16] fix compile bug --- source/module_cell/read_atom_species.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp index 4fa309bdd9..724d566028 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -33,7 +33,7 @@ bool read_atom_species(std::ifstream& ifa, { std::getline(ifa, one_line); ss << one_line; - ss >> ucell.atom_label[i] + ss >> ucell.atom_label[i]; ss >> ucell.atom_mass[i]; ucell.pseudo_fn[i] = "auto"; ucell.pseudo_type[i] = "auto"; @@ -103,7 +103,7 @@ bool read_atom_species(std::ifstream& ifa, ucell.descriptor_file = PARAM.inp.orbital_dir + ucell.orbital_fn[0]; } } -#ifdef (__LCAO) && (__MPI) && (__EXX) +#if defined(__LCAO) && defined(__MPI) && defined(__EXX) // Peize Lin add 2016-09-23 if( GlobalC::exx_info.info_global.cal_exx || PARAM.inp.rpa ) { From 28b20d5067d791827eefd58061ad2ee3f13c9245 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 04:59:45 +0000 Subject: [PATCH 11/16] [pre-commit.ci lite] apply automatic fixes --- source/module_relax/relax_old/test/for_test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_relax/relax_old/test/for_test.h b/source/module_relax/relax_old/test/for_test.h index 8ef5d2ac05..cc1597671b 100644 --- a/source/module_relax/relax_old/test/for_test.h +++ b/source/module_relax/relax_old/test/for_test.h @@ -68,7 +68,7 @@ UnitCell::UnitCell() UnitCell::~UnitCell() { } -void UnitCell::print_tau(void) const +void UnitCell::print_tau() const { } Magnetism::Magnetism() From 3479a4e641de33c4c14c67ddb0c1e216ab75ca8d Mon Sep 17 00:00:00 2001 From: liutao <3158793232@qq.com> Date: Wed, 8 Jan 2025 11:33:32 +0800 Subject: [PATCH 12/16] Revert "fix compile bug" This reverts commit 9a51ca36193624144c45c510a9d04a6f241d28d5. --- source/module_cell/read_atom_species.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp index 724d566028..4fa309bdd9 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -33,7 +33,7 @@ bool read_atom_species(std::ifstream& ifa, { std::getline(ifa, one_line); ss << one_line; - ss >> ucell.atom_label[i]; + ss >> ucell.atom_label[i] ss >> ucell.atom_mass[i]; ucell.pseudo_fn[i] = "auto"; ucell.pseudo_type[i] = "auto"; @@ -103,7 +103,7 @@ bool read_atom_species(std::ifstream& ifa, ucell.descriptor_file = PARAM.inp.orbital_dir + ucell.orbital_fn[0]; } } -#if defined(__LCAO) && defined(__MPI) && defined(__EXX) +#ifdef (__LCAO) && (__MPI) && (__EXX) // Peize Lin add 2016-09-23 if( GlobalC::exx_info.info_global.cal_exx || PARAM.inp.rpa ) { From d8fee18060a1863e3bff088219f8d995aa24d28f Mon Sep 17 00:00:00 2001 From: liutao <3158793232@qq.com> Date: Wed, 8 Jan 2025 11:34:04 +0800 Subject: [PATCH 13/16] Revert "modify the reszie of the atom_mass" This reverts commit f9cc2b947c45cc26a50cad48fcabb0af9be48fad. --- source/module_cell/read_atom_species.cpp | 30 +++++++++++++----------- source/module_cell/unitcell.cpp | 4 ---- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp index 4fa309bdd9..9cfb8c636e 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -18,9 +18,6 @@ bool read_atom_species(std::ifstream& ifa, delete[] ucell.orbital_fn; ucell.orbital_fn = new std::string[ntype]; // filename of orbitals std::string word; - std::string one_line; - std::string one_string; - std::stringstream ss; //========================================== // read in information of each type of atom @@ -31,10 +28,12 @@ bool read_atom_species(std::ifstream& ifa, 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] - ss >> ucell.atom_mass[i]; + ss >> ucell.atom_label[i] >> ucell.atom_mass[i]; ucell.pseudo_fn[i] = "auto"; ucell.pseudo_type[i] = "auto"; @@ -103,8 +102,10 @@ bool read_atom_species(std::ifstream& ifa, ucell.descriptor_file = PARAM.inp.orbital_dir + ucell.orbital_fn[0]; } } -#ifdef (__LCAO) && (__MPI) && (__EXX) +#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") ) @@ -117,6 +118,9 @@ bool read_atom_species(std::ifstream& ifa, } } } + +#endif // __EXX +#endif // __MPI #endif // __LCAO return true; } @@ -137,19 +141,19 @@ bool read_lattice_constant(std::ifstream& ifa, ModuleBase::GlobalFunc::READ_VALUE(ifa, lat0); if(lat0<=0.0) { - ModuleBase::WARNING_QUIT("read_lattice_constant","lat0<=0.0"); + ModuleBase::WARNING_QUIT("read_atom_species","lat0<=0.0"); } lat0_angstrom = lat0 * 0.529177; - lat.tpiba = ModuleBase::TWO_PI / lat0; - lat.tpiba2 = lat.tpiba * lat.tpiba; 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, @@ -157,8 +161,7 @@ bool read_lattice_constant(std::ifstream& ifa, true, false)) { - ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant", - "do not use LATTICE_PARAMETERS without explicit specification of lattice type"); + 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") ) { @@ -184,8 +187,7 @@ bool read_lattice_constant(std::ifstream& ifa, true, false)) { - ModuleBase::WARNING_QUIT("unitcell::read_lattice_constant", - "do not use LATTICE_VECTORS along with explicit specification of lattice type"); + 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 diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index 2d90750464..6f40994422 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -331,10 +331,6 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { bool ok2 = true; // (3) read in atom information - this->atom_mass.resize(ntype); - this->atom_label.resize(ntype); - this->pseudo_fn.resize(ntype); - this->pseudo_type.resize(ntype); if (GlobalV::MY_RANK == 0) { // open "atom_unitcell" file. std::ifstream ifa(fn.c_str(), std::ios::in); From ecb0a9d792de8247200b7b84e465b3f94ae91f7d Mon Sep 17 00:00:00 2001 From: liutao <3158793232@qq.com> Date: Wed, 8 Jan 2025 11:36:21 +0800 Subject: [PATCH 14/16] update the resize --- source/module_cell/unitcell.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index 6f40994422..b37c166118 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -331,6 +331,10 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { bool ok2 = true; // (3) read in atom information + this->atom_mass.resize(ntype); + this->atom_label.resize(ntype); + this->pseudo_fn.reszie(ntype); + this->pseudo_type.resize(ntype); if (GlobalV::MY_RANK == 0) { // open "atom_unitcell" file. std::ifstream ifa(fn.c_str(), std::ios::in); From c9813034a9bbacc248f9cca292683883cfa20f71 Mon Sep 17 00:00:00 2001 From: liutao <3158793232@qq.com> Date: Wed, 8 Jan 2025 12:10:32 +0800 Subject: [PATCH 15/16] fix unitest bug --- source/module_cell/read_atom_species.cpp | 3 --- source/module_cell/test/unitcell_test.cpp | 14 +++++++++----- .../test/unitcell_test_setupcell.cpp | 18 ++++++++++++------ .../module_cell/test_pw/unitcell_test_pw.cpp | 11 ++++++++--- source/module_cell/unitcell.cpp | 4 ++-- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp index 9cfb8c636e..f09df97602 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -14,9 +14,6 @@ bool read_atom_species(std::ifstream& ifa, { ModuleBase::TITLE("UnitCell","read_atom_species"); const int ntype = ucell.ntype; - - delete[] ucell.orbital_fn; - ucell.orbital_fn = new std::string[ntype]; // filename of orbitals std::string word; //========================================== diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 2370618b09..2a783630dc 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -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 @@ -1132,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()); @@ -1150,7 +1154,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning1) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadLatticeConstantWarning1) +TEST_F(UcellTestReadStru, ReadLatticeConstantWarning1) { std::string fn = "./support/STRU_MgO_Warning2"; std::ifstream ifa(fn.c_str()); @@ -1168,7 +1172,7 @@ TEST_F(UcellDeathTest, ReadLatticeConstantWarning1) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadLatticeConstantWarning2) +TEST_F(UcellTestReadStru, ReadLatticeConstantWarning2) { std::string fn = "./support/STRU_MgO_Warning3"; std::ifstream ifa(fn.c_str()); @@ -1187,7 +1191,7 @@ TEST_F(UcellDeathTest, ReadLatticeConstantWarning2) remove("read_atom_species.tmp"); } -TEST_F(UcellDeathTest, ReadLatticeConstantWarning3) +TEST_F(UcellTestReadStru, ReadLatticeConstantWarning3) { std::string fn = "./support/STRU_MgO_Warning4"; std::ifstream ifa(fn.c_str()); @@ -1793,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()); 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/unitcell_test_pw.cpp b/source/module_cell/test_pw/unitcell_test_pw.cpp index 82b266f4b0..2e41265090 100644 --- a/source/module_cell/test_pw/unitcell_test_pw.cpp +++ b/source/module_cell/test_pw/unitcell_test_pw.cpp @@ -44,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); } }; @@ -57,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(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); @@ -85,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(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); @@ -116,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 368b47b488..54e14adb21 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -230,9 +230,9 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { // (3) read in atom information this->atom_mass.resize(ntype); this->atom_label.resize(ntype); - this->pseudo_fn.reszie(ntype); + this->pseudo_fn.resize(ntype); this->pseudo_type.resize(ntype); - orbital_fn.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); From 0e32ffdb7d0f571c9db7b2acba1620e0cd3b33e0 Mon Sep 17 00:00:00 2001 From: liutao <3158793232@qq.com> Date: Thu, 9 Jan 2025 03:16:21 +0000 Subject: [PATCH 16/16] change the compile bug --- source/module_cell/read_atom_species.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_cell/read_atom_species.cpp b/source/module_cell/read_atom_species.cpp index f09df97602..a50d4ee6d1 100644 --- a/source/module_cell/read_atom_species.cpp +++ b/source/module_cell/read_atom_species.cpp @@ -77,7 +77,7 @@ bool read_atom_species(std::ifstream& ifa, if((PARAM.inp.basis_type == "lcao") ||(PARAM.inp.basis_type == "lcao_in_pw") - ||((PARAM.inp.basis_type == "pw")&&(PARAM.inp.psi_initializer)&&(PARAM.inp.init_wfc.substr(0, 3) == "nao")) + ||((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") )