| from __future__ import annotations |
|
|
| from pathlib import Path |
| from typing import Any, Dict |
|
|
| from Bio.PDB import MMCIFParser, PDBParser |
|
|
|
|
| def load_structure(path: str | Path, structure_id: str = "target") -> Any: |
| """Load PDB or mmCIF structure object using Biopython.""" |
| source = Path(path) |
| suffix = source.suffix.lower() |
| if suffix in {".pdb", ".ent"}: |
| parser = PDBParser(QUIET=True) |
| return parser.get_structure(structure_id, str(source)) |
| if suffix in {".cif", ".mmcif"}: |
| parser = MMCIFParser(QUIET=True) |
| return parser.get_structure(structure_id, str(source)) |
| raise ValueError(f"Unsupported structure extension: {source}") |
|
|
|
|
| def summarize_structure(path: str | Path) -> Dict[str, int]: |
| structure = load_structure(path) |
| residues = [r for r in structure.get_residues() if r.id[0] == " "] |
| atoms = list(structure.get_atoms()) |
| chains = list(structure.get_chains()) |
| return {"residue_count": len(residues), "atom_count": len(atoms), "chain_count": len(chains)} |
|
|