schrodinger.application.glide_ws.utils module

Common utility functions and constants needed by multiple Glide WS-related modules.

Copyright Schrodinger, LLC. All rights reserved.

exception schrodinger.application.glide_ws.utils.GlideWSError

Bases: Exception

Exception class for fatal errors in the Glide WS driver.

class schrodinger.application.glide_ws.utils.ObjectEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: json.encoder.JSONEncoder

JSON encoder to encode simple “struct-like” objects as dicts, by encoding the objects __dict__ attribute.

default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
schrodinger.application.glide_ws.utils.print_and_flush(msg, eol=True)

Print a string to stdout with or without an eol and flush.

schrodinger.application.glide_ws.utils.logwrapper(level, msg, eol=True)

Top-level function to write info/warning/error messages. Here “level” is an arbitrary string passed by the caller.

schrodinger.application.glide_ws.utils.my_mkdir(dirname)

Create new directory if it doesn’t already exist. If there’s an existing file (not a directory) by the same name, rename it to “backup” name. If there’s an existing file or directory with the backup name, delete it if possible, exit otherwise.

schrodinger.application.glide_ws.utils.myAddOutputFile(fname, copy_now=False)

Register an output file with job control if possible. If copy_now is true, ask job control to transfer the file immediately, instead of waiting until the end of the job.

schrodinger.application.glide_ws.utils.require_file(dirname, filename, description=None, message=None)

Wrapper for os.path.isfile and isdir that aborts if the dir/file is not found.

schrodinger.application.glide_ws.utils.runtime_path_property(name, doc='')

Create a “magic property” that automatically accounts for the backend runtime path.

schrodinger.application.glide_ws.utils.glide_merge(inputs, output, **kwargs)

Call glide_merge on a list of filenames ‘inputs’, writing <output> (if it already has a recognized extension), or else <output>_lib.maegz.

Additional arguments to glide_merge can be provided as keyword arguments. See ‘GlideSortUtility’ documentation for details.

schrodinger.application.glide_ws.utils.parallel_reader(readers)

A generator to read several files in parallel. On each iteration, it returns a list of tuples, with up to one pose per file (there may be fewer poses than readers if a reader returns no pose in a given iteration, or if it reached EOF; Each tuple is (pose, reader), where pose is a Structure object and reader is the reader object whence the pose came.

schrodinger.application.glide_ws.utils.model_reader(node, complexes, require_file=True)

Get a “parallel reader” that will return, for each ligand, all the poses for that ligand in the ensemble. The files to read are obtained by calling node.raw_filename(complex, offset).

If require_file is False, then an absent file is not treated as an error, but as equivalent to an empty file when an MMGBSA subjob was not needed for a given complex.

schrodinger.application.glide_ws.utils.combined_reader(docking_node, mmgbsa_node, complexes, offsets, apply_offsets=False)

Return a reader that returns tuples (lig, wscore_poses, mmgbsa_poses) for each ligand, where each *_poses is itself a tuple of poses and both are in the same order. That is, for a two-receptor ensemble:

((wscore_lig1_recep1, wscore_lig1_recep2),
 (mmgbsa_lig1_recep1, mmgbsa_lig1_recep2))

And so on for the rest of the ligands. Missing poses are denoted by None. If ligand failed to dock in all receptors, it is skipped.

If ‘apply_offsets’ is True, the offset values in the offset dict are applied to the poses before returning them. This should be used when the docking jobs were run with the default offset value but one want to emulate the results that would have been obtained with different offsets.

class schrodinger.application.glide_ws.utils.LignumReader(reader, ligoffset=0)

Bases: object

A thin class wrapper around the lignum_reader function. Besides acting like an iterator, it provides the ‘reader’ property which contains the original reader object that was used to create the LignumReader object. It also provides the filename property, which delegates to reader.filename.

__init__(reader, ligoffset=0)
property filename
schrodinger.application.glide_ws.utils.write_libfile(fname, poses)

Write a list of poses to a file. As a special case, create an empty file when there are no poses.

schrodinger.application.glide_ws.utils.condensed_hosts_list(hosts)

Given a hosts list in which some hosts appear more than once (e.g., [(‘host1’, 1), (‘host1’, 2)]), returns the “condensed hosts list”, in which a given host appears only once, with its total number of CPUs. For the example above, the return value is [(‘host1’, 3)]. The order of the hosts is preserved based on first appearance.

schrodinger.application.glide_ws.utils.scaled_hosts_list(hosts, denominator)

Given a hosts list (e.g., [(‘host1’,1), (‘host2’, 10)]), returns the the same hosts lists with the number of CPUs for each host divided by ‘denominator’. The result is rounded down, but guaranteed to be at least 1.

schrodinger.application.glide_ws.utils.extract_gridfile(gridfile)

For gridfile = <gridbase>.zip, extract all of its contents to a new directory <gridbase>/; check that there exists exactly one file with the .grd extension in the archive or else raise an exception.

Returns the path to the .grd file.

schrodinger.application.glide_ws.utils.logfile_is_complete(logfile)

Returns true if the logfile has the “Total elapsed time” line at the end.

schrodinger.application.glide_ws.utils.mmgbsa_logfile_is_complete(logfile)

Returns true if the logfile has the “All Entries Succesfully Processed” line at the end.

schrodinger.application.glide_ws.utils.tail(log_file, nlines=20)

Print the last ‘nlines’ lines from a file. If the file does not exist, print a message saying so.

schrodinger.application.glide_ws.utils.timestamp()
schrodinger.application.glide_ws.utils.xrange_float(low, high, delta)

Method to act as a float xrange

schrodinger.application.glide_ws.utils.add_wmap_data_to_receptor_ct(rct, wmfile)
schrodinger.application.glide_ws.utils.create_epv_from_lib(complexes, libfile, epvfile)

Write an epv given a libfile. The poses in the libfile must already have values for ‘i_epv_best_receptor’, and the value must be the 1-based index of a Complex in the ‘complexes’ list.

schrodinger.application.glide_ws.utils.write_json_file(basename, data, job_dir)
schrodinger.application.glide_ws.utils.sanitize_string(s, name='string')

Return the sanitized version of s or raise a ValueError if not possible. Replaces whitespace with underscores and checks that all characters after that are in the whitelist.

schrodinger.application.glide_ws.utils.strip_invalid_characters(s, name='string')

A more aggresive version of sanitize_string(): removes all invalid characters from the string. Raises ValueError if the resulting string is empty.

schrodinger.application.glide_ws.utils.partition_njobs(job_sizes, njobs)

Split each job into subjobs such that the total number of subjobs equals njobs (but there must be at least one subjob per job, so njobs will be exceeded when njobs < len(job_sizes)), while minimizing the size of the largest subjob.

For example, if job job_sizes == [15, 42, 6, 31] and njobs == 1, the resulting number of subjobs for each job will be [1, 3, 1, 3]. The larger jobs get more subjobs. The subjob sizes end up being [15, 14, 6, 11].

Parameters
  • job_sizes (list of int) – list with the size of each job (e.g., number of ligands)

  • njobs (int) – target value for total number of jobs

Returns

subjob sizes and number of subjobs for each job

Return type

(list(int), list(int))

schrodinger.application.glide_ws.utils.get_data_file(relpath: str) str

Return the path to a file in the Glide-WS data directory.

Parameters

relpath – path to the file relative to the data directory (usually this is just the basename)