{"spec_id":"line-reaction-coordinate","library":"makie","language":"julia","code":"# anyplot.ai\n# line-reaction-coordinate: Reaction Coordinate Energy Diagram\n# Library: makie 0.22.10 | Julia 1.11.9\n# Quality: 90/100 | Created: 2026-06-24\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\nconst THEME       = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG     = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst ELEVATED_BG = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\nconst INK         = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT    = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nconst INK_MUTED   = THEME == \"light\" ? colorant\"#6B6A63\" : colorant\"#A8A79F\"\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\", colorant\"#C475FD\", colorant\"#4467A3\", colorant\"#BD8233\",\n    colorant\"#AE3030\", colorant\"#2ABCCD\", colorant\"#954477\", colorant\"#99B314\",\n]\nconst BRAND = IMPRINT_PALETTE[1]\n\n# Data — single-step exothermic reaction\nE_r  = 50.0   # reactant energy level (kJ/mol)\nE_ts = 120.0  # transition state energy (kJ/mol)\nE_p  = 20.0   # product energy level (kJ/mol)\n\nx_peak = 0.38  # transition state position on [0, 1]\nsigma  = 0.14  # Gaussian half-width controls barrier sharpness\n\nn_pts = 300\nx_vals = collect(LinRange(0.0, 1.0, n_pts))\nlinear_baseline = E_r .+ (E_p - E_r) .* x_vals\nbarrier_height = E_ts - (E_r + (E_p - E_r) * x_peak)\nenergy = linear_baseline .+ barrier_height .* exp.(-(x_vals .- x_peak).^2 ./ (2 * sigma^2))\n\nE_a     = Int(E_ts - E_r)  # activation energy = 70 kJ/mol\ndelta_H = Int(E_p - E_r)   # enthalpy change = -30 kJ/mol\n\n# Figure\ntitle_str = \"line-reaction-coordinate · julia · makie · anyplot.ai\"\n\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = title_str,\n    titlesize          = 20,\n    titlecolor         = INK,\n    xlabel             = \"Reaction Coordinate\",\n    ylabel             = \"Potential Energy (kJ/mol)\",\n    xlabelsize         = 14,\n    ylabelsize         = 14,\n    xticklabelsize     = 12,\n    yticklabelsize     = 12,\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xticklabelcolor    = INK_SOFT,\n    yticklabelcolor    = INK_SOFT,\n    xtickcolor         = INK_SOFT,\n    ytickcolor         = INK_SOFT,\n    backgroundcolor    = PAGE_BG,\n    topspinevisible    = false,\n    rightspinevisible  = false,\n    leftspinecolor     = INK_SOFT,\n    bottomspinecolor   = INK_SOFT,\n    xgridvisible       = false,\n    ygridvisible       = true,\n    ygridcolor         = RGBAf(INK.r, INK.g, INK.b, 0.12),\n    xticklabelsvisible = false,\n    xticksvisible      = false,\n)\n\n# Reaction energy curve\nlines!(ax, x_vals, energy; color = BRAND, linewidth = 3.5)\n\n# Horizontal dashed reference lines at reactant and product energy levels\nhlines!(ax, E_r; color = INK_MUTED, linewidth = 1.2, linestyle = :dash)\nhlines!(ax, E_p; color = INK_MUTED, linewidth = 1.2, linestyle = :dash)\n\n# Axis limits — extra right margin for annotation labels\nxlims!(ax, -0.05, 1.20)\nylims!(ax, E_p - 15.0, E_ts + 30.0)\n\n# Labels: reactants, transition state, products\ntext!(ax, 0.04, E_r + 6.0;\n      text  = \"Reactants\\n50 kJ/mol\",\n      color = INK, fontsize = 13, align = (:left, :bottom))\ntext!(ax, x_peak, E_ts + 8.0;\n      text  = \"Transition State ‡\\n120 kJ/mol\",\n      color = INK, fontsize = 13, align = (:center, :bottom))\ntext!(ax, 0.94, E_p + 6.0;\n      text  = \"Products\\n20 kJ/mol\",\n      color = INK, fontsize = 13, align = (:right, :bottom))\n\n# Activation energy (Eₐ) double-headed arrow: from reactant level to transition state\nx_ea = 0.62\narrows!(ax, [x_ea], [E_r], [0.0], [E_ts - E_r]; color = INK, linewidth = 1.5)\narrows!(ax, [x_ea], [E_ts], [0.0], [-(E_ts - E_r)]; color = INK, linewidth = 1.5)\ntext!(ax, x_ea + 0.03, (E_r + E_ts) / 2.0;\n      text  = \"Eₐ = $(E_a) kJ/mol\",\n      color = INK, fontsize = 12, align = (:left, :center))\n\n# Enthalpy change (ΔH) double-headed arrow: between reactant and product levels\nx_dh = 0.85\narrows!(ax, [x_dh], [E_p], [0.0], [E_r - E_p]; color = INK, linewidth = 1.5)\narrows!(ax, [x_dh], [E_r], [0.0], [-(E_r - E_p)]; color = INK, linewidth = 1.5)\ntext!(ax, x_dh + 0.03, (E_r + E_p) / 2.0;\n      text  = \"ΔH = $(delta_H) kJ/mol\",\n      color = INK, fontsize = 12, align = (:left, :center))\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}