Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
OPSStorageLoadMultiple for INIT_CONDS
  • Loading branch information
dwhswenson committed Dec 8, 2020
commit 7948e37fc0210e6ab80da38819972cad37a32d9e
48 changes: 48 additions & 0 deletions paths_cli/param_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,51 @@ def get(self, storage, name):
raise RuntimeError("Couldn't find %s", name)

return result


class OPSStorageLoadMultiple(OPSStorageLoadSingle):
"""Objects that can guess a single object or have multiple specified.

Parameters
----------
param : :class:`.AbstractParameter`
the Option or Argument wrapping a click decorator
store : Str
the name of the store to search
value_strategies : List[Callable[(:class:`.Storage`, Str), Any]]
The strategies to be used when the CLI provides a value for this
parameter. Each should be a callable taking a storage and the string
input from the CLI, and should return the desired object or None if
it cannot be found.
none_strategies : List[Callable[:class:`openpathsampling.Storage, Any]]
The strategies to be used when the CLI does not provide a value for
this parameter. Each should be a callable taking a storage, and
returning the desired object or None if it cannot be found.
"""
def get(self, storage, names):
"""Load desired objects from storage.

Parameters
----------
storage : openpathsampling.Storage
the input storage to search
names : List[Str] or None
strings from CLI providing the identifier (name or index) for
this object; None if not provided
"""
if names == tuple():
names = None

if names is None or isinstance(names, (str, int)):
listified = True
names = [names]
else:
listified = False

results = [super(OPSStorageLoadMultiple, self).get(storage, name)
for name in names]

if listified:
results = results[0]

return results
8 changes: 4 additions & 4 deletions paths_cli/parameters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click
from paths_cli.param_core import (
Option, Argument, OPSStorageLoadSingle, OPSStorageLoadNames,
StorageLoader, GetByName, GetByNumber, GetOnly, GetOnlySnapshot,
GetPredefinedName
Option, Argument, OPSStorageLoadSingle, OPSStorageLoadMultiple,
OPSStorageLoadNames, StorageLoader, GetByName, GetByNumber, GetOnly,
GetOnlySnapshot, GetPredefinedName
)


Expand All @@ -18,7 +18,7 @@
store='schemes',
)

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