openforcefield / openff-toolkit

The Open Forcefield Toolkit provides implementations of the SMIRNOFF format, parameterization engine, and other tools. Documentation available at http://open-forcefield-toolkit.readthedocs.io
http://openforcefield.org
MIT License
301 stars 88 forks source link

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

Open j-wags opened 5 years ago

j-wags commented 5 years ago

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.

jchodera commented 5 years ago

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?

j-wags commented 5 years ago

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)

jchodera commented 5 years ago

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)

?

j-wags commented 5 years ago

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

mattwthompson commented 2 years ago

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