qrunch.chemistry.qrackle.scf.self_consistent_field_solver
Self-consistent field (SCF) solver.
Classes
Self-consistent field solver. |
|
Build SCF solvers that share one-electron calculators and stepper builders. |
|
Options for the SCF solver. |
- class SelfConsistentFieldSolver
Bases:
SelfConsistentFieldSolverProtocol[TSCFMatrix],Generic[TSCFMatrix,TSCFVector,TMatrix,TVector]Self-consistent field solver.
Iteratively solves the Hartree-Fock (or Kohn-Sham) equations until the density matrix converges to self-consistency. An optional stability checker enables post-convergence instability following, which tries to escape orbital saddle points without resetting the iteration budget.
- __init__(scf_matrix_module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], kinetic_calculator: KineticCalculatorProtocol[TMatrix, TVector], nuclear_attraction_calculator: NuclearAttractionCalculatorProtocol[TMatrix, TVector], overlap_calculator: OverlapCalculatorProtocol[TMatrix, TVector], fock_builder: FockBuilderProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], global_scf_stepper: SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], local_scf_stepper: SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], initial_density_builder: InitialDensityProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector] | None = None, options: SelfConsistentFieldSolverOptions | None = None, data_persister_manager: DataPersisterManager | None = None, stability_checker: StabilityCheckerProtocol[TSCFMatrix] | None = None, accelerator: SCFAcceleratorProtocol[TSCFMatrix] | None = None) None
Initialise the SCF solver.
- Parameters:
scf_matrix_module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module for algebraic operations.
kinetic_calculator (KineticCalculatorProtocol[TMatrix, TVector]) – Calculator for the kinetic energy matrix.
nuclear_attraction_calculator (NuclearAttractionCalculatorProtocol[TMatrix, TVector]) – Calculator for the nuclear attraction matrix.
overlap_calculator (OverlapCalculatorProtocol[TMatrix, TVector]) – Calculator for the overlap matrix.
fock_builder (FockBuilderProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – Builder for the Fock (or Kohn-Sham) matrix builder.
global_scf_stepper (SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF stepper used in the global region far from convergence.
local_scf_stepper (SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF stepper used in the local region close to convergence.
initial_density_builder (InitialDensityProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector] | None) – Builder for the initial density. Required when initial_density is not provided.
options (SelfConsistentFieldSolverOptions | None) – Options for the SCF solver. If None, default options are used.
data_persister_manager (DataPersisterManager | None) – Optional manager used to load and save converged SCF results.
stability_checker (StabilityCheckerProtocol[TSCFMatrix] | None) – Optional post-convergence orbital stability checker. If None (the default), a converged density is returned without checking for orbital instabilities.
accelerator (SCFAcceleratorProtocol[TSCFMatrix] | None) – Optional accelerator that improves the initial density of a fresh solve. Final convergence, energy, stability and persistence use the physical Fock builder.
- Return type:
None
- classmethod persistence_checkpoints() list[str]
Define the persistence checkpoints used during the process.
These checkpoints specify computational stages where intermediate results can be saved and loaded to optimize computations and ensure reproducibility.
- Return type:
list[str]
- solve(molecular_configuration: MolecularConfiguration, initial_density: TSCFMatrix | None = None, additional_potential_matrix: TSCFMatrix | None = None) RestrictedMolecularOrbitalCalculatorResult | UnrestrictedMolecularOrbitalCalculatorResult
Run the SCF loop until convergence.
- Parameters:
molecular_configuration (MolecularConfiguration) – The molecular configuration.
initial_density (TSCFMatrix | None) – Optional pre-computed initial density matrix.
additional_potential_matrix (TSCFMatrix | None) – Optional one-electron potential added to the core Hamiltonian.
- Raises:
ValidationError – If the molecular configuration carries a QM/MM environment, which this solver does not apply.
- Return type:
RestrictedMolecularOrbitalCalculatorResult | UnrestrictedMolecularOrbitalCalculatorResult
- with_updated_options(**updates: Unpack[SelfConsistentFieldSolverOptionUpdates]) Self
Return a copy of the solver with updated SCF solver options.
The copy shares calculators, steppers and builders with this solver.
- Parameters:
updates (Unpack[SelfConsistentFieldSolverOptionUpdates]) – Option values to change; omitted options keep their current values.
- Return type:
Self
- class SelfConsistentFieldSolverBuilder
Bases:
SelfConsistentFieldSolverBuilderProtocol[TMatrix,TVector]Build SCF solvers that share one-electron calculators and stepper builders.
- __init__(kinetic_calculator: KineticCalculatorProtocol[TMatrix, TVector], nuclear_attraction_calculator: NuclearAttractionCalculatorProtocol[TMatrix, TVector], overlap_calculator: OverlapCalculatorProtocol[TMatrix, TVector], global_scf_stepper_builder: SCFStepperBuilderProtocol, local_scf_stepper_builder: SCFStepperBuilderProtocol, fallback_scf_stepper_builder: SCFStepperBuilderProtocol, options: SelfConsistentFieldSolverOptions | None = None) None
Initialise the builder.
- Parameters:
kinetic_calculator (KineticCalculatorProtocol[TMatrix, TVector]) – Calculator for the kinetic energy matrix.
nuclear_attraction_calculator (NuclearAttractionCalculatorProtocol[TMatrix, TVector]) – Calculator for the nuclear attraction matrix.
overlap_calculator (OverlapCalculatorProtocol[TMatrix, TVector]) – Calculator for the overlap matrix.
global_scf_stepper_builder (SCFStepperBuilderProtocol) – Builder for the global SCF stepper.
local_scf_stepper_builder (SCFStepperBuilderProtocol) – Builder for the local SCF stepper.
fallback_scf_stepper_builder (SCFStepperBuilderProtocol) – Builder for the steppers’ fallback stepper.
options (SelfConsistentFieldSolverOptions | None) – Options for the created solvers. If None, default options are used.
- Return type:
None
- create_solver(scf_matrix_module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], fock_builder: FockBuilderProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) SelfConsistentFieldSolver[TSCFMatrix, TSCFVector, TMatrix, TVector]
Create an SCF solver with fresh steppers bound to
fock_builder.- Parameters:
scf_matrix_module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module (restricted or unrestricted).
fock_builder (FockBuilderProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – Fock builder that defines the SCF problem.
- Return type:
SelfConsistentFieldSolver[TSCFMatrix, TSCFVector, TMatrix, TVector]
- class SelfConsistentFieldSolverOptions
Bases:
MetadataFromFields,DataclassPublicAPIOptions for the SCF solver.
- Parameters:
max_iterations – Maximum total number of physical SCF iterations, including accelerator physical checks and any post-instability continuation. Following an instability does not reset this budget. Inner approximate-Fock iterations use a separate budget.
convergence_tolerance – Convergence threshold on the gradient (size-consistent RMS Frobenius norm of the error matrix). Convergence also requires a symmetric density, determinant occupations, and the correct electron count in each spin channel.
scf_queue_max_length – Maximum number of Fock/error pairs to retain in the SCF queue.
lienient_convergence – If True, return an unconverged result from the last accepted density when the iteration budget is exhausted. If no trial was accepted, use the final proposal instead.
local_region_gradient_threshold – Gradient norm threshold below which to consider switching to the local stepper.
local_region_gradient_exit_threshold – Gradient norm threshold above which to switch back to the global stepper.
convergence_slope_threshold – Slope threshold of log10(gradient) for switching to the local stepper.
energy_increase_threshold – Energy increase threshold above which energy changes are considered real increases rather than numerical precision noise.
number_of_iterations_for_stability_fit – Number of recent iterations used in the stability fit.
minimum_number_of_iterations_for_stability_fit – Minimum number of iterations required before performing the stability fit.
minimum_number_of_global_iterations_after_fallback – Minimum number of global stepper iterations required after falling back to the global stepper before attempting to switch to the local stepper again.
occupation_tolerance – Tolerance on the orthonormal-basis symmetry and idempotency residuals and the per-spin electron-count errors used to verify density validity before accepting a small gradient as converged.
- __init__(*, max_iterations: int = 100, convergence_tolerance: float = 1e-08, scf_queue_max_length: int = 6, lienient_convergence: bool = False, local_region_gradient_threshold: float = 0.0005, local_region_gradient_exit_threshold: float = 0.001, convergence_slope_threshold: float = -0.2, energy_increase_threshold: float = 1e-07, number_of_iterations_for_stability_fit: int = 3, minimum_number_of_iterations_for_stability_fit: int = 3, minimum_number_of_global_iterations_after_fallback: int = 3, occupation_tolerance: float = 1e-08) None
- Parameters:
max_iterations (int)
convergence_tolerance (float)
scf_queue_max_length (int)
lienient_convergence (bool)
local_region_gradient_threshold (float)
local_region_gradient_exit_threshold (float)
convergence_slope_threshold (float)
energy_increase_threshold (float)
number_of_iterations_for_stability_fit (int)
minimum_number_of_iterations_for_stability_fit (int)
minimum_number_of_global_iterations_after_fallback (int)
occupation_tolerance (float)
- Return type:
None
- convergence_slope_threshold: float = -0.2
- convergence_tolerance: float = 1e-08
- energy_increase_threshold: float = 1e-07
- lienient_convergence: bool = False
- local_region_gradient_exit_threshold: float = 0.001
- local_region_gradient_threshold: float = 0.0005
- max_iterations: int = 100
- minimum_number_of_global_iterations_after_fallback: int = 3
- minimum_number_of_iterations_for_stability_fit: int = 3
- number_of_iterations_for_stability_fit: int = 3
- occupation_tolerance: float = 1e-08
- scf_queue_max_length: int = 6