Electrostatic correction of Makov-Payne type #7354
Open
kluonju wants to merge 9 commits into
Open
Conversation
…or-cubic-systems Implement Makov–Payne isolated-cell correction and input option
…rs-in-elecstate_energy Fix elecstate energy unit test link dependencies
There was a problem hiding this comment.
Pull request overview
Adds an isolated-supercell electrostatic correction option (Makov–Payne) for non-neutral systems, wired into the energy evaluation path and exposed via a new assume_isolated input keyword.
Changes:
- Introduces
assume_isolatedinput parameter (defaultnone) with Makov–Payne options and cubic-lattice validation. - Implements Makov–Payne correction (+ optional corrected vacuum-level estimate) and integrates it into
ElecStatetotal-energy accounting via a newfenergy::correction_elterm. - Updates build/test targets and adds a
Potentialaccessor to retrieve the associatedUnitCell.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| source/source_io/module_parameter/read_input_item_system.cpp | Adds assume_isolated input item, documentation, normalization, and validation. |
| source/source_io/module_parameter/input_parameter.h | Adds Input_para::assume_isolated with default none. |
| source/source_estate/elecstate_energy.cpp | Computes and applies Makov–Payne correction during energy evaluation. |
| source/source_estate/makov_payne.h | Declares Makov–Payne correction API and result struct. |
| source/source_estate/makov_payne.cpp | Implements Makov–Payne correction and vacuum-level estimation. |
| source/source_estate/fp_energy.h | Adds correction_el energy component. |
| source/source_estate/fp_energy.cpp | Includes correction_el in totals/clearing/printing. |
| source/source_estate/module_pot/potential_new.h | Adds Potential::get_ucell() accessor. |
| source/source_estate/CMakeLists.txt | Adds makov_payne.cpp to estate objects. |
| source/Makefile.Objects | Adds makov_payne.o to estate object list. |
| source/source_estate/test/CMakeLists.txt | Updates MODULE_ESTATE_elecstate_energy test linkage/sources for new symbols. |
Comments suppressed due to low confidence (2)
source/source_estate/elecstate_energy.cpp:365
- This Makov–Payne block recomputes a full Hartree potential (
H_Hartree_pw::v_hartree) and the correction every timecal_energies()is called. In the main SCF loopcal_energies(1)andcal_energies(2)are both called, so this work will be duplicated each iteration. Suggest computing/caching the correction once per potential update (or at least only in one of the two calls) and reusing it for the other energy functional.
if (PARAM.inp.assume_isolated == "makov-payne")
{
const UnitCell* ucell = this->pot->get_ucell();
if (ucell == nullptr || this->charge == nullptr || this->charge->rhopw == nullptr)
{
ModuleBase::WARNING_QUIT("ElecState::cal_energies",
"Makov-Payne correction requires an initialized unit cell and charge density.");
}
std::vector<double> v_elecstat;
const double* v_elecstat_ptr = nullptr;
{
ModuleBase::matrix vh(PARAM.inp.nspin, this->charge->rhopw->nrxx);
vh = elecstate::H_Hartree_pw::v_hartree(*ucell, this->charge->rhopw, PARAM.inp.nspin, this->charge->rho);
v_elecstat.assign(this->charge->rhopw->nrxx, 0.0);
const double* v_fixed = this->pot->get_fixed_v();
for (int ir = 0; ir < this->charge->rhopw->nrxx; ++ir)
{
v_elecstat[ir] = vh(0, ir) + v_fixed[ir];
}
v_elecstat_ptr = v_elecstat.data();
}
source/source_estate/elecstate_energy.cpp:371
- The new Makov–Payne execution path (including acceptance of
assume_isolated = mp/m-p/makov-payneand the actual correction applied tof_en.correction_el) is not covered by unit tests. Sincesource/source_estate/test/elecstate_energy_test.cppalready testscal_energies(), please add at least one test that enables Makov–Payne and asserts thatcorrection_elis non-zero/expected (and that the code path does not error for a supported cubiclatname).
if (PARAM.inp.assume_isolated == "makov-payne")
{
const UnitCell* ucell = this->pot->get_ucell();
if (ucell == nullptr || this->charge == nullptr || this->charge->rhopw == nullptr)
{
ModuleBase::WARNING_QUIT("ElecState::cal_energies",
"Makov-Payne correction requires an initialized unit cell and charge density.");
}
std::vector<double> v_elecstat;
const double* v_elecstat_ptr = nullptr;
{
ModuleBase::matrix vh(PARAM.inp.nspin, this->charge->rhopw->nrxx);
vh = elecstate::H_Hartree_pw::v_hartree(*ucell, this->charge->rhopw, PARAM.inp.nspin, this->charge->rho);
v_elecstat.assign(this->charge->rhopw->nrxx, 0.0);
const double* v_fixed = this->pot->get_fixed_v();
for (int ir = 0; ir < this->charge->rhopw->nrxx; ++ir)
{
v_elecstat[ir] = vh(0, ir) + v_fixed[ir];
}
v_elecstat_ptr = v_elecstat.data();
}
this->f_en.correction_el = makov_payne_correction(*ucell, *this->charge, v_elecstat_ptr).total;
}
else
{
this->f_en.correction_el = 0.0;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the help of codex, I have included the correction of Markov-Payne type for non-neutral isolated system. One can activate this function with
assume_isolated mpand by default it is setnone.Note: this will only work with cubic system so far and we need to specify the lattice type using something like
latname sc. This has been tested on LiH with fractional charge.Further implementation on Martyna-Tuckerman type would be nice to have, which does not have such limitation.