File size: 1,655 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
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,
        )