Skip to content
Merged
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
Next Next commit
Add support for --table option in contents
  • Loading branch information
dwhswenson committed Dec 8, 2020
commit 695ed8b973f73e6c28899316de0d6dc3e6272ea3
36 changes: 29 additions & 7 deletions paths_cli/commands/contents.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
import click
from paths_cli.parameters import INPUT_FILE

UNNAMED_SECTIONS = {
'Steps': lambda storage: storage.steps,
'Move Changes': lambda storage: storage.movechanges,
'SampleSets': lambda storage: storage.samplesets,
'Trajectories': lambda storage: storage.trajectories,
'Snapshots': lambda storage: storage.snapshots
}

@click.command(
'contents',
short_help="list named objects from an OPS .nc file",
)
@INPUT_FILE.clicked(required=True)
def contents(input_file):
@click.option('--table', type=str, required=False,
help="table to show results from")
def contents(input_file, table):
"""List the names of named objects in an OPS .nc file.

This is particularly useful when getting ready to use one of simulation
scripts (i.e., to identify exactly how a state or engine is named.)
"""
storage = INPUT_FILE.get(input_file)
print(storage)
if table is None:
report_all_tables(storage)
else:
table_attr = table.lower()
try:
store = getattr(storage, table_attr)
except AttributeError:
print("This needs to raise a good error; bad table name")
else:
if table_attr in UNNAMED_SECTIONS:
print(get_unnamed_section_string(table_attr, store))
else:
print(get_section_string_nameable(table_attr, store,
_get_named_namedobj))

def report_all_tables(storage):
store_section_mapping = {
'CVs': storage.cvs, 'Volumes': storage.volumes,
'Engines': storage.engines, 'Networks': storage.networks,
Expand All @@ -26,12 +52,8 @@ def contents(input_file):
print(get_section_string_nameable('Tags', storage.tags, _get_named_tags))

print("\nData Objects:")
unnamed_sections = {
'Steps': storage.steps, 'Move Changes': storage.movechanges,
'SampleSets': storage.samplesets,
'Trajectories': storage.trajectories, 'Snapshots': storage.snapshots
}
for section, store in unnamed_sections.items():
for section, store_func in UNNAMED_SECTIONS.items():
store = store_func(storage)
print(get_unnamed_section_string(section, store))

def _item_or_items(count):
Expand Down