-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add initial attempt at a plugin detector. #292
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #292 +/- ##
=========================================
- Coverage 86.55% 85.76% -0.8%
=========================================
Files 14 15 +1
Lines 1220 1236 +16
=========================================
+ Hits 1056 1060 +4
- Misses 164 176 +12 |
plugin_loader_func = eval("foyer.forcefields.{}".format(plugin_func)) | ||
# Assumes all plugins are named "load_{plugin_name}" | ||
plugin_name = "_".join(plugin_func.split("_")[1:]) | ||
# TODO: plugin_version = get_version_info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any initial thoughts on how we should store this information? I see we want it to be accessible from the loader but I'm not sure how to go about doing that - maybe these functions should be expanded into (lightweight) classes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out my plugins branch for the PFE repo. To demonstrate how FF versioning would work, I added some dummy forcefield versions and file organization for adding forcefields versions. Version and xml_path are returned when the forcefield is loaded, and can be easily accessed by the plugin detector in foyer:
>>> import foyer
>>> pfe = foyer.forcefields.load_PFE()
>>> pfe.version
'1.0.0'
>>> pfe.xml_path
['/Users/parashara/Documents/devel/git/forcefield_perfluoroethers/perfluoroethers/xml/current/PFE.xml']
>>> pfe = foyer.forcefields.load_PFE("0.0.2")
>>> pfe.version
'0.0.2'
>>> pfe.xml_path
['/Users/parashara/Documents/devel/git/forcefield_perfluoroethers/perfluoroethers/xml/versions/0.0.2/PFE.xml']
# TODO: plugin_xml_path = get_xml_path | ||
# This assumes that plugin directory tree is consistent. | ||
# Does not consider versioned FFs. | ||
plugin_xml_path = glob.glob("{}/xml/*xml".format(plugin_dir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to semi-intelligently glob recursively, i.e. to get both '{}/xml/*xml'
and '{}/*xml'
? We probably don't need arbitrary recursion, maybe handling 2-3 cases is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me this is what I get:
(Pdb) plugin_dir
'/Users/raymatsumoto/science/forcefields/forcefield_perfluoroethers/perfluoroethers/perfluoroethers.py'
(Pdb)
So I'm unable to glob this path.
Ideally all of this information (like the xml file location and version) will be stored in the forcefield class, so we don't have to do any globbing. I think this is something @mattwthompson is working on |
Here is an attempt at a writing a plugin detector (fixes #290). See
foyer.plugins:collect_plugins()
Functions named
foyer.forcefields.load_{plugin_name}
are detected as plugins, but there is also aplugin_names
argument to supply a list of plugin function names that don't fit that mold. Theversion
,xml_file
, andload_function
are collected into adict
and returned.I still don't know how to get the
version
. Maybe we could add it as an attribute of the plugin forcefield object when we load it up: