Skip to content

Utils

Implementation of utility functions for the analysis module.

STANDARD_RESIDUES = {'ALA', 'ARG', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TRP', 'TYR', 'VAL', 'HIE', 'HID', 'HIP', 'CYX', 'ASH', 'GLH'}

calc_mcs(ref_file, target_file, timeout=10, add_hs=False)

Find the MCS between two molecule files. Returns aligned atom indices. Args: ref_file : Path to the reference molecule file (PDB, MOL2, or SDF). target_file : Path to the target molecule file (PDB, MOL2, or SDF). timeout : Maximum time (in seconds) to spend on MCS calculation. Default is 10 seconds. add_hs : Whether to add hydrogens when loading molecules. Default is False. Returns: A tuple of two lists: (ref_indices, target_indices) corresponding to the MCS atom indices in the reference and target molecules, respectively.

clean_and_standardize_file(file_path, add_hs=False)

Clean and standardize a ligand structure file (.pdb or .mol2) using RDKit. Attempts RDKit load, Open Babel fix, nitrogen valence fix, and atom type fix. Args: file_path : Path to the input file. add_hs : Whether to add hydrogens to the molecule. Default is False. Returns: Path to the cleaned .pdb file.

eval_pose(docked_pose, reference_pose, protein, outfmt='csv', multiple=True, output_file=str, top_n=None, max_workers=None)

Run posebuster (bust) command line tool to evaluate predicted pose whether the poses are physically valid Args: docked_pose : Path to the docked pose file. reference_pose : Path to the reference pose file. protein : Path to the protein file. outfmt : Output format for bust. Default is "short". Ir can be "short", "long", or "csv". multiple : Whether to run bust on multiple poses. Default is True. If True, docked_pose should be a csv file and reference_pose should be None output_file : Path to save the output file. If None, will return top_n : Number of top results to return. Default is None (return all). max_workers : Maximum number of workers to use for parallel processing. Default is None (use all available). Returns: Path to the output file or a pandas DataFrame with the results.

fix_mol2_atom_types(input_file, output_file)

Fix atom types in a mol2 file. Args: input_file : Path to the input mol2 file. output_file : Path to the output mol2 file.

fix_valence_and_aromaticity_issues(mol)

Fix valence issues (e.g. 4-bonded neutral N) and unmark non-ring aromatics.

RETURNS DESCRIPTION
Mol

Fixed molecule (sanitized)

guess_atom_type(atom_name)

Guess the atom type based on the atom name. This is a simple heuristic function that maps common atom names in mol2 files Args: atom_name : Atom name to guess the type for. Returns: Guessed atom type.

load_mol(path, add_hs=False)

Load a molecule from a file using RDKit. Args: path : Path to the file. add_hs : Whether to add hydrogens to the molecule. Default is False. Returns: Loaded molecule or None if loading failed.

mae_convert(input_file, output_file, concatenate=True, remove_hs=True, sanitize=False, protein=False)

Convert a .mae file to SDF or PDB using maeparser from RDKit. Args: input_file: Path to the input .mae or .maegz file. output_file: Path to the output file (.sdf or .pdb). concatenate: Whether to concatenate all molecules into a single file (only applies to SDF). Default is True. remove_hs: Whether to remove hydrogens. Default is True. sanitize: Whether to sanitize molecules. Default is False. Set to False for docked poses to preserve coordinates. protein: Whether to output the protein if exists to a separate file with a _protein suffix. Default is False. Returns: List of output file paths written.

obabel_convert(test_file, output_filename, hydrogen=False)

Interconvert ligand(s) file formats using obabel.

PARAMETER DESCRIPTION
test_file

Test file name or file object.

output_filename

Output file name.

hydrogen

Whether to add hydrogens to the molecule. Default is False.

TYPE: bool DEFAULT: False

split_mol_file(file_path, lig_name)

Split a .mol2 file to get the ligand and protein separately.

PARAMETER DESCRIPTION
file_path

Path to the input .mol2 file.

lig_name

Name of the ligand to extract (residue name in the mol2 file).

RETURNS DESCRIPTION
str

Path to the split ligand file (PDB format).

to_delta_g(affinity, temperature=300.0)

Convert CNNaffinity (pK) to ΔG in kcal/mol.

PARAMETER DESCRIPTION
affinity

CNNaffinity value(s) in pK units.

TYPE: float | ndarray

temperature

Temperature in Kelvin. Defaults to 300K (gnina default).

TYPE: float DEFAULT: 300.0

Returns: A numpy array or float with the ΔG value(s) in kcal/mol.

to_kd(affinity, unit='uM')

Convert CNNaffinity (pK) to Kd.

PARAMETER DESCRIPTION
affinity

CNNaffinity value(s) in pK units.

TYPE: float | ndarray

unit

Concentration unit. One of M, mM, uM, nM, pM. Defaults to uM.

TYPE: str DEFAULT: 'uM'

Returns: A numpy array or float with the Kd value(s) in the specified unit.

to_pActivity(value, unit='uM')

Convert experimental affinity to pActivity (-log10(Molar)).

PARAMETER DESCRIPTION
value

Kd value(s) in the specified unit.

TYPE: float | ndarray

unit

One of M, mM, uM, nM, pM. Defaults to uM.

TYPE: str DEFAULT: 'uM'

Returns: A numpy array or float with the pActivity value(s) of the experimental data.

write_sdf(path, remove_hs=True)

Write a molecule or list of molecules to an SDF file, optionally removing hydrogens. Args: path: Path to the imput file (PDB or MOL2) or list of paths. remove_hs: Whether to remove hydrogens from the molecule(s) before writing. Default is True. Returns: Path(s) to the output SDF file(s).