Skip to content

Commit 7948e37

Browse files
committed
OPSStorageLoadMultiple for INIT_CONDS
1 parent f983f35 commit 7948e37

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

paths_cli/param_core.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,51 @@ def get(self, storage, name):
273273
raise RuntimeError("Couldn't find %s", name)
274274

275275
return result
276+
277+
278+
class OPSStorageLoadMultiple(OPSStorageLoadSingle):
279+
"""Objects that can guess a single object or have multiple specified.
280+
281+
Parameters
282+
----------
283+
param : :class:`.AbstractParameter`
284+
the Option or Argument wrapping a click decorator
285+
store : Str
286+
the name of the store to search
287+
value_strategies : List[Callable[(:class:`.Storage`, Str), Any]]
288+
The strategies to be used when the CLI provides a value for this
289+
parameter. Each should be a callable taking a storage and the string
290+
input from the CLI, and should return the desired object or None if
291+
it cannot be found.
292+
none_strategies : List[Callable[:class:`openpathsampling.Storage, Any]]
293+
The strategies to be used when the CLI does not provide a value for
294+
this parameter. Each should be a callable taking a storage, and
295+
returning the desired object or None if it cannot be found.
296+
"""
297+
def get(self, storage, names):
298+
"""Load desired objects from storage.
299+
300+
Parameters
301+
----------
302+
storage : openpathsampling.Storage
303+
the input storage to search
304+
names : List[Str] or None
305+
strings from CLI providing the identifier (name or index) for
306+
this object; None if not provided
307+
"""
308+
if names == tuple():
309+
names = None
310+
311+
if names is None or isinstance(names, (str, int)):
312+
listified = True
313+
names = [names]
314+
else:
315+
listified = False
316+
317+
results = [super(OPSStorageLoadMultiple, self).get(storage, name)
318+
for name in names]
319+
320+
if listified:
321+
results = results[0]
322+
323+
return results

paths_cli/parameters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import click
22
from paths_cli.param_core import (
3-
Option, Argument, OPSStorageLoadSingle, OPSStorageLoadNames,
4-
StorageLoader, GetByName, GetByNumber, GetOnly, GetOnlySnapshot,
5-
GetPredefinedName
3+
Option, Argument, OPSStorageLoadSingle, OPSStorageLoadMultiple,
4+
OPSStorageLoadNames, StorageLoader, GetByName, GetByNumber, GetOnly,
5+
GetOnlySnapshot, GetPredefinedName
66
)
77

88

@@ -18,7 +18,7 @@
1818
store='schemes',
1919
)
2020

21-
INIT_CONDS = OPSStorageLoadSingle(
21+
INIT_CONDS = OPSStorageLoadMultiple(
2222
param=Option('-t', '--init-conds', multiple=True,
2323
help=("identifier for initial conditions "
2424
+ "(sample set or trajectory)" + HELP_MULTIPLE)),

0 commit comments

Comments
 (0)