Skip to content

kups.application.potential.classical.blocking

State-binding constructors for blocking sphere potentials.

These adapters take a :class:~kups.core.lens.Lens into a concrete simulation state and wire its particles, groups, systems, neighbor list, and parameters into the state-agnostic factories in kups.potential.classical.blocking.

Parameters may live on the state (state.blocking_spheres_parameters) or be passed directly via parameters=; in the latter case they are bound with a constant lens and the state need not carry a parameter field.

IsBlockingSpheresGraphState

Bases: IsState[_BlockingParticles, HasCell[AnyPeriodicity]], IsNeighborListState[IsUniversalNeighborlistParams], Protocol

Particles, groups, systems, and neighbor list (no parameters).

Source code in src/kups/application/potential/classical/blocking.py
class IsBlockingSpheresGraphState(
    IsState[_BlockingParticles, HasCell[AnyPeriodicity]],
    IsNeighborListState[IsUniversalNeighborlistParams],
    Protocol,
):
    """Particles, groups, systems, and neighbor list (no parameters)."""

    @property
    def groups(self) -> Table[GroupId, HasMotifIndex]: ...

IsBlockingSpheresState

Bases: IsBlockingSpheresGraphState, Protocol

:class:IsBlockingSpheresGraphState that also carries parameters on the state.

Source code in src/kups/application/potential/classical/blocking.py
class IsBlockingSpheresState(IsBlockingSpheresGraphState, Protocol):
    """:class:`IsBlockingSpheresGraphState` that also carries parameters on the state."""

    @property
    def blocking_spheres_parameters(self) -> BlockingSpheresParameters: ...

make_blocking_spheres_from_state(state, probe=None, *, parameters=None, neighborlist_factory=AdaptiveNeighborList.from_state)

make_blocking_spheres_from_state(
    state: Lens[State, IsBlockingSpheresState],
    probe: None = None,
    *,
    parameters: None = None,
    neighborlist_factory: NeighborListFactory[
        IsBlockingSpheresState
    ] = ...,
) -> Potential[State, EmptyType, EmptyType, Patch[Any]]
make_blocking_spheres_from_state(
    state: Lens[State, IsBlockingSpheresState],
    probe: Probe[State, P, IsBlockingSpheresProbe],
    *,
    parameters: None = None,
    neighborlist_factory: NeighborListFactory[
        IsBlockingSpheresState
    ] = ...,
) -> Potential[State, EmptyType, EmptyType, P]
make_blocking_spheres_from_state(
    state: Lens[State, IsBlockingSpheresGraphState],
    probe: None = None,
    *,
    parameters: BlockingSpheresParameters,
    neighborlist_factory: NeighborListFactory[
        IsBlockingSpheresGraphState
    ] = ...,
) -> Potential[State, EmptyType, EmptyType, Patch[Any]]
make_blocking_spheres_from_state(
    state: Lens[State, IsBlockingSpheresGraphState],
    probe: Probe[State, P, IsBlockingSpheresProbe],
    *,
    parameters: BlockingSpheresParameters,
    neighborlist_factory: NeighborListFactory[
        IsBlockingSpheresGraphState
    ] = ...,
) -> Potential[State, EmptyType, EmptyType, P]

Create a blocking spheres potential, optionally with incremental updates.

Parameters:

Name Type Description Default
state Any

Lens into the sub-state providing particles, groups, systems, and neighbor list (plus blocking_spheres_parameters when parameters is not given).

required
probe Any

Probe returning a IsBlockingSpheresProbe; None for full recomputation.

None
parameters BlockingSpheresParameters | None

Constant blocking sphere parameters. When given they are bound with a constant lens and the state need not carry blocking_spheres_parameters.

None
neighborlist_factory NeighborListFactory[Any]

Builds a NeighborList[Literal[2]] from the sub-state and per-system cutoffs.

from_state

Returns:

Type Description
Any

Configured blocking spheres Potential.

Source code in src/kups/application/potential/classical/blocking.py
def make_blocking_spheres_from_state(
    state: Any,
    probe: Any = None,
    *,
    parameters: BlockingSpheresParameters | None = None,
    neighborlist_factory: NeighborListFactory[Any] = AdaptiveNeighborList.from_state,
) -> Any:
    """Create a blocking spheres potential, optionally with incremental updates.

    Args:
        state: Lens into the sub-state providing particles, groups, systems, and
            neighbor list (plus ``blocking_spheres_parameters`` when
            ``parameters`` is not given).
        probe: Probe returning a IsBlockingSpheresProbe; ``None`` for full
            recomputation.
        parameters: Constant blocking sphere parameters. When given they are
            bound with a constant lens and the state need not carry
            ``blocking_spheres_parameters``.
        neighborlist_factory: Builds a ``NeighborList[Literal[2]]`` from the
            sub-state and per-system cutoffs.

    Returns:
        Configured blocking spheres Potential.
    """
    gradient_lens: Any = EMPTY_LENS
    patch_idx_view: Any = None
    if probe is not None:
        patch_idx_view = patch_idx_view or empty_patch_idx_view

    if parameters is not None:
        param_view: Any = const_lens(parameters)
    else:
        param_view = state.focus(lambda x: x.blocking_spheres_parameters)

    def neighborlist_view(s: Any) -> BlockingSpheresNeighborListFactory:
        return lambda cutoffs: neighborlist_factory(state(s), cutoffs)

    return make_blocking_spheres_potential(
        state.focus(lambda x: x.particles),
        state.focus(lambda x: x.groups),
        state.focus(lambda x: x.systems),
        param_view,
        neighborlist_view,
        probe,
        gradient_lens,
        EMPTY_LENS,
        EMPTY_LENS,
        patch_idx_view,
    )