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

using Markdown
using InteractiveUtils

# ╔═╡ 5b938195-d4d0-461c-9989-dd7fe4dc953b
begin
    import Pkg
    Pkg.activate(joinpath(@__DIR__, ".."))
    using CoupledDipole
    using CairoMakie
    using Rotations
end

# ╔═╡ a58eefc8-d4de-470a-804c-02eb1863d96f
md"""
# Coupled uniaxial dye molecules

For point dipoles the material function returns a polarisability, not a
dielectric function. The sizes `(0, 0, 1)` select a uniaxial molecular response;
they do not describe an ellipsoidal particle. Compare an isolated molecule
with a side-by-side pair separated by 0.8 nm in water.

The wave propagates along x, so one of its transverse polarisations excites
the molecular z axis. Molecular scattering is tiny compared with absorption.
Cross-sections are reported per molecule in nm^2.
"""

# ╔═╡ 4d480b29-89df-4fb1-ad37-b8fd4cd3c94a
begin
    wavelengths = collect(400.0:5.0:700.0)
    material = Material(wavelengths,
        Dict("Rhodamine" => alpha_lorentzmolecule, "medium" => λ -> 1.33))
    single = cluster_single(0, 0, 1, 0, 0, 0, "Rhodamine", PointDipole())
    pair = cluster_dimer(0.8, 0, 0, 1, 0, 0, 0, "Rhodamine", PointDipole())
    incidence = [RotY(π / 2)]
end

# ╔═╡ 85738696-3b1c-477d-856a-797dc2344548
begin
    isolated = spectrum_dispersion(single, material, incidence)
    coupled = spectrum_dispersion(pair, material, incidence)
    @assert size(coupled.extinction) == (length(wavelengths), 2)
    @assert all(isfinite, coupled.extinction)
end

# ╔═╡ bf2568dd-98b4-4ffd-95fa-33af29e2e164
let
    fig = Figure(size=(650, 350))
    ax = Axis(fig[1, 1], xlabel="Wavelength / nm", ylabel="Extinction / nm^2")
    lines!(ax, wavelengths, isolated.extinction[:, 1]; label="single")
    lines!(ax, wavelengths, coupled.extinction[:, 1]; label="pair")
    axislegend(ax)
    fig
end

# ╔═╡ Cell order:
# ╠═5b938195-d4d0-461c-9989-dd7fe4dc953b
# ╟─a58eefc8-d4de-470a-804c-02eb1863d96f
# ╠═4d480b29-89df-4fb1-ad37-b8fd4cd3c94a
# ╠═85738696-3b1c-477d-856a-797dc2344548
# ╠═bf2568dd-98b4-4ffd-95fa-33af29e2e164
