"""
Dihedral angle type enumeration.

AUTO-GENERATED by codegen/generate.py - DO NOT EDIT MANUALLY.
"""

from ..utils import IndexEnum


class DihedralType(IndexEnum):
    """
    Named dihedral angle types for proteins and nucleic acids.

    Dihedral angles describe rotations around bonds and are fundamental
    to describing the conformation of biomolecules. Values are integers
    that can be used directly as array indices.

    Protein backbone dihedrals:
        PHI: C(i-1) - N(i) - CA(i) - C(i)
        PSI: N(i) - CA(i) - C(i) - N(i+1)
        OMEGA: CA(i) - C(i) - N(i+1) - CA(i+1)

    Nucleic acid backbone dihedrals:
        ALPHA: O3'(i-1) - P(i) - O5'(i) - C5'(i)
        BETA: P(i) - O5'(i) - C5'(i) - C4'(i)
        GAMMA: O5'(i) - C5'(i) - C4'(i) - C3'(i)
        DELTA: C5'(i) - C4'(i) - C3'(i) - O3'(i)
        EPSILON: C4'(i) - C3'(i) - O3'(i) - P(i+1)
        ZETA: C3'(i) - O3'(i) - P(i+1) - O5'(i+1)

    Glycosidic dihedrals:
        CHI_PURINE: O4' - C1' - N9 - C4 (adenine, guanine)
        CHI_PYRIMIDINE: O4' - C1' - N1 - C2 (cytosine, uracil, thymine)

    Protein sidechain dihedrals:
        CHI1: N - CA - CB - XG (varies by residue)
        CHI2: CA - CB - CG - XD (varies by residue)
        CHI3: CB - CG - CD - XE (varies by residue)
        CHI4: CG - CD - XE - XZ (LYS, ARG only)

    Example:
        >>> DihedralType.PHI.value  # Returns 0, usable as array index
        0
        >>> DihedralType.dict()  # Returns name -> value mapping
        {'PHI': 0, 'PSI': 1, ...}
    """

    PHI = 0
    PSI = 1
    OMEGA = 2
    ALPHA = 3
    BETA = 4
    GAMMA = 5
    DELTA = 6
    EPSILON = 7
    ZETA = 8
    CHI_PURINE = 9
    CHI_PYRIMIDINE = 10
    CHI1 = 11
    CHI2 = 12
    CHI3 = 13
    CHI4 = 14


# Convenience tuples for common dihedral groups
PROTEIN_BACKBONE: tuple[DihedralType, ...] = (DihedralType.PHI, DihedralType.PSI, DihedralType.OMEGA,)

RNA_BACKBONE: tuple[DihedralType, ...] = (DihedralType.ALPHA, DihedralType.BETA, DihedralType.GAMMA, DihedralType.DELTA, DihedralType.EPSILON, DihedralType.ZETA,)

RNA_GLYCOSIDIC: tuple[DihedralType, ...] = (DihedralType.CHI_PURINE, DihedralType.CHI_PYRIMIDINE,)

# Extended backbone includes glycosidic for full conformational description
RNA_BACKBONE_EXTENDED: tuple[DihedralType, ...] = RNA_BACKBONE + (DihedralType.CHI_PYRIMIDINE,)

PROTEIN_SIDECHAIN: tuple[DihedralType, ...] = (DihedralType.CHI1, DihedralType.CHI2, DihedralType.CHI3, DihedralType.CHI4,)


# String name -> DihedralType lookup
DIHEDRAL_NAME_TO_TYPE: dict[str, DihedralType] = {
    "phi": DihedralType.PHI,
    "psi": DihedralType.PSI,
    "omega": DihedralType.OMEGA,
    "alpha": DihedralType.ALPHA,
    "beta": DihedralType.BETA,
    "gamma": DihedralType.GAMMA,
    "delta": DihedralType.DELTA,
    "epsilon": DihedralType.EPSILON,
    "zeta": DihedralType.ZETA,
    "chi_purine": DihedralType.CHI_PURINE,
    "chi_pyrimidine": DihedralType.CHI_PYRIMIDINE,
    "chi1": DihedralType.CHI1,
    "chi2": DihedralType.CHI2,
    "chi3": DihedralType.CHI3,
    "chi4": DihedralType.CHI4,
}


# Atom names defining each dihedral type (Python naming convention)
DIHEDRAL_ATOMS: dict[DihedralType, tuple[str, str, str, str]] = {
    DihedralType.PHI: ("C", "N", "CA", "C"),
    DihedralType.PSI: ("N", "CA", "C", "N"),
    DihedralType.OMEGA: ("CA", "C", "N", "CA"),
    DihedralType.ALPHA: ("O3p", "P", "O5p", "C5p"),
    DihedralType.BETA: ("P", "O5p", "C5p", "C4p"),
    DihedralType.GAMMA: ("O5p", "C5p", "C4p", "C3p"),
    DihedralType.DELTA: ("C5p", "C4p", "C3p", "O3p"),
    DihedralType.EPSILON: ("C4p", "C3p", "O3p", "P"),
    DihedralType.ZETA: ("C3p", "O3p", "P", "O5p"),
    DihedralType.CHI_PURINE: ("O4p", "C1p", "N9", "C4"),
    DihedralType.CHI_PYRIMIDINE: ("O4p", "C1p", "N1", "C2"),
    DihedralType.CHI1: ("N", "CA", "CB", "XG"),
    DihedralType.CHI2: ("CA", "CB", "CG", "XD"),
    DihedralType.CHI3: ("CB", "CG", "CD", "XE"),
    DihedralType.CHI4: ("CG", "CD", "XE", "XZ"),
}


# Legacy constants (for backwards compatibility)
INDEX_TO_DIHEDRAL_TYPE: dict[int, DihedralType] = {dt.value: dt for dt in DihedralType}
NUM_PROTEIN_BACKBONE_DIHEDRALS: int = len(PROTEIN_BACKBONE)
NUM_RNA_BACKBONE_DIHEDRALS: int = len(RNA_BACKBONE_EXTENDED)
MAX_DIHEDRALS_PER_RESIDUE: int = max(NUM_PROTEIN_BACKBONE_DIHEDRALS, NUM_RNA_BACKBONE_DIHEDRALS)
