Skip to content

deeporigin.drug_discovery.docking

A unified class to perform molecular docking on DeepOrigin.

Attributes

Number module-attribute

Number = float | int

Classes

Docking

Bases: Execution, SyncExecutableMixin, AsyncExecutableMixin, NotebookWatchMixin

Molecular docking via the tools API (client.executions.create).

The execution request body includes sync (true = blocking, false = immediate DTO). :meth:run sets "sync": true for exactly one ligand; the server blocks until the run finishes and returns the completed execution. :meth:quote (default mode="async") and :meth:start set "sync": false (non-blocking).

:meth:start is for multiple ligands only: one create with all ligands. The call returns immediately with an execution DTO. For a single ligand, use :meth:run instead of :meth:start. Track async jobs with .sync(), .wait(), from_id(), and list(). In Jupyter, use await docking.watch() (see :class:~deeporigin.drug_discovery.notebook_watch_mixin.NotebookWatchMixin).

Attributes:

Name Type Description
protein Protein

Target protein structure.

ligands LigandSet

Set of ligands to dock.

pocket Pocket

Binding pocket defining the docking box.

effort int

Docking effort level (1 = fastest, 5 = most thorough).

name

Execution label, set automatically from protein and ligands unless overridden.

batch_size int

For async :meth:start, workflow batch size (ligands per workflow batch), a positive multiple of 4. Defaults to 16. Sent as batchSize on the execution create payload.

Attributes

app instance-attribute
app: str | None = None
approve_amount instance-attribute
approve_amount: int | None = None
batch_size property
batch_size: int

Workflow batch size for async :meth:start (default 16).

client instance-attribute
client: DeepOriginClient = client
completed_at instance-attribute
completed_at: str | None = None
cost property
cost: float | None

Actual cost in dollars, set after execution completes.

This property cannot be set manually.

created_at instance-attribute
created_at: str | None = None
created_by instance-attribute
created_by: str | None = None
dto property
dto: dict[str, Any] | None

Last tools execution DTO from the platform, if any.

effort class-attribute instance-attribute
effort: int = effort
estimate property
estimate: float | None

Cost estimate in dollars, populated when the platform returns a quotation.

Set after run(quote=True), start(quote=True), or any call with approve_amount=0. None until a quotation result is received. This property cannot be set manually.

id property
id: str | None

Platform execution ID when set (read-only).

ligands property
ligands: LigandSet

Set of ligands to dock.

name instance-attribute
name = (
    name
    if name is not None
    else _docking_default_name(protein, ligands)
)
pocket property
pocket: Pocket

Binding pocket defining the docking box.

progress instance-attribute
progress: dict | None = None
protein property
protein: Protein

Target protein structure.

runtime property
runtime: float | None

Seconds from DTO startedAt to completedAt or current UTC time.

Uses :attr:dto (same shape as client.executions.get). When completedAt is present, it is the end time; otherwise the end time is datetime.now(timezone.utc). Returns None if there is no DTO or startedAt is missing or empty.

session instance-attribute
session: str | None = None
started_at instance-attribute
started_at: str | None = None
status instance-attribute
status: PlatformStatus | None = None
tool_key class-attribute instance-attribute
tool_key: str = TOOL_KEYS_AND_VERSIONS["docking"][
    "tool_key"
]
tool_version instance-attribute
tool_version = tool_version

Methods:

cancel
cancel() -> None

Cancel a running or queued execution.

Raises:

Type Description
ValueError

If the job has no execution ID.

ValueError

If the job is not in a cancellable state.

confirm
confirm() -> None

Confirm a quoted tools execution on the platform.

Requires :attr:id and status equal to "Quoted". Uses :meth:~deeporigin.platform.executions.Executions.confirm with :data:~deeporigin.utils.constants.TOOL_EXECUTION_POST_TIMEOUT_SECONDS (10 minutes) and retry=False, then applies the returned DTO via :meth:update_from_dto so status, :attr:cost, and :attr:dto reflect the platform response. For direct (blocking) tools the response is typically terminal (Succeeded); for async tools it may be Created or Running — call :meth:sync until the job finishes.

Raises:

Type Description
ValueError

If there is no platform execution id or status is not "Quoted".

duplicate
duplicate(
    *, client: DeepOriginClient | None = None
) -> Self

Create a fresh copy with the same configuration but no execution state.

Useful after from_id() to re-run the same calculation. The returned instance has no id, status, estimate, or cost — it is ready for run() / start().

Parameters:

Name Type Description Default
client DeepOriginClient | None

Optional API client for the new instance. Falls back to the current instance's client.

None

Returns:

Type Description
Self

A new instance sharing the same domain-specific configuration.

from_dto classmethod
from_dto(
    dto: dict, *, client: DeepOriginClient | None = None
) -> Self

Construct a Docking instance from an execution DTO.

Rehydrates the protein, pocket, and ligands from the stored userInputs. Protein and ligand structure files are not downloaded; Protein.remote_path and each ligand's remote_path are set from the execution payload (and API metadata) so you can call :meth:~deeporigin.drug_discovery.structures.entity.Entity.download later if needed.

Parameters:

Name Type Description Default
dto dict

Execution payload (same shape as client.executions.get).

required
client DeepOriginClient | None

Optional API client. Uses the default if not provided.

None

Returns:

Type Description
Self

A fully-hydrated Docking instance with status from the DTO.

from_id classmethod
from_id(
    id: str, *, client: DeepOriginClient | None = None
) -> Self

Construct an instance from an existing platform execution ID.

Fetches the execution DTO via client.executions.get and delegates to :meth:from_dto. Concrete subclasses override :meth:from_dto to attach domain state from userInputs.

Parameters:

Name Type Description Default
id str

Platform execution ID.

required
client DeepOriginClient | None

Optional API client. Uses the default if not provided.

None

Returns:

Type Description
Self

A partially-hydrated instance with common fields populated.

Raises:

Type Description
NotImplementedError

If cls has no tool_key (bare :class:Execution).

get_poses
get_poses(*, all_poses: bool = False) -> LigandSet

Download pose SDFs from the platform and return a LigandSet.

Parameters:

Name Type Description Default
all_poses bool

If True, download all poses for each ligand. If False (default), download only the best pose per ligand.

False

Returns:

Type Description
LigandSet

A LigandSet of docked poses.

Raises:

Type Description
ValueError

If no execution has been started.

DeepOriginException

If no poses could be loaded.

get_results
get_results(
    dto: dict[str, Any] | None = None,
    *,
    all_poses: bool = False
) -> LigandSet

Load docked poses for this execution from the data platform or jobOutputs.

Tries :meth:~deeporigin.drug_discovery.structures.ligand.LigandSet.from_result first (fast metadata path, no SDF download). On failure, parses jobOutputs.poses from dto, or fetches the execution DTO via client.executions.get when dto is omitted.

To convert the result to a DataFrame::

poses = docking.get_results()
df = poses.to_dataframe()

Parameters:

Name Type Description Default
dto dict[str, Any] | None

Optional execution payload (executions.create / executions.get). Passing it avoids an extra GET when the data platform path fails but the sync response included jobOutputs.

None
all_poses bool

When True, include every pose instead of only the best pose per ligand.

False

Returns:

Type Description
LigandSet

A LigandSet of docked poses.

Raises:

Type Description
ValueError

If :attr:id is unset.

DeepOriginException

If no poses could be loaded from the data platform or jobOutputs.

get_undocked_ligands
get_undocked_ligands() -> LigandSet | None

Get a list of ligands that failed to dock.

Note: we cannot rely on the tool progress report to determine failed ligands, because catastrophic tool failures will not update the progress report.

Returns:

Type Description
LigandSet | None

A LigandSet of failed ligands, or None if no failed ligands yet.

get_user_logs
get_user_logs(
    *,
    limit: int | None = None,
    offset: int | None = None,
    select: list[str] | None = None,
    with_total_count: bool = False
) -> dict[str, Any] | None

Search data-platform user_logs rows for this execution.

Uses :meth:deeporigin.platform.user_logs.UserLogs.search with this execution's id (tools executionId), stored as execution_id on user_logs rows — the same string passed to :meth:get_results as compute_job_id.

When no execution id is assigned yet, returns None without calling the API.

Parameters:

Name Type Description Default
limit int | None

Max rows to return (forwarded to UserLogs.search).

None
offset int | None

Skip offset (forwarded).

None
select list[str] | None

Columns to select (forwarded).

None
with_total_count bool

Request total count from the server (forwarded).

False

Returns:

Type Description
dict[str, Any] | None

The search response dict (typically data / meta), or

dict[str, Any] | None

None if this instance has no execution id yet.

list classmethod
list(
    *,
    client: DeepOriginClient | None = None,
    status: list[str] | None = None
) -> list[Self]

List executions of this tool type from the platform.

Calls client.executions.list(fetch_all_pages=True, tool_key=...), then builds instances via :meth:from_dto. Optional status filters hydrated instances by instance.status.

Parameters:

Name Type Description Default
client DeepOriginClient | None

Optional API client. Uses the default if not provided.

None
status list[str] | None

Optional list of statuses to keep (membership test).

None

Returns:

Type Description
list[Self]

Instances of this class, one per matching execution.

Raises:

Type Description
NotImplementedError

If cls has no tool_key (bare :class:Execution).

run
run(
    *,
    quote: bool = False,
    approve_amount: int | None = None
) -> LigandSet | None

Execute docking synchronously (blocking).

Submits one synchronous tools execution and returns docked poses from the data platform. Requires exactly one ligand in :attr:ligands; use :meth:start for multiple ligands.

Pass quote=True (or approve_amount=0) to request a cost estimate only. In that case the platform returns a Quoted DTO, the instance is updated with estimate and status="Quoted", and None is returned.

Parameters:

Name Type Description Default
quote bool

Shorthand for approve_amount=0.

False
approve_amount int | None

Spend cap forwarded to the platform as approveAmount.

None

Returns:

Type Description
LigandSet | None

A LigandSet of docked poses, or None when the platform

LigandSet | None

responds with Quoted status.

Raises:

Type Description
ValueError

If :attr:ligands does not contain exactly one ligand.

DeepOriginException

If effort is outside 1–5, the execution does not succeed, or poses could not be loaded.

show
show() -> None

Display the current execution in Jupyter using the execution card HTML view.

If no platform execution ID exists yet, shows the same card with a short notice instead of raising (see :meth:~deeporigin.platform.execution_display.ExecutionDisplay.from_pending).

show_box
show_box() -> str

Visualize the protein with the docking search box in a Jupyter notebook.

Renders the target protein and a wireframe box from :attr:pocket center and box_size_x / box_size_y / box_size_z (same geometry as :meth:run and :meth:start submit to the docking tool). Requires the tools optional dependency (deeporigin-molstar).

Returns:

Type Description
str

HTML string for the Mol* viewer (wrapped for display by

str

func:~deeporigin.drug_discovery.utils.visualize.jupyter_visualization).

Raises:

Type Description
DeepOriginException

If the protein structure cannot be loaded locally.

start
start(
    *,
    quote: bool = False,
    approve_amount: int | None = None,
    **kwargs: Any
) -> None

Submit a persisted async execution. Requires at least two ligands.

For a single ligand, use :meth:run instead.

Parameters:

Name Type Description Default
quote bool

Shorthand for approve_amount=0.

False
approve_amount int | None

Spend cap forwarded to the platform.

None
**kwargs Any

Forwarded to _start_impl.

{}
stop_watching
stop_watching() -> None

Cancel an in-flight watch loop if one is running.

Safe to call when no watch is active. Does not cancel the caller's current task when invoked from inside the watch loop.

sync
sync() -> None

Fetch the latest tools execution from the platform and refresh fields.

Calls client.executions.get for :attr:id and applies the response with :meth:update_from_dto. Use when the job may have changed outside this process (for example after submission from the web UI), to poll lifecycle state, or to refresh an instance built from an older DTO. Available on sync-only and async execution types alike.

If executions.get returns a falsy value, this instance is left unchanged.

Raises:

Type Description
ValueError

If this instance has no execution id yet.

NotImplementedError

If type(self).tool_key is empty (bare :class:Execution).

ValueError

If the returned DTO tool.key does not match this class (see :meth:update_from_dto).

update_from_dto
update_from_dto(dto: dict[str, Any]) -> None

Apply tools execution fields from dto onto this instance.

Updates id, pricing, lifecycle fields, and _dto the same way as :meth:from_dto for a newly created instance. Use after a live executions.create / sync() response to refresh state without constructing a new object (domain inputs on self are unchanged).

Parameters:

Name Type Description Default
dto dict[str, Any]

Execution payload (same shape as client.executions.get).

required

Raises:

Type Description
NotImplementedError

If type(self) has no tool_key (bare :class:Execution).

ValueError

If the DTO tool.key does not match tool_key.

wait
wait(
    *,
    poll_interval: float = 5.0,
    timeout: float | None = None
) -> dict[str, Any] | None

Block until this execution reaches a terminal state.

Parameters:

Name Type Description Default
poll_interval float

Seconds to sleep between polling cycles.

5.0
timeout float | None

Maximum total seconds to wait. If None, waits indefinitely.

None

Returns:

Type Description
dict[str, Any] | None

The latest execution DTO, or None if the platform returned no DTO.

Raises:

Type Description
ValueError

If this instance has no execution id yet.

TimeoutError

If timeout elapses before the execution terminates.

watch async
watch(
    *, interval: float = 5.0, blocking: bool = False
) -> Task | None

Start live notebook updates; optionally block until the job finishes.

By default, awaiting this coroutine finishes in one event-loop turn, so the cell returns while the display keeps updating in the background. Use this when you need to run other cells while the job runs::

task = await abfe.watch()

Set blocking=True or export JOB_WATCH_BLOCK=1 (truthy values: 1, true, yes, on) to run the poll loop inline so the cell does not return until a terminal state — useful for nbconvert --execute and doc CI (see :data:~deeporigin.utils.constants.JOB_WATCH_BLOCK_ENV)::

await abfe.watch(blocking=True)
# or: export JOB_WATCH_BLOCK=1

Parameters:

Name Type Description Default
interval float

Seconds between polls.

5.0
blocking bool

When True, await the watch loop instead of returning a background task. Also blocks when JOB_WATCH_BLOCK is truthy.

False

Returns:

Type Description
Task | None

The background task when not blocking; None when blocking.

Task | None

Cancel a background watch with :meth:stop_watching or task.cancel().

Functions: