from pathlib import Path
import string


def guess_pdb_type(pdb_file: str) -> str:
    """Guess PDB file type from file name.

    Examples
    --------
    >>> _guess_pdb_type('4dkl.pdb')
    'pdb'
    >>> _guess_pdb_type('/tmp/4dkl.cif.gz')
    'cif'
    """
    for suffix in reversed(Path(pdb_file).suffixes):
        suffix = suffix.lower().strip(string.digits)
        if suffix in [".pdb", ".ent"]:
            return "pdb"
        elif suffix in [".cif", ".mmcif"]:
            return "cif"
        elif suffix in [".mmtf"]:
            return "mmtf"
    raise Exception(f"Could not guess pdb type for file '{pdb_file}'!")