Skip to content

Commit f8d0db4

Browse files
committed
add EvalHelperFunc, help for CVs, lambda_min/max
1 parent b898478 commit f8d0db4

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

‎paths_cli/wizard/cvs.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _mdtraj_summary(wizard, context, result):
138138
builder=partial(_mdtraj_cv_builder, func_name='compute_angles'),
139139
prerequisite=TOPOLOGY_CV_PREREQ,
140140
intro=_MDTRAJ_INTRO.format(user_str="angle made by three atoms"),
141-
description=...,
141+
description="This CV will calculate the angle between three atoms.",
142142
summary=_mdtraj_summary,
143143
)
144144

@@ -148,7 +148,8 @@ def _mdtraj_summary(wizard, context, result):
148148
builder=partial(_mdtraj_cv_builder, func_name='compute_dihedrals'),
149149
prerequisite=TOPOLOGY_CV_PREREQ,
150150
intro=_MDTRAJ_INTRO.format(user_str="dihedral made by four atoms"),
151-
description=...,
151+
description=("This CV will calculate the dihedral angle made by "
152+
"four atoms"),
152153
summary=_mdtraj_summary,
153154
)
154155

‎paths_cli/wizard/helper.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,37 @@ def force_exit(cmd, ctx):
4545
'restart': _RESTART_HELP,
4646
}
4747

48+
49+
_SHORT_EVAL_HELP = ("This parameter can be generated using our custom "
50+
"evaluation method. For details, ask for help with "
51+
"'?eval'.")
52+
_LONG_EVAL_HELP = ("The value for this parameter can be generated using a "
53+
"Python-like syntax. You're limited to a single "
54+
"expression (generally, a single line of Python) and "
55+
"the imports math and numpy (as np). However, this "
56+
"allows you to do simple calculations such as:\n"
57+
" 100 * np.pi / 180 # 100 degrees in radians")
58+
class EvalHelperFunc:
59+
"""Helper function (input to :class:`.Helper`) for evaluated parameters.
60+
61+
Parameters
62+
----------
63+
param_helper : str or Callable[str, dict] -> str
64+
help string or method that takes arguments and context dict and
65+
results the help string
66+
"""
67+
def __init__(self, param_helper, context=None):
68+
if isinstance(param_helper, str):
69+
helper = lambda wizard, context: param_helper
70+
else:
71+
helper = param_helper
72+
self.helper = helper
73+
74+
def __call__(self, helpargs, context):
75+
if helpargs == "eval":
76+
return _LONG_EVAL_HELP
77+
return self.helper(helpargs, context) + "\n\n" + _SHORT_EVAL_HELP
78+
4879
class Helper:
4980
"""Manage help and command passing on command line.
5081

‎paths_cli/wizard/volumes.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
LoadFromOPS, WizardParameterObjectPlugin, WizardObjectPlugin,
55
WrapCategory
66
)
7+
from paths_cli.wizard.helper import EvalHelperFunc, Helper
78
from paths_cli.wizard.plugin_registration import get_category_wizard
89
from paths_cli.wizard.core import interpret_req
910
import paths_cli.compiling.volumes
@@ -22,6 +23,9 @@ def _binary_func_volume(wizard, context, op):
2223
vol = op(vol1, vol2)
2324
return vol
2425

26+
_LAMBDA_HELP = ("This is the {minmax} boundary value for this volume. "
27+
"Note that periodic CVs will correctly wrap values "
28+
"outside the periodic bounds.")
2529
_LAMBDA_STR = ("What is the {minmax} allowed value for "
2630
"'{{obj_dict[cv].name}}' in this volume?")
2731
CV_DEFINED_VOLUME_PLUGIN = WizardParameterObjectPlugin.from_proxies(
@@ -38,12 +42,16 @@ def _binary_func_volume(wizard, context, op):
3842
ProxyParameter(
3943
name="lambda_min",
4044
ask=_LAMBDA_STR.format(minmax="minimum"),
41-
helper="foo",
45+
helper=Helper(
46+
EvalHelperFunc(_LAMBDA_HELP.format(minmax="minimum"))
47+
),
4248
),
4349
ProxyParameter(
4450
name='lambda_max',
4551
ask=_LAMBDA_STR.format(minmax="maximum"),
46-
helper="foo",
52+
helper=Helper(
53+
EvalHelperFunc(_LAMBDA_HELP.format(minmax="maximum"))
54+
),
4755
),
4856
],
4957
compiler_plugin=paths_cli.compiling.volumes.CV_VOLUME_PLUGIN,

‎paths_cli/wizard/wizard.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ def _speak(self, content, preface):
6565
lines = statement.split("\n")
6666
wrapped = textwrap.wrap(lines[0], width=width, subsequent_indent=" "*3)
6767
for line in lines[1:]:
68-
wrap_line = textwrap.indent(line, " "*3)
69-
wrapped.append(wrap_line)
68+
if line == "":
69+
wrapped.append("")
70+
wrap_line = textwrap.wrap(line, width=width,
71+
initial_indent=" "*3,
72+
subsequent_indent=" "*3)
73+
# wrap_line = textwrap.indent(line, " "*3)
74+
wrapped.extend(wrap_line)
7075
self.console.print("\n".join(wrapped))
7176

7277
@get_object

0 commit comments

Comments
 (0)