Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: consider fractional electron number #4770

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions source/module_cell/atom_pseudo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

Atom_pseudo::Atom_pseudo()
{
for (int is = 0; is < 4; is++)
for (int is = 0; is < 4; is++) {
this->index1_soc[is] = nullptr;
for (int is = 0; is < 4; is++)
}
for (int is = 0; is < 4; is++) {
this->index2_soc[is] = nullptr;
}
}

Atom_pseudo::~Atom_pseudo()
{
for (int is = 0; is < 4; is++)
{
if (this->index1_soc[is] != nullptr)
if (this->index1_soc[is] != nullptr) {
delete[] this->index1_soc[is];
if (this->index2_soc[is] != nullptr)
}
if (this->index2_soc[is] != nullptr) {
delete[] this->index2_soc[is];
}
}
}

Expand Down Expand Up @@ -118,8 +122,9 @@ void Atom_pseudo::set_d_so(ModuleBase::ComplexMatrix& d_so_in,
{
for (int is2 = 0; is2 < 2; is2++)
{
if (is >= GlobalV::NSPIN)
if (is >= GlobalV::NSPIN) {
break;
}
for (int L1 = 0; L1 < nproj_soc; L1++)
{
for (int L2 = 0; L2 < nproj_soc; L2++)
Expand Down Expand Up @@ -165,7 +170,7 @@ void Atom_pseudo::bcast_atom_pseudo()
Parallel_Common::bcast_int(nchi);
Parallel_Common::bcast_int(nbeta);
Parallel_Common::bcast_int(nv);
Parallel_Common::bcast_int(zv);
Parallel_Common::bcast_double(zv);

// double
Parallel_Common::bcast_double(etotps);
Expand Down Expand Up @@ -240,8 +245,9 @@ void Atom_pseudo::bcast_atom_pseudo()
// == end of pseudo_vl ==

// == pseudo ==
if (nbeta == 0)
if (nbeta == 0) {
return;
}

if (GlobalV::MY_RANK != 0)
{
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/pseudo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class pseudo
bool tvanp = false; // .true. if Ultrasoft
bool nlcc = false; // Non linear core corrections(bool)
std::string xc_func; // Exch-Corr type
int zv = 0; // z valence
double zv = 0; // z valence
double etotps = 0.0; // total energy
double ecutwfc = 0.0; // suggested cut-off for wfc
double ecutrho = 0.0; // suggested cut-off for rho
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/read_pp_blps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int Pseudopot_upf::read_pseudo_blps(std::ifstream &ifs, Atom_pseudo& pp)
double zatom;
double zion;
ifs >> zatom >> zion;
pp.zv = static_cast<int>(zion);
pp.zv = zion;
ifs.ignore(300, '\n');

atom_in ai;
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/read_pp_upf201.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void Pseudopot_upf::read_pseudo_upf201_header(std::ifstream& ifs, Atom_pseudo& p
}
else if (name[ip] == "z_valence")
{
pp.zv = atof(val[ip].c_str());
pp.zv = std::stod(val[ip]);
}
else if (name[ip] == "total_psenergy")
{
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/read_pp_vwr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int Pseudopot_upf::read_pseudo_vwr(std::ifstream &ifs, Atom_pseudo& pp)
GlobalV::ofs_running << std::setw(15) << "ATOM" << std::setw(15) << pp.psd << std::endl;
// (4) valence electron number
ifs >> value; length = value.find(","); value.erase(length,1);
pp.zv = std::atoi( value.c_str() );
pp.zv = std::stod( value );
GlobalV::ofs_running << std::setw(15) << "Z(VALENCE)" << std::setw(15) << pp.zv << std::endl;
// (5) spd_loc, which local pseudopotential should I choose
ifs >> value; length = value.find(","); value.erase(length,1);
Expand Down
3 changes: 2 additions & 1 deletion source/module_io/berryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ void berryphase::Macroscopic_polarization(const int npwx,
{
for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++)
{
if (GlobalC::ucell.atoms[it].ncpp.zv % 2 == 1)
// should consider fractional electron number
if (int(GlobalC::ucell.atoms[it].ncpp.zv) % 2 == 1)
{
mod_ion[atom_index] = 1;
lodd = true;
Expand Down
2 changes: 1 addition & 1 deletion source/module_io/json_output/init_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void gen_init(UnitCell* ucell)
{
std::string label = ucell->atoms[it].label;
int atom_number = ucell->atoms[it].na;
int number = ucell->atoms[it].ncpp.zv;
double number = ucell->atoms[it].ncpp.zv;

nelec_total += ucell->atoms[it].ncpp.zv * ucell->atoms[it].na;
AbacusJson::add_json({"init", "natom_each_type", label}, atom_number, false);
Expand Down
6 changes: 3 additions & 3 deletions source/module_io/json_output/test/para_json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ TEST(AbacusJsonTest, InitInfo)
ASSERT_STREQ(Json::AbacusJson::doc["init"]["point_group"].GetString(), "T_d");
ASSERT_STREQ(Json::AbacusJson::doc["init"]["point_group_in_space"].GetString(), "O_h");

ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["Si"].GetInt(), 3);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["C"].GetInt(), 4);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["O"].GetInt(), 5);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["Si"].GetDouble(), 3);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["C"].GetDouble(), 4);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["O"].GetDouble(), 5);

ASSERT_EQ(Json::AbacusJson::doc["init"]["natom_each_type"]["Si"].GetInt(), 1);
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom_each_type"]["C"].GetInt(), 2);
Expand Down
Loading