-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convenience methods for listing installed force fields #477
Comments
This is made more important because currently, we build and install the https://github.com/openforcefield/smirnoff99Frosst and https://github.com/openforcefield/openforcefields repos as compressed eggs. Because if this, the I might just not know how to use |
Extending this idea/spec:
|
There is an unambiguous order specified by PEP 440. See the information on ordering. There are packages that handle sorting for you. What does |
Now that |
@j-wags @dotsdl @mattwthompson : Now that we are releasing more force fields via the |
@mattwthompson I wrote this awhile back to search for a user-specified ff string to load. You may find parts of it helpful: https://github.com/MobleyLab/openff-spellbook/blob/master/offsb/op/openforcefield.py#L27-L36
I adapted it from an example laying around that @j-wags might have at the tip of his fingers. I can't seem to find it. |
I'm still, embarrassingly, not that great at python package config, and I treat the entry point access methods as olde incatations whenever I need them. Here's the ur-instance of entry point usage that I keep coming back to: https://github.com/openforcefield/openforcefield/blob/master/openforcefield/typing/engines/smirnoff/forcefield.py#L63-L85 @mattwthompson, I'd be happy if you tackled this Issue. I think we're all equally inexperienced with entry points. |
I could take this on. I've done similar things in the past for other packages with data files. |
Just a heads-up that I've cut Once this issue is implemented and there are API methods to query what force fields are available and retrieve the corresponding file paths for available force fields, I can remove some ugly hacks that were needed to make this work. But the good news is that the QCEngine based on this |
Ah! I see that @mattwthompson added #643! Is there a way to modify the behavior so that the most current force fields (maybe based on a date tag?) are listed first? That way, it's easier to pick the latest force field as a sensible default. |
Is there also a way to get the force field file associated with a given filename? I have this clunky method I'd like to replace since it uses a private openforcefield toolkit API: def _search_paths(self, filename):
"""Search registered openforcefield plugin directories
Parameters
----------
filename : str
The filename to find the full path for
Returns
-------
fullpath : str
Full path to identified file, or None if no file found
.. todo ::
Replace this with an API call once this issue is addressed:
https://github.com/openforcefield/openforcefield/issues/477
"""
# TODO: Replace this method once there is a public API in the openforcefield toolkit for doing this
from openforcefield.utils import get_data_file_path
from openforcefield.typing.engines.smirnoff.forcefield import _get_installed_offxml_dir_paths
# Check whether this could be a file path
if isinstance(filename, str):
# Try first the simple path.
searched_dirs_paths = ['']
# Then try a relative file path w.r.t. an installed directory.
searched_dirs_paths.extend(_get_installed_offxml_dir_paths())
# Determine the actual path of the file.
# TODO: What is desired toolkit behavior if two files with the desired name are available?
for dir_path in searched_dirs_paths:
file_path = os.path.join(dir_path, filename)
if os.path.isfile(file_path):
return file_path
# No file found
return None |
One more request: A variant of the behavior where we can also only return the force field names (without Here's what I originally had: @ClassProperty
@classmethod
def INSTALLED_FORCEFIELDS(cls):
"""Return a list of the offxml files shipped with the openforcefield package.
Returns
-------
file_names : str
The file names of available force fields
.. todo ::
Replace this with an API call once this issue is addressed:
https://github.com/openforcefield/openforcefield/issues/477
"""
# TODO: Replace this method once there is a public API in the openforcefield toolkit for doing this
# TODO: Impose some sort of ordering by preference?
from openforcefield.utils import get_data_file_path
from openforcefield.typing.engines.smirnoff.forcefield import _get_installed_offxml_dir_paths
from glob import glob
file_names = list()
for dir_path in _get_installed_offxml_dir_paths():
file_pattern = os.path.join(dir_path, '*.offxml')
file_paths = [file_path for file_path in glob(file_pattern)]
for file_path in file_paths:
basename = os.path.basename(file_path)
root, ext = os.path.splitext(basename)
# Only add variants without '_unconstrained'
if '_unconstrained' not in root:
file_names.append(root)
return file_names |
I'd envision the following, which I think would satisfy your needs as laid out Two new arguments to
This would attempt to parse the date tag in the force field, either by loading it up completely (a source of errors/warnings) or do some risky parsing of the top of the file. I'd advocate for this to be turned off by default to avoid warnings/errors associated with loading un-supported force fields (unless SMIRNOFF up-converters are implemented) and avoid the ~1-200 ms load time for each file.
This would just look for And a new utility function along the lines of
i.e. |
This all sounds good!
The name of this argument doesn't indicate whether this sorting would yield the most recent first, or oldest first. Is there a better name, like
Good point. I suppose an alternative would be to just lean on semantic versioning for ordering, but we wouldn't know what order to list force field series ( Perhaps a further alternative would be to have an API for returning available FF series, then returning the installed files in those series using semantic versioning to sort? |
Is your feature request related to a problem? Please describe.
Currently, it's hard for users to perform operations like
openforcefield
,smirnoff99Frosst
) are installedsmirnoff99Frosst
issmirnoff99Frosst-1.1.0.offxml
) to use the most up-to-date force fieldDescribe the solution you'd like
It would be useful to have a convenience method for listing all installed force field files located in plugin directories, such as:
We could go further and list all installed force field series (truncating the semantic versioning):
and allow us to retrieve the latest versions of a specific series
or retrieve full paths
Describe alternatives you've considered
In principle, a user could access some of the private methods and attributes in
openforcefield.typing.engines.smirnoff
, but the API for these is not guaranteed to be stable.Additional context
I am working on incorporating support for the Open Force Field Initiative force fields into the OpenMM
ForceField
object in http://github.com/choderalab/openmm-forcefieldsThe text was updated successfully, but these errors were encountered: