molforge.wrappers.docking¶
docking ¶
Docking-engine wrappers.
Concrete engines
- :class:
Vina— implemented (AutoDock Vina; small-molecule docking) - :class:
DiffDock— implemented (diffusion-based blind docking)
All engines write poses sorted best-first into
:attr:DockingResult.poses.
DockingEngine ¶
Bases: ABC
Abstract base for receptor-ligand docking engines.
Subclasses must implement :meth:dock. They should also handle their
own receptor and ligand preparation (charge assignment, conversion
to engine-specific formats) inside :meth:dock rather than exposing
that complexity to users — that's the whole point of having a wrapper.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable engine name (set by subclasses). |
dock
abstractmethod
¶
Dock ligand against receptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receptor
|
Protein
|
The receptor structure. |
required |
ligand
|
object
|
The ligand. Type is engine-dependent — typically a
path to an SDF/MOL2, a SMILES string, or a
:class: |
required |
**kwargs
|
object
|
Engine-specific options. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DockingResult
|
class: |
DockingEngineNotInstalledError ¶
Bases: ImportError
Raised when a docking engine's heavy dependencies aren't installed.
The message points at the relevant pip install extras so users
can fix it without grepping the docs.
DockingResult
dataclass
¶
DockingResult(
poses: list[Pose] = list(),
receptor: Protein | None = None,
engine: str = "",
metadata: dict[str, object] = dict(),
)
Collection of poses returned by a docking engine.
Attributes:
| Name | Type | Description |
|---|---|---|
poses |
list[Pose]
|
List of :class: |
receptor |
Protein | None
|
The receptor structure that was docked against. |
engine |
str
|
Engine name ( |
metadata |
dict[str, object]
|
Engine-specific run metadata (search box, exhaustiveness, walltime, etc.). |
Pose
dataclass
¶
Pose(
ligand: Protein,
score: float,
rank: int = 0,
rmsd_lb: float | None = None,
rmsd_ub: float | None = None,
metadata: dict[str, object] = dict(),
)
A single docked ligand pose.
Attributes:
| Name | Type | Description |
|---|---|---|
ligand |
Protein
|
The ligand structure for this pose as a :class: |
score |
float
|
Engine-specific scalar score. Convention: lower = better (e.g. Vina returns kcal/mol affinity estimates as negative numbers). |
rank |
int
|
0-indexed rank within the result (0 = best). |
rmsd_lb |
float | None
|
Vina-style "RMSD lower bound" between this pose and the best pose, if reported by the engine. |
rmsd_ub |
float | None
|
Vina-style "RMSD upper bound" between this pose and the best pose, if reported. |
metadata |
dict[str, object]
|
Engine-specific extras (component-energy breakdown, confidence scores, etc.). |
DiffDock ¶
DiffDock(
*,
repo_dir: str | PathLike[str] | None = None,
python_executable: str | None = None,
samples_per_complex: int = 10,
inference_steps: int = 20,
batch_size: int = 10,
)
Bases: DockingEngine
Wrapper around DiffDock (diffusion-based blind docking).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_dir
|
str | PathLike[str] | None
|
Path to a cloned |
None
|
python_executable
|
str | None
|
Python interpreter used to run DiffDock's
|
None
|
samples_per_complex
|
int
|
Number of poses DiffDock samples (and the cap on how many ranked poses are returned). DiffDock's default is 10. |
10
|
inference_steps
|
int
|
Reverse-diffusion steps. DiffDock's default is 20; more steps cost runtime roughly linearly. |
20
|
batch_size
|
int
|
Sampling batch size passed through to DiffDock. |
10
|
Example
from molforge.wrappers.docking import DiffDock import molforge as mf
receptor = mf.load("receptor.pdb") result = DiffDock().dock( ... receptor=receptor, ... ligand="CC(=O)Oc1ccccc1C(=O)O", # aspirin SMILES ... ) best = result.best best.metadata["confidence"] # DiffDock confidence score 0.74
dock ¶
dock(
receptor: Protein | str | PathLike[str],
ligand: str | PathLike[str],
*,
timeout: float | None = None,
**_kwargs: object,
) -> DockingResult
Dock ligand against receptor with DiffDock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receptor
|
Protein | str | PathLike[str]
|
A :class: |
required |
ligand
|
str | PathLike[str]
|
Either a SMILES string or a path to an
|
required |
timeout
|
float | None
|
Optional subprocess timeout in seconds. |
None
|
**_kwargs
|
object
|
Reserved for future DiffDock options. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DockingResult
|
class: |
DockingResult
|
DiffDock reports a confidence (higher = better); each |
|
DockingResult
|
class: |
|
DockingResult
|
|
|
DockingResult
|
negation, so |
|
DockingResult
|
the convention used by :class: |
Raises:
| Type | Description |
|---|---|
DockingEngineNotInstalledError
|
If the DiffDock repo cannot be located. |
RuntimeError
|
If the DiffDock subprocess fails or produces no output. |
Vina ¶
Bases: DockingEngine
Wrapper around AutoDock Vina.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scoring
|
str
|
Scoring function name. |
'vina'
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
cpu
|
int
|
Number of CPU threads to use. |
0
|
verbosity
|
int
|
Vina's internal verbosity (0 = silent, 1 = some, 2 = verbose). |
0
|
Example
from molforge.wrappers.docking import Vina import molforge as mf
receptor = mf.load("receptor_prepared.pdbqt") result = Vina().dock( ... receptor=receptor, ... ligand="ligand.pdbqt", ... center=(10.0, 5.0, -2.0), ... box_size=(20.0, 20.0, 20.0), ... exhaustiveness=8, ... n_poses=9, ... ) best = result.best best.score # Vina affinity in kcal/mol -8.4
dock ¶
dock(
receptor: Protein | str | PathLike[str],
ligand: Protein | str | PathLike[str],
*,
center: tuple[float, float, float],
box_size: tuple[float, float, float] = (
20.0,
20.0,
20.0,
),
exhaustiveness: int = 8,
n_poses: int = 9,
energy_range: float = 3.0,
min_rmsd: float = 1.0,
**_kwargs: object,
) -> DockingResult
Dock ligand against receptor using Vina.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receptor
|
Protein | str | PathLike[str]
|
A :class: |
required |
ligand
|
Protein | str | PathLike[str]
|
A :class: |
required |
center
|
tuple[float, float, float]
|
|
required |
box_size
|
tuple[float, float, float]
|
|
(20.0, 20.0, 20.0)
|
exhaustiveness
|
int
|
Sampling intensity. Vina default is 8; use 16 or 32 for more thorough searches. Linear in runtime. |
8
|
n_poses
|
int
|
Maximum number of poses to return. |
9
|
energy_range
|
float
|
Maximum energy difference (kcal/mol) between best and worst returned pose. |
3.0
|
min_rmsd
|
float
|
Minimum RMSD between distinct poses. |
1.0
|
**_kwargs
|
object
|
Reserved for future Vina options. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DockingResult
|
class: |
DockingResult
|
affinity) first. Each :class: |
|
DockingResult
|
and |
Raises:
| Type | Description |
|---|---|
DockingEngineNotInstalledError
|
If |
is_pdbqt_path ¶
True iff value is a path string pointing to a .pdbqt file.
prepare_ligand ¶
prepare_ligand(
ligand: str | PathLike[str],
out_path: str | PathLike[str],
*,
from_smiles: bool = False,
add_hydrogens: bool = True,
generate_3d: bool = True,
) -> Path
Prepare a ligand for AutoDock Vina, writing a PDBQT to out_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ligand
|
str | PathLike[str]
|
One of:
|
required |
out_path
|
str | PathLike[str]
|
Destination path for the PDBQT file. |
required |
from_smiles
|
bool
|
Treat |
False
|
add_hydrogens
|
bool
|
Add explicit hydrogens (needed by Vina). |
True
|
generate_3d
|
bool
|
Generate a 3-D conformer via RDKit's ETKDG. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
The path the PDBQT was written to. |
Raises:
| Type | Description |
|---|---|
DockingEngineNotInstalledError
|
If |
prepare_receptor ¶
prepare_receptor(
receptor: Protein | str | PathLike[str],
out_path: str | PathLike[str],
*,
rigid_only: bool = True,
) -> Path
Prepare a receptor for AutoDock Vina, writing a PDBQT to out_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receptor
|
Protein | str | PathLike[str]
|
A :class: |
required |
out_path
|
str | PathLike[str]
|
Destination path for the PDBQT file. |
required |
rigid_only
|
bool
|
If True (default), treat the entire receptor as rigid (the usual case). Set False if you've added side-chain flexibility annotations upstream. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
The path the PDBQT was written to. |
Raises:
| Type | Description |
|---|---|
DockingEngineNotInstalledError
|
If |