Skip to main content

QEqSolver

Struct QEqSolver 

Source
pub struct QEqSolver<'p> { /* private fields */ }
Expand description

The main solver for charge equilibration calculations.

This struct holds references to atomic parameters and solver options, providing methods to perform QEq calculations on molecular systems. It implements an iterative SCF procedure to solve the non-linear charge equilibration equations.

Implementations§

Source§

impl<'p> QEqSolver<'p>

Source

pub fn new(parameters: &'p Parameters) -> Self

Creates a new QEqSolver with default options.

§Arguments
  • parameters - A reference to the Parameters containing element data.
§Returns

A new QEqSolver instance with default SolverOptions.

§Examples
use cheq::get_default_parameters;
use cheq::QEqSolver;

let params = get_default_parameters();
let solver = QEqSolver::new(params);
Source

pub fn with_options(self, options: SolverOptions) -> Self

Configures the solver with custom options.

This method allows setting non-default solver parameters such as tolerance and maximum iterations. It consumes the solver and returns a new instance with the updated options.

§Arguments
  • options - The SolverOptions to apply to the solver.
§Returns

A new QEqSolver instance with the specified options.

§Examples
use cheq::get_default_parameters;
use cheq::{QEqSolver, SolverOptions};

let params = get_default_parameters();
let options = SolverOptions {
    max_iterations: 100,
    tolerance: 1e-6,
    ..Default::default()
};

let solver = QEqSolver::new(params).with_options(options);
Source

pub fn solve<A: AtomView>( &self, atoms: &[A], total_charge: f64, ) -> Result<CalculationResult, CheqError>

Solves the charge equilibration equations for a given molecular system.

This method performs the SCF iterative procedure to compute partial atomic charges that equalize the chemical potential across all atoms, subject to the total charge constraint. The process involves building and solving a linear system in each iteration, with special handling for hydrogen atoms whose hardness depends on their charge.

§Arguments
  • atoms - A slice of atom data implementing the AtomView trait.
  • total_charge - The desired total charge of the system.
§Returns

A Result containing CalculationResult with the computed charges and metadata on success, or a CheqError on failure.

§Errors
  • CheqError::NoAtoms - If the input atom list is empty.
  • CheqError::ParameterNotFound - If an atom’s parameters are missing.
  • CheqError::NotConverged - If the SCF procedure fails to converge within the maximum iterations.
  • CheqError::LinalgError - If the linear system solver encounters an error.
§Examples
use cheq::get_default_parameters;
use cheq::QEqSolver;
use cheq::Atom;

// 1. Setup parameters and solver
let params = get_default_parameters();
let solver = QEqSolver::new(params);

// 2. Define a molecule (e.g., H2)
let atoms = vec![
    Atom { atomic_number: 1, position: [0.0, 0.0, 0.0] },
    Atom { atomic_number: 1, position: [0.74, 0.0, 0.0] },
];

// 3. Run calculation
let result = solver.solve(&atoms, 0.0).unwrap();

assert_eq!(result.charges.len(), 2);
println!("Charges: {:?}", result.charges);
Source

pub fn solve_in_field<A: AtomView>( &self, atoms: &[A], total_charge: f64, external: &ExternalPotential, ) -> Result<CalculationResult, CheqError>

Solves the charge equilibration equations in the presence of an external electrostatic field.

This method extends the standard QEq calculation to include the effect of an external electrostatic environment on the charge distribution. The external potential modifies the effective electronegativity of each atom, allowing the QEq subsystem to polarize in response to its surroundings.

§Arguments
  • atoms - A slice of atom data implementing the AtomView trait.
  • total_charge - The desired total charge of the QEq subsystem.
  • external - The external electrostatic potential acting on the system.
§Returns

A Result containing CalculationResult with the computed charges and metadata on success, or a CheqError on failure.

§Errors
  • CheqError::NoAtoms - If the input atom list is empty.
  • CheqError::ParameterNotFound - If parameters are missing for any atom (QEq or external).
  • CheqError::NotConverged - If the SCF procedure fails to converge.
  • CheqError::LinalgError - If the linear system solver encounters an error.
§Examples
use cheq::{get_default_parameters, QEqSolver, Atom, ExternalPotential, PointCharge};

let params = get_default_parameters();
let solver = QEqSolver::new(params);

// A simple diatomic molecule
let ligand = vec![
    Atom { atomic_number: 6, position: [0.0, 0.0, 0.0] },
    Atom { atomic_number: 8, position: [1.2, 0.0, 0.0] },
];

// An external positive charge nearby
let external = ExternalPotential::from_point_charges(vec![
    PointCharge::new(7, [3.0, 0.0, 0.0], 0.5),
]);

let result = solver.solve_in_field(&ligand, 0.0, &external).unwrap();

// The oxygen should become more negative due to the nearby positive charge
println!("C charge: {:.4}, O charge: {:.4}", result.charges[0], result.charges[1]);

Auto Trait Implementations§

§

impl<'p> Freeze for QEqSolver<'p>

§

impl<'p> RefUnwindSafe for QEqSolver<'p>

§

impl<'p> Send for QEqSolver<'p>

§

impl<'p> Sync for QEqSolver<'p>

§

impl<'p> Unpin for QEqSolver<'p>

§

impl<'p> UnsafeUnpin for QEqSolver<'p>

§

impl<'p> UnwindSafe for QEqSolver<'p>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V