openff-toolkit icon indicating copy to clipboard operation
openff-toolkit copied to clipboard

Add functions to see which cheminformatics toolkits are being used on the backend

Open j-wags opened this issue 6 years ago • 5 comments

Currently, the interface to see which toolkits are being used is a bit clunky. The code I sent out to check this is here:

print(GLOBAL_TOOLKIT_REGISTRY.registered_toolkits)
print(OpenEyeToolkitWrapper.toolkit_is_available())
print(RDKitToolkitWrapper.toolkit_is_available())

We could think of a better way to do this. Since each function will be resolved independently, and because we kind of hide the fact that GLOBAL_TOOLKIT_REGISTRY does the work behind the scenes, something like a cleaner interface to GLOBAL_TOOLKIT_REGISTRY.resolve(method_name) would be a good solution.

j-wags avatar Jan 12 '19 00:01 j-wags

Is the main challenge to see which toolkits are registered, which toolkits are used for a given method, or whether a given toolkit has a particular method available?

jchodera avatar Jan 14 '19 22:01 jchodera

My original intent was "which toolkits are used for a given method".

That said, I was pretty rushed when I wrote this, so it may not be well thought-through. The only solution I can think of now would be some openforcefield.utils module-level function. It's not clear to me that it would be superior to a GLOBAL_TOOLKIT_REGISTRY.resolve() call, especially because it would effectively be a wrapper for that function (except that it would return the ToolkitWrapper instead of the method)

j-wags avatar Jan 14 '19 22:01 j-wags

I find it's easier to design the API if you pitch how you're going to use it.

Do you want to be able to call something like

method = toolkit_registry.resolve_method(method)

or

wrapper = toolkit_registry.resolve_method_supplier(method)

?

jchodera avatar Jan 14 '19 23:01 jchodera

wrapper = toolkit_registry.resolve_method_supplier(method) is what I'm advocating for.

So a possible API would be

class ToolkitRegistry:
    def resolve_wrapper(method):
        '''
        Returns the ToolkitWrapper that would be used to call a given method.
        
        Parameters
        ----------
        method : str
            The method name to look up

        Returns
        -------
        wrapper : openforcefield.utils.ToolkitWrapper
            The ToolkitWrapper that would be called to perform the method.

The first option you posted (method = toolkit_registry.resolve_method(method)) actually already exists. https://open-forcefield-toolkit.readthedocs.io/en/topology/api/generated/openforcefield.utils.toolkits.ToolkitRegistry.html#openforcefield.utils.toolkits.ToolkitRegistry.resolve

j-wags avatar Jan 14 '19 23:01 j-wags

I came across this wile searching ToolkitRegistry in the issue tracker. I think this is implemented (although improvements were proposed in #540)?

mattwthompson avatar Sep 13 '21 15:09 mattwthompson