schrodinger.application.phase.packages.phase_utils module

Module with common functionality for all Phase backends.

Copyright Schrodinger LLC, All Rights Reserved.

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.

__init__(*args, **kwargs)
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

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