Skip to content

feat(solver): Implement the Self-Consistent QEq Solver Engine#8

Merged
TKanX merged 7 commits intomainfrom
feature/7-implement-the-self-consistent-qeq-solver-engine
Oct 21, 2025
Merged

feat(solver): Implement the Self-Consistent QEq Solver Engine#8
TKanX merged 7 commits intomainfrom
feature/7-implement-the-self-consistent-qeq-solver-engine

Conversation

@TKanX
Copy link
Member

@TKanX TKanX commented Oct 21, 2025

Summary:

Introduces the core computational engine of the cheq library: a robust, self-consistent Charge Equilibration (QEq) solver. A new solver module has been created, featuring a QEqSolver that constructs and iteratively solves the QEq linear system to determine atomic partial charges. The implementation handles both linear (non-H) and non-linear (H-containing) systems, incorporates a flexible options structure, and uses the high-performance faer crate for all linear algebra operations.

Changes:

  • Implemented the QEqSolver:

    • Created a QEqSolver struct responsible for orchestrating the entire charge calculation process.
    • Implemented the main solve method, which takes a slice of atoms and a total charge, and returns a CalculationResult.
    • The solver correctly handles the charge-dependent hardness of hydrogen atoms, triggering an iterative Self-Consistent Field (SCF) process until convergence is reached.
  • Developed the Linear System Builder:

    • Implemented the build_system method, which dynamically constructs the QEq matrix (A) and vector (b) for each SCF iteration.
    • Diagonal Elements (Hardness): The diagonal of the matrix is populated with atomic hardness (J_ii), including the special non-linear term for hydrogen.
    • Off-Diagonal Elements (Shielding): Off-diagonal elements are populated using the gaussian_coulomb_integral function to calculate the shielded Coulomb interaction (J_ij).
    • Charge Constraint: The system is augmented with an additional row and column to enforce the total charge constraint (sum(q_i) = Q_total).
  • Integrated a High-Performance Linear Algebra Backend:

    • Added the faer crate as a dependency for fast and robust linear algebra operations.
    • The solver uses faer's partial-pivoting LU decomposition (partial_piv_lu) to solve the linear system in each iteration.
    • Implemented panic-safe error handling around the solve call to gracefully manage potential linear algebra failures (e.g., singular matrices).
  • Added Solver Configuration Options:

    • Created a SolverOptions struct to allow users to configure the solver's behavior, including tolerance, max_iterations, and the shielding scale factor lambda_scale.
    • The QEqSolver can be instantiated with custom options via the with_options builder method.
  • Included Comprehensive Solver Tests:

    • Developed an extensive test suite covering various chemical systems:
      • Linear System: Carbon monoxide (CO).
      • Non-Linear System: Water (H₂O).
      • Symmetry: Dihydrogen (H₂).
      • Ionic System: Lithium hydride (LiH).
    • Tests verify charge conservation, chemical trends (NaCl vs. NaBr), and correct error handling for edge cases like empty input, missing parameters, and non-convergence.

@TKanX TKanX self-assigned this Oct 21, 2025
Copilot AI review requested due to automatic review settings October 21, 2025 20:52
@TKanX TKanX added the enhancement ✨ New feature or request label Oct 21, 2025
@TKanX TKanX linked an issue Oct 21, 2025 that may be closed by this pull request
44 tasks
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces the core QEq (Charge Equilibration) solver engine that computes atomic partial charges through an iterative self-consistent field approach. The implementation uses the high-performance faer linear algebra library and handles both linear systems (non-hydrogen atoms) and non-linear systems (hydrogen-containing molecules with charge-dependent hardness).

Key Changes:

  • Implemented QEqSolver with iterative SCF convergence for charge-dependent hydrogen hardness
  • Built dynamic linear system construction with Gaussian-shielded Coulomb interactions and charge constraints
  • Integrated faer crate for robust LU-decomposition-based linear system solving

Reviewed Changes

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

Show a summary per file
File Description
src/solver/options.rs Defines configurable solver parameters (tolerance, max iterations, lambda scale)
src/solver/mod.rs Module declaration exposing QEqSolver and SolverOptions
src/solver/implementation.rs Core solver implementation with system builder, SCF loop, and comprehensive test suite
src/lib.rs Adds solver module to library public API
Cargo.toml Adds faer dependency for linear algebra operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@TKanX TKanX merged commit 9c366f9 into main Oct 21, 2025
2 checks passed
@TKanX TKanX deleted the feature/7-implement-the-self-consistent-qeq-solver-engine branch October 21, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement ✨ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the Self-Consistent QEq Solver Engine

2 participants