-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Toolkit Wrapper and Registry API docs (#1787)
* Add NAGLToolkitWrapper to API docs * Write docstrings for NAGLToolkitWrapper * Update changelog * Move toolkit wrapper API docs to own page * Update changelog with #1787 * fix indentation * Add newlines to python doc examples in toolkits.md * Revise and augment toolkit registry API docs * Write API docs for GLOBAL_TOOLKIT_REGISTRY * Revise toolkit API table of contents and overview docs * Typos * Fix rdkit/oetk to_smiles output * Clarify toolkits.md and move complex info to API docs * Improve docs for toolkit wrapper base class * Fix API docs formatting * Move ToolkitRegistry.call to top of methods list * Rephrase toolkit_registry_manager guidance * Update phrasing of release history * Lint Markdown/rST files --------- Co-authored-by: Jeff Wagner <[email protected]> Co-authored-by: Matthew W. Thompson <[email protected]>
- Loading branch information
1 parent
ef2f514
commit 60abeb4
Showing
9 changed files
with
340 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Toolkit Wrappers and Registries | ||
|
||
The toolkit wrappers provide a simple uniform API for accessing some functionality of cheminformatics toolkits. They are used internally by the OpenFF Toolkit to avoid re-implementing existing scientific algorithms, and can be used by users to specify exactly what software is used for any given section of code. | ||
|
||
These toolkit wrappers are generally used through a [`ToolkitRegistry`], which facilitates combining software with different capabilities and can be constructed with a list of toolkit wrappers ordered by precedence. | ||
|
||
```pycon | ||
>>> from openff.toolkit import ( | ||
... ToolkitRegistry, | ||
... OpenEyeToolkitWrapper, | ||
... RDKitToolkitWrapper, | ||
... AmberToolsToolkitWrapper, | ||
... ) | ||
>>> toolkit_registry = ToolkitRegistry( | ||
... [ | ||
... OpenEyeToolkitWrapper, | ||
... RDKitToolkitWrapper, | ||
... AmberToolsToolkitWrapper, | ||
... ] | ||
... ) | ||
|
||
``` | ||
|
||
The toolkit wrappers' functionality can then be accessed through the registry. The first toolkit in the list that provides a method with the given name will be used: | ||
|
||
```pycon | ||
>>> from openff.toolkit import Molecule | ||
>>> molecule = Molecule.from_smiles('Cc1ccccc1') | ||
>>> smiles = toolkit_registry.call('to_smiles', molecule) | ||
|
||
``` | ||
|
||
For further details on how this search is performed and how it handles exceptions, see the [`ToolkitRegistry.call()` API docs]. | ||
|
||
Many functions in the OpenFF Toolkit API include a `toolkit_registry` argument that can be used to specify the toolkit wrappers used by a call to that function. The value of this argument can be either a single toolkit wrapper instance, or an entire toolkit registry: | ||
|
||
```pycon | ||
>>> smiles = molecule.to_smiles(toolkit_registry=RDKitToolkitWrapper()) | ||
>>> smiles = molecule.to_smiles(toolkit_registry=toolkit_registry) | ||
|
||
``` | ||
|
||
For example, differences in `to_smiles` functionality between the OpenEye and RDKit can be explored by specifying the desired toolkit wrapper: | ||
|
||
```pycon | ||
>>> molecule.to_smiles(toolkit_registry=RDKitToolkitWrapper()) | ||
'[H][c]1[c]([H])[c]([H])[c]([C]([H])([H])[H])[c]([H])[c]1[H]' | ||
>>> molecule.to_smiles(toolkit_registry=OpenEyeToolkitWrapper()) | ||
'[H]c1c(c(c(c(c1[H])[H])C([H])([H])[H])[H])[H]' | ||
|
||
``` | ||
|
||
The default value of this argument is the [`GLOBAL_TOOLKIT_REGISTRY`], which by default includes all the toolkits that OpenFF recommends for everyday use: | ||
|
||
```pycon | ||
>>> from openff.toolkit import GLOBAL_TOOLKIT_REGISTRY | ||
>>> len(GLOBAL_TOOLKIT_REGISTRY.registered_toolkits) | ||
4 | ||
|
||
``` | ||
|
||
The [`toolkit_registry_manager`] context manager allows `GLOBAL_TOOLKIT_REGISTRY` to be changed temporarily: | ||
|
||
```pycon | ||
>>> from openff.toolkit.utils import toolkit_registry_manager | ||
>>> print(len(GLOBAL_TOOLKIT_REGISTRY.registered_toolkits)) | ||
4 | ||
>>> with toolkit_registry_manager(ToolkitRegistry([RDKitToolkitWrapper(), AmberToolsToolkitWrapper()])): | ||
... print(len(GLOBAL_TOOLKIT_REGISTRY.registered_toolkits)) | ||
2 | ||
|
||
``` | ||
|
||
For more information about modifying `GLOBAL_TOOLKIT_REGISTRY`, see the [`GLOBAL_TOOLKIT_REGISTRY` API docs]. | ||
|
||
[`ToolkitRegistry`]: openff.toolkit.utils.toolkits.ToolkitRegistry | ||
[`ToolkitRegistry.call()` API docs]: openff.toolkit.utils.toolkits.ToolkitRegistry.call | ||
[`ToolkitRegistry.call`]: openff.toolkit.utils.toolkits.ToolkitRegistry.call | ||
[`GLOBAL_TOOLKIT_REGISTRY`]: openff.toolkit.utils.toolkits.GLOBAL_TOOLKIT_REGISTRY | ||
[`toolkit_registry_manager`]: openff.toolkit.utils.toolkits.toolkit_registry_manager | ||
[`GLOBAL_TOOLKIT_REGISTRY` API docs]: openff.toolkit.utils.toolkits.GLOBAL_TOOLKIT_REGISTRY | ||
|
||
```{eval-rst} | ||
.. currentmodule:: openff.toolkit.utils.toolkits | ||
.. autosummary:: | ||
:nosignatures: | ||
:toctree: generated/ | ||
ToolkitRegistry | ||
ToolkitWrapper | ||
OpenEyeToolkitWrapper | ||
RDKitToolkitWrapper | ||
AmberToolsToolkitWrapper | ||
NAGLToolkitWrapper | ||
BuiltInToolkitWrapper | ||
GLOBAL_TOOLKIT_REGISTRY | ||
toolkit_registry_manager | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.