kinoml.utils
¶
Miscellaneous utilities
Module Contents¶
- kinoml.utils.APPDIR¶
- kinoml.utils.PACKAGE_ROOT¶
- class kinoml.utils.FromDistpatcherMixin¶
- classmethod _from_dispatcher(value, handler, handler_argname, prefix)¶
- class kinoml.utils.LocalFileStorage¶
Generate standardized paths for storing and reading data locally.
- DIRECTORY¶
- static rcsb_structure_pdb(pdb_id, directory=DIRECTORY)¶
- static rcsb_structure_cif(pdb_id, directory=DIRECTORY)¶
- static rcsb_ligand_sdf(pdb_id, chain_id, expo_id, altloc, directory=DIRECTORY)¶
- static rcsb_electron_density_mtz(pdb_id, directory=DIRECTORY)¶
- static klifs_ligand_mol2(structure_id, directory=DIRECTORY)¶
- static klifs_structure_db(directory=DIRECTORY)¶
- static klifs_kinase_db(directory=DIRECTORY)¶
- static featurizer_result(featurizer_name, result_details, file_format, directory=DIRECTORY)¶
- static pdb_smiles_json(directory=DIRECTORY)¶
- class kinoml.utils.FileDownloader¶
Download and store files locally.
- DIRECTORY¶
- static rcsb_structure_pdb(pdb_id, directory=DIRECTORY)¶
- static rcsb_structure_cif(pdb_id, directory=DIRECTORY)¶
- static rcsb_electron_density_mtz(pdb_id, directory=DIRECTORY)¶
- kinoml.utils.datapath(path: str) pathlib.Path ¶
Return absolute path to a file contained in this package’s
data
directory.- Parameters
path (str) – Relative path to file in data.
- Returns
Absolute path to the file in the KinoML data directory. Existence is not checked or guaranteed.
- Return type
path pathlib.Path
- kinoml.utils.grouper(iterable: Iterable, n: int, fillvalue: Any = None) Iterable ¶
Given an iterable, consume it in n-sized groups, filling it with fillvalue if needed.
- Parameters
iterable (list, tuple, str or iterable) – Something that can be split in sub-items and grouped.
n (int) – Size of the group
fillvalue (object) – Last group will be padded with this object until
len(group)==n
- class kinoml.utils.defaultdictwithargs(call: Callable)¶
Bases:
collections.defaultdict
A defaultdict that will create new values based on the missing value
- Parameters
call (class or callable) – Factory to be called on missing key
- __missing__(key)¶
- kinoml.utils.download_file(url: str, path: str)¶
Download a file and save it locally.
- Parameters
url (str) – URL for downloading data.
path (str) – Path to save downloaded data.
- Returns
True if successful, else False.
- Return type
bool
- kinoml.utils.seed_everything(seed=1234)¶
Fix the random number generator seed in several pieces of the Python runtime: Python itself, NumPy, Torch.
- Parameters
seed (int, optional=1234) –
- kinoml.utils.watermark()¶
Check and log versions and environment details of the execution context. We currently check for:
Whatever
watermark
(the library) returnsThe output of
nvidia-smi
, if availableThe output of
conda info
, if availableThe output of
conda list
, if available
Note
This assumes you are running the function inside a Jupyter notebook.
- kinoml.utils.collapsible(function, *args, **kwargs)¶
An IPython widget that can collapse its contents.
- Parameters
function (callable) – A function that generates some kind of output (print, plots, etc). Args and kwargs will be forwarded here.
- Return type
ipywidgets.Accordion
- kinoml.utils.fill_until_next_multiple(container, multiple_of: int, factory)¶
Fill
container
with instances offactory
until its length reaches the next multiple of multiple_of.container
gets modified in place and returned.- Parameters
container (list or set) – Extendable container
multiple_of (int) – The final size of container will match the next multiple of this number.
factory (callable) – This callable will be run to produce the filler elements used to extend
container
- Returns
Modified in place
- Return type
container
- kinoml.utils.import_object(import_path: str)¶
Import an object using its full import path
- Parameters
import_path (str) – Full import path to object, like kinoml.core.measurements.MeasurementType.
- Return type
object
- kinoml.utils.sha256_objects(objects_to_hash: Iterable[object]) str ¶
Generate a SHA256 hash of pickable objects.
- Parameters
objects_to_hash (Iterable of object) – Objects that should be hashed.
- Returns
The SHA256 of given objects.
- Return type
str