Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

uppittu11
Copy link
Member

@uppittu11 uppittu11 commented Nov 1, 2019

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 a plugin_names argument to supply a list of plugin function names that don't fit that mold. The version, xml_file, and load_function are collected into a dict 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:

def load_OPLSAA():
    ff = get_forcefield(name='oplsaa')
    ff.version = "0.0.1"
    return ff

@codecov
Copy link

codecov bot commented Nov 1, 2019

Codecov Report

Merging #292 into master will decrease coverage by 0.79%.
The diff coverage is 25%.

@@            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
Copy link
Member

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?

Copy link
Member Author

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))
Copy link
Member

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.

Copy link
Contributor

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.

@uppittu11
Copy link
Member Author

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

@mattwthompson mattwthompson added this to the 0.7.4 milestone Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugin Detector
3 participants