from __future__ import annotations from abc import ABC, abstractmethod from dataclasses import dataclass, field from pathlib import Path from typing import Any, Dict, Sequence @dataclass class BackendCapability: backend_name: str available: bool details: Dict[str, Any] @dataclass class DockingResult: ligand_id: str docking_score: float pose_path: Path | None backend_name: str backend_mode: str score_source: str raw_output_file: str parsed_from: str fallback_used: bool success: bool message: str = "" command: str = "" extra: Dict[str, Any] = field(default_factory=dict) class DockingError(RuntimeError): """Generic docking backend error.""" class BackendUnavailableError(DockingError): """Raised when requested backend capability is not available.""" class DockingBackend(ABC): """Common backend interface for all docking engines.""" @abstractmethod def check_capability(self) -> BackendCapability: pass @abstractmethod def prepare_target(self, target_path: str | Path, work_dir: str | Path) -> Dict[str, Any]: pass @abstractmethod def prepare_ligand(self, ligand_id: str, smiles: str, work_dir: str | Path) -> Path: pass @abstractmethod def build_site_or_constraints( self, target_context: Dict[str, Any], reference_ligand: Path, work_dir: str | Path, ) -> Path: pass @abstractmethod def dock( self, target_context: Dict[str, Any], ligand_files: Sequence[Path], work_dir: str | Path, allow_mock: bool = False, require_real_backend: bool = False, ) -> list[DockingResult]: pass @abstractmethod def parse_results(self, results: Sequence[DockingResult]) -> list[dict[str, Any]]: pass @abstractmethod def extract_interface_features(self, parsed_results: Sequence[dict[str, Any]]) -> list[dict[str, float]]: pass