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_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_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_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_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