SciPySolver

class openff.recharge.charges.resp.solvers.SciPySolver(method: Literal['SLSQP', 'trust-constr'] = 'SLSQP')[source]

Bases: RESPNonLinearSolver

Attempts to find a set of charges that minimizes the RESP loss function using the scipy.optimize.minimize function.

Methods

__init__([method])

Parameters

method -- The minimizer to use.

initial_guess(design_matrix, ...)

Compute an initial guess of the charge values by solving the lagrangian constrained Ax + b equations using harmonic rather than hyperbolic restraints.

jacobian(beta, design_matrix, ...)

Returns the jacobian of the loss function with respect to beta.

loss(beta, design_matrix, reference_values, ...)

Returns the current value of the loss function complete with restraints on specified charges.

solve(design_matrix, reference_values, ...)

Attempts to find a minimum solution to the RESP loss function.

__init__(method: Literal['SLSQP', 'trust-constr'] = 'SLSQP')[source]
Parameters

method – The minimizer to use.

classmethod initial_guess(design_matrix: ndarray, reference_values: ndarray, constraint_matrix: ndarray, constraint_values: ndarray, restraint_a: float, restraint_indices: List[int], n_conformers: int) ndarray

Compute an initial guess of the charge values by solving the lagrangian constrained Ax + b equations using harmonic rather than hyperbolic restraints.

Parameters
  • design_matrix – The design matrix that when right multiplied by beta yields the ESP due to the charges applied to the molecule of interest with shape=(n_grid_points, n_values)

  • reference_values – The reference ESP values with shape=(n_grid_points, 1).

  • constraint_matrix – A matrix that when right multiplied by the vector of charge values should yield a vector that is equal to constraint_values with shape=(n_constraints, n_values).

  • constraint_values – The expected values of the constraints with shape=(n_constraints, 1)

  • restraint_a – The a term in the hyperbolic RESP restraint function.

  • restraint_indices – The indices of the charges in beta that the restraint should be applied to.

Return type

An initial guess of the charge values with shape=(n_values, 1)

classmethod jacobian(beta: ndarray, design_matrix: ndarray, reference_values: ndarray, constraint_matrix: ndarray, restraint_a: float, restraint_b: float, restraint_indices: List[int], n_conformers: int)

Returns the jacobian of the loss function with respect to beta.

Parameters
  • beta – The current vector of charge values with shape=(n_values,)

  • design_matrix – The design matrix that when right multiplied by beta yields the ESP due to the charges applied to the molecule of interest with shape=(n_grid_points, n_values)

  • reference_values – The reference ESP values with shape=(n_grid_points, 1).

  • constraint_matrix – A matrix that when right multiplied by the vector of charge values should yield a vector that is equal to constraint_values with shape=(n_constraints, n_values).

  • restraint_a – The a term in the hyperbolic RESP restraint function.

  • restraint_b – The b term in the hyperbolic RESP restraint function.

  • restraint_indices – The indices of the charges in beta that the restraint should be applied to.

Return type

The value of the jacobian with shape=(n_values,)

classmethod loss(beta: ndarray, design_matrix: ndarray, reference_values: ndarray, constraint_matrix: ndarray, restraint_a: float, restraint_b: float, restraint_indices: List[int], n_conformers: int) ndarray

Returns the current value of the loss function complete with restraints on specified charges.

Parameters
  • beta – The current vector of charge values with shape=(n_values,)

  • design_matrix – The design matrix that when right multiplied by beta yields the ESP due to the charges applied to the molecule of interest with shape=(n_grid_points, n_values)

  • reference_values – The reference ESP values with shape=(n_grid_points, 1).

  • constraint_matrix – A matrix that when right multiplied by the vector of charge values should yield a vector that is equal to constraint_values with shape=(n_constraints, n_values).

  • restraint_a – The a term in the hyperbolic RESP restraint function.

  • restraint_b – The b term in the hyperbolic RESP restraint function.

  • restraint_indices – The indices of the charges in beta that the restraint should be applied to.

Return type

The value of the loss function with shape=(1,)

solve(design_matrix: ndarray, reference_values: ndarray, constraint_matrix: ndarray, constraint_values: ndarray, restraint_a: float, restraint_b: float, restraint_indices: List[int], n_conformers: int) ndarray

Attempts to find a minimum solution to the RESP loss function.

Parameters
  • design_matrix – The design matrix that when right multiplied by beta yields the ESP due to the charges applied to the molecule of interest with shape=(n_grid_points, n_values)

  • reference_values – The reference ESP values with shape=(n_grid_points, 1).

  • constraint_matrix – A matrix that when right multiplied by the vector of charge values should yield a vector that is equal to constraint_values with shape=(n_constraints, n_values).

  • constraint_values – The expected values of the constraints with shape=(n_constraints, 1)

  • restraint_a – The a term in the hyperbolic RESP restraint function.

  • restraint_b – The b term in the hyperbolic RESP restraint function.

  • restraint_indices – The indices of the charges in beta that the restraint should be applied to.

Raises

RESPSolverError

Returns

  • The set of charge values that minimize the RESP loss function with

  • shape=(n_values, 1)