Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ _POSEBUSTERS_CONFIG_FLAG = $(if $(POSEBUSTERS_CONFIG),--posebusters-config $(POS
EXCLUDE_NON_PHYSICAL ?=
_EXCLUDE_NON_PHYSICAL_FLAG = $(if $(EXCLUDE_NON_PHYSICAL),--exclude-non-physical,)

# DiffDock pocket restriction: auto (default; pocket box when available, blind
# otherwise), box (pocket required), or blind (ignore any box).
DIFFDOCK_POCKET ?=
_DIFFDOCK_POCKET_FLAG = $(if $(DIFFDOCK_POCKET),--diffdock-pocket $(DIFFDOCK_POCKET),)

# Internal docker run flags reused across targets.
# Mounts a generated /etc/passwd so pwd.getpwuid() works for the host UID
# (required by PyTorch / boltz inside the container).
Expand Down Expand Up @@ -140,7 +145,7 @@ _NO_DECOYS_FLAG = $(if $(NO_DECOYS),--no-decoys,)
_BOX_FLAG = $(if $(BOX),--box $(BOX),)
_N_WORKERS_FLAG = $(if $(N_WORKERS),--n-workers $(N_WORKERS),)
_VINA_EXHAUSTIVENESS_FLAG = $(if $(VINA_EXHAUSTIVENESS),--vina-exhaustiveness $(VINA_EXHAUSTIVENESS),)
_OPTIONAL_FLAGS = $(_CLEAN_FLAG) $(_KNOWN_BINDERS_FLAG) $(_HEAD_FLAG) $(_DECOYS_FLAG) $(_NO_DECOYS_FLAG) $(_BOX_FLAG) $(_N_WORKERS_FLAG) $(_NO_GPU_FLAG) $(_GNINA_INPUT_MODE_FLAG) $(_FLEXIBLE_DOCKING_FLAG) $(_FLEXRES_GNINA_FLAG) $(_VINA_EXHAUSTIVENESS_FLAG) $(_POSES_DIR_FLAG) $(_POSE_MODE_FLAG) $(_NO_POSEBUSTERS_FLAG) $(_POSEBUSTERS_CONFIG_FLAG) $(_EXCLUDE_NON_PHYSICAL_FLAG)
_OPTIONAL_FLAGS = $(_CLEAN_FLAG) $(_KNOWN_BINDERS_FLAG) $(_HEAD_FLAG) $(_DECOYS_FLAG) $(_NO_DECOYS_FLAG) $(_BOX_FLAG) $(_N_WORKERS_FLAG) $(_NO_GPU_FLAG) $(_GNINA_INPUT_MODE_FLAG) $(_FLEXIBLE_DOCKING_FLAG) $(_FLEXRES_GNINA_FLAG) $(_VINA_EXHAUSTIVENESS_FLAG) $(_POSES_DIR_FLAG) $(_POSE_MODE_FLAG) $(_NO_POSEBUSTERS_FLAG) $(_POSEBUSTERS_CONFIG_FLAG) $(_EXCLUDE_NON_PHYSICAL_FLAG) $(_DIFFDOCK_POCKET_FLAG)

# Generate an /etc/passwd that includes the container's original entries plus
# the host user. This fixes pwd.getpwuid() failures for LDAP/SSSD users
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ make run-vina \
| `NO_POSEBUSTERS` | *(empty)* | Set to `1` to skip the PoseBusters pose-validity step. On by default (mirrors PLIP): ~400ms/pose, and adds `<method>_pb_valid`/`<method>_pb_pose` to `guild_scores.txt`. See [PoseBusters](#posebusters). |
| `POSEBUSTERS_CONFIG` | *(empty → `dock`)* | `dock` \| `dock_fast`. `dock_fast` skips the `internal_energy` conformer-ensemble check — a lever worth trying on large/very flexible ligand sets. |
| `EXCLUDE_NON_PHYSICAL` | *(empty)* | Set to `1` to null non-physical Vina-family raw scores (e.g. a positive binding energy) before ranking, for a **new** run. Off by default — see [Raw score plausibility](#raw-score-plausibility). |
| `DIFFDOCK_POCKET` | *(empty → `auto`)* | `auto` \| `box` \| `blind`. How DiffDock's pose is restricted to the pocket. `auto` keeps the highest-confidence sample whose centroid lies inside the combination's pocket box, and falls back to blind selection when no pocket exists; `box` requires a pocket (no box, or no sample inside it, scores NaN); `blind` ignores any box. DiffDock always docks into the prepared receptor chain(s), in every mode. See [DiffDock pocket restriction](#diffdock-pocket-restriction). |
| `MIN_MOL_WT` | `250` | Minimum molecular weight filter for known-binder expansion |
| `MAX_MOL_WT` | `450` | Maximum molecular weight filter for known-binder expansion |
| `CHEMBL_VERSION` | `chembl_36` | ChEMBL version string used for known-binder lookup |
Expand Down Expand Up @@ -458,6 +459,32 @@ All four are in kcal/mol (lower = stronger predicted binding), independently ran
protein. The gnina tracks also emit `gnina_rescore_*_cnn_score` as a confidence side channel,
which is not ranked.

DiffDock poses are locally minimised before both rescores (Vina `optimize()`, gnina
`--local_only`), against the same prepared receptor DiffDock docked into, with hydrogens added
to the heavy-atom-only ligand. A DiffDock pose with no receptor heavy atom within 4 Å scores
NaN instead of the near-zero energy an empty grid would return.

### DiffDock pocket restriction

DiffDock is a blind docker with no pocket argument. Guild gives it the same prepared receptor
as Vina and gnina (`proteins/<id>_single_chain_clean.pdb`: the receptor chain(s) only), so
partner chains in the deposited file (G proteins, antibodies, fusion domains) are never
searched. Whether the chosen pose must lie in the pocket is set by `DIFFDOCK_POCKET`
(`--diffdock-pocket`):

| Mode | Pocket box present | No pocket box |
|------|--------------------|---------------|
| `auto` (default) | highest-confidence sample whose heavy-atom centroid is inside the box | highest-confidence sample |
| `box` | as `auto` | failure (NaN) |
| `blind` | highest-confidence sample | highest-confidence sample |

A combination whose samples all fall outside the box scores NaN (`no_sample_in_box`). The
outcome is recorded per combination in the `diffdock_pose_selection` column (`box`, `blind`,
`no_sample_in_box`, `no_box`, `no_samples`) and in
`batches/<batch>/diffdock/results/<combination>/selected_pose.json`. The DiffDock confidence
score, both rescores, the complex PDB and PoseBusters all use that same pose. Use `box` for
benchmarks, so a missing pocket can never silently become blind docking.

> **Rank-percentile orientation.** Every `rp_*_score` and the `global_rp_score` is bounded to
> `(0, 1]` with **0 = best**. A ligand that is uniquely best for a protein scores `1 / n` and the
> uniquely worst `1.0`, but ties share their average rank, so tied extremes fall short of those
Expand Down
23 changes: 10 additions & 13 deletions guild/analysis/posebusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
not check".
"""

import glob
import logging
import multiprocessing as mp
import os
Expand Down Expand Up @@ -65,6 +64,7 @@
POSEBUSTERS_MAX_POSES,
POSEBUSTERS_REPORT_ID_COLUMNS,
)
from guild.docking.diffdock import _diffdock_samples, read_selected_pose
from guild.tools.pose_molecules import (
mol_from_pdb_block,
mols_from_sdf,
Expand Down Expand Up @@ -112,19 +112,16 @@ def _pose_mols(
poses = [mol_from_pdb_block(b, smiles) for b in split_pdbqt_models(pdbqt_path)]

elif docking_method == DIFFDOCK_PREFIX:
# Confidence from the filename matches how the complex PDB picked its
# pose, and avoids the rank<N> lexicographic trap (rank10 < rank2).
# The recorded selection (the pose in the complex PDB and behind every
# DiffDock score) comes first; the remaining samples follow by
# confidence for the escalate/all scopes.
results_dir = f"{method_folder}/results/{combination_id}"
scored = []
for path in glob.glob(f"{results_dir}/*_confidence*.sdf"):
try:
confidence = float(
os.path.basename(path).split("_confidence")[1].replace(".sdf", "")
)
except (IndexError, ValueError):
continue
scored.append((confidence, path))
for _, path in sorted(scored, key=lambda item: item[0], reverse=True):
ordered = [path for _, path in _diffdock_samples(results_dir)]
selection = read_selected_pose(results_dir)
if selection and selection.get("sdf") in ordered:
ordered.remove(selection["sdf"])
ordered.insert(0, selection["sdf"])
for path in ordered:
poses.extend(mols_from_sdf(path, smiles))

if not poses:
Expand Down
25 changes: 19 additions & 6 deletions guild/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
SMILES_NAMES_DICTIONARY_KEY,
)
from guild.constants.diffdock import (
DEFAULT_DIFFDOCK_POCKET,
DIFFDOCK_COMBINATIONS_FILE,
DIFFDOCK_POCKET_KEY,
DIFFDOCK_POCKET_MODES,
DIFFDOCK_RESULTS_FOLDER,
)
from guild.constants.guild import (
Expand Down Expand Up @@ -337,6 +340,7 @@ def __init__(
pose_mode=DEFAULT_POSE_MODE,
flexible_docking: bool = False,
flexres_gnina: str = None,
diffdock_pocket: str = DEFAULT_DIFFDOCK_POCKET,
):
"""
BulkRun class for running multiple docking simulations and performing guild scoring.
Expand Down Expand Up @@ -384,6 +388,12 @@ def __init__(
gnina's ``--flexres`` flag (e.g. ``"A:88,91"`` or ``"A:88,91_B:7"``). Applied
to every row; when set it takes precedence over the automatic box/flexdist
selection that ``flexible_docking`` uses.
:param diffdock_pocket: How DiffDock's pose is restricted to the pocket.
``"auto"`` (default) keeps the highest-confidence sample inside the
pocket box when the combination has one and falls back to blind
selection when it does not; ``"box"`` requires a pocket box (no box,
or no sample inside it, is a failure); ``"blind"`` ignores any box.
DiffDock always docks into the prepared receptor chain(s).
"""

# Pathing variables
Expand All @@ -402,6 +412,11 @@ def __init__(
self.n_workers = n_workers if n_workers is not None else mp.cpu_count()
self.vina_exhaustiveness = vina_exhaustiveness
self.predict_binding_pocket = predict_binding_pocket
if diffdock_pocket not in DIFFDOCK_POCKET_MODES:
raise ValueError(
f"Invalid diffdock_pocket={diffdock_pocket!r}; expected one of {DIFFDOCK_POCKET_MODES}."
)
self.diffdock_pocket = diffdock_pocket

if "_" in project_name:
raise ValueError("Project name cannot contain underscores!")
Expand Down Expand Up @@ -478,10 +493,7 @@ def __init__(
self.methods_to_run = list(self.methods_to_run) + [GNINA_RESCORE_BOLTZ_PREFIX]
# boltz_affinity isn't a docking method (no docking step of its own,
# like the rescore tracks above) — listed only so scoring ranks/votes it.
if (
BOLTZ_PREFIX in self.methods_to_run
and BOLTZ_AFFINITY_PREFIX not in self.methods_to_run
):
if BOLTZ_PREFIX in self.methods_to_run and BOLTZ_AFFINITY_PREFIX not in self.methods_to_run:
self.methods_to_run = list(self.methods_to_run) + [BOLTZ_AFFINITY_PREFIX]

# Resolve gnina_input_mode against the (now auto-extended) methods
Expand Down Expand Up @@ -692,6 +704,7 @@ def _generate_batched_dictionary(self, input_table, batch_size=1000):
current_batch_table=current_batch_table,
batch_folder=batch_folder,
)
self.batched_dictionary[current_batch][DIFFDOCK_POCKET_KEY] = self.diffdock_pocket

self.batched_dictionary[current_batch] = identify_previously_ran_combinations(
current_batch=current_batch,
Expand Down Expand Up @@ -2125,7 +2138,7 @@ def run_interactions_analysis(self, methods_to_analyze=None):
logger.info(
f"PLIP/ProLIF coverage: {sorted(unsupported)} produce no complex "
f"PDB by design and are excluded from interaction analysis — "
f"structurally not applicable, not \"analyzed and found nothing\"."
f'structurally not applicable, not "analyzed and found nothing".'
)

logger.info("Starting interactions analysis")
Expand Down Expand Up @@ -2431,7 +2444,7 @@ def run_pose_validity_analysis(
logger.info(
f"PoseBusters coverage: {unsupported} produce no complex PDB by "
f"design and are excluded from pose validity — structurally not "
f"applicable, not \"checked and passed\". Validating: {supported}."
f'applicable, not "checked and passed". Validating: {supported}.'
)

logger.info(
Expand Down
37 changes: 37 additions & 0 deletions guild/constants/diffdock.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,40 @@
COMPLEX_NAME = "complex_name"
LIGAND_DESCRIPTION = "ligand_description"
PROTEIN_SEQUENCE = "protein_sequence"

"""
Pocket restriction
"""
# auto: restrict to the pocket box when one exists, otherwise blind.
# box: a pocket box is required; no box or no sample inside it is a failure.
# blind: ignore any box and keep DiffDock's top-confidence sample.
DIFFDOCK_POCKET_AUTO = "auto"
DIFFDOCK_POCKET_BOX = "box"
DIFFDOCK_POCKET_BLIND = "blind"
DIFFDOCK_POCKET_MODES = (DIFFDOCK_POCKET_AUTO, DIFFDOCK_POCKET_BOX, DIFFDOCK_POCKET_BLIND)
DEFAULT_DIFFDOCK_POCKET = DIFFDOCK_POCKET_AUTO

# Batch-dictionary key carrying the pocket mode to the scoring/complex helpers.
DIFFDOCK_POCKET_KEY = "diffdock_pocket"

# Per-combination record of which sample was chosen and why, so the score,
# both rescores, the complex PDB and PoseBusters all describe the same pose.
SELECTED_POSE_FILE = "selected_pose.json"

# Outcomes written to the diffdock_pose_selection column.
POSE_SELECTED_BOX = "box"
POSE_SELECTED_BLIND = "blind"
POSE_NO_SAMPLE_IN_BOX = "no_sample_in_box"
POSE_NO_BOX = "no_box"
POSE_NO_SAMPLES = "no_samples"

# A rescored pose with no receptor heavy atom within this distance (Å) is not
# bound to the receptor; its score is reported as NaN rather than ~0.
RECEPTOR_CONTACT_CUTOFF = 4.0

# Side-channel column in the scores table; not a score, never ranked.
DIFFDOCK_POSE_SELECTION = "diffdock_pose_selection"

# Prepared receptor written by Guild prep (receptor chain(s), altlocs
# collapsed, Vina/box frame): {proteins}/{protein_conf_id}{suffix}.pdb/.pdbqt
CLEAN_RECEPTOR_SUFFIX = "_single_chain_clean"
Loading
Loading