{"spec_id":"line-tanabe-sugano","library":"makie","language":"julia","code":"# anyplot.ai\n# line-tanabe-sugano: Tanabe-Sugano Diagram for Crystal Field Theory\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 89/100 | Created: 2026-10-01\n\nusing CairoMakie\nusing Colors\nusing LinearAlgebra\n\n# Theme tokens — see prompts/default-style-guide.md \"Theme-adaptive Chrome\"\nconst THEME    = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG  = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst INK      = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\n\n# Imprint palette — positions 1-8 in canonical order, one per term curve\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\", colorant\"#C475FD\", colorant\"#4467A3\", colorant\"#BD8233\",\n    colorant\"#AE3030\", colorant\"#2ABCCD\", colorant\"#954477\", colorant\"#99B314\",\n]\n\n# Data — d⁸ (Ni²⁺) octahedral terms, all energies in units of the Racah B\nc_over_b = 4.71\ndelta_over_b = range(0, 40, length = 320)\ndq = delta_over_b ./ 10\n\n# Free-ion term energies relative to ³F, from the Racah parameters B and C\ne_3p = 15.0\ne_1d = 5.0 + 2 * c_over_b\ne_1g = 12.0 + 2 * c_over_b\ne_1s = 22.0 + 7 * c_over_b\n\n# Each symmetry block is a Tanabe-Sugano matrix: free-ion energies on the\n# diagonal plus Dq times the ligand-field coupling, diagonalized per Δ_o/B\nmix_eg = 40 * sqrt(3) / 7\nmix_t2g = 20 * sqrt(3) / 7\nmix_a1g = 4 * sqrt(6)\n\nfree_t1g = [0.0 0.0; 0.0 e_3p]\nfield_t1g = [6.0 4.0; 4.0 0.0]\nfree_singlet = [e_1d 0.0; 0.0 e_1g]\nfield_eg = [-24/7 mix_eg; mix_eg -4/7]\nfield_t2g = [16/7 mix_t2g; mix_t2g 26/7]\nfree_a1g = [e_1g 0.0; 0.0 e_1s]\nfield_a1g = [-4.0 mix_a1g; mix_a1g 0.0]\n\n# The ³A₂g ground term lies at -12Dq, so +12q puts every curve on the E/B scale\nt1g = [eigvals(Symmetric(free_t1g .+ q .* field_t1g)) .+ 12q for q in dq]\neg = [eigvals(Symmetric(free_singlet .+ q .* field_eg)) .+ 12q for q in dq]\nt2g = [eigvals(Symmetric(free_singlet .+ q .* field_t2g)) .+ 12q for q in dq]\na1g = [eigvals(Symmetric(free_a1g .+ q .* field_a1g)) .+ 12q for q in dq]\n\n# Term symbol, curve, palette position, and whether the spin is ground-term spin\nterms = [\n    (rich(superscript(\"3\"), \"A\", subscript(\"2g\")), zeros(length(dq)), 1, true),\n    (rich(superscript(\"3\"), \"T\", subscript(\"2g\")), collect(delta_over_b), 2, true),\n    (rich(superscript(\"3\"), \"T\", subscript(\"1g\"), \"(F)\"), first.(t1g), 3, true),\n    (rich(superscript(\"3\"), \"T\", subscript(\"1g\"), \"(P)\"), last.(t1g), 4, true),\n    (rich(superscript(\"1\"), \"E\", subscript(\"g\")), first.(eg), 5, false),\n    (rich(superscript(\"1\"), \"T\", subscript(\"2g\")), first.(t2g), 6, false),\n    (rich(superscript(\"1\"), \"A\", subscript(\"1g\")), first.(a1g), 7, false),\n    (rich(superscript(\"1\"), \"T\", subscript(\"1g\")), e_1g .+ 10 .* dq, 8, false),\n]\n\n# Plot\nfig = Figure(size = (1200, 1200), fontsize = 20, backgroundcolor = PAGE_BG)\n\nax = Axis(\n    fig[1, 1];\n    title = \"line-tanabe-sugano · julia · makie · anyplot.ai\",\n    titlesize = 26,\n    titlecolor = INK,\n    subtitle = \"d⁸ (Ni²⁺), octahedral field, C/B = 4.71 · solid = spin-allowed, dashed = spin-forbidden\",\n    subtitlesize = 20,\n    subtitlecolor = INK_SOFT,\n    subtitlegap = 10,\n    xlabel = rich(\"Δ\", subscript(\"o\"), \"/B — reduced ligand-field strength\"),\n    ylabel = \"E/B — reduced term energy\",\n    xlabelsize = 20,\n    ylabelsize = 20,\n    xlabelcolor = INK,\n    ylabelcolor = INK,\n    xticklabelsize = 20,\n    yticklabelsize = 20,\n    xticklabelcolor = INK_SOFT,\n    yticklabelcolor = INK_SOFT,\n    xtickcolor = INK_SOFT,\n    ytickcolor = INK_SOFT,\n    xticks = 0:10:40,\n    yticks = 0:20:80,\n    backgroundcolor = PAGE_BG,\n    topspinevisible = false,\n    rightspinevisible = false,\n    leftspinecolor = INK_SOFT,\n    bottomspinecolor = INK_SOFT,\n    xgridcolor = RGBAf(INK.r, INK.g, INK.b, 0.15),\n    ygridcolor = RGBAf(INK.r, INK.g, INK.b, 0.15),\n    xminorgridvisible = false,\n    yminorgridvisible = false,\n    limits = (0, 47, -2.2, 90),\n)\n\nfor (symbol, energy, position, spin_allowed) in terms\n    lines!(\n        ax, delta_over_b, energy;\n        color = IMPRINT_PALETTE[position],\n        linewidth = spin_allowed ? 6 : 3,\n        linestyle = spin_allowed ? :solid : :dash,\n    )\n    text!(\n        ax, 41.0, energy[end];\n        text = symbol,\n        color = IMPRINT_PALETTE[position],\n        fontsize = 22,\n        align = (:left, :center),\n    )\nend\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}