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: |
|
---|
Methods
add_toolkit (toolkit_wrapper) |
Append a ToolkitWrapper onto the list of toolkits in this ToolkitRegistry |
call (method_name, *args, **kwargs) |
Execute the requested method by attempting to use all registered toolkits in order of precedence. |
register_toolkit (toolkit_wrapper[, …]) |
Register the provided toolkit wrapper class, instantiating an object of it. |
resolve (method_name) |
Resolve the requested method name by checking all registered toolkits in order of precedence for one that provides the requested method. |
__init__
(register_imported_toolkit_wrappers=False, toolkit_precedence=None, exception_if_unavailable=True)[source]¶Create an empty toolkit registry.
Parameters: |
|
---|
Methods
__init__ ([…]) |
Create an empty toolkit registry. |
add_toolkit (toolkit_wrapper) |
Append a ToolkitWrapper onto the list of toolkits in this ToolkitRegistry |
call (method_name, *args, **kwargs) |
Execute the requested method by attempting to use all registered toolkits in order of precedence. |
register_toolkit (toolkit_wrapper[, …]) |
Register the provided toolkit wrapper class, instantiating an object of it. |
resolve (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. |
registered_toolkits
¶List registered toolkits.
Warning
This API is experimental and subject to change.
Todo
Should this return a generator? Deep copies? Classes? Toolkit names?
Returns: |
|
---|
register_toolkit
(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.
Todo
This method should raise an exception if the toolkit is unavailable, unless an optional argument is specified that silently avoids registration of toolkits that are unavailable.
Parameters: |
|
---|
add_toolkit
(toolkit_wrapper)[source]¶Append a ToolkitWrapper onto the list of toolkits in this ToolkitRegistry
Warning
This API is experimental and subject to change.
Parameters: |
|
---|
resolve
(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: |
|
---|---|
Returns: |
|
Raises: |
|
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)
Todo
Is there a better way to figure out which toolkits implement given methods by introspection?
call
(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: |
|
---|---|
Raises: |
|
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)