Skip to content

Commit 9fe9801

Browse files
committed
json types for most compiler plugins
1 parent 59bc1b9 commit 9fe9801

8 files changed

Lines changed: 86 additions & 21 deletions

File tree

‎paths_cli/compiling/_gendocs/json_type_handlers.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ def __init__(self, type_name, link_to=None):
133133
CategoryHandler("engine"),
134134
CategoryHandler("cv"),
135135
CategoryHandler("volume"),
136+
CategoryHandler("network"),
137+
CategoryHandler("strategy"),
138+
CategoryHandler("scheme"),
136139
EvalHandler("EvalInt"),
140+
EvalHandler("EvalIntStrictPos"),
137141
EvalHandler("EvalFloat"),
138142
]
139143

‎paths_cli/compiling/cvs.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from paths_cli.compiling.errors import InputError
55
from paths_cli.utils import import_thing
66
from paths_cli.compiling.plugins import CVCompilerPlugin, CategoryPlugin
7+
from paths_cli.compiling.json_type import json_type_eval
78

89

910
class AllowedPackageHandler:
@@ -40,13 +41,16 @@ def _cv_kwargs_remapper(dct):
4041
json_type='object', default=None,
4142
description="keyword arguments for ``func``"),
4243
Parameter('period_min', custom_eval, default=None,
44+
json_type=json_type_eval('Float'),
4345
description=("minimum value for a periodic function, "
4446
"None if not periodic")),
4547
Parameter('period_max', custom_eval, default=None,
48+
json_type=json_type_eval('Float'),
4649
description=("maximum value for a periodic function, "
4750
"None if not periodic")),
4851

4952
],
53+
description="Use an MDTraj analysis function to calculate a CV.",
5054
name="mdtraj"
5155
)
5256

‎paths_cli/compiling/engines.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from paths_cli.compiling.core import Parameter
44
from paths_cli.compiling.tools import custom_eval_int_strict_pos
55
from paths_cli.compiling.plugins import EngineCompilerPlugin, CategoryPlugin
6+
from paths_cli.compiling.json_type import json_type_eval
67

78

89
def load_openmm_xml(filename):
@@ -34,8 +35,10 @@ def _openmm_options(dct):
3435
Parameter('integrator', load_openmm_xml, json_type='string',
3536
description="XML file with the OpenMM integrator"),
3637
Parameter('n_steps_per_frame', custom_eval_int_strict_pos,
38+
json_type=json_type_eval('IntStrictPos'),
3739
description="number of MD steps per saved frame"),
3840
Parameter("n_frames_max", custom_eval_int_strict_pos,
41+
json_type=json_type_eval('IntStrictPos'),
3942
description=("maximum number of frames before aborting "
4043
"trajectory")),
4144
]

‎paths_cli/compiling/json_type.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11

22
def json_type_ref(category):
33
return {"$ref": f"#/definitions/{category}_type"}
4+
5+
def json_type_eval(check_type):
6+
return {"$ref": f"#/definitions/Eval{check_type}"}
7+
8+
def json_type_list(item_type):
9+
return {'type': 'array',
10+
'items': item_type}

‎paths_cli/compiling/networks.py‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@
44
from paths_cli.compiling.tools import custom_eval
55
from paths_cli.compiling.plugins import NetworkCompilerPlugin, CategoryPlugin
66
from paths_cli.compiling.root_compiler import compiler_for
7+
from paths_cli.compiling.json_type import (
8+
json_type_ref, json_type_list, json_type_eval
9+
)
710

811
build_interface_set = InstanceCompilerPlugin(
912
builder=Builder('openpathsampling.VolumeInterfaceSet'),
1013
parameters=[
11-
Parameter('cv', compiler_for('cv'), description="the collective "
12-
"variable for this interface set"),
13-
Parameter('minvals', custom_eval), # TODO fill in JSON types
14-
Parameter('maxvals', custom_eval), # TODO fill in JSON types
14+
Parameter('cv', compiler_for('cv'), json_type=json_type_ref('cv'),
15+
description=("the collective variable for this interface "
16+
"set")),
17+
Parameter('minvals', custom_eval,
18+
json_type=json_type_list(json_type_eval("Float")),
19+
description=("minimum value(s) for interfaces in this"
20+
"interface set")),
21+
Parameter('maxvals', custom_eval,
22+
json_type=json_type_list(json_type_eval("Float")),
23+
description=("maximum value(s) for interfaces in this"
24+
"interface set")),
1525
],
1626
name='interface-set'
1727
)
@@ -49,8 +59,10 @@ def tis_trans_info(dct):
4959
builder=Builder('openpathsampling.TPSNetwork'),
5060
parameters=[
5161
Parameter('initial_states', compiler_for('volume'),
62+
json_type=json_type_list(json_type_ref('volume')),
5263
description="initial states for this transition"),
5364
Parameter('final_states', compiler_for('volume'),
65+
json_type=json_type_list(json_type_ref('volume')),
5466
description="final states for this transition")
5567
],
5668
name='tps'

‎paths_cli/compiling/schemes.py‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
11
from paths_cli.compiling.core import (
22
Builder, Parameter
33
)
4-
from paths_cli.compiling.tools import custom_eval
4+
from paths_cli.compiling.tools import (
5+
custom_eval, custom_eval_int_strict_pos
6+
)
57
from paths_cli.compiling.strategies import SP_SELECTOR_PARAMETER
68
from paths_cli.compiling.plugins import SchemeCompilerPlugin, CategoryPlugin
79
from paths_cli.compiling.root_compiler import compiler_for
10+
from paths_cli.compiling.json_type import (
11+
json_type_ref, json_type_list, json_type_eval
12+
)
813

914

10-
NETWORK_PARAMETER = Parameter('network', compiler_for('network'))
15+
NETWORK_PARAMETER = Parameter(
16+
'network',
17+
compiler_for('network'),
18+
json_type=json_type_ref('network'),
19+
description="network to use with this scheme"
20+
)
1121

12-
ENGINE_PARAMETER = Parameter('engine', compiler_for('engine')) # reuse?
22+
ENGINE_PARAMETER = Parameter(
23+
'engine', compiler_for('engine'),
24+
json_type=json_type_ref('engine'),
25+
description="engine to use with this scheme",
26+
) # reuse?
1327

1428
STRATEGIES_PARAMETER = Parameter('strategies', compiler_for('strategy'),
29+
json_type=json_type_ref('strategy'),
1530
default=None)
1631

1732

1833
SPRING_SHOOTING_PLUGIN = SchemeCompilerPlugin(
1934
builder=Builder('openpathsampling.SpringShootingMoveScheme'),
2035
parameters=[
2136
NETWORK_PARAMETER,
22-
Parameter('k_spring', custom_eval),
23-
Parameter('delta_max', custom_eval),
37+
Parameter('k_spring', custom_eval,
38+
json_type=json_type_eval("Float"),
39+
description="spring constant for the spring shooting move"),
40+
Parameter('delta_max', custom_eval_int_strict_pos,
41+
json_type=json_type_eval("IntStrictPos"),
42+
description=("maximum shift in shooting point (number of "
43+
"frames)"),
44+
),
2445
ENGINE_PARAMETER
2546
],
2647
name='spring-shooting',

‎paths_cli/compiling/strategies.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _strategy_name(class_name):
1212

1313

1414
def _group_parameter(group_name):
15-
return Parameter('group', str, default=group_name,
15+
return Parameter('group', str, json_type="string", default=group_name,
1616
description="the group name for these movers")
1717

1818

@@ -29,8 +29,16 @@ def _group_parameter(group_name):
2929
REPEX_GROUP_PARAMETER = _group_parameter('repex')
3030
MINUS_GROUP_PARAMETER = _group_parameter('minus')
3131

32-
REPLACE_TRUE_PARAMETER = Parameter('replace', bool, default=True)
33-
REPLACE_FALSE_PARAMETER = Parameter('replace', bool, default=False)
32+
REPLACE_TRUE_PARAMETER = Parameter(
33+
'replace', bool, json_type="bool", default=True,
34+
description=("whether this should replace existing objects (default "
35+
"True)")
36+
)
37+
REPLACE_FALSE_PARAMETER = Parameter(
38+
'replace', bool, json_type="bool", default=False,
39+
description=("whether this should replace existing objects (default "
40+
"False)")
41+
)
3442

3543

3644
ONE_WAY_SHOOTING_STRATEGY_PLUGIN = StrategyCompilerPlugin(

‎paths_cli/compiling/volumes.py‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from paths_cli.compiling.tools import custom_eval
66
from paths_cli.compiling.plugins import VolumeCompilerPlugin, CategoryPlugin
77
from paths_cli.compiling.root_compiler import compiler_for
8-
from paths_cli.compiling.json_type import json_type_ref
8+
from paths_cli.compiling.json_type import (
9+
json_type_ref, json_type_eval, json_type_list
10+
)
911

1012

1113
# TODO: extra function for volumes should not be necessary as of OPS 2.0
@@ -29,30 +31,31 @@ def cv_volume_build_func(**dct):
2931
Parameter('cv', compiler_for('cv'), json_type=json_type_ref('cv'),
3032
description="CV that defines this volume"),
3133
Parameter('lambda_min', custom_eval,
34+
json_type=json_type_eval("Float"),
3235
description="Lower bound for this volume"),
3336
Parameter('lambda_max', custom_eval,
37+
json_type=json_type_eval("Float"),
3438
description="Upper bound for this volume")
3539
],
40+
description=("A volume defined by an allowed range of values for the "
41+
"given CV."),
3642
name='cv-volume',
3743
)
3844

3945
build_cv_volume = CV_VOLUME_PLUGIN
4046

41-
# jsonschema type for combination volumes
42-
VOL_ARRAY_TYPE = {
43-
'type': 'array',
44-
'items': json_type_ref('volume'),
45-
}
46-
4747

4848
INTERSECTION_VOLUME_PLUGIN = VolumeCompilerPlugin(
4949
builder=lambda subvolumes: functools.reduce(operator.__and__,
5050
subvolumes),
5151
parameters=[
5252
Parameter('subvolumes', compiler_for('volume'),
53-
json_type=VOL_ARRAY_TYPE,
53+
json_type=json_type_list(json_type_ref('volume')),
5454
description="List of the volumes to intersect")
5555
],
56+
description=("A volume determined by the intersection of its "
57+
"constituent volumes; i.e., to be in this volume a point "
58+
"must be in *all* the constituent volumes."),
5659
name='intersection',
5760
)
5861

@@ -64,9 +67,12 @@ def cv_volume_build_func(**dct):
6467
subvolumes),
6568
parameters=[
6669
Parameter('subvolumes', compiler_for('volume'),
67-
json_type=VOL_ARRAY_TYPE,
70+
json_type=json_type_list(json_type_ref('volume')),
6871
description="List of the volumes to join into a union")
6972
],
73+
description=("A volume defined by the union of its constituent "
74+
"volumes; i.e., a point that is in *any* of the "
75+
"constituent volumes is also in this volume."),
7076
name='union',
7177
)
7278

0 commit comments

Comments
 (0)