Package schrodinger :: Package application :: Package matsci :: Module jobutils
[hide private]
[frames] | no frames]

Module jobutils

Classes [hide private]
  StringCleaner
Manages the cleaning of strings.
Functions [hide private]
 
add_keyword_parser_argument(parser, arghelp=None)
Add a keyword argument to the parser
 
parse_keyword_list(options, exit_on_error=True)
Adds keystring and keydict properties to the argparse options object that are the list of keyword arguments turned into, respectively, a string or a dictionary.
bool or (bool, str)
check_license(panel=None, token=license.MATERIALSCIENCE_MAIN, name="", as_validator=False)
Check if a valid token exists
str or None
create_run_dir(panel, jobname)
Create a subdirectory to run a job in, asking the user and removing existing directories if needed.
 
string_to_value(string)
Change a text string from a file to a value.
 
working_directory(path)
A context manager which changes the working directory to the given path, and then changes it back to its previous value on exit.
 
zip_and_set_incorporation(zipname, filelist)
Zip up all the requested files and set the resulting zip file as the job control backend structure output file (if runnning under job control).
Function Details [hide private]

add_keyword_parser_argument(parser, arghelp=None)

 

Add a keyword argument to the parser

Parameters:
  • parser (argparse.ArgumentParser) - The parser to add this argument to

parse_keyword_list(options, exit_on_error=True)

 

Adds keystring and keydict properties to the argparse options object that are the list of keyword arguments turned into, respectively, a string or a dictionary. Valid keyword syntax is checked for.

Typical usage:

jobutils.add_keyword_parser_argument(parser) options = parser.parse_args(args) jobutils.parse_keyword_list(options) print options.keystring, options.keydict

Parameters:
  • options (argparse.Namespace) - The parser Namespace object with a keywords attribute
  • exit_on_error (bool) - True if the ValueError for keyword syntax should result in a message being printed and sys.exit() being called, False if the error should just be raised.
Raises:
  • ValueError - If an invalid keyword pair syntax is detected and handle_error is False

check_license(panel=None, token=license.MATERIALSCIENCE_MAIN, name="", as_validator=False)

 

Check if a valid token exists

Parameters:
  • panel (schrodinger.ui.qt.appframework.AppFramework) - panel to use to put up an error dialog if no license
  • token (schrodinger.utils.license constant) - A token type from the schrodinger.utils.license module, such as MATERIALSCIENCE_MAIN or MATERIALSCIENCE_GA
  • name (str) - The user-identifiable name for the token - used for error messages. If not provided, the string used in the license module for this token (if one exists) will be used.
  • as_validator (bool) - If True, this function will work as an AF2 validation method. Instead of posting a dialog or printing a message for a failed license check, it will return (False, error_message).
Returns: bool or (bool, str)
True if valid license exists. If no valid license exists, False will be returned by default, but (False, msg) will be returned if as_validator=True. Note that (False, msg) evalutes to True so must be handled by the calling routine as not a boolean if as_validator=True.

create_run_dir(panel, jobname)

 

Create a subdirectory to run a job in, asking the user and removing existing directories if needed.

Parameters:
  • panel (schrodinger.ui.qt.appframework.AppFramework) - panel to use to put up an error dialog if no license
  • jobname (str) - The name of the job. The directory will be jobname + _dir
Returns: str or None
The path to the directory or None if an existing directory was found and the user elected not to remove it

string_to_value(string)

 

Change a text string from a file to a value. Converts string values of special Python tokens such as True, False or None to the Python tokens. Converts numbers to int or float if possible.

Parameters:
  • string (str) - The string to convert
Returns:
string converted to, in order of preference: [True|False|None], int, float, or input type

working_directory(path)

 

A context manager which changes the working directory to the given path, and then changes it back to its previous value on exit.

Decorators:
  • @contextlib.contextmanager

zip_and_set_incorporation(zipname, filelist)

 

Zip up all the requested files and set the resulting zip file as the job control backend structure output file (if runnning under job control).

Parameters:
  • zipname (str) - The name of the zip archive to create
  • filelist (list) - Each item in filelist is the name of a file to add to file zipname