### A Pluto.jl notebook ###
# v1.0.0

using Markdown
using InteractiveUtils

# ╔═╡ b315da60-3607-4cd7-8ee6-131b972e9421
begin
    import Pkg
    Pkg.activate(joinpath(@__DIR__, ".."))
    using CoupledDipole
    using CairoMakie
end

# ╔═╡ f23e5f94-bf01-42d9-a9c4-489f7bd963d7
md"""
# Chiral gold-nanorod dimer

Two crossed nanorods couple to produce circular dichroism. Compare their
orientation-averaged response with an isolated rod. All lengths are in nm;
cross-sections are in nm^2 **per particle**. The host value below is its
refractive index, whereas `epsilon_Au` returns the gold dielectric function.

Edit the separation or twist and rerun the notebook. The modest wavelength
grid keeps this example quick; refine it and the angular cubature for research.
"""

# ╔═╡ 3d586ca9-a58d-46e0-a1c8-c3fca26384bd
begin
    wavelengths = collect(450.0:1.0:850.0)
    material = Material(wavelengths, Dict("Au" => epsilon_Au, "medium" => λ -> 1.33))
    separation = 80.0
    twist = π / 4
    single = cluster_single(20, 20, 40)
    dimer = cluster_dimer(separation, 20, 20, 40, twist)
end

# ╔═╡ 31390f03-d514-4c65-b846-83013a3bce85
begin
    isolated = spectrum_oa(single, material)
    coupled = spectrum_oa(dimer, material)
    @assert all(isfinite, coupled.average.extinction)
    @assert length(coupled.average.extinction) == length(wavelengths)
end

# ╔═╡ 85847244-0db4-4ef5-b4e1-86ebd0cd17ea
let
    fig = Figure(size=(800, 350))
    average = Axis(fig[1, 1], xlabel="Wavelength / nm", ylabel="Extinction / nm^2")
    dichroism = Axis(fig[1, 2], xlabel="Wavelength / nm", ylabel="Circular dichroism / nm^2")
    lines!(average, wavelengths, isolated.average.extinction; label="single")
    lines!(average, wavelengths, coupled.average.extinction; label="dimer")
    lines!(dichroism, wavelengths, coupled.dichroism.extinction)
    axislegend(average)
    fig
end

# ╔═╡ Cell order:
# ╠═b315da60-3607-4cd7-8ee6-131b972e9421
# ╟─f23e5f94-bf01-42d9-a9c4-489f7bd963d7
# ╠═3d586ca9-a58d-46e0-a1c8-c3fca26384bd
# ╠═31390f03-d514-4c65-b846-83013a3bce85
# ╠═85847244-0db4-4ef5-b4e1-86ebd0cd17ea
