| from __future__ import annotations |
|
|
| from dataclasses import dataclass |
| from pathlib import Path |
| from typing import Optional, Sequence |
|
|
| import numpy as np |
|
|
| from .graph_builders import build_protein_graph, protein_sequence_from_structure |
| from .schemas import ProteinEncoding |
| from .sequence_features import compute_sequence_features |
| from .structure_features import compute_structure_features |
|
|
|
|
| @dataclass |
| class ProteinEncoderConfig: |
| distance_threshold: float = 8.0 |
|
|
|
|
| class ProteinEncoder: |
| """Encode protein structures from PDB/mmCIF for scheduling/modeling.""" |
|
|
| def __init__(self, config: Optional[ProteinEncoderConfig] = None): |
| self.config = config or ProteinEncoderConfig() |
|
|
| def encode_structure( |
| self, |
| target_id: str, |
| structure_path: str | Path, |
| pocket_residues: Sequence[str] | None = None, |
| ) -> ProteinEncoding: |
| sequence = protein_sequence_from_structure(structure_path) |
| seq_features = compute_sequence_features(sequence) |
| struct_features = compute_structure_features(structure_path, pocket_residues=pocket_residues) |
| graph = build_protein_graph( |
| structure_path, |
| distance_threshold=self.config.distance_threshold, |
| pocket_residues=pocket_residues, |
| ) |
| combined = {**seq_features, **struct_features} |
| vector = np.asarray(list(combined.values()), dtype=float) |
| return ProteinEncoding( |
| target_id=target_id, |
| sequence=sequence, |
| sequence_features=seq_features, |
| structure_features=struct_features, |
| graph=graph, |
| vector=vector, |
| ) |
|
|