schrodinger.tasks.param_cli module

schrodinger.tasks.param_cli.get_input_group(parser: ArgumentParser)

Get the standard task input group from a parser. Allows users to add custom arguments to the input group even if they don’t map directly to a task input param.

class schrodinger.tasks.param_cli.ParamCLI

Bases: object

The command line interface for a compound param class. Subclass this class to define custom command line interfaces for compound param classes.

Manages construction and customization of the param argspec objects, construction and customization of the parser, conversion of command line arguments to param instances, and conversion of param instances to command line arguments.

Subclasses should define the ParamClass and implement mainFunction.

A param argument is a parser argument that corresponds to a param in the self.ParamClass. Param arguments can be customized by calling updateParamArg, skipParamArg, and flattenParamArgs in the customizeParamArgs method.

Additional arguments that do not directly correspond to a param in ParamClass can be defined and processed in customizeParser and customProcessParsedArgs methods.

For more control, subclasses can instead reimplement makeParser and makeParamFromNamespace for creating a custom parser and namespace processing.

Example usage:

# foo.py
class FooParam(CompoundParam):
    ...

class FooCLI(ParamCLI):
    ParamClass = FooParam

    def customizeParamArgs(self):
        self.updateParamArg(FooParam.c1.x, name='-c1x', required=True)

A command line interface is available now at $SCHRODINGER/run foo.py -h.

ParamClass = NotImplemented
ADD_MODULE_FUNCTIONS = True
inCustomizeParamArgs()
customizeParamArgs() None

A param arg is a parser argument that corresponds to a param in the self.ParamClass. See customizeParser for adding non-param args.

The following methods can be called from this method to customize param args:

updateParamArg(param: CompoundParam, positional_order: int = None, **kwargs) None

Update param arg for the given abstract param.

Parameters:
  • param – Abstract param for which we want to customize the argument. For example, FooParam.coord.x.

  • positional_order – When specified, makes the argument positional and sets its order relative to other positional args.

  • kwargs – kwargs for argparse.ArgumentParser.add_argument

skipParamArg(param: CompoundParam) None

Omit the param and any of its children from the auto-generated argparse arguments.

Parameters:

param – Abstract param to skip. For example, FooParam.coord or FooParam.coord.x.

flattenParamArgs(param: CompoundParam) None

Flatten the argument name for the specified param and its children in the auto-generated argparse arguments. E.g. -x instead of -coord.x and -baz instead of -foo.bar.baz.

Parameters:

param – Abstract param to flatten. For example, FooParam.coord or FooParam.coord.x.

customizeParser(parser: ArgumentParser) None

Use this method to add additional arguments that do not correspond directly to any param in self.ParamClass. If custom arguments are added, override customProcessParsedArgs to consume the values of these custom arguments after they have been parsed.

customProcessParsedArgs(param: NotImplemented, namespace: Namespace) None

Process the parsed namespace to populate the param instance with desired values.

makeParamFromArgs(argv: list[str]) NotImplemented

Make a param instance from command-line arguments.

makeParamFromNamespace(namespace: Namespace) NotImplemented

Make and populate a param instance from a namespace of parsed args.

If makeParser is reimplemented, then this method should also be reimplemented to handle the custom namespace.

makeArgsFromParam(param: NotImplemented) list[str]

Make a list of cmdline arguments from a param instance.

makeOptionalArgsFromParam(param: NotImplemented) list[str]

Make optional args from a param. Only param-mapped arguments are generated in the default implementation. Override to include additional arguments.

makePositionalArgsFromParam(param: NotImplemented) list[str]

Make positional args from a param. Only param-mapped arguments are generated in the default implementation. Override to include additional arguments.

makeCmd(param: NotImplemented) list[str]

Return a command that invokes this CLI using inputs from the given param instance.

makeParser() ArgumentParser

Make the argument parser.

Subclasses can reimplement this method to create a completely custom parser that doesn’t get populated with any auto-generated arguments.

createBaseParser() ArgumentParser

Create the base parser to which all params will be added.

getParserDescription() Optional[str]

Return a description for the parser to use. If the CLI has a docstring, it will be used, otherwise the docstring of the param class is used.

main(argv: list[str] = None) int

This method serves as the main function, and will be added to the module’s namespace as main. Implement mainFunction to define the execution behavior of the CLI.

mainFunction(param: CompoundParam) int
classmethod getInstance()
__init__()
schrodinger.tasks.param_cli.get_description(*objects) Optional[str]

Get description from the docstring of the first object that has a docstring.