-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
63 lines (45 loc) · 1.41 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Tools
=====
Module to make a nice registry of WESTPA commands
"""
import subprocess
from .westcli import CommandBase
west_tools = ('w_bins', 'w_truncate', 'w_fork', 'w_assign', 'w_trace', 'w_fluxanl',
'w_ipa', 'w_pdist', 'w_succ', 'w_crawl', 'w_direct', 'w_select',
'w_states', 'w_eddist', 'w_ntop', 'w_multi_west', 'plothist', 'ploterr')
class WESTPAToolLoadingError(Exception):
"""Raised when no WESTPA tool could be found."""
def tool_factory(clsname, command_name, base=CommandBase):
""" Factory for WESTPA commands."""
clsdict = {
'command_name': command_name,
}
return type(clsname, (base,), clsdict)
def load_tools():
""" Load the tools
Parameters
----------
Returns
-------
"""
cmds = west_tools
tools = {}
for cmd in cmds:
try:
out = subprocess.check_output([cmd, '--help'])
except (subprocess.CalledProcessError, OSError):
pass
clsname = cmd.split()[0].title()
tools[cmd] = tool_factory(clsname, cmd)
if not tools:
raise ValueError("Failed to load tools.")
return tools
try:
registry = load_tools()
except WESTPAToolLoadingError:
errmsg = "Autoloading was unable to load any Gromacs tool"
raise WESTPAToolLoadingError(errmsg)
# Add registry of classes to this modules scope!
globals().update(registry)
__all__ = list(registry.keys())