Plugin System

Core Classes

class sloth.mmcif.plugins.Plugin[source]

Bases: ABC

Abstract base class for plugins that extend dot-notation functionality.

abstract create_wrapper(target)[source]

Return a PluginWrapper (or subclass) bound to target.

Return type:

PluginWrapper

abstract execute(target, *args, **kwargs)[source]

Run the plugin logic on target. Called by PluginWrapper.__call__().

Return type:

Any

class sloth.mmcif.plugins.PluginWrapper[source]

Bases: object

Chainable wrapper returned when a plugin is accessed via dot-notation.

Calling the wrapper executes the plugin and returns self so that additional methods (defined by subclasses) can be chained:

block._atom_site.validate().against(block._entity)
value = block._atom_site.statistics().result
__init__(target, plugin)[source]
Parameters:

plugin (Plugin)

property result: Any

The return value of the last __call__() invocation.

class sloth.mmcif.plugins.FunctionPlugin[source]

Bases: Plugin

Adapter that wraps a plain callable as a Plugin.

__init__(func)[source]
Parameters:

func (Callable)

create_wrapper(target)[source]

Return a PluginWrapper (or subclass) bound to target.

Return type:

PluginWrapper

execute(target, *args, **kwargs)[source]

Run the plugin logic on target. Called by PluginWrapper.__call__().

Return type:

Any

class sloth.mmcif.plugins.PluginFactory[source]

Bases: object

Lightweight plugin registry keyed by name.

Plugins are registered with a name (the attribute that will appear via dot-notation access) and can be looked up or listed.

__init__()[source]
register(name, plugin)[source]

Register a plugin.

Parameters:
  • name (str) – The dot-notation attribute name (e.g. "validate").

  • plugin – A Plugin instance or a plain callable (auto-wrapped as FunctionPlugin).

Return type:

None

get_wrapper(name, target)[source]

Return a bound PluginWrapper for name, or None.

Return type:

Optional[PluginWrapper]

Parameters:

name (str)

has_plugin(name)[source]

Return True if a plugin is registered for name.

Return type:

bool

Parameters:

name (str)

get_plugin(name)[source]

Return the raw Plugin for name, or None.

Return type:

Optional[Plugin]

Parameters:

name (str)

list_plugins()[source]

Return registered plugin names.

Return type:

List[str]

Model-Level Registration

All DataContainer subclasses (Category, DataBlock, MMCIFDataContainer) expose register(name, plugin) β€” see DataContainer.

Validation as a Plugin Example

See sloth.mmcif.validator for ValidatorPlugin, CategoryValidator, and concrete rule factories β€” the canonical example of the plugin system.