Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5ad9726
fix(lr): report ground-state forces in single-point ks-lr runs
maki49 Nov 4, 2026
96183b8
Allow nspin=1 LR calculations to select the triplet channel
maki49 Nov 9, 2026
251b0b7
Reuse scalar GGA coefficients across LR response orders
maki49 Nov 16, 2026
196427a
fix(lr): separate HSE ground-state and excitation kernels
Shane-Sayoko Nov 16, 2026
3a4421c
fix(lr): apply HSE sigma-cutoff chain rule to GXC
Shane-Sayoko Nov 16, 2026
96e1603
fix(lr): support empty local XC grids
Shane-Sayoko Nov 16, 2026
8055f67
perf(lr): reuse scalar GGA derivatives for open-shell response
maki49 Nov 16, 2026
75c50d6
test(lr): move XC regressions into unittests
maki49 Nov 16, 2026
02a8694
fix(lr): retry non-finite HSE ground-state response
maki49 Nov 18, 2026
4ed35a1
Merge remote-tracking branch 'origin/develop' into lr-xc-fixes
maki49 Nov 18, 2026
788fc80
docs(lr): remove response notes from the PR branch
maki49 Nov 18, 2026
645563d
fix(lr): include closed- and open-shell virtual-window response in gr…
maki49 Nov 1, 2026
9115410
fix(tests): accept excitation-energy LR force headings
maki49 Nov 18, 2026
7b9f3e7
test(lr): refresh PBE and coarse unrestricted HF references
maki49 Nov 18, 2026
ea4bada
test(lr): allow a second EXX update in unrestricted HF
maki49 Nov 18, 2026
8dfbd33
fix(lr): address review feedback and test triplet window output
maki49 Nov 19, 2026
0e16d39
fix(lr): clarify window limits and isolate density reruns
maki49 Nov 19, 2026
961e66f
Merge origin/develop into lr-xc-fixes
maki49 Nov 21, 2026
6313c42
Merge origin/develop into lr-xc-fixes
maki49 Nov 23, 2026
2b37609
Address LR force reporting and XC review feedback
maki49 Nov 25, 2026
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
2 changes: 2 additions & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,8 @@ OBJS_LR_GRAD=lr_force.o\
grad_jt.o\
gradient_output.o\
lr_grad_cs.o\
window_response.o\
window_response_math.o\
lr_grad_os.o\
exx_proj.o\
cvcx_serial.o\
Expand Down
25 changes: 17 additions & 8 deletions source/source_esolver/esolver_lr_grad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "source_lcao/module_lr/gradient_output.h"
#include "source_lcao/module_lr/lr_amp.h"
#include "source_lcao/module_lr/lr_force.h"
#include "source_lcao/module_lr/window_response.h"
#include "source_lcao/module_lr/zeq_solver.h"
#include <algorithm>
#include <complex>
Expand Down Expand Up @@ -71,7 +72,11 @@ ct::Tensor ModuleESolver::ESolver_LR<T, TR>::pad_X_to_z_(const int ispin, const
}

template <typename T, typename TR>
ct::Tensor ModuleESolver::ESolver_LR<T, TR>::solve_zvector_eqation(const int ispin, const int nst, const ct::Tensor &Xz)
ct::Tensor ModuleESolver::ESolver_LR<T, TR>::solve_zvector_eqation(
const int ispin,
const int nst,
const ct::Tensor &Xz,
const std::vector<std::vector<ct::Tensor>> &window_density)
{
ModuleBase::TITLE("ESolver_LR", "cal_force");
ModuleBase::timer::start("ESolver_LR", "solve_zvector_eqation");
Expand All @@ -91,7 +96,7 @@ ct::Tensor ModuleESolver::ESolver_LR<T, TR>::solve_zvector_eqation(const int isp
std::weak_ptr<PotHxcLR> pot_weak = inputs.pot[ispin];
Z_vector_equation(
inputs, x_data, z_data, nst, pot_weak, this->spin_types[ispin], this->in_dir, this->openshell,
this->inp_->lr_grad_solver);
this->inp_->lr_grad_solver, window_density);
ModuleBase::timer::end("ESolver_LR", "solve_zvector_eqation");
return Z;
}
Expand Down Expand Up @@ -149,9 +154,11 @@ std::vector<ModuleBase::matrix> ModuleESolver::ESolver_LR<T, TR>::cal_force_Xz(
ModuleBase::timer::start("ESolver_LR", "cal_force_Xz");
const int nst = static_cast<int>(omega.size());
const int channel = ispin;
const ct::Tensor Z = this->solve_zvector_eqation(channel, nst, Xz);
const auto dm_gs = this->cal_dm_gs();
const LR::GradientInputs<T> inputs = this->gradient_inputs_();
const LR::WindowResponse<T> window
= LR::build_window_response(inputs, Xz, nst, this->nvirt[0], ispin, this->in_dir);
const ct::Tensor Z = this->solve_zvector_eqation(channel, nst, Xz, window.density);
const auto dm_gs = this->cal_dm_gs();
const LR::ForceSettings force_settings{
this->nspin, this->inp_->test_force, this->inp_->vl_in_h, this->inp_->vh_in_h, this->inp_->dft_functional};
LR_Force<T> force_terms(
Expand All @@ -162,7 +169,8 @@ std::vector<ModuleBase::matrix> ModuleESolver::ESolver_LR<T, TR>::cal_force_Xz(
inputs.exx_lri, inputs.hybrid_alpha
#endif
);
const auto forces = LR::evaluate_closed_shell_force(inputs, force_terms, dm_gs, Xz, Z, omega, label_begin, ispin);
const auto forces =
LR::evaluate_closed_shell_force(inputs, force_terms, dm_gs, Xz, Z, omega, label_begin, ispin, window);
ModuleBase::timer::end("ESolver_LR", "cal_force_Xz");
return forces;
}
Expand Down Expand Up @@ -346,9 +354,10 @@ std::vector<ModuleBase::matrix> ModuleESolver::ESolver_LR<T, TR>::cal_force_open
ModuleBase::timer::start("ESolver_LR", "cal_force_openshell_Xz");
const int nst = static_cast<int>(omega.size());
const int channel = 0;
const ct::Tensor Z = this->solve_zvector_eqation(channel, nst, Xz);
const auto dm_gs = this->cal_dm_gs();
const LR::GradientInputs<T> inputs = this->gradient_inputs_();
const LR::WindowResponse<T> window = LR::build_open_shell_window_response(inputs, Xz, nst, this->nvirt);
const ct::Tensor Z = this->solve_zvector_eqation(channel, nst, Xz, window.density);
const auto dm_gs = this->cal_dm_gs();
const LR::ForceSettings force_settings{
this->nspin, this->inp_->test_force, this->inp_->vl_in_h, this->inp_->vh_in_h, this->inp_->dft_functional};
LR_Force<T> force_terms(
Expand All @@ -359,7 +368,7 @@ std::vector<ModuleBase::matrix> ModuleESolver::ESolver_LR<T, TR>::cal_force_open
inputs.exx_lri, inputs.hybrid_alpha
#endif
);
const auto forces = LR::evaluate_open_shell_force(inputs, force_terms, dm_gs, Xz, Z, omega, label_begin);
const auto forces = LR::evaluate_open_shell_force(inputs, force_terms, dm_gs, Xz, Z, omega, label_begin, window);
ModuleBase::timer::end("ESolver_LR", "cal_force_openshell_Xz");
return forces;
}
Expand Down
16 changes: 14 additions & 2 deletions source/source_esolver/esolver_lr_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ void ModuleESolver::ESolver_LR<T, TR>::runner(BaseCell &basecell, const int iste
this->spin_types =
this->openshell ? std::vector<std::string>({"updown"}) : std::vector<std::string>({"singlet", "triplet"});

if (this->nspin == 1)
{
this->spin_types = {this->inp_->lr_target_spin};
Comment thread
maki49 marked this conversation as resolved.
Resolved
}

// a relaxation writes these once per ionic step; without the suffix every step would overwrite
// the last, and the trajectory would be impossible to inspect afterwards
const std::string step_suffix = this->excited_relax_ ? "_step" + std::to_string(istep) : "";
Expand Down Expand Up @@ -203,6 +208,11 @@ void ModuleESolver::ESolver_LR<T, TR>::runner(BaseCell &basecell, const int iste
}
}
}
if (this->ks_ && this->inp_->cal_force && !this->excited_relax_)
{
// Cache the KS force shared by all single-point excited states.
this->ks_->cal_force(ucell, this->force_gs_);
}
if (this->excited_relax_)
{
// Re-select which root to follow BEFORE taking the gradient, so the force belongs to
Expand Down Expand Up @@ -266,15 +276,17 @@ void ModuleESolver::ESolver_LR<T, TR>::after_all_runners(BaseCell &basecell)
for (int is = 0; is < this->nspin; ++is)
{
const T *const amplitudes = this->X[0].template data<T>();
lr_density.output_eh_density_all_states(amplitudes, is, nstates, this->ofs_running_);
const std::string density_label = is == 0 ? "up" : "down";
lr_density.output_eh_density_all_states(amplitudes, is, nstates, density_label, this->ofs_running_);
}
}
else
{
for (int is = 0; is < this->X.size(); ++is)
{
const T *const amplitudes = this->X[is].template data<T>();
lr_density.output_eh_density_all_states(amplitudes, is, nstates, this->ofs_running_);
lr_density.output_eh_density_all_states(
amplitudes, is, nstates, this->spin_types[is], this->ofs_running_);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion source/source_esolver/esolver_lr_lcao_tddft.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ class ESolver_LR : public ModuleESolver::ESolver_FP
///========================== for gradient calculation =========================
void init_pot_groundstate(const Charge &chg_gs);
/// Solve the Z-vector equation for `nst` independent blocks of `Xz`.
ct::Tensor solve_zvector_eqation(const int ispin, const int nst, const ct::Tensor &Xz);
ct::Tensor solve_zvector_eqation(
const int ispin,
const int nst,
const ct::Tensor &Xz,
const std::vector<std::vector<ct::Tensor>> &window_density);
/// Excited-state gradients d(Omega)/dR, one matrix per state solved. `istate_only >= 0`
/// restricts it to that one state: geometry relaxation follows a single state, and the
/// Z-vector solve dominates the cost. -1 does all `nstates`.
Expand Down
9 changes: 7 additions & 2 deletions source/source_esolver/esolver_lr_orb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "source_lcao/module_lr/ri_benchmark/ri_benchmark.h"
#include "source_lcao/module_lr/utils/lr_util.h"
#include <algorithm>
#include <type_traits>

using namespace LR;

Expand Down Expand Up @@ -281,8 +282,12 @@ void ModuleESolver::ESolver_LR<T, TR>::fill_z_window_(const int *desc_src)
// the same windows. Diagnose once, without changing the truncated eigenproblem.
if (!this->ks_initialized_)
{
const std::string warning =
LR_Util::force_window_warning(this->nbasis, this->eig_ks_all.nc, start_band, this->nvirt, this->nvirt_z_);
// Real-Gamma forces include the virtual-window response for both spin formulations.
// Retain diagnostics for missing occupied orbitals and uncomputed bands.
const bool virtual_response = std::is_same<T, double>::value && this->nk == 1 && start_band == 0;
const auto &diagnosed_virtuals = virtual_response ? this->nvirt_z_ : this->nvirt;
const std::string warning = LR_Util::force_window_warning(
this->nbasis, this->eig_ks_all.nc, start_band, diagnosed_virtuals, this->nvirt_z_);
if (!warning.empty())
{
this->ofs_running_ << warning << std::endl;
Expand Down
18 changes: 8 additions & 10 deletions source/source_esolver/esolver_lr_rlx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,13 @@ void ModuleESolver::ESolver_LR<T, TR>::setup_relax_target_()
"triplet are separate states with separate gradients. Pick one of them, or set "
"lr_unrestricted to run spin-unrestricted.");
}
this->target_is_ = (spin == "triplet") ? 1 : 0;
if (this->target_is_ >= this->nspin)
{
ModuleBase::WARNING_QUIT(
"ESolver_LR", "lr_target_spin=triplet requires nspin=2: the triplet channel is not built here.");
}
this->target_is_ = (spin == "triplet" && this->nspin == 2) ? 1 : 0;
}
this->force_gs_.create(this->ucell_->nat, 3);
this->lr_force_.create(this->ucell_->nat, 3);
this->target_state_ = this->inp_->lr_target_state; // seed; overlap takes over from step 2
this->ofs_running_ << " Excited-state relaxation follows state " << this->inp_->lr_target_state << " of the "
<< (this->openshell ? "updown" : (this->target_is_ == 1 ? "triplet" : "singlet"))
<< (this->openshell ? "updown" : this->inp_->lr_target_spin)
<< " channel, tracked by cross-geometry orbital and amplitude overlap." << std::endl;
}

Expand Down Expand Up @@ -133,6 +128,10 @@ void ModuleESolver::ESolver_LR<T, TR>::cal_force(BaseCell &basecell, ModuleBase:
{
basecell.require_kind(BaseCell::Kind::unitcell, __FUNCTION__);
const UnitCell &ucell = static_cast<const UnitCell &>(basecell);
if (this->ks_ && this->force_gs_.nr == ucell.nat)
{
ModuleIO::print_force(this->ofs_running_, ucell, "GROUND-STATE FORCE (eV/Angstrom)", this->force_gs_, false);
}
if (!this->excited_relax_)
{ // single-point runs print the gradients of every state from `after_all_runners` instead
return;
Expand All @@ -143,9 +142,8 @@ void ModuleESolver::ESolver_LR<T, TR>::cal_force(BaseCell &basecell, ModuleBase:
"ESolver_LR::cal_force", "the excited-state gradient has not been computed for this geometry.");
}
// Both halves already follow the ABACUS force convention F = -dE/dR (Ry/Bohr), so they add.
// The "Gradients of each excited state" heading that `cal_force(int)` prints under is a
// misnomer: the finite-difference reference it was validated against (`abacus-fd lr-custom`)
// computes (E(-h) - E(+h))/h, which is -d(Omega)/dR, and the two agree in sign.
// The per-state LR table reports the excitation-energy contribution -d(Omega)/dR;
// adding the ground-state force gives the total force on the excited-state surface.
force.create(ucell.nat, 3);
force = this->force_gs_ + this->lr_force_;
ModuleIO::print_force(this->ofs_running_, ucell, "EXCITED-STATE TOTAL-FORCE (eV/Angstrom)", force, false);
Expand Down
2 changes: 1 addition & 1 deletion source/source_io/module_parameter/input_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ struct Input_para
// ============== #Parameters (10.lr-tddft) ===========================
int lr_nstates = 1; ///< the number of 2-particle states to be solved
int lr_target_state = 0; ///< which excited state the geometry relaxation follows (0-based)
std::string lr_target_spin = "singlet"; ///< spin channel of that state: singlet / triplet / updown
std::string lr_target_spin = "singlet"; ///< nspin=1 LR channel, or relaxation target at nspin=2: singlet / triplet / updown
double lr_degen_thr
= 0.0; ///< max excitation-energy spread of a degenerate multiplet whose gradient matrix is computed (Ry); 0 disables
std::string lr_degen_mode = "state"; ///< what a relaxation follows when the target state sits in a degenerate multiplet: state / average
Expand Down
Loading
Loading