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]
launchapi.JobSpecificationArgsBuilder
prepare_job_spec_builder(argv, program_name, default_jobname, input_fn=None, set_driver_reserves_cores=False)
Prepare generic job specification builder.
str
get_matsci_user_data_dir()
Get the absolute path to the user's local MatSci data directory for storing custom templates, protocols, etc.
dict
parse_restart_parameters_file(path)
Parse parameters file.
 
write_restart_parameters_file(driver, args, outpath)
Write out original arguments to parameters file and add the file as an output file to any existing jobcontrol backend.
str
get_restart_id_filename(jobname)
For the given restart jobname, return the name of the file containing the job id.
 
extract_job_data(options)
Unzip the archive in the current directory.
 
archive_job_data(zip_path, files_path)
Create a zip archive in the current directory from the provided list of file paths.
 
create_restart_launcher(script, prog, input_name, output_name, zip_name, options, args)
list
create_restart_jobcmd(driver_path, zip_fn, restart_options, args, default_jobname)
Generate command-line list for the job restart.
 
write_idfile(jobobj)
Store the job id in a file as a signal to the GUI that a new job has been launched.
any
get_option(options, flag)
Return the option value associated with flag
 
set_option(options, flag, value)
Set the option value associated with flag
 
add_restart_parser_arguments(parser)
Add restart arguments to the parser
tuple
get_restart_options(options)
Get the command line options from the -restart_x flags
 
add_keyword_parser_argument(parser, arghelp=None)
Add a keyword argument to the parser
 
parse_keyword_list(options, exit_on_error=True, logger=None, validate=False)
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.
 
add_save_desmond_files_parser_argument(parser)
Add a SAVE_FLAG argument to the parser
bool or (bool, str)
check_license(panel=None, token=94, 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(*args, **kwds)
A context manager which changes the working directory to the given path, and then changes it back to its previous value on exit.
str
clean_string(string, default='title')
Cleans the given string by removing special characters to make it acceptable for a file name.
 
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).
Variables [hide private]
  FLAG_KEYWORDS = '-keywords'
  SAVE_FLAG = '-save_trj_data'
  SAVE_NONE = 'none'
  SAVE_CMS = 'cms'
  SAVE_TRJ = 'trj'
  SAVE_FLAG_OPTS = ['none', 'cms', 'trj']
  DRIVER = 'driver'
  ARGS = 'args'
  RESTART_PARAMETERS_FILENAME = 'parameters.cmd'
  FLAG_USEZIPDATA = '-use_zip_data'
  FLAG_RESTART_PROJ = '-restart_proj'
  FLAG_RESTART_DISP = '-restart_disp'
  FLAG_RESTART_VIEWNAME = '-restart_viewname'
  FLAG_RESTART_HOST = '-restart_host'
  FLAG_RESTART_JOBNAME = '-restart_jobname'
  RESTART_PROGRAM_NAME = 'RestartWorkflow'
  RESTART_DEFAULT_JOBNAME = 'restart_workflow'
  CLEAN_AND_UNIQUIFY_MAX_LEN = 100
  APP_DIR = 'matsci_templates'
  __package__ = 'schrodinger.application.matsci'
Function Details [hide private]

prepare_job_spec_builder(argv, program_name, default_jobname, input_fn=None, set_driver_reserves_cores=False)

 

Prepare generic job specification builder. If set_driver_reserves_cores script (driver) is set to True, script is expected to use all the cores (cpus), similar to umbrella mode in multisim. For an example see stress-strain driver. For all other cases (such as in opto/hopping/amorphous) keep set_driver_reserves_cores to False.

Parameters:
  • argv (list) - The list of command line arguments, including the script name at [0], similar to that returned by sys.argv
  • program_name (str) - Program name
  • default_jobname (str) - Default job name
  • input_fn (str) - Input filename
  • set_driver_reserves_cores (bool) - If True, enable launchapi.setDriverReservesCores
Returns: launchapi.JobSpecificationArgsBuilder
Job specification builder object

get_matsci_user_data_dir()

 

Get the absolute path to the user's local MatSci data directory for storing custom templates, protocols, etc.

Returns: str
The absolute path the Materials Science data parent directory

parse_restart_parameters_file(path)

 

Parse parameters file.

Format of the file: 1st line is driver's filename 2nd line is original arguments passed to the driver

Parameters:
  • path (str) - Path to the file with original arguments
Returns: dict
Dictionary with parsed values

write_restart_parameters_file(driver, args, outpath)

 

Write out original arguments to parameters file and add the file as an output file to any existing jobcontrol backend.

Parameters:
  • driver (str) - Driver's filename
  • args (list) - Original arguments passed to driver
  • outpath (str) - Path to the parameters file to write original arguments

get_restart_id_filename(jobname)

 

For the given restart jobname, return the name of the file containing the job id.

Returns: str
The name of the restart jobid file

extract_job_data(options)

 

Unzip the archive in the current directory. All the error handling is on the caller function.

Parameters:
  • options (argparse.Namespace) - The object holding all the option values

archive_job_data(zip_path, files_path)

 

Create a zip archive in the current directory from the provided list of file paths. All the error handling is on the caller function.

Parameters:
  • path (zip_path) - Path to the new zip archive to be created
  • path (zip_path) - List of files to be zipped

create_restart_jobcmd(driver_path, zip_fn, restart_options, args, default_jobname)

 

Generate command-line list for the job restart.

Parameters:
  • driver_path (str) - Path to the driver
  • zip_fn (str) - Filename of the zip file with all restart files
  • restart_options (argparse.Namespace) - The object holding all the option values
  • args (list) - List of the arguments passed to the original run
  • default_jobname (str) - Default job name
Returns: list

write_idfile(jobobj)

 

Store the job id in a file as a signal to the GUI that a new job has been launched.

Parameters:

get_option(options, flag)

 

Return the option value associated with flag

Parameters:
  • options (argparse.Namespace) - The object holding all the option values
  • flag (str) - The flag for the desired option.
Returns: any
The value associated with flag, or None if flag (minus any leading dashes) is not found as a property on options

set_option(options, flag, value)

 

Set the option value associated with flag

Parameters:
  • options (argparse.Namespace) - The object holding all the option values
  • flag (str) - The flag for the desired option. If the string starts with a '-', the '-' is removed.
  • value (any) - The value to set the option.flag value to

add_restart_parser_arguments(parser)

 

Add restart arguments to the parser

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

get_restart_options(options)

 

Get the command line options from the -restart_x flags

Returns: tuple
tuple of strings (viewname, incorporation, project, host:cpu, jobname)

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, logger=None, validate=False)

 

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.
  • logger (logging.Logger) - The logger to use for recording error messages, otherwise they'll be printed.
  • validate (bool) - Whether keywords/values not recognized by Jaguar should be considered an error.
Raises:

add_save_desmond_files_parser_argument(parser)

 

Add a SAVE_FLAG argument to the parser

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

check_license(panel=None, token=94, 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(*args, **kwds)

 

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

clean_string(string, default='title')

 

Cleans the given string by removing special characters to make it acceptable for a file name. If the string is blank, it will be replaced by the value of default.

Parameters:
  • string (str) - The string to clean.
  • default (str) - The name to use if string is blank
Returns: str
A string usable as a filename

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