Download libs/encoders/protein_encoder.py from QPromaQ/Docking_project: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/libs/encoders/protein_encoder.py
- Command line
-
hf download hf://datasets/QPromaQ/Docking_project/libs/encoders/protein_encoder.py
-
curl -L -o protein_encoder.py https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/libs/encoders/protein_encoder.py
1.66 kB
| 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 | |
| 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, | |
| ) | |