Skip to content

Commit

Permalink
Merge pull request #178 from TheoChem-VU/177-add-cli-command-to-read-…
Browse files Browse the repository at this point in the history
…a-calculation

177 add cli command to read a calculation
  • Loading branch information
YHordijk authored Mar 21, 2024
2 parents 3c743ff + 5c352c9 commit 8a09e88
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/tcutility/cli_scripts/read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
""" Module containing functions for reading and printing calculation results to the CL """
import argparse
from tcutility import results
from pprint import pprint


def create_subparser(parent_parser: argparse.ArgumentParser):
desc = "Read results from a calculation."
subparser = parent_parser.add_parser('read', help=desc, description=desc)
subparser.add_argument("-s", "--status",
help="Shortcut to only print the status of the calculation.",
default=False,
action="store_true")
subparser.add_argument("-p", "--properties",
help="Shortcut to only print calculated properties for the calculation.",
default=False,
action="store_true")
subparser.add_argument("workdir",
type=str,
help="The calculation directory to read the results from.")
subparser.add_argument("keys",
type=str,
nargs='*',
help="The keys to read from the results.")


def main(args: argparse.Namespace):
res = results.read(args.workdir)

# if status flag was set we print the status name
if args.status:
print(res.status.name)
return

# if properties flag was set we print all properties
if args.properties:
pprint(res.properties)
return

# print specific keys
if len(args.keys) > 0:
ret = {k: res.get_multi_key(k) for k in args.keys}
# if only one key was given we just print the value
if len(ret) == 1:
print(list(ret.values())[0])
return
pprint(ret)
return

# if we did not give keys or set flags we just print everything
pprint(res)
3 changes: 2 additions & 1 deletion src/tcutility/cli_scripts/tcparser.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from tcutility.cli_scripts import concatenate_irc, job_script
from tcutility.cli_scripts import read, job_script, concatenate_irc

# to add a script:
# 1. Add a create_subparser function and main function to your script.
# 2. Import the script.
# 3. Add it to the dictionary below {program_name: script-module}.
sub_programs = {
"read": read,
"optimize": job_script,
"concat-irc": concatenate_irc,
}
Expand Down

0 comments on commit 8a09e88

Please sign in to comment.