schrodinger.application.glide.utils module

Glide utility functions.

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.application.glide.utils.OutfileNameAttributes(suffix, ext)

Bases: tuple

suffix: str

Alias for field number 0

ext: str

Alias for field number 1

__contains__(key, /)

Return key in self.

__len__()

Return len(self).

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

exception schrodinger.application.glide.utils.GlideError

Bases: RuntimeError

Exception class for fatal errors raised by Glide.

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

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

class schrodinger.application.glide.utils.DictAction(option_strings, dest, default=None, *a, **k)

Bases: argparse.Action

Argparse action class that uses values of the form key=val (see parseKeyval for more details) to fill a dictionary. (Similar to the “append” action, but for dicts.)

__init__(option_strings, dest, default=None, *a, **k)
parseKeyval(string)

Return a (key, val) tuple given a string. The string must start with the key, which is made of word characters (alphanumeric or underscore). Any non-word character optionally followed by whitespace acts as a separator, and everything else is the value. If the value is delimited by brackets or braces, it is parsed as JSON. If there is no delimiter, the value is interpreted as “yes”.

class schrodinger.application.glide.utils.EnvAction(option_strings, dest, **k)

Bases: argparse.Action

Argparse action class that, in addition to “store_true”, sets SCHRODINGER_GLIDE_<dest>=1 in the environment.

__init__(option_strings, dest, **k)
class schrodinger.application.glide.utils.EpvReader(sts_source)

Bases: object

Class to read EPV files. Supports pv files as well. Must be provided an iterable of structures, most likely a StructureReader.

Example usage:

with StructureReader(filename) as reader:
    epv_reader = EpvReader(reader)
    for lig, recep in epv_reader:
        pass

Requirements for the file:

  • The file must have at least one receptor, as tagged by b_glide_receptor property;

  • if there is more than one receptor, each receptor must have a unique i_epv_receptor value, and all the ligands must have i_epv_best_receptor set to the same value as one of the i_epv_receptor values from the receptors in the file.

If any of the requirements are not met, raises ValueError.

__init__(sts_source)
Parameters

sts_source (iterable of structure.Structure) – An iterable of structures, most likely a StructureReader.

schrodinger.application.glide.utils.m2io_type_convert(prop_name, value)

Convert a string into the correct Python type corresponding to a m2io property name.

Parameters
  • prop_name (str) – The m2io property name.

  • value (str) – The value associated with that property

Returns

The value converted to the appropriate Python type.

schrodinger.application.glide.utils.convert_flags_to_underscore(argv=None, logger=None)

Convert all command-line flags to underscore-delimited words instead of dash-delimited words. Some legacy scripts allowed that either be used.

schrodinger.application.glide.utils.parse_size(size) int

Parse user input to convert human-readable file size into bytes. Accepted suffixes are {K, M, G, T} corresponding to SI file sizes (powers of 10). :param str size: A representation a file size. :return: The file size in bytes.

schrodinger.application.glide.utils.get_output_file_name(config: schrodinger.glide.Config, suffix_override: Optional[str] = None) str

Determines output file name depending on the job configuration. Filename suffix can be overridden.

schrodinger.application.glide.utils.get_raw_file_name(config: schrodinger.glide.Config) str

Returns the name of the raw file.

schrodinger.application.glide.utils.get_skipped_file_name(config: schrodinger.glide.Config) str

Returns the name of the skipped file.

schrodinger.application.glide.utils.get_job_output_filenames(config: schrodinger.glide.Config) List[str]

Returns list of filenames of the expected Glide docking job output files. Should be used in tandem with the new Glide API. this function only applies to serial docking jobs. Distributed jobs don’t write a state file, but a sqlite file instead. Work in progress: will add other output files when corresponding options are implemented in schrodinger.glide.runner module.

schrodinger.application.glide.utils.get_sort_filters_from_config(config) Dict[str, float]

Return a filters dictionary suitable for use with GlideSortUtility based on the given Glide input configuration.

Parameters

config (glide.Config) – Glide configuration

schrodinger.application.glide.utils.sort_output_file(config, output_filename, raw_filename, logger)

Sorts and filters final poses stored in the raw file and saves the resulting file.

Parameters
  • config (glide.Config) – Glide configuration

  • output_filename (str) – name of the output file

  • raw_filename (str) – name of the raw file to be sorted

  • logger (logging.Logger) – logger

schrodinger.application.glide.utils.format_human_time(seconds: float) str

Returns a string representation of the time duration in seconds. Calculates the number of days, hours, minutes, and seconds.

Example outputs:

"1 day, 10 hours, 17 minutes, and 36 seconds"
"1 hour, 1 minute, and 1 second"
"1 minute and 1 second"
schrodinger.application.glide.utils.is_valid_pv_file(file_name, require_poses=False)

Returns bool indicating if the file appears to be a valid PV file.

This function with throw an exception is the file is not a valid Maestro structure file.

The checks for this are simple, and may not be conclusive. The test is content, and not file-extension based, since there are valid PV or EPV files that lack any indication that they are PV files in the file extension. If you need to check the extension as well see fileutils.is_poseviewer_file.

A PV file has exactly one structure with a true value for b_glide_receptor.

An EPV file has one or more structures with a true value for b_glide_receptor at the beginning of the file. Single-receptor EPV files are therefore considered PV files, but not EPV files with two or more receptors.

Parameters
  • file_name (str) – path to the structure file

  • require_poses (bool) – pv file must contain more than one structure

Returns

bool indicating if the file appears to be a valid PV file

Return type

bool

schrodinger.application.glide.utils.is_valid_epv_file(file_name)

Returns bool indicating if the file appears to be a valid EPV file.

Parameters

file_name (str) – path to the structure file

Returns

bool indicating if the file appears to be a valid EPV file

Return type

bool

schrodinger.application.glide.utils.get_recep_structure_from_grid(gridfile)

Return a Structure object given a grid file (may be .grd or .zip)

schrodinger.application.glide.utils.is_grid_good_for_ligand(gridfile, lig_st) bool

Check whether the ligand structure fits in the outer box of the grid.

Parameters
schrodinger.application.glide.utils.check_required_gridfiles(gridfile)

Check whether all required gridfiles exist for the given uncompressed gridfile

Parameters

gridfile (str) – Path to the grid file (.grd)

schrodinger.application.glide.utils.extract_file_from_grid(grid_file, ext)

Extract the file with requested extension form the given grid file archive. Will return None if the requested file is not present in the archive. If the specified grid file is uncompressed, will simply return the file with the same extension in the same location as the grid.

Parameters
  • grid_file (str) – Path to the grid file (.zip or .grd)

  • ext (str) – Extension of the requested file.

Return type

str or None

Returns

File path or None

schrodinger.application.glide.utils.parse_xvol_file(xvol_file)

Returns a list of excluded volumes in the specified excluded volumes file.

Parameters

xvol_file (str) – Path to the excluded volumes file

Return type

List of tuples

Returns

Each tuple defines an excluded volume. First item is the name (str), second item is a tuple of XYZ coordinates, third item is a radius (float).

class schrodinger.application.glide.utils.PoseWriter(filename, *, is_pv, overwrite, grid, **kwargs)

Bases: schrodinger.structure._io.StructureWriter

StructureWriter that will prepend the receptor to the top of the file when entering its context, if is_pv argument is True. The append argument is used to determine whether StructureWriter should overwrite the file or append.

__init__(filename, *, is_pv, overwrite, grid, **kwargs)
Parameters

kwargs – Passed down to parent class.

append(ct)

Append the provided structure to the open file.

close()

Close the file.

extend(cts)

Append all provided structures to the open file.

setOption(option, value)

Set a single option for this writer. This method is meant for options that may not be supported for all writer formats. See the StructureWriter class documentation for details on the available options.

Raises an OptionError subclass (either UnsupportedOption or UnsupportedOptionValue) if unsuccessful.

Parameters
  • option (str) – The name of the option to set.

  • value – The value for the option. The data type of this parameter depends on the option being set.

static write(st, filename)

Writes the given Structure to the specified file, overwriting the file if it already exists.

Parameters
  • st (structure.Structure) – structure object to write to file

  • filename (str or pathlib.Path) – filename to write to

class schrodinger.application.glide.utils.LigandNumberIterator(sts, offset=0)

Bases: object

A pass-through iterator that will assign a ligand number (“i_i_glide_lignum”) to structures. Integers start at 1 (plus specified offset) and increase with each new structure.

__init__(sts, offset=0)
Parameters
  • sts (Iterable[structure.Structure]) – An iterable of ligands.

  • offset (int) – Offset the ligand numbers by this amount.

schrodinger.application.glide.utils.get_git_hashes()

Return a string of git hashes for the relevant products using existing .git_hash files in the corresponding directories.

schrodinger.application.glide.utils.add_output_file(*output_files, incorporate=False)

Add files to jobcontrol output files.

Parameters
  • output_files (str) – files to be transferred.

  • incorporate (bool) – marked files for incorporation by maestro.

schrodinger.application.glide.utils.add_input_file(jsb, *input_files)

Check the existence of input file(s). Add it as jobcontrol input file if it exists, otherwise exit with error.

Parameters
schrodinger.application.glide.utils.concatenate_logs(combined_logfile, subjob_logfile_list, logger=None)

Combine subjob logfiles into single combined logfile.

Parameters
  • combined_logfile (str) – combined log file name

  • subjob_logfile_list (list(str)) – list of subjob logfile names to be combined.

  • logger (Logger or None) – logger for receiving the info and error message.

schrodinger.application.glide.utils.extra_keywords_args(keywords_dict)

Convert a keywords dict into a list of -set key=value arguments suitable for the command line.

schrodinger.application.glide.utils.multi_inputconfig(*sources)

Returns a dict combining multiple inputconfig-compatible sources (e.g, filenames or dicts). Values from latter sources take precedence. Note: the merging is shallow!

schrodinger.application.glide.utils.get_jobname(input_filename)

Get the job name from the environment, if set. If not, get it from the basename of the provided input filename.

schrodinger.application.glide.utils.dev_keywords()

Return a set with the known developer keywords.

schrodinger.application.glide.utils.get_runtime_path(path)
schrodinger.application.glide.utils.get_product_name(glide_job)
schrodinger.application.glide.utils.is_receptor(st)

Return True if st is a receptor Structure.

schrodinger.application.glide.utils.unzip_grids(grid_archive, jobname)

Extract the contents of the grid archive to a temporary directory if the subjobs will be running locally.

Returns

2-tuple with the path to the temporary directory and the .grd file.

Return type

tuple of str

schrodinger.application.glide.utils.write_readme(dirname)

Write a README file to a directory explaining the temporary nature of said directory.

schrodinger.application.glide.utils.find_grd_file(dirname)

Find the *.grd file in a directory. There must be one and only one!

schrodinger.application.glide.utils.get_host_ncpu()

Return the host and number of CPU that should be used to submit subjobs. This function works both running under job control and not.

Return type

str, int

schrodinger.application.glide.utils.timer(obj, propname)

A context manager that computes the elapsed time and sets it as a property of the given object. If the property already has a value, the time is added to it.

@param obj: object to modify @type obj: object

@param propname: name of property to set @type propname: str

schrodinger.application.glide.utils.dont_ignore_stereo()

A context manager that temporarily disables MMSTEREO_IGNORE_STEREO_PROP and MMSTEREO_USE_GEOM_STEREO.

schrodinger.application.glide.utils.get_data_file(basename)

Return a set with the path to an optional data file, which may be found in the CWD or in the glide user data directory. The set may be empty.

schrodinger.application.glide.utils.get_csv_header(ligand_files)

Return the header row if the ligands come from CSV file(s). Raises a GlideError if different files have different headers.

Returns

first line on the file, including EOL

Return type

str

schrodinger.application.glide.utils.parse_csv_line(line)
schrodinger.application.glide.utils.write_csv_record_to_string(record)
schrodinger.application.glide.utils.get_csv_props(glide_job, ligfile_fields=None)

Return the list of the names of properties that should be stored in the properties table, based on the value of CSV_PROPS_FILE, if present, or else the default CSV config file. Will also inspect the ligand file column names and append them.

Parameters
  • glide_job (glide_input.GlideJob) – Glide job object (dict of SIF keyword-value pairs)

  • ligfile_fields (Optional[list[str]]) – The fields found in the input CSV file(s).

Returns

A list of CSV properties.

Return type

list[str]

schrodinger.application.glide.utils.parse_csv_props_file(filename, precision)

Parse the CSV props config file. This is the file specified by the CSV_PROPS_FILE keyword.

Parameters

precision (str) – SP, XP, or WScore

Returns

A list of CSV properties

Return type

list[str]

schrodinger.application.glide.utils.get_prop(st, prop)

Retrieve the property from a structure, even if the name is mangled by an upstream process. Is able to access properties based on their original name in a CSV header, even if the structure has been processed by the mmshare CSV reader or Ligprep.

Parameters
Returns

The property, if found. Otherwise an empty string.

schrodinger.application.glide.utils.get_props(st, props)

Return a list with the values of all the Structure properties listed in props. If a property is not preset, this will try several variants of the property name by adding prefixes that are used by the mmshare CSV reader and Ligprep.

schrodinger.application.glide.utils.format_row(row, precision=4)

Format the numeric values in a CSV row to a fixed precision.

schrodinger.application.glide.utils.get_ligprep_parser()

Generate ligprep argparse instance and return it.

Returns

ligprep argument parser

Return type

argparse.ArgumentParser

schrodinger.application.glide.utils.get_ligprep_files(args)

Get the paths of files in ligprep arguments.

Parameters

args (str) – ligprep argument string

Returns

set of ligprep option input file paths.

Return type

set(str)

schrodinger.application.glide.utils.read_json(source: str) dict

Parse a JSON object, either from a string or from a filename.

schrodinger.application.glide.utils.max_atomic_displacement_and_rmsd(test_pose: schrodinger.structure._structure.Structure, ref_pose: schrodinger.structure._structure.Structure, pose_atom_list: list, use_symmetry: bool = False)

Calculate the maximum atomic displacement and rmsd in angstroms between the test pose and the reference pose. The maximum atomic displacement is the maximum euclidian distance in angstroms between atoms of the test pose and the reference pose. The poses must belong to the same ligand and must have the same atom numbering.

Parameters
  • test_pose (pose.Structure object) – structure of the test pose

  • ref_pose (pose.Structure object) – structure of the reference pose

  • pose_atom_list (list[int]) – list of heavy atom indices in the poses

  • use_symmetry (boolean) – Adjust test_pose_atom_list index order such that it is optimized with regard to molecular symmetry.

Returns

maximum atomic displacement and root mean squared deviation.

Return type

tuple(float, float)

schrodinger.application.glide.utils.max_pose_torsion_diff(test_pose: schrodinger.structure._structure.Structure, ref_pose: schrodinger.structure._structure.Structure, torsion_atom_indices: list) float

Calculate the maximum dihedral difference between the test and reference poses.

Parameters
  • test_pose (pose.Structure object) – structure of the test pose

  • ref_pose (pose.Structure object) – structure of the reference pose

  • torsion_atom_indices (list[tuple]) – list of tuples of atom indices in a SMARTS match

Returns

maximum difference in dihedral angle normalized to 180 degrees

Return type

float

schrodinger.application.glide.utils.remove_duplicate_poses(poses: list, pose_rmsd: float, pose_displacement: float = 1.3, pose_htorsion: Optional[float] = None, max_poses_w_sym: int = 100) list

Removes duplicate poses from a list of poses for a given ligand. A duplicate pose is any pose that has an (RMSD < pose_rmsd, or max_atomic_displacement < pose_displacement) and max_torsion < pose_htorsion to any previous pose (thus, the output is order-dependent; for example, the first pose is always accepted). The original list of poses is not modified.

Parameters
  • poses (list of [pose.Structure] objects) – A list of sorted docked poses for a ligand

  • pose_rmsd (float) – RMSD cut off between duplicate poses

  • pose_displacement (float) – minimum heavy-atom “max displacement” between duplicate poses Default is 1.3

  • pose_htorsion (float) – minimum deviation (degrees) in polar H torsion between duplicate poses Default is None

  • max_poses_w_sym (int) – maximum number of poses to use with symmetry Default is 100

Raises

ValueError if not all the poses come from the same ligand

Returns

list of unique poses

Return type

list of [pose.Structure] objects