File size: 2,008 Bytes
c289d87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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