schrodinger.application.phase.packages.phase_utils module

Module with common functionality for all Phase backends.

Copyright Schrodinger LLC, All Rights Reserved.

exception schrodinger.application.phase.packages.phase_utils.MissingInputFileError

Bases: Exception

Used when an input file for a job is missing.

class schrodinger.application.phase.packages.phase_utils.RequireValue(option_strings, dest, nargs=None, const=None, **kwargs)

Bases: argparse.Action

For arguments of the form -flag <value>, this class stores <value> at the appropriate destination, while prohibiting <value> from being an empty or pure whitespace string. This class may be used as follows for a string-valued argument:

parser.add_argument(‘-out’, action=RequireValue, help=’Output File.’)

It may also be used for positional arguments, numeric arguments, and arguments with choices. However, in the case of numeric arguments, an empty/whitespace value will be rejected before reaching this class since such a value is not numeric. If choices are supplied, an empty/whitespace value will reach this class and be rejected only if that value is one of the allowed choices, in which case this class isn’t appropriate.

__init__(option_strings, dest, nargs=None, const=None, **kwargs)
class schrodinger.application.phase.packages.phase_utils.RestrictedRange(lower_limit, upper_limit, lower_inclusive=True, upper_inclusive=True)

Bases: object

Provides generalized range checking suitable for the add_argument function of argparser.ArgumentParser. For example:

parser = argparse.ArgumentParser()
parser.add_argument("-dihed", type=float, metavar="<degrees>",
                    choices=[RestrictedRange(-180.0, 180.0)],
                    help="Dihedral angle in degrees.")
parser.add_argument("-path", type=int, metavar="<length>",
                    choices=[RestrictedRange(1, None)],
                    help="Non-zero path length in bonds.")

More general usage is as follows:

legal_range = RestrictedRange(-180.0, 180.0)
dihed = 120.0
if dihed in legal_range:
    print("Dihedral is legal")
__init__(lower_limit, upper_limit, lower_inclusive=True, upper_inclusive=True)

Constructor taking lower and upper limits and whether those limits are inclusive. Use None for a limit that doesn’t exist.

Parameters
  • lower_limit (Any numeric type or None) – Lower limit of legal range

  • upper_limit (Any numeric type or None) – Upper limit of legal range

  • lower_inclusive (bool) – True if lower limit is inclusive

  • upper_inclusive (bool) – True if upper limit is inclusive

__contains__(value)

The “in” operator for the provided value.

exception schrodinger.application.phase.packages.phase_utils.ValidationError

Bases: Exception

Used to simplify error passing in argument validation code.

schrodinger.application.phase.packages.phase_utils.calculate_njobs() int

Derives the number of subjobs from the original host list. Behaves like jobcontrol.calculate_njobs(), except that it returns 1, instead of the maximum possible number of processors, when submitting a job to a cluster queue without specifying the number of CPUs, e.g., -HOST boltcpu_short.

schrodinger.application.phase.packages.phase_utils.combine_log_files(subjobs, logger)

Concatenates the contents of subjob log files.

Parameters
  • subjobs (list(str)) – Subjob names

  • logger (Logger) – Logger to which concatenated log files are to be written

schrodinger.application.phase.packages.phase_utils.convert_to_sd(maefile, sdfile)

Converts a Maestro file to a compressed SD file. Fails only if maefile is missing or defective.

Parameters
  • maefile (str) – Maestro file to be converted

  • sdfile – Output SD file, which is assuemd to be compressed

  • sdfile – str

schrodinger.application.phase.packages.phase_utils.get_default_feature_definitions()

Reads and returns the default Phase feature definitions.

Returns

Default Phase feature definitions.

Return type

list(phase.PhpFeatureDefinition)

schrodinger.application.phase.packages.phase_utils.get_file_names_from_list_file(list_file, prefer_cwd=False)

Returns the names of the files in the provided list file, taking proper account of whether the current process is running under job control and whether any of the files are Phase databases.

Parameters
  • list_file – Name of the .list file

  • prefer_cwd (bool) – Use file in CWD if it exists, even if the file also exists in the location specified in list_file

Returns

Names of files in the .list file

Return type

list(str)

schrodinger.application.phase.packages.phase_utils.get_glide_sort_path() str

Returns the path to the glide_sort utility.

schrodinger.application.phase.packages.phase_utils.get_host_args(default_host_args='localhost:1')

Returns the host specification (e.g., ‘terminator:2’) found in the environment or in the backend job. Returns default_host_args if there was no host specification supplied on the original command line. May be used regardless of whether the job has been launched.

schrodinger.application.phase.packages.phase_utils.get_jobname(args, filename)

Returns the job name from subjob if defined, otherwise via jobcontrol.

Parameters
  • args (argparse.Namespace) – Command line arguments

  • filename (str) – Name of file to use as a last resort job name

Returns

job name

Return type

str

schrodinger.application.phase.packages.phase_utils.get_internal_zip_path(*argv)

Joins the components of a path within a Zip file using forward slashes, as per the Zip spec.

Parameters

argv (tuple of str) – Components in path

Returns

Components in path joined with forward slashes

Return type

str

schrodinger.application.phase.packages.phase_utils.get_proper_path(file_path, use_runtime=False)

Returns the appropriate path to use for the provided file, taking into account whether the current process is running under job control and whether file_path is a Phase database.

Parameters
  • file_path (str) – File whose proper path is being sought

  • use_runtime (bool) – Forces use of runtime path even if not running as job

Returns

The proper path to use for the provided file

Return type

str

schrodinger.application.phase.packages.phase_utils.get_subjob_names(num_subjobs, prefix)

Returns a list of subjobs names of the form <prefix>_sub_<n>, where <n> runs from 1 to num_subjobs.

Parameters
  • num_subjobs (int) – Number of subjobs

  • prefix (str) – Prefix for all subjob names

Returns

Subjob names

Return type

list(str)

schrodinger.application.phase.packages.phase_utils.get_subset_name(subset)

Strips the subset file extension from subset if found and returns the result.

Parameters
  • subset – Subset or subset file name

  • subset – str

Returns

Proper subset name

Return type

str

schrodinger.application.phase.packages.phase_utils.is_numeric(value)

Returns True if the provided string value can be cast to a float.

Parameters

value (str) – The string to be tested

Returns

Whether value is numeric

Return type

bool

schrodinger.application.phase.packages.phase_utils.is_phase_database_path(source)

Returns whether the provided source of structures is a Phase database.

Parameters

source (str) – Path to source of structures

Returns

whether the source is a Phase database

Return type

bool

schrodinger.application.phase.packages.phase_utils.is_phase_project_path(file_path, zipped=False)

Returns True if the file_path corresponds to a Phase project. Set zipped to True to check for a zipped project.

Parameters
  • file_path – Path to file

  • file_path – str

Returns

Whether file_path is a Phase project (or zipped project)

Return type

bool

schrodinger.application.phase.packages.phase_utils.make_display_command(command)

Converts a command provided as a list of strings to a space-delimited string, with quotes around arguments that contain embedded spaces.

Parameters

command (list[str]) – Command to display

Returns

Space-delimited command

Return type

str

schrodinger.application.phase.packages.phase_utils.must_register_input_file(infile, nocopy=False)

Determines whether infile needs to be registered as a job control input file. Returns False if nocopy is True or if infile is an absolute file path that doesn’t exist locally. In the latter case, it’s assumed that infile will exist on the remote host, or that the remote backend will handle the error. Returns True if none of the previous conditions applies.

Parameters
  • infile (str) – Input file to test

  • nocopy (bool) – If True, function returns False unconditionally

Returns

Whether infile should be registered as an input file

Return type

bool

schrodinger.application.phase.packages.phase_utils.partition_values(num_values, num_bins)

Partitions num_values as equally as possible over num_bins and returns the population of each bin. For example, if num_values is 1007 and num_bins is 5, this function would return [201, 202, 201, 202, 201].

Parameters
  • num_values (int) – The number of values to be partitioned

  • num_bins (int) – The number of bins over which to divide num_values

Returns

The population of each bin

Return type

list[int]

Raises

ValueError if an illegal combination num_values and num_bins is provided

schrodinger.application.phase.packages.phase_utils.read_lines_in_file(file_name)

Reads and returns the non-empty lines in a file.

Parameters

file_name (str) – The file to read

Returns

The lines in the file, minus any leading/trailing whitespace

Return type

list(str)

schrodinger.application.phase.packages.phase_utils.set_jsb_input_file(jsb, infile_path, want_exit=False)

Wrapper for JobSpecificationArgsBuilder.setInputFile which may be used to avoid the traceback that occurs when an input file is missing. Instead, the RuntimeError raised in that specific case is trapped and a MissingInputFileError is raised, or sys.exit is called with the error message. Any other exceptions are passed through unmodified.

Parameters
Want_exit

Whether to call sys.exit with the error message

Raises

MissingInputFileError if the input file is missing and want_exit is False

schrodinger.application.phase.packages.phase_utils.split_string(s, delimiter=',')

Uses the csv module to split a delimited string that may contain occurrences of the delimiter protected by quotes.

Parameters
  • s (str) – The delimited string to split

  • delimiter (str) – The delimiter on which to split

Returns

Tokens resulting from the split

Return type

list[str]

schrodinger.application.phase.packages.phase_utils.write_list_to_file(file_name, list_of_strings)

Writes a list of strings to a file with newlines after each string.

Parameters
  • file_name (str) – Name of file to which the strings should be written

  • list_of_strings – The list of strings to write

schrodinger.application.phase.packages.phase_utils.write_string_to_file(file_name, s)

Writes a string to a file with a trailing newline.

Parameters
  • file_name (str) – Name of file to which the string should be written

  • s (str) – The string to write