Domain: Chemistry — Physical Chemistry

Problem:
Implement an algorithm to find the **Transition Probability Score ($T_{score}$)** for the $H_2^+$ molecular ion. This final score is a single, unitless value derived from a highly interdependent set of quantum mechanical calculations.

**Computational Method:**
To find this score, you must first model the molecule using the LCAO-MO method by solving the generalized eigenvalue problem $\mathbf{H C} = E \mathbf{S C}$ for its lowest energy eigenvalue ($E_\text{bonding}$).

A potential energy surface (PES) must be generated by calculating the total energy ($E_\text{total}(R) = E_\text{bonding}(R) + 1/R$) at exactly **50 discrete points** for the internuclear distance *R* from 0.5 to 4.0 Bohr.

**Intermediate Calculations:**
This PES must then be analyzed to find its two key properties:
1.  **$R_e$ (Equilibrium Bond Length):** The value of *R* (in Bohr) at the minimum of the PES.
2.  **$D_e$ (Electronic Dissociation Energy):** The energy difference $D_e = E_{atom} - E(R_e)$, where $E(R_e)$ is the minimum total energy on the PES, and $E_{atom}$ is the energy of the separated fragments (defined in the formulas).

**Final Calculation (Logical Branch):**
Using the two calculated intermediates ($R_e$, $D_e$), calculate the final $T_{score}$ based on the following logic:

1.  **Check Condition:** First, check if the molecule is bound ($D_e > 0$).
    * If $D_e \le 0$, the $T_{score}$ is **0.0**.
2.  **Calculate $T_{score}$ (if bound):**
    * If $D_e > 0$, the score is the product of the dissociation energy and the magnitude of the transition dipole moment ($M_z$) at the equilibrium distance $R_e$.
    * $$T_{score} = D_e \times |M_z(R_e)|$$
    * The transition dipole moment, $M_z(R_e)$, is calculated using the value of $R_e$ (in Bohr) and the overlap integral $S_{12}$ evaluated *at $R_e$*:
        * First, calculate $S_{12}(R_e) = \exp(-\alpha R_e^2 / 2)$
        * Then, calculate $M_z(R_e) = \frac{R_e}{2 \sqrt{1 - S_{12}(R_e)^2}}$

All values used in this final formula must be in their calculated atomic units ($R_e$ in Bohr, $D_e$ in Ha, $S_{12}$ is unitless).

**Required Data, Formulas, and Constants (Atomic Units):**
* **Method:** LCAO-MO
* **Gaussian Exponent:** $\alpha = 0.4166$
* **Separated Atom Energy ($E_{atom}$):**
    * $E_{atom} = \frac{3\alpha}{2} - 2\sqrt{\frac{2\alpha}{\pi}}$
* **Integrals (all R-dependent):**
    * $S_{11} = 1.0$
    * $S_{12} = \exp(-\alpha R^2 / 2)$
    * $T_{12} = S_{12} \cdot \frac{\alpha}{2} (3 - \alpha R^2)$
    * $V_{12} = -S_{12} \cdot \frac{2}{R} \cdot \text{erf}(\sqrt{2\alpha} \frac{R}{2})$
    * **$H_{11}(R) = E_{atom} - \frac{1}{R} \text{erf}(\sqrt{2\alpha} R)$**
    * $H_{12} = T_{12} + V_{12}$
    * (Note: By symmetry, $H_{22}(R) = H_{11}(R)$)

**Output Requirement:**
The final answer must be a single numerical value for $T_{score}$, formatted to **3 decimal places**. Do not include any other text or list formatting.

**Your final answer must be the output from the implemented algorithm.**

Answer: 13.431

Solution code:
import numpy as np
from scipy.special import erf
from scipy.linalg import eigh
import warnings

def solution():
    """
    Calculates the Transition Probability Score (T_score) for the H2+ ion.
    
    This version uses a physically correct, R-dependent H11 matrix element
    to ensure the molecule is bound, leading to a non-zero score.
    """

    # --- 1. Define Constants and Parameters (Atomic Units) ---

    # Gaussian exponent for the STO-1G basis set
    ALPHA = 0.4166

    # Calculate the constant Separated Atom Energy (E_atom)
    # This is the energy of H(1s) + H+ at R=infinity
    E_ATOM = (3 * ALPHA / 2) - (2 * np.sqrt(2 * ALPHA / np.pi))

    # --- 2. Part 1: Potential Energy Surface (PES) Scan ---

    # Scan R from 0.5 to 4.0 Bohr with 50 points
    R_values_bohr = np.linspace(0.5, 4.0, 50)
    E_total_hartree = []

    # Suppress runtime warnings (e.g., division by zero if R=0, though not in our range)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=RuntimeWarning)

        for R in R_values_bohr:
            # --- a. Calculate Matrix Elements for distance R ---

            # Overlap Integral (S12)
            S12 = np.exp(-ALPHA * R**2 / 2)

            # Kinetic Energy Integral (T12)
            T12 = S12 * (ALPHA / 2) * (3 - ALPHA * R**2)

            # Nuclear Attraction Integral (V12)
            V12 = -S12 * (2 / R) * erf(np.sqrt(2 * ALPHA) * R / 2)

            # Off-diagonal Hamiltonian Element (H12)
            H12 = T12 + V12
            
            # (NEW) R-dependent On-diagonal Hamiltonian Element (H11)
            # This includes the attraction of the electron on A to nucleus B
            H11 = E_ATOM - (1 / R) * erf(np.sqrt(2 * ALPHA) * R)
            H22 = H11 # By symmetry

            # --- b. Construct Hamiltonian (H) and Overlap (S) Matrices ---
            H = np.array([
                [H11, H12],
                [H12, H22]
            ])
            S = np.array([
                [1.0, S12],
                [S12, 1.0]
            ])

            # --- c. Solve the Generalized Eigenvalue Problem ---
            # H*C = E*S*C
            energies, _ = eigh(H, S)

            # The lowest energy is the bonding molecular orbital
            E_bonding = energies[0]

            # --- d. Calculate Nuclear Repulsion and Total Energy ---
            E_nuclear = 1.0 / R
            E_total = E_bonding + E_nuclear

            # Store the results
            E_total_hartree.append(E_total)

    E_total_hartree = np.array(E_total_hartree)

    # --- 3. Intermediate Calculations ---

    # Find the minimum energy and the corresponding R
    min_idx = np.argmin(E_total_hartree)
    E_min_hartree = E_total_hartree[min_idx]
    R_e_bohr = R_values_bohr[min_idx]

    # Calculate De (Electronic Dissociation Energy)
    # De = E(R->inf) - E(R_e)
    D_e = E_ATOM - E_min_hartree

    # --- 4. Final Calculation (Logical Branch) ---

    T_score = 0.0

    # Check if the molecule is bound (D_e > 0)
    # This should now be true
    if D_e > 0:
        # Calculate S12 at the equilibrium distance R_e
        S12_at_Re = np.exp(-ALPHA * R_e_bohr**2 / 2)
        
        # Calculate the transition dipole moment (M_z) at R_e
        denominator = 2 * np.sqrt(1 - S12_at_Re**2)
        
        if denominator > 1e-9: # Avoid division by zero
            M_z = R_e_bohr / denominator
            
            # Calculate the final T_score
            T_score = D_e * np.abs(M_z)
        # else T_score remains 0.0

    # --- 5. Output Requirement ---

    # Format to 3 decimal places
    final_answer = f"{T_score:.3f}"
    print(final_answer)

if __name__ == "__main__":
    solution()