schrodinger.application.glide.utils module¶
Glide utility functions.
Copyright Schrodinger, LLC. All rights reserved.
- class schrodinger.application.glide.utils.OutfileNameAttributes(suffix, ext)¶
Bases:
NamedTuple
- suffix: str¶
Alias for field number 0
- ext: str¶
Alias for field number 1
- exception schrodinger.application.glide.utils.GlideError¶
Bases:
RuntimeError
Exception class for fatal errors raised by Glide.
- 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.
- class schrodinger.application.glide.utils.Progress(total: int, current: int = 0, num_of_updates: int = 10, logger=None)¶
Bases:
object
A simple class to track progress of a loop and print progress in percentage. Reports progress to the job control backend if available. To use it, create an instance of the class with the total number of iterations and call increment() method in the loop. :param logger: logger to print progress :type logger: logging.Logger :param total: total number of iterations :param current: current iteration :param num_of_updates: number of updates to print progress
- __init__(total: int, current: int = 0, num_of_updates: int = 10, logger=None)¶
- update(steps=1)¶
Update the progress by a given number of steps and print progress in percentage. The progress will be printed every total // num_of_updates iterations. :param steps: number of steps to increment the progress :type steps: int
- 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) str ¶
Returns output file name depending or None if the job produces no output file.
- schrodinger.application.glide.utils.get_raw_file_name(config: schrodinger.glide.Config) str ¶
Returns the name of the raw file or None if the job produces no output 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
gridfile (str) – Filename of gridfile
lig_st (schrodinger.structure.Structure) – Ligand structure
- 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.
- class schrodinger.application.glide.utils.LigandNumberIterator(sts, lignum_start=1, lignum_end=None)¶
Bases:
object
A pass-through iterator that will assign a ligand number (“i_i_glide_lignum”) to structures. Ligand numbers start at lignum_start and increase with each new structure until lignum_end if it is defined, otherwise until no more structures.
- __init__(sts, lignum_start=1, lignum_end=None)¶
- Parameters
sts (Iterable[structure.Structure]) – An iterable of ligands.
lignum_start (int) – The first ligand number to process.
lignum_end (int) – The last ligand number to process.
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
jsb (launchapi.JobSpecificationArgsBuilder) – job specification builder
input_files (str) – input file(s) to be added.
- schrodinger.application.glide.utils.add_logfile(fho, logfile, logger=None)¶
Add the log file to a file handle.
- Parameters
fho – file handle of the combined log file
logfile – log file to be added
- 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.append_logfile(combined_logfile, subjob_logfile, logger=None)¶
Append subjob logfile to the combined logfile.
- Parameters
combined_logfile (str) – combined log file name
subjob_logfile (str) – subjob logfile name to be appended.
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, timer_func=<built-in function monotonic>)¶
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
@param timer_func: function to use to get the current time @type timer_func: callable
- 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
st (structure.Structure) – The structure.
prop (str) – The property name.
- 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, pose_rmsd: float, pose_displacement: float = 1.3, pose_htorsion: float = None, use_symmetry: bool = True)¶
Removes duplicate poses from an iterable 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 (iterable of poses. May be Structure objects or anything with a getStructure(), such as glide.Pose or glide.RefinedPose.) – A list of sorted docked poses for a ligand
pose_rmsd – RMSD cut off between duplicate poses
pose_displacement – minimum heavy-atom “max displacement” between duplicate poses. Default is 1.3
pose_htorsion – minimum deviation (degrees) in polar H torsion between duplicate poses. Default is None
use_symmetry – consider topological symmetry when measuring RMSD?
- Raises
ValueError if not all the poses come from the same ligand
- Returns
generator of unique poses
- schrodinger.application.glide.utils.remove_bad_poses(pose_sts: list)¶
Removes poses for a given ligand whose GSCORE property is equal to glide.BAD_SCORE(10000). The original list of poses is not modified.
- Parameters
poses (list of [pose.Structure] objects) – A list of sorted docked poses for a ligand
- Returns
list of good poses
- Return type
list of [pose.Structure] objects