xnn.ffnn.models.amoeba.DipolePredictor#

class xnn.ffnn.models.amoeba.DipolePredictor(kind='aspc', history=6)[source]#

Bases: object

Extrapolate the induced dipoles of the next step from the last few.

In molecular dynamics the converged dipoles change smoothly from step to step, so a linear combination of the last m sets, mu_p = sum_j B_j mu(t - j dt), is a much better start for the iterative solve than the direct dipoles. The schemes:

  • "aspc": the always stable predictor-corrector coefficients of Kolafa, J. Comput. Chem. 25, 335 (2004), with k = m - 2: B_j = (-1)^(j+1) j C(2k+4, k+2-j) / C(2k+2, k+1); time reversible and stable, exact for linear motion;

  • "gear": polynomial extrapolation through the m points, B_j = (-1)^(j+1) C(m, j), exact for polynomials of degree m - 1;

  • "previous": the last dipoles.

Fewer stored sets than m (the first steps) use the same scheme on the sets there are. A change of shape, dtype or device starts a new history. The solve is converged to the model’s tolerance, so the prediction only changes the number of iterations, not the dipoles.

Parameters:
  • kind (str, optional) – "aspc" (default), "gear" or "previous".

  • history (int, optional) – The number m of past dipole sets (6).

static coefficients(kind, m)[source]#

The weights B_1 .. B_m of the last m sets, newest first.

Parameters:
  • kind (str) – "aspc", "gear" or "previous".

  • m (int) – Number of sets.

Returns:

The weights (they sum to one).

Return type:

list of float

reset()[source]#

Forget the stored dipoles.

Return type:

None

push(mu)[source]#

Store the converged dipoles of a step.

Parameters:

mu (Tensor) – The dipoles (N, 3).

Return type:

None

rewind()[source]#

Take back the dipoles of the last push(), as many times as it ran (a recorded CUDA graph pushes on every replay), before a step is evaluated again at the same positions: the history then holds each step once. Only the last push can be taken back.

Return type:

None

predict(like)[source]#

The extrapolated dipoles, or None without a compatible history.

Parameters:

like (Tensor) – A tensor of the dipoles’ shape, dtype and device.

Returns:

The prediction (N, 3).

Return type:

Tensor or None