openforcefield.utils.toolkits.ToolkitRegistry

class openforcefield.utils.toolkits.ToolkitRegistry(register_imported_toolkit_wrappers=False, toolkit_precedence=None, exception_if_unavailable=True)[source]

Registry for ToolkitWrapper objects

Examples

Register toolkits in a specified order, skipping if unavailable

>>> from openforcefield.utils.toolkits import ToolkitRegistry
>>> toolkit_registry = ToolkitRegistry()
>>> toolkit_precedence = [OpenEyeToolkitWrapper, RDKitToolkitWrapper, AmberToolsToolkitWrapper]
>>> for toolkit in toolkit_precedence:
...     if toolkit.is_available():
...         toolkit_registry.register_toolkit(toolkit)

Register specified toolkits, raising an exception if one is unavailable

>>> toolkit_registry = ToolkitRegistry()
>>> toolkits = [OpenEyeToolkitWrapper, AmberToolsToolkitWrapper]
>>> for toolkit in toolkits:
...     toolkit_registry.register_toolkit(toolkit)

Register all available toolkits in arbitrary order

>>> from openforcefield.utils import all_subclasses
>>> toolkits = all_subclasses(ToolkitWrapper)
>>> for toolkit in toolkit_precedence:
...     if toolkit.is_available():
...         toolkit_registry.register_toolkit(toolkit)

Retrieve the global singleton toolkit registry, which is created when this module is imported from all available toolkits:

>>> from openforcefield.utils.toolkits import GLOBAL_TOOLKIT_REGISTRY as toolkit_registry
>>> available_toolkits = toolkit_registry.registered_toolkits

Warning

This API is experimental and subject to change.

Attributes
registered_toolkits

List registered toolkits.

Methods

add_toolkit(self, toolkit_wrapper)

Append a ToolkitWrapper onto the list of toolkits in this ToolkitRegistry

call(self, method_name, \*args, \*\*kwargs)

Execute the requested method by attempting to use all registered toolkits in order of precedence.

register_toolkit(self, toolkit_wrapper[, …])

Register the provided toolkit wrapper class, instantiating an object of it.

resolve(self, method_name)

Resolve the requested method name by checking all registered toolkits in order of precedence for one that provides the requested method.

__init__(self, register_imported_toolkit_wrappers=False, toolkit_precedence=None, exception_if_unavailable=True)[source]

Create an empty toolkit registry.

Parameters
register_imported_toolkit_wrappersbool, optional, default=False
If True, will attempt to register all imported ToolkitWrapper subclasses that can be found, in no particular

order.

toolkit_precedencelist, optional, default=None

List of toolkit wrapper classes, in order of desired precedence when performing molecule operations. If None, defaults to [OpenEyeToolkitWrapper, RDKitToolkitWrapper, AmberToolsToolkitWrapper].

exception_if_unavailablebool, optional, default=True

If True, an exception will be raised if the toolkit is unavailable

Methods

__init__(self[, …])

Create an empty toolkit registry.

add_toolkit(self, toolkit_wrapper)

Append a ToolkitWrapper onto the list of toolkits in this ToolkitRegistry

call(self, method_name, \*args, \*\*kwargs)

Execute the requested method by attempting to use all registered toolkits in order of precedence.

register_toolkit(self, toolkit_wrapper[, …])

Register the provided toolkit wrapper class, instantiating an object of it.

resolve(self, method_name)

Resolve the requested method name by checking all registered toolkits in order of precedence for one that provides the requested method.

Attributes

registered_toolkits

List registered toolkits.

property registered_toolkits

List registered toolkits.

Warning

This API is experimental and subject to change.

Returns
toolkitsiterable of toolkit objects
register_toolkit(self, toolkit_wrapper, exception_if_unavailable=True)[source]

Register the provided toolkit wrapper class, instantiating an object of it.

Warning

This API is experimental and subject to change.

Parameters
toolkit_wrapperinstance or subclass of ToolkitWrapper

The toolkit wrapper to register or its class.

exception_if_unavailablebool, optional, default=True

If True, an exception will be raised if the toolkit is unavailable

add_toolkit(self, toolkit_wrapper)[source]

Append a ToolkitWrapper onto the list of toolkits in this ToolkitRegistry

Warning

This API is experimental and subject to change.

Parameters
toolkit_wrapperopenforcefield.utils.ToolkitWrapper

The ToolkitWrapper object to add to the list of registered toolkits

resolve(self, method_name)[source]

Resolve the requested method name by checking all registered toolkits in order of precedence for one that provides the requested method.

Parameters
method_namestr

The name of the method to resolve

Returns
method

The method of the first registered toolkit that provides the requested method name

Raises
NotImplementedError if the requested method cannot be found among the registered toolkits

Examples

Create a molecule, and call the toolkit to_smiles() method directly

>>> from openforcefield.topology import Molecule
>>> molecule = Molecule.from_smiles('Cc1ccccc1')
>>> toolkit_registry = ToolkitRegistry(register_imported_toolkit_wrappers=True)
>>> method = toolkit_registry.resolve('to_smiles')
>>> smiles = method(molecule)
call(self, method_name, *args, **kwargs)[source]

Execute the requested method by attempting to use all registered toolkits in order of precedence.

*args and **kwargs are passed to the desired method, and return values of the method are returned

This is a convenient shorthand for toolkit_registry.resolve_method(method_name)(*args, **kwargs)

Parameters
method_namestr

The name of the method to execute

Raises
NotImplementedError if the requested method cannot be found among the registered toolkits

Examples

Create a molecule, and call the toolkit to_smiles() method directly

>>> from openforcefield.topology import Molecule
>>> molecule = Molecule.from_smiles('Cc1ccccc1')
>>> toolkit_registry = ToolkitRegistry(register_imported_toolkit_wrappers=True)
>>> smiles = toolkit_registry.call('to_smiles', molecule)