SimpleSpringMEHPForceEvaluator

class pylimer_tools_cpp.SimpleSpringMEHPForceEvaluator(self: pylimer_tools_cpp.SimpleSpringMEHPForceEvaluator, kappa: SupportsFloat = 1.0)

Bases: MEHPForceEvaluator

This is equal to a spring evaluator for Gaussian chains.

The force for a certain spring is given by: \(f = 0.5 \cdot \kappa r\), where \(r\) is the spring [between crosslinkers] length.

Recommended optimization algorithm: “LD_LBFGS”

Parameters:

kappa – The spring constant \(\kappa\)

Attributes Summary

Methods Summary

evaluate_force_set_gradient(self, n, ...[, ...])

Evaluate the force and optionally compute its gradient.

evaluate_stress_contribution(self, ...)

Evaluate the stress-contribution for a single spring.

prepare_for_evaluations(self)

Prepare the evaluator for a series of evaluations.

Attributes Documentation

is_2d
network

Methods Documentation

evaluate_force_set_gradient(self: pylimer_tools_cpp.MEHPForceEvaluator, n: SupportsInt, spring_distances: Annotated[numpy.typing.ArrayLike, numpy.float64, '[m, 1]'], compute_gradient: bool = False) tuple

Evaluate the force and optionally compute its gradient.

This is one of the primary methods to override when creating a custom force evaluator. Override this in Python by defining a method that returns a tuple of (force, gradient).

Parameters:
  • n – The dimensionality of the problem (the number of coordinates)

  • spring_distances – The sequential (x, y, z) spring distances as a vector

  • compute_gradient – If True, the gradient should be computed and returned

Returns:

A tuple (force, gradient) where: - force: The computed force value (float) - gradient: The gradient as a list (or None if compute_gradient was False)

Example implementation in Python:

def evaluate_force_set_gradient(self, n, spring_distances, compute_gradient):
    force = 0.0
    # ... compute force ...

    gradient = None
    if compute_gradient:
        gradient = [0.0] * n
        # ... compute gradient ...

    return (force, gradient)
evaluate_stress_contribution(self: pylimer_tools_cpp.MEHPForceEvaluator, spring_distances: SupportsFloat, i: SupportsInt, j: SupportsInt, spring_index: SupportsInt) float

Evaluate the stress-contribution for a single spring.

Parameters:
  • spring_distances – The three coordinate differences for one spring (list of 3 floats)

  • i – The row index of the stress tensor

  • j – The column index of the stress tensor

  • spring_index – The index of the spring being evaluated

Returns:

The stress contribution value

prepare_for_evaluations(self: pylimer_tools_cpp.MEHPForceEvaluator) None

Prepare the evaluator for a series of evaluations. This method is called before a batch of force evaluations, allowing for any necessary setup or precomputation.