schrodinger.application.matsci.parserutils module

Utilities for working with argument parsers

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.application.matsci.parserutils.type_ranged_num(arg, top=None, bottom=0.0, top_allowed=False, bottom_allowed=False, typer=<class 'float'>)

Validate that the argument is a number over a given range.

Note:This function can be used to directly create argparse typing for
numbers within a specified range using a lambda function such as:
eqopts.add_argument(
FLAG_TEMP, action=’store’, type=lambda x:parserutils.type_ranged_num(x, top=423, bottom=273), metavar=’KELVIN’, help=’Simulation temperature for MD equilibration step’)
Parameters:
  • arg (str) – The argument to validate
  • top (float or int) – The upper limit of the allowed range
  • bottom (float or int) – The lower limit of the allowed range
  • top_allowed (bool) – Whether arg may take the top value or not (whether the upper limit is inclusive or exclusive)
  • bottom_allowed (bool) – Whether arg may take the bottom value or not (whether the bottom limit is inclusive or exclusive)
  • typer (callable) – Should be one of the built-in float or int functions and defines the type of the value returned from this function.
Return type:

float or int

Returns:

The argument converted to a float or int, depending on the value of the typer keyword argument

Raises:

argparse.ArgumentTypeError – If the argument cannot be converted to a ranged floating point number in the given range

schrodinger.application.matsci.parserutils.type_ranged_int(*args, **kwargs)

Validate that the argument is an int over a given range

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_positive_float(arg)

Validate that the argument is a positive float

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_negative_float(arg)

Validate that the argument is a negative float

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_positive_int(arg)

Validate that the argument is a positive int

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_nonnegative_int(arg)

Validate that the argument is a nonnegative int

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_nonpositive_float(arg)

Validate that the argument is a nonpositive float

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_nonzero_percent(arg)

Validate that the argument is a percent but not zero

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_random_seed(arg)

Validate that the argument is a valid random seed value. If a random value is requested, that value is generated and returned.

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_file(arg)

Validate that the argument is an existing filename

Parameters:arg (str or unicode) – The argument to validate
Return type:str
Returns:The str-ed argument
Raises:argparse.ArgumentTypeError – If the given filename does not exist
schrodinger.application.matsci.parserutils.type_nonnegative_float(arg)

Validate that the argument is a nonnegative float

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.get_trj_dir_name(st)

Get the trajectory directory name from the given structure.

Parameters:st (schrodinger.structure.Structure) – the structure
Return type:str or None
Returns:the trajectory directory name or None if there isn’t one
schrodinger.application.matsci.parserutils.type_cms_file(arg, ensure_trj=False)

Validate that the argument is a cms file.

Parameters:
  • arg (str or unicode) – the argument to validate
  • ensure_trj (bool) – ensure that the cms file has trajectory information, for example is a Desmond output file
Raises:

argparse.ArgumentTypeError – if the given argument is not a cms file

Return type:

str

Returns:

the str-ed argument

schrodinger.application.matsci.parserutils.type_cms_with_trj(arg)

Validate that the argument is a cms file with trajectory information.

Parameters:arg (str or unicode) – the argument to validate
Return type:str
Returns:the str-ed argument
schrodinger.application.matsci.parserutils.type_json_file(arg)

Validate that the argument is a json file.

Parameters:arg (str or unicode) – the argument to validate
Raises:argparse.ArgumentTypeError – if the given argument is not a json file
Return type:str
Returns:the str-ed argument
schrodinger.application.matsci.parserutils.type_yaml_file(arg)

Validate that the argument is a yaml file.

Parameters:arg (str or unicode) – the argument to validate
Raises:argparse.ArgumentTypeError – if the given argument is not a yaml file
Return type:str
Returns:the str-ed argument
schrodinger.application.matsci.parserutils.type_yaml_str(arg)

Load the arg as a yaml string.

Parameters:arg (str or unicode) – the argument to validate
Raises:argparse.ArgumentTypeError – if the given argument is not in yaml format
Return type:dict
Returns:loaded yaml string
schrodinger.application.matsci.parserutils.type_structure_file(arg)

Validate that the argument is a structure file that can be read by StructureReader.

Parameters:arg (str or unicode) – the argument to validate
Raises:argparse.ArgumentTypeError – if the given argument is not a readable structure file
Return type:str
Returns:the str-ed argument
schrodinger.application.matsci.parserutils.type_periodic_structure_file(arg)

Validate that the argument is a periodic structure file (priority is chorus followed by pdb).

Parameters:arg (str or unicode) – the argument to validate
Raises:argparse.ArgumentTypeError – if the given argument is not a periodic structure file
Return type:str
Returns:the str-ed argument
schrodinger.application.matsci.parserutils.type_element(value)

Validate that the argument is a valid atomic atymbol

Parameters:value (str) – The argument to validate
Return type:str
Returns:The validated argument
Raises:argparse.ArgumentTypeError – If the argument is not a valid atomic symbol
schrodinger.application.matsci.parserutils.type_forcefield(value)

Validate that the argument is a valid force field name

This accepts both OPLS3 and OPLS3e for force field #16

Parameters:value (str) – The argument to validate
Return type:str
Returns:The canonical force field name
Raises:argparse.ArgumentTypeError – If the argument is not a valid atomic symbol
schrodinger.application.matsci.parserutils.type_forcefield_and_get_number(value)

Validate that the argument is a valid force field name and returns both the canonical force field name and number.

This accepts both OPLS3 and OPLS3e for force field #16

Parameters:value (str) – The argument to validate
Return type:str, int
Returns:The canonical force field name and the corresponding force field int
Raises:argparse.ArgumentTypeError – If the argument is not a valid atomic symbol
schrodinger.application.matsci.parserutils.type_desmond_ensemble(value)

Validate that the argument is a valid desmond ensemble

Parameters:value (str) – The argument to validate
Return type:str
Returns:The validated argument
Raises:argparse.ArgumentTypeError – If the argument is not a valid desmond ensemble
schrodinger.application.matsci.parserutils.valid_forcefield_info()

Get an informative sentence that can be included in help messages that indicate the valid force field names.

Note that these are the default names and type_forcefield will accept many variants of them, including OPLS3 for OPLS3E.

Return type:str
Returns:A full sentence describing the valid force field names
schrodinger.application.matsci.parserutils.type_keywords_to_dict(value)

Convert a string of ‘keyword=value keyword=value …’ to a dictionary keyed by keyword. Values are the keyword values.

Note:

When calling parser.add_argument for the flag that uses this function, do not use “nargs=+”. That will result in the return value from this function being placed as an item in a list. Instead, do not use nargs at all and simply use “action=’store’”. All of the keyword=value pairs will then be passed into this function as a single string. Example:

parser.add_argument(

jobutils.FLAG_KEYWORDS, action=’store’, metavar=’KEYWORD=VALUE KEYWORD=VALUE …’, type=parserutils.type_keywords_to_dict, help=’Jaguar keywords given as a space-separated keyword=value ‘

‘ pairs’

)

will result in options.keyword = the dictionary returned by this function

Parameters:

value (str) – The argument to validate

Return type:

dict

Returns:

A dictionary with keywords as key keyword values as values

Raises:

argparse.ArgumentTypeError – If the argument is not a valid keyword string

schrodinger.application.matsci.parserutils.type_keywords_to_string(value)

Validate the format of a string of ‘keyword=value keyword=value …’

Note:

When calling parser.add_argument for the flag that uses this function, do not use “nargs=+”. That will result in the return value from this function being placed as an item in a list. Instead, do not use nargs at all and simply use “action=’store’”. All of the keyword=value pairs will then be passed into this function as a single string. Example:

parser.add_argument(

jobutils.FLAG_KEYWORDS, action=’store’, metavar=’KEYWORD=VALUE KEYWORD=VALUE …’, type=parserutils.type_keywords_to_string, help=’Jaguar keywords given as a space-separated keyword=value ‘

‘ pairs’

)

will result in options.keyword = the string returned by this function

Parameters:

value (str) – The argument to validate

Return type:

string

Returns:

The original command line string

Raises:

argparse.ArgumentTypeError – If the argument is not a valid keyword string

schrodinger.application.matsci.parserutils.type_positive_integer_comma_list(value)

Validate that the argument is a interger list separated by comma

Parameters:value (str) – string containing numbers separated by commas
Return type:list
Returns:The validated argument positive integers coverted to list
Raises:argparse.ArgumentTypeError – If the argument is not a valid desmond ensemble
schrodinger.application.matsci.parserutils.type_percentage(value)

Validate that the argument is a percentage between 0 and 100

see type_ranged_num for documentation of arguments, return values and exceptions raised

schrodinger.application.matsci.parserutils.type_asl(asl)

Validate ASL.

Return type:str
Returns:ASL
Raises:argparse.ArgumentTypeError – If ASL is not valid
schrodinger.application.matsci.parserutils.type_desmond_cfg(arg)

Validate that the argument is a desmond CFG file.

Parameters:arg (str or unicode) – the argument to validate
Raises:argparse.ArgumentTypeError – if the given argument is not a readable CFG file
Return type:str
Returns:the str-ed argument
class schrodinger.application.matsci.parserutils.DriverParser(*args, **kwargs)

Bases: argparse.ArgumentParser

Subclass that shows driver usage relative to python/scripts or python/common directories and adds a help argument by default

__init__(*args, **kwargs)

Accepts all arguments normally given for an ArgumentParser

add_argument(dest, ..., name=value, ...)

add_argument(option_string, option_string, …, name=value, …)

add_argument_group(*args, **kwargs)
add_mutually_exclusive_group(**kwargs)
add_subparsers(**kwargs)
convert_arg_line_to_args(arg_line)
error(message: string)

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

exit(status=0, message=None)
format_help()
format_usage()
get_default(dest)
parse_args(args=None, namespace=None)
parse_known_args(args=None, namespace=None)
print_help(file=None)
print_usage(file=None)
register(registry_name, value, object)
set_defaults(**kwargs)