|
ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
|
Namespaces | |
| namespace | pw |
Classes | |
| struct | ScInitParams |
| struct | ScAtomData |
| Per-atom spin constraint parameters parsed from STRU file. More... | |
| class | ScState |
| class | SpinConstrain |
| Singleton class implementing spin-constrained DFT (DeltaSpin). More... | |
| class | SpinConstrainTest |
Functions | |
| void | init_sc_state (const ScInitParams ¶ms, const UnitCell &ucell, ScState &state) |
| Populate ScState from UnitCell and input parameters. | |
| template<typename TK> | |
| void | print_termination (const SpinConstrain< TK > &sc, std::ostream &ofs_running) |
| Print final spin and lambda values when the lambda loop terminates. | |
| template<typename TK> | |
| bool | check_rms_stop (const SpinConstrain< TK > &sc, int outer_step, int i_step, double rms_error, double duration, double total_duration, std::ostream &ofs_running) |
| Check if RMS error is below convergence threshold or max steps reached. | |
| template<typename TK> | |
| void | print_header (const SpinConstrain< TK > &sc, std::ostream &ofs_running) |
| Print header at start of lambda optimization loop. | |
| template<typename TK> | |
| void | check_restriction (const SpinConstrain< TK > &sc, const std::vector< ModuleBase::Vector3< double > > &search, double &alpha_trial, std::ostream &ofs_running) |
| Cap step size to prevent overshooting in lambda optimization. | |
| template<typename TK> | |
| double | cal_alpha_opt (const SpinConstrain< TK > &sc, std::vector< ModuleBase::Vector3< double > > spin, std::vector< ModuleBase::Vector3< double > > spin_plus, const double alpha_trial) |
| Compute optimal step size via linear interpolation. | |
| template<typename TK> | |
| bool | check_gradient_decay (const SpinConstrain< TK > &sc, const std::vector< ModuleBase::Vector3< double > > &new_spin, const std::vector< ModuleBase::Vector3< double > > &spin, const std::vector< ModuleBase::Vector3< double > > &delta_lambda, const std::vector< ModuleBase::Vector3< double > > &dnu_last_step, bool print, std::ostream &ofs_running) |
| Check if the magnetic susceptibility gradient dM/dlambda has decayed below threshold. | |
| template<typename TK> | |
| void | print_Mi (const SpinConstrain< TK > &sc, std::ostream &ofs_running) |
| Print atomic magnetic moments Mi in a formatted table. | |
| template<typename TK> | |
| void | print_Mag_Force (const SpinConstrain< TK > &sc, std::ostream &ofs_running) |
| Print the magnetic force (-lambda) per atom in eV/uB. | |
| template void | print_termination< std::complex< double > > (const SpinConstrain< std::complex< double > > &, std::ostream &) |
| template bool | check_rms_stop< std::complex< double > > (const SpinConstrain< std::complex< double > > &, int, int, double, double, double, std::ostream &) |
| template void | print_header< std::complex< double > > (const SpinConstrain< std::complex< double > > &, std::ostream &) |
| template void | check_restriction< std::complex< double > > (const SpinConstrain< std::complex< double > > &, const std::vector< ModuleBase::Vector3< double > > &, double &, std::ostream &) |
| template double | cal_alpha_opt< std::complex< double > > (const SpinConstrain< std::complex< double > > &, std::vector< ModuleBase::Vector3< double > >, std::vector< ModuleBase::Vector3< double > >, const double) |
| template bool | check_gradient_decay< std::complex< double > > (const SpinConstrain< std::complex< double > > &, const std::vector< ModuleBase::Vector3< double > > &, const std::vector< ModuleBase::Vector3< double > > &, const std::vector< ModuleBase::Vector3< double > > &, const std::vector< ModuleBase::Vector3< double > > &, bool, std::ostream &) |
| template void | print_Mi< std::complex< double > > (const SpinConstrain< std::complex< double > > &, std::ostream &) |
| template void | print_Mag_Force< std::complex< double > > (const SpinConstrain< std::complex< double > > &, std::ostream &) |
| template void | print_Mi< double > (const SpinConstrain< double > &, std::ostream &) |
| template void | print_Mag_Force< double > (const SpinConstrain< double > &, std::ostream &) |
| void | accumulate_Mi_from_becp (const std::complex< double > *becp, int nkb, int nbands, int npol, int spin_sign, const double *wg_ik, const int *nh_iat, std::vector< ModuleBase::Vector3< double > > &mi) |
| Accumulate atomic magnetic moments from becp coefficients for one k-point. | |
| std::array< std::complex< double >, 4 > | pauli_vector_to_spinor (const ModuleBase::Vector3< double > &lambda) |
| Convert a Cartesian Pauli vector to a spinor-space operator. | |
| ModuleBase::Vector3< double > | pauli_to_moment (const std::complex< double > occ[4], double weight) |
| Convert spinor occupation matrix to magnetic moment vector using Pauli matrices. | |
| TEST (LambdaLoopHelper, GradientDecayUsesAtomsOfEachType) | |
Tested function:
| void spinconstrain::accumulate_Mi_from_becp | ( | const std::complex< double > * | becp, |
| int | nkb, | ||
| int | nbands, | ||
| int | npol, | ||
| int | spin_sign, | ||
| const double * | wg_ik, | ||
| const int * | nh_iat, | ||
| std::vector< ModuleBase::Vector3< double > > & | mi ) |
Accumulate atomic magnetic moments from becp coefficients for one k-point.
For npol=2 (nspin=4), computes full Pauli decomposition: occ[0] = sum(becp_up^* * becp_up), occ[1] = sum(becp_up^* * becp_dn), occ[2] = sum(becp_dn^* * becp_up), occ[3] = sum(becp_dn^* * becp_dn) Mi = pauli_to_moment(occ, weight) For npol=1 (nspin=2), only z-component: occ = sum(|becp|^2), Mi.z += weight * occ * spin_sign
| becp | Projector coefficients <alpha_{l,m}|psi_{k,i}> |
| nkb | Total number of projectors |
| nbands | Number of bands |
| npol | Number of spinor components (1 for collinear, 2 for non-collinear) |
| spin_sign | +1 for spin-up, -1 for spin-down (nspin=2 only); unused for npol=2 |
| wg_ik | Band occupation weights for this k-point (from Fermi-Dirac) |
| nh_iat | Array of projector counts per atom: nh_iat[iat] = nproj for atom iat |
| mi | [in,out] Magnetic moments vector to accumulate into (size = nat) |
| double spinconstrain::cal_alpha_opt | ( | const SpinConstrain< TK > & | sc, |
| std::vector< ModuleBase::Vector3< double > > | spin, | ||
| std::vector< ModuleBase::Vector3< double > > | spin_plus, | ||
| const double | alpha_trial ) |
Compute optimal step size via linear interpolation.
Compute the optimal step size via two-point linear interpolation.
alpha_opt = sum_k / sum_k2 * alpha_trial
where: sum_k = sum((target - spin) . (spin_plus - spin)) over constrained components sum_k2 = sum(|spin - spin_plus|^2) over constrained components
| sc | SpinConstrain instance |
| spin | Mi at current lambda |
| spin_plus | Mi at trial lambda (current + alpha_trial * search) |
| alpha_trial | Current trial step size |
| template double spinconstrain::cal_alpha_opt< std::complex< double > > | ( | const SpinConstrain< std::complex< double > > & | , |
| std::vector< ModuleBase::Vector3< double > > | , | ||
| std::vector< ModuleBase::Vector3< double > > | , | ||
| const double | ) |
| bool spinconstrain::check_gradient_decay | ( | const SpinConstrain< TK > & | sc, |
| const std::vector< ModuleBase::Vector3< double > > & | new_spin, | ||
| const std::vector< ModuleBase::Vector3< double > > & | spin, | ||
| const std::vector< ModuleBase::Vector3< double > > & | delta_lambda, | ||
| const std::vector< ModuleBase::Vector3< double > > & | dnu_last_step, | ||
| bool | print, | ||
| std::ostream & | ofs_running ) |
Check if the magnetic susceptibility gradient dM/dlambda has decayed below threshold.
Check whether the magnetic susceptibility gradient dM/dlambda has decayed below the per-atom-type threshold.
| sc | SpinConstrain instance |
| new_spin | Mi at current lambda |
| spin | Mi at previous lambda |
| delta_lambda | Current lambda change |
| dnu_last_step | Previous cumulative step |
| Whether to print detailed gradient info | |
| ofs_running | Log output stream |
| template bool spinconstrain::check_gradient_decay< std::complex< double > > | ( | const SpinConstrain< std::complex< double > > & | , |
| const std::vector< ModuleBase::Vector3< double > > & | , | ||
| const std::vector< ModuleBase::Vector3< double > > & | , | ||
| const std::vector< ModuleBase::Vector3< double > > & | , | ||
| const std::vector< ModuleBase::Vector3< double > > & | , | ||
| bool | , | ||
| std::ostream & | ) |
| void spinconstrain::check_restriction | ( | const SpinConstrain< TK > & | sc, |
| const std::vector< ModuleBase::Vector3< double > > & | search, | ||
| double & | alpha_trial, | ||
| std::ostream & | ofs_running ) |
Cap step size to prevent overshooting in lambda optimization.
Cap the step size to prevent the optimizer from overshooting.
If |alpha_trial * max(search)| > restrict_current_, reduce alpha_trial so that the maximum lambda change per step is bounded by restrict_current_.
This prevents the optimizer from taking steps that are too large, which could lead to oscillation or divergence.
"boundary after = X eV/uB": The actual maximum lambda change
If |alpha_trial * max(search)| exceeds restrict_current_, the trial step is reduced so that the maximum lambda change per step is bounded. alpha_trial is modified in place.
| sc | SpinConstrain instance |
| search | Current search direction (per atom, 3 components) |
| alpha_trial | Trial step size, modified in place if capped |
| ofs_running | Log output stream |
| template void spinconstrain::check_restriction< std::complex< double > > | ( | const SpinConstrain< std::complex< double > > & | , |
| const std::vector< ModuleBase::Vector3< double > > & | , | ||
| double & | , | ||
| std::ostream & | ) |
| bool spinconstrain::check_rms_stop | ( | const SpinConstrain< TK > & | sc, |
| int | outer_step, | ||
| int | i_step, | ||
| double | rms_error, | ||
| double | duration, | ||
| double | total_duration, | ||
| std::ostream & | ofs_running ) |
Check if RMS error is below convergence threshold or max steps reached.
Check whether RMS error is below the convergence threshold or the maximum number of inner steps has been reached.
| sc | SpinConstrain instance |
| outer_step | Current SCF outer iteration |
| i_step | Current inner lambda step |
| rms_error | Current RMS error of Mi - M_target |
| duration | Wall time for this step (s) |
| total_duration | Cumulative wall time for the inner loop (s) |
| ofs_running | Log output stream |
| template bool spinconstrain::check_rms_stop< std::complex< double > > | ( | const SpinConstrain< std::complex< double > > & | , |
| int | , | ||
| int | , | ||
| double | , | ||
| double | , | ||
| double | , | ||
| std::ostream & | ) |
| void spinconstrain::init_sc_state | ( | const ScInitParams & | params, |
| const UnitCell & | ucell, | ||
| ScState & | state ) |
Populate ScState from UnitCell and input parameters.
Performs the solver-independent portion of init_sc():
| params | Input parameters (see ScInitParams) |
| ucell | Unit cell with STRU constraint data |
| state | ScState to fill (in/out) |
|
inline |
Convert spinor occupation matrix to magnetic moment vector using Pauli matrices.
For a two-component spinor wavefunction, the occupation array is: occ = |a|^2 a^*b | = | (1+Mz)/2 (Mx+iMy)/2 | |b^*a |b|^2 | | (Mx-iMy)/2 (1-Mz)/2 | In this bra-first storage convention, the magnetic moment components are: Mx = occ[1] + occ[2] (real part) My = Im(occ[1] - occ[2]) Mz = occ[0] - occ[3] (real part) where occ = {|a|^2, a^*b, b^*a, |b|^2} from becp coefficients.
| occ | 4-element array of occupation matrix elements (complex) |
| weight | k-point weight for integration |
|
inline |
Convert a Cartesian Pauli vector to a spinor-space operator.
For sigma_y = [[0, -i], [i, 0]], lambda dot sigma is stored in row-major order as {lambda_z, lambda_x - i lambda_y, lambda_x + i lambda_y, -lambda_z}.
| void spinconstrain::print_header | ( | const SpinConstrain< TK > & | sc, |
| std::ostream & | ofs_running ) |
Print header at start of lambda optimization loop.
Print header at the start of the lambda optimization loop.
| sc | SpinConstrain instance |
| ofs_running | Log output stream |
| template void spinconstrain::print_header< std::complex< double > > | ( | const SpinConstrain< std::complex< double > > & | , |
| std::ostream & | ) |
| void spinconstrain::print_Mag_Force | ( | const SpinConstrain< TK > & | sc, |
| std::ostream & | ofs_running ) |
Print the magnetic force (-lambda) per atom in eV/uB.
Lifted from SpinConstrain<TK>::print_Mag_Force; accesses state via getters. lambda is read via get_sc_lambda() and converted from Ry to eV on output.
| sc | SpinConstrain instance |
| ofs_running | Log output stream |
| template void spinconstrain::print_Mag_Force< double > | ( | const SpinConstrain< double > & | , |
| std::ostream & | ) |
| template void spinconstrain::print_Mag_Force< std::complex< double > > | ( | const SpinConstrain< std::complex< double > > & | , |
| std::ostream & | ) |
| void spinconstrain::print_Mi | ( | const SpinConstrain< TK > & | sc, |
| std::ostream & | ofs_running ) |
Print atomic magnetic moments Mi in a formatted table.
Lifted from SpinConstrain<TK>::print_Mi; accesses state via getters.
| sc | SpinConstrain instance |
| ofs_running | Log output stream |
| template void spinconstrain::print_Mi< double > | ( | const SpinConstrain< double > & | , |
| std::ostream & | ) |
| template void spinconstrain::print_Mi< std::complex< double > > | ( | const SpinConstrain< std::complex< double > > & | , |
| std::ostream & | ) |
| void spinconstrain::print_termination | ( | const SpinConstrain< TK > & | sc, |
| std::ostream & | ofs_running ) |
Print final spin and lambda values when the lambda loop terminates.
| sc | SpinConstrain instance (read Mi_ and lambda_) |
| ofs_running | Log output stream |
| template void spinconstrain::print_termination< std::complex< double > > | ( | const SpinConstrain< std::complex< double > > & | , |
| std::ostream & | ) |
| spinconstrain::TEST | ( | LambdaLoopHelper | , |
| GradientDecayUsesAtomsOfEachType | ) |