schrodinger.application.desmond.packages.cui module

Common command-line interface for Desmond scripts

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.application.desmond.packages.cui.info(message)
schrodinger.application.desmond.packages.cui.warn(message)
schrodinger.application.desmond.packages.cui.error(message, exit_code=1, should_exit=True)
schrodinger.application.desmond.packages.cui.all_fnames_in_dir(dname)

Returns all regular files under the given directory, including those in subdirectories.

Parameters

dname (str) – Path of the directory

Return type

list of str

schrodinger.application.desmond.packages.cui.jc_reg_input(builder, fname)

Register an input file for jobcontrol to transfer.

Parameters
  • builder (launchapi.JobSpecificationArgsBuilder) – You can get a builder by calling CommandLine.get_job_spec.

  • fname (str) – Input file name to be transferred by jobcontrol. The file can be a directory, and in this case all regular files under this directory will be transferred. If fname contains a relative path, the relative path will be preserved on the host.

schrodinger.application.desmond.packages.cui.jc_reg_output(builder, fname)

Preregister an output file for jobcontrol to transfer.

Parameters
  • builder (launchapi.JobSpecificationArgsBuilder) – You can get a builder by calling CommandLine.get_job_spec.

  • fname (str) – Input file name to be transferred by jobcontrol. The file can be a directory.

schrodinger.application.desmond.packages.cui.jc_backend_reg_output(fname)

Register (on the fly) an output file for jobcontrol to transfer. No effects if the process is not under jobcontrol.

Parameters

fname (str) – Output file name to be transferred by jobcontrol. The file can be a directory.

schrodinger.application.desmond.packages.cui.parse_slice(s)

Return a slice object derived from the given string s, in format of ‘i’, ‘start:end’, or ‘start:end:step’.

schrodinger.application.desmond.packages.cui.validate_and_enclose_asl(value, allow_empty=False, allow_dynamic=True)
class schrodinger.application.desmond.packages.cui.LazyParser(parser, priority=0)

Bases: object

Some argument parsers are so slow, e.g., the msys parser. We should avoid running them unless they are really needed. For example, when user just wants to see the help, or when there is another parsing errors which interrupts the execution of the command, there is no need to run these slow parsers. Some arguments depend on the values of other arguments to be fully parsed, e.g., -trj-frame-cutting (see its parser _parse_trj_frame_cutting above). For both types of arguments, we can use this class to delay and order their parsings.

__init__(parser, priority=0)
Parameters
  • parser (Callable object) – It should take a string argument, parse the string, and return the resultant object.

  • priority (int: 0-9) – Specify the priority of parsing. High numbered object will be parsed earlier.

parse(*args, **kwargs)

Calls the actual parser on the cached string and returns the parsing result.

property string

Return the original string from the command line.

property priority

Return the priority of this parser.

Return type

int

class schrodinger.application.desmond.packages.cui.CommandLine(spec=46, **kwargs)

Bases: argparse.ArgumentParser

Use this class to define common command line arguments such input cms file, input trajectory, output file base name, trajectory slicing option, and so on.

After calling parse_args method, you will have those arguments parsed properly, and you will get the cms.Cms object, the msys.System object, and the trajectory object (sliced properly), automatically.

You can use the spec argument to custom your command line interface. Examples:

1: spec = REQUIRE_MSYS_CMS + REQUIRE_TRJ + REQUIRE_OUT + SLICE_TRJ # This will give you the following: # cms - First positional argument for cms input, and when it’s parsed, # you will get both msys and cms models. # trj - Second positional argument for trajectory input # out - Third positional argument for output base name # -slice-trj # - Option for slicing trajectory

2: spec = REQUIRE_CMS_ONLY + REQUIRE_TRJ + REQUIRE_OUT + SLICE_TRJ # Similar to the first example, but parsing the cms input file will return # only the cms model.

3: spec = REQUIRE_CMS_ONLY + OPTIONAL_TRJ + REQUIRE_OUT + SLICE_TRJ # This will give you the following: # cms - First positional argument for cms input, and when it’s parsed, # you will get the cms models. # out - Second positional argument for output base name # -trj - Option for trajectory input # -slice-trj # - Option for slicing trajectory

Other standard options:
-ref-mae

Reference geometry from given .mae or .cms file. After parsing, the ref_mae attribute will provide (structure.Structure, str), where the first element is the Structure object of the file and the second the file’s name. If this option is unspecified, the attribute’ value will be None. spec: REF_MAE

-ref-frame

Reference geometry from a trajectory frame. After parsing, the ref_frame attribute will provide (traj.Frame, int), where the first element is the specified frame and the second the index of the frame. If this option is overridden by -ref-mae, or if the trajectory is not provided, the attribute’s value will be None. spec: REF_FRAME

-output-trajectory-format

Allow user to specify the output trajectory format. After parsing, the value of the out_trj_format attribute will be one of the contants defined within traj.Fmt. spec: OUT_TRJ_FORMAT

-trj-frame-cutting

Allow user to edit the trajectory in a by-frame fashion. The following are examples to demo the syntax of the value:

-trj-frame-cutting 0 # 1-frame trajectory containing only the 1st frame. Note that # frame index is 0-based, which is consistent with the # -slice-trj option.

-trj-frame-cutting 0,1,2 # 3-frame trajectory containing the initial three frames

-trj-frame-cutting “0 1 2” # Both spaces and commas can be used as the delimiter. Multiple # spaces or commas are allowed, and they are treated as a # single space.

-trj-frame-cutting 0,0,1,2 # 4-frame trajectory where the first frame in the original # trajectory is duplicated and inserted into the new trajectory # as the second frame.

-trj-frame-cutting 2,1,0,0 # Similar to the above, but the frame order is reversed.

-trj-frame-cutting 0:5 # 6-frame trajectory containing initial six frames from the # original trajectory. Note the range syntax. Note that the # range is inclusive, which diverges from the Python syntax that # -slice-trj uses, this is because the exclusive range is # extremely error prone and difficult to use for selections # though it’s fine for slicing.

-trj-frame-cutting “0: 5” # Invalid range expression: No space/commas allowed within a # range expression. But if no trajectory specified, this option # will be completely ignored, and no checking on the syntax will # be done.

-trj-frame-cutting 0:-2 # Similar to the original trajectory, but with the last frame # of the original trajectory dropped. Note the range syntax # again.

-trj-frame-cutting :: # A tricky way to select the whole original trajectory. # Note the defaults: # start = 0 # end = (number_of_frame - 1) # step = 1

-trj-frame-cutting 0:10:2 # Note the range syntax again. :2 specifies a step of 2. # Selected frame indices: 0, 2, 4, 6, 8, 10.

-trj-frame-cutting 0:-1,0:-1 # Duplicate the original trajectory, and concatenate the two # copies in a tail-to-head fashion.

-trj-frame-cutting -1:0 # Reverse the original trajectory

-trj-frame-cutting 0:4,6:-1 # Delete the frame 5.

__init__(spec=46, **kwargs)
del_argument(flag=None, dest=None)

Delete previously registered arguments that have the given flag or/and dest. No effects if such arguments are not found. Note: Positional arguments do NOT have flags. Specify dest to identify the positional argument to delete.

edit_argument_help(flag=None, dest=None, new_help='', edit='replace')

Sometimes we want to use a standard option with a custom help message. This method enables that.

Edit the help message of a previously registered argument as identified by the flag or/and dest argument. Note: Positional arguments do NOT have flags. Specify dest to identify the positional argument to edit.

Parameters
  • new_help (str, or cui.SUPPRESS) – The custom help message. If it is cui.SUPPRESS, the argument will NOT be shown in the help message.

  • edit (str. Must be one of the following: "replace", "prepend", and "append" (case sensitive)) – Indicate how to edit the existing help message. “replace” - Replace the old help message with new_help. “append” - Append the old help message with new_help. “prepend” - Prepend the old help message with new_help.

Raises

KeyError, if no argument is found.

parse_args(args=None, **kwargs)
get_job_spec(args=None, **kwargs)

Usage example:

In the python script:

def _get_cml():
    cml = cui.CommandLine(spec=(cui.REQUIRE_MSYS_CMS +                   cui.REQUIRE_TRJ + cui.SLICE_TRJ + cui.REQUIRE_OUT + cui.JC),
       description="my script")
    cml.add_argument(...)
    # Other application-specific options.

    return cml

def get_job_spec_from_args(argv):
    return _get_cml().get_job_spec(argv)[0]

The standard in-/output file options will be automatically registered for jobcontrol to transfer. If you have non-standard in-/output files, you can register them by yourself, for example:

def get_job_spec_from_args(argv):
    _, builder, a = _get_cml().get_job_spec(argv)
    cui.jc_reg_input(builder, a["input"])
    cui.jc_reg_input(builder, "data/auxiliary_file_in_a_dir")
    cui.jc_reg_output(builder, a["another_output"])
    return builder.getJobSpec()
Return type

(launchapi.JobSpecification, launchapi.JobSpecificationArgsBuilder, dict)

add_argument(dest, ..., name=value, ...)
add_argument(option_string, option_string, ..., name=value, ...) None
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_intermixed_args(args=None, namespace=None)
parse_known_args(args=None, namespace=None)
parse_known_intermixed_args(args=None, namespace=None)
print_help(file=None)
print_usage(file=None)
register(registry_name, value, object)
set_defaults(**kwargs)