{"spec_id":"line-tanabe-sugano","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nline-tanabe-sugano: Tanabe-Sugano Diagram for Crystal Field Theory\nLibrary: plotly 7.1.0 | Python 3.13.15\nQuality: 89/100 | Created: 2026-10-01\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport plotly.graph_objects as go\n\n\n# Theme tokens (see prompts/default-style-guide.md \"Theme-adaptive Chrome\")\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nGRID = \"rgba(26,26,23,0.15)\" if THEME == \"light\" else \"rgba(240,239,232,0.15)\"\nSPIN_ALLOWED = \"#009E73\"  # Imprint palette position 1 — spin-allowed (triplet) terms\nSPIN_FORBIDDEN = \"#C475FD\"  # Imprint palette position 2 — spin-forbidden (singlet) terms\n\n# Data — d² (V³⁺) in an octahedral field at C/B = 4.5.\n# Diagonal elements of the Tanabe-Sugano matrices are in units of B relative to the\n# free-ion ³F term, with Dq = Δ_o/10; off-diagonal elements do not depend on Dq.\n# The ground term is subtracted at the end, so E/B = 0 runs along the x axis.\nc_over_b = 4.5\ndelta_over_b = np.linspace(0, 40, 320)\ndq = delta_over_b / 10\n\noff_3t1 = np.full_like(dq, 6.0)\noff_1d = np.full_like(dq, 2 * np.sqrt(3))\noff_1a1 = np.full_like(dq, np.sqrt(6) * (2 + c_over_b))\n\ne_3t1 = np.linalg.eigvalsh(np.array([[-8 * dq + 3, off_3t1], [off_3t1, 2 * dq + 12]]).T)\ne_1t2 = np.linalg.eigvalsh(np.array([[-8 * dq + 9 + 2 * c_over_b, off_1d], [off_1d, 2 * dq + 8 + 2 * c_over_b]]).T)\ne_1eg = np.linalg.eigvalsh(np.array([[-8 * dq + 9 + 2 * c_over_b, off_1d], [off_1d, 12 * dq + 8 + 2 * c_over_b]]).T)\ne_1a1 = np.linalg.eigvalsh(np.array([[-8 * dq + 18 + 5 * c_over_b, off_1a1], [off_1a1, 12 * dq + 16 + 4 * c_over_b]]).T)\nground = e_3t1[:, 0]\n\n# (term label, energy, spin-allowed, label nudge for near-degenerate pairs)\nterms = [\n    (\"<sup>3</sup>T<sub>1g</sub>(F)\", e_3t1[:, 0], True, 0.0),\n    (\"<sup>3</sup>T<sub>2g</sub>\", 2 * dq, True, 0.5),\n    (\"<sup>3</sup>T<sub>1g</sub>(P)\", e_3t1[:, 1], True, 0.0),\n    (\"<sup>3</sup>A<sub>2g</sub>\", 12 * dq, True, 0.0),\n    (\"<sup>1</sup>T<sub>2g</sub>(D)\", e_1t2[:, 0], False, -2.1),\n    (\"<sup>1</sup>E<sub>g</sub>(D)\", e_1eg[:, 0], False, 2.1),\n    (\"<sup>1</sup>A<sub>1g</sub>(G)\", e_1a1[:, 0], False, -0.5),\n    (\"<sup>1</sup>T<sub>2g</sub>(G)\", e_1t2[:, 1], False, 0.0),\n    (\"<sup>1</sup>T<sub>1g</sub>(G)\", 2 * dq + 12 + 2 * c_over_b, False, 0.0),\n]\n\n# Plot — one curve per term, labelled in the right margin\nfig = go.Figure()\nfor label, energy, spin_allowed, label_nudge in terms:\n    energy_over_b = energy - ground\n    fig.add_trace(\n        go.Scatter(\n            x=delta_over_b,\n            y=energy_over_b,\n            mode=\"lines\",\n            name=label,\n            line=dict(\n                color=SPIN_ALLOWED if spin_allowed else SPIN_FORBIDDEN,\n                width=3.0 if spin_allowed else 1.8,\n                dash=\"solid\" if spin_allowed else \"dash\",\n            ),\n        )\n    )\n    fig.add_annotation(\n        x=1.015,\n        xref=\"paper\",\n        xanchor=\"left\",\n        y=energy_over_b[-1] + label_nudge,\n        yref=\"y\",\n        text=label,\n        showarrow=False,\n        font=dict(size=13, color=INK if spin_allowed else INK_SOFT),\n    )\n\n# Style\nfig.add_annotation(\n    x=1.0,\n    y=78,\n    xanchor=\"left\",\n    yanchor=\"top\",\n    align=\"left\",\n    text=(\n        \"d<sup>2</sup> (V<sup>3+</sup>) in an octahedral field, C/B = 4.5<br>\"\n        \"solid: spin-allowed (triplet) · dashed: spin-forbidden (singlet)\"\n    ),\n    showarrow=False,\n    font=dict(size=13, color=INK_SOFT),\n)\nfig.update_layout(\n    autosize=False,\n    margin=dict(l=70, r=104, t=72, b=62),\n    showlegend=False,\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font=dict(color=INK),\n    title=dict(\n        text=\"line-tanabe-sugano · python · plotly · anyplot.ai\", font=dict(size=16, color=INK), x=0.5, xanchor=\"center\"\n    ),\n    xaxis=dict(\n        title=dict(text=\"Δ<sub>o</sub>/B  (reduced ligand-field strength)\", font=dict(size=12, color=INK)),\n        tickfont=dict(size=10, color=INK_SOFT),\n        range=[0, 40],\n        tick0=0,\n        dtick=10,\n        ticks=\"\",\n        gridcolor=GRID,\n        linecolor=INK_SOFT,\n        zeroline=False,\n    ),\n    yaxis=dict(\n        title=dict(text=\"E/B  (reduced term energy)\", font=dict(size=12, color=INK)),\n        tickfont=dict(size=10, color=INK_SOFT),\n        range=[-2, 80],\n        tick0=0,\n        dtick=10,\n        ticks=\"\",\n        gridcolor=GRID,\n        linecolor=INK_SOFT,\n        zeroline=False,\n    ),\n)\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=600, height=600, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}