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
- class schrodinger.application.glide.utils.DictAction(option_strings, dest, default=None, *a, **k)¶
Bases:
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:
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
- class schrodinger.application.glide.utils.ResidueInteraction(chain: str = '', resnum: int = 0, inscode: str = '', pdbres: str = '', molecule_number: int = 0, vdw: float = 0.0, coul: float = 0.0, hbond: float = 0.0, dist: float = 0.0, Eint: float = 0.0, lipo: float = 0.0)¶
Bases:
object
- chain: str = ''¶
- resnum: int = 0¶
- inscode: str = ''¶
- pdbres: str = ''¶
- molecule_number: int = 0¶
- vdw: float = 0.0¶
- coul: float = 0.0¶
- hbond: float = 0.0¶
- dist: float = 0.0¶
- Eint: float = 0.0¶
- lipo: float = 0.0¶
- __init__(chain: str = '', resnum: int = 0, inscode: str = '', pdbres: str = '', molecule_number: int = 0, vdw: float = 0.0, coul: float = 0.0, hbond: float = 0.0, dist: float = 0.0, Eint: float = 0.0, lipo: float = 0.0) None ¶
- class schrodinger.application.glide.utils.ResidueId(chain, resnum, inscode)¶
Bases:
tuple
- chain¶
Alias for field number 0
- inscode¶
Alias for field number 2
- resnum¶
Alias for field number 1
- 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: 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: 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: Config) str ¶
Returns the name of the skipped ligands file, or None if KEEPSKIPPED is false.
- schrodinger.application.glide.utils.get_structure_output_file(config: Config) Optional[str] ¶
Return the name of the structure output file for a job, for incorporation in Maestro; may be None if the job is not configured to produce structure output.
- schrodinger.application.glide.utils.get_raw_csv_filenames(config)¶
Return the name of the raw CSV file and the skipped-ligands raw CSV file, if applicable; otherwise an empty list.
- schrodinger.application.glide.utils.get_csv_filenames(config)¶
Return the name of the final CSV file and the skipped-ligands final CSV file, if applicable; otherwise an empty list.
- schrodinger.application.glide.utils.get_job_output_filenames(config: Config) list[str] ¶
Determine the expected output files for a serial docking job from the job Config.
- Returns:
list of output filenames.
- 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
- class schrodinger.application.glide.utils.PoseWriter(filename, *, is_pv, overwrite, grid, **kwargs)¶
Bases:
object
StructureWriter-like class 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.This writer opens and closes the file for each call to append() or extend(); this is to ensure the validity of the file if the job dies between writes.
Also, unlike the default StructureWriter, an empty file is written even if no structures were written. This is for compatibility with long-standing Glide behavior.
- __init__(filename, *, is_pv, overwrite, grid, **kwargs)¶
- Parameters:
kwargs – Passed down to underlying StructureWriter
- append(st)¶
- extend(sts)¶
- close()¶
- 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.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_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: Structure, ref_pose: 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: Structure, ref_pose: 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 not below 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
- schrodinger.application.glide.utils.get_error_tagged_structure(skip_reason: SkipReason, error_message: str = '') Structure ¶
Return an empty Structure with the s_glide_skip_exception set to the JSON representation of a SkipLigand exception.
- schrodinger.application.glide.utils.get_mol_ids(db_path: str, subset_file: str = None, ligand_start: int = 1, ligand_end: Optional[int] = None) list[int] ¶
- Parameters:
db_path – path to database directory
subset_file – path to subset file listing the mol IDs to read
ligand_start – 1-based index of the first mol ID to read. For example, if the subset file lists mol IDs (2, 3, 5, 7, 11, 13), and ligand_start==3, the first mol ID to be read is 5.
ligand_end – 1-based index of the last mol ID to read.
- Raises:
GlideError – if the subset file is invalid or empty.
- schrodinger.application.glide.utils.phase_db_reader(db_path: str, mol_ids: Iterable[int] = (), num_confs: int = 1)¶
Read structures from a Phase database and add properties expected by the Glide docking workflow. Multiple conformers per ligand may be yielded when num_confs > 1, but the structures are yielded one by one, that is, conformer by conformer. The following properties are added, which can help tell where each ligand begins and ends:
b_glide_firstconf: true for the first conformer of a given ligand
b_glide_lastconf: true for the last conformer of a given ligand
i_glide_molID: Phase mol ID.
This is a legacy Glide protocol used by other readers; that’s the reason why we don’t simply return a list of conformers for each ligand.
When there is a non-fatal error, such as mol ID not found, the generator yields an empty structure with these s_glide_skip_exception property set to describe the error. We do this instead of raising an exception because this function is usually called within nested loops/generators, and exiting all the loops with an exception would make retrying with the next ligand impractical.
- Parameters:
db_path – path to database directory
mol_ids – Phase mol IDs to read (all by default)
num_confs – maximum number of conformers to return for each ligand
- Returns:
generator of Structure
- Raises:
GlideError – when there is a fatal error (e.g., unreadable database).
- schrodinger.application.glide.utils.get_residues(st: Structure) dict[schrodinger.application.glide.utils.ResidueId, schrodinger.structure._structure.Residue] ¶
Return a dict with all the residues in
st
, indexed by ResidueId (chain, residue number, and insertion code).
- schrodinger.application.glide.utils.parse_residue_interactions(interaction_property: str)¶
Parse the residue interaction information from a structure property. Required format: r_glide_res:{chain}{residue_number}{insertion_code}_{interaction}
- Parameters:
interaction_property (Structure property holding residue interaction information.) – str
- Returns:
the residue ID and interaction type.
- Return type:
tuple(ResidueId, str)
- Raises:
ValueError if residue interaction information could not be matched.
- schrodinger.application.glide.utils.get_residue_interactions(st, residues)¶
Get all the residue interactions between a docked ligand-receptor pair.
- Parameters:
st (Ligand structure) – structure.Structure
residues (dict[ResidueId, structure.Residue]) – dict of residues by ResidueId
- Returns:
A dictionary of ResidueInteraction objects. The keys are tuples of chain, residue number, insertion code.
- Return type:
dict(ResidueInteraction)
- schrodinger.application.glide.utils.pretty_print_residue_interactions(st, residues, logger)¶
Pretty-print a table of residue interactions. Example output:
RESIDUE MOL/CH/INS EvdW ECoul HB DCLOSE EInt ELipo --------- ---------- --------- --------- --------- --------- --------- --------- ILE 16 1 A -0.09691 18.73169 0.00000 6.57707 18.63478 0.00000 [...]
- Parameters:
st (structure.Structure) – Ligand structure.
residues (dict[ResidueId, structure.Residue]) – dict of residues by ResidueId
logger (logging.Logger) – logger to print output.
- schrodinger.application.glide.utils.running_under_wscore()¶
- schrodinger.application.glide.utils.running_under_epharmacophores()¶
- schrodinger.application.glide.utils.running_under_ifdx()¶
- schrodinger.application.glide.utils.running_under_safe()¶
- schrodinger.application.glide.utils.running_under_skate()¶
- schrodinger.application.glide.utils.to_list(obj)¶
- schrodinger.application.glide.utils.get_job_dj(options)¶