Skip to content

EXX cal_dHs including Hellmann-Feynman term#10

Open
maki49 wants to merge 4 commits into
abacusmodeling:masterfrom
maki49:h1-api
Open

EXX cal_dHs including Hellmann-Feynman term#10
maki49 wants to merge 4 commits into
abacusmodeling:masterfrom
maki49:h1-api

Conversation

@maki49

@maki49 maki49 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

$d\langle\phi|H_{\text{EXX}}|\phi\rangle/d\tau_I$, where $\tau_I$ is the I-th atom position.

Copilot AI review requested due to automatic review settings June 16, 2026 08:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new cal_dHs API to compute dH contributions split into Pulay and Hellmann–Feynman (HF) components, and introduces save-flag setters to control output.

Changes:

  • Introduced Exx::cal_dHs(...) implementation to compute dHs (Pulay) plus new dHs_HF (HF) terms.
  • Added public setters to toggle saving dHs/dHRs.
  • Added dHs_HF storage and clarified dHs comment/shape.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
include/RI/physics/Exx.hpp Implements cal_dHs, including new HF accumulation via temporary slicing of Ds in lri.data_pool.
include/RI/physics/Exx.h Exposes cal_dHs, adds save-flag setters, and introduces dHs_HF member with documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +487 to +545
auto set_D_slots = [&](const std::string& name) {
for (const Label::ab lab : { Label::ab::a1b1, Label::ab::a1b2, Label::ab::a2b1, Label::ab::a2b2 })
this->lri.data_ab_name[lab] = name;
};
auto install_slice = [&](std::map<TA, std::map<TAC, Tensor<Tdata>>> slice) {
Data_Pack<TA, TC, Tdata> pack;
pack.Ds_ab = std::move(slice);
pack.index_Ds_ab = RI_Tools::get_index(pack.Ds_ab);
this->lri.data_pool[tmp] = std::move(pack);
set_D_slots(tmp);
};

for (const TA& Apin : pin_atoms)
{
// ===== a-side (K = Apin): slice Ds by OUTER key (TA) =====
{
std::map<TA, std::map<TAC, Tensor<Tdata>>> slice;
slice[Apin] = Ds.at(Apin); // shallow; tensors shared
install_slice(std::move(slice));
}
// dC part, sign-flipped vs Pulay block 0: a=dCs, a0b0=Vs, b=Cs
this->lri.data_ab_name[Label::ab::a] = dC;
this->lri.data_ab_name[Label::ab::a0b0] = "Vs_" + sfx1;
this->lri.data_ab_name[Label::ab::b] = "Cs_" + sfx0;
this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b1, Label::ab_ab::a0b0_a1b2 }, this->dHs_HF[ipos][Apin], -1.0);
this->lri.cal_loop3({ Label::ab_ab::a0b0_a2b1, Label::ab_ab::a0b0_a2b2 }, this->dHs_HF[ipos][Apin], 1.0);
// dV part, a1 labels (V a-abf = K): a=Cs, a0b0=dVs, b=Cs
this->lri.data_ab_name[Label::ab::a] = "Cs_" + sfx0;
this->lri.data_ab_name[Label::ab::a0b0] = dV;
this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b1, Label::ab_ab::a0b0_a1b2 }, this->dHs_HF[ipos][Apin], -1.0);

// ===== b-side (L = Apin): slice Ds by INNER key (TAC.first) =====
{
std::map<TA, std::map<TAC, Tensor<Tdata>>> slice;
for (const auto& kv : Ds)
{
std::map<TAC, Tensor<Tdata>> inner;
for (const auto& lc : kv.second)
if (lc.first.first == Apin)
inner.insert(lc); // shallow
if (!inner.empty())
slice[kv.first] = std::move(inner);
}
install_slice(std::move(slice));
}
// dC part, sign-flipped vs Pulay block 1, in b-slot: a=Cs, a0b0=Vs, b=dCs
this->lri.data_ab_name[Label::ab::a] = "Cs_" + sfx0;
this->lri.data_ab_name[Label::ab::a0b0] = "Vs_" + sfx1;
this->lri.data_ab_name[Label::ab::b] = dC;
this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b1, Label::ab_ab::a0b0_a2b1 }, this->dHs_HF[ipos][Apin], -1.0);
this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b2, Label::ab_ab::a0b0_a2b2 }, this->dHs_HF[ipos][Apin], 1.0);
// dV part, b1 labels (V b-abf = L): a=Cs, a0b0=dVs, b=Cs
this->lri.data_ab_name[Label::ab::a] = "Cs_" + sfx0;
this->lri.data_ab_name[Label::ab::a0b0] = dV;
this->lri.data_ab_name[Label::ab::b] = "Cs_" + sfx0;
this->lri.cal_loop3({ Label::ab_ab::a0b0_a1b1, Label::ab_ab::a0b0_a2b1 }, this->dHs_HF[ipos][Apin], 1.0);
}
set_D_slots(Ds_full); // restore the four density-matrix slots
this->lri.data_pool.erase(tmp);
Comment thread include/RI/physics/Exx.hpp
Comment thread include/RI/physics/Exx.hpp Outdated
const std::string dC = "dCs_" + std::to_string(ipos) + "_" + save_names_suffix[3];
const std::string dV = "dVs_" + std::to_string(ipos) + "_" + save_names_suffix[4];
const std::string Ds_full = "Ds_" + save_names_suffix[2];
const std::string tmp = "__Exx_HF_Ds_tmp";
@maki49

maki49 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Suggestions 2 and 3 about performance are adopted while others are not.
reply-to-copilot-review.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants