pyscivr.hessian module

Hessian evaluation in the active internal coordinates along a trajectory.

See section II C of the paper for details.

Notation:
  • N: number of atoms.

  • T: number of time steps of the trajectory.

  • S: number of steps at which the Hessian is evaluated.

  • m: number of active coordinates.

pyscivr.hessian.eval_hess_active(calculator, coord_all, active_idx, posi, steps, *, eps=0.0001, chunk_size=100)[source]

Evaluate directional derivative of the gradient at selected steps of a trajectory.

Computes \(K A_A \equiv \nabla^2 V A_A\) (Eq. (52) in the paper), where

\[A_A = \frac{\partial q}{\partial Q_A}, \quad B_A = \frac{\partial Q_A}{\partial q}\]
Parameters:
  • calculator (Calculator) – Calculator whose energy_forces accepts (n_batch, N, 3) geometries and returns (energy, forces).

  • coord_all (InternalCoordinates) – InternalCoordinates for the full system. It must define 3N coordinates for coordinate transformation.

  • active_idx (ArrayLike) – (m,) row indices of the active coordinates in coord_all, in the row order after build() (e.g. InternalCoordinates.find_coordinate or coord_all.inv_argsort[active_idx_original]).

  • posi (ArrayLike) – (T, N, 3) trajectory.

  • steps (ArrayLike) – (S,) indices of the steps to evaluate.

  • eps (float) – Displacement [Angs].

  • chunk_size (int | None) – Number of geometries passed to the calculator at once If None, all geometries are passed at once.

Returns:

(KA, AA, BA), where

  • KA: (S, 3N, m) \(K A_A\)

  • AA: (S, 3N, m) \(A_A\)

  • BA: (S, m, 3N) \(B_A\)

Return type:

tuple[NDArray[np.float64], NDArray[np.float64], NDArray[np.float64]]

Note

\(A_A\) is decomposed as \(A_A = Q R\) via QR decomposition, the gradient is differentiated along the orthonormal columns of \(Q\) by central differences with step eps, and \(K A_A\) is obtained as \((K Q) R\). This requires \(2 S m\) gradient evaluations.

Warning

The obtained \(K A_A\) can be numerically unstable near singularities (i.e., where the active coordinates are not independent). It is recommended to check the trajectory in advance and choose steps that avoid such regions.

pyscivr.hessian.projected_hessian(KA, AA, BA, *, symmetrize=True)[source]

Compute the Hessian projected onto the active coordinates.

Eq. (50) in the paper:

\[\mathfrak{P}^T K \mathfrak{P} = \mathfrak{P}^T (K A_A) B_A, \quad \mathfrak{P} = A_A B_A\]
Parameters:
Returns:

(S, 3N, 3N) projected Hessians \mathfrak{P}^T K \mathfrak{P}.

Return type:

NDArray[np.float64]

pyscivr.hessian.interpolate_hessian(steps, hess, n_step)[source]

Interpolate the Hessian along the trajectory using cubic splines.

Parameters:
  • steps (ArrayLike) – (S,) strictly increasing indices of the steps where the Hessians are evaluated.

  • hess (NDArray[np.float64]) – (S, 3N, 3N) Hessians at the given steps.

  • n_step (int) – Total number of steps in the trajectory.

Returns:

(n_step, 3N, 3N) interpolated Hessians at every step 0, 1, ..., n_step-1.

Return type:

NDArray[np.float64]