schrodinger.application.desmond.packages.cui module

Common command-line interface for Desmond scripts

Copyright Schrodinger, LLC. All rights reserved.

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
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)
parse_args(args=None, **kwargs)
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. We use this class to delay slow parsers’ running.

parse()

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

priority

Return the priority of this parser.

Return type:int
string

Return the original string from the command line.

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.error(message, exit_code=1, should_exit=True)
schrodinger.application.desmond.packages.cui.info(message)
schrodinger.application.desmond.packages.cui.jc_backend_reg_output(fname)

Register (on the fly) an output file for jobcontrol to transfer.

Parameters:fname (str) – Output file name to be transferred by jobcontrol. The file can be a directory.
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.warn(message)