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

using Markdown
using InteractiveUtils

# ╔═╡ 04e43804-4264-4364-bc36-92fbba5366be
begin
    import Pkg
    Pkg.activate(joinpath(@__DIR__, ".."))
    using CoupledDipole
    using CairoMakie
end

# ╔═╡ b4056d58-3c11-4dab-aa68-d7022cb4279d
md"""
# Mirror-image helices

Opposite handedness should reverse circular dichroism while preserving the
orientation-averaged extinction. This is also a useful numerical symmetry check.
Lengths are in nm and cross-sections are in nm^2 per particle.
Finite angular cubature introduces a small error; increase `N_inc` and `N_sca`
to assess convergence rather than assuming the plotted curves are exact.
"""

# ╔═╡ 2893c465-d8bc-41f0-a2de-dbeef2e3de27
begin
    wavelengths = collect(450.0:10.0:850.0)
    material = Material(wavelengths, Dict("Au" => epsilon_Au, "medium" => λ -> 1.33))
    left = cluster_helix(8, 20, 20, 40, 100, 400, π / 2, 0, "left")
    right = cluster_helix(8, 20, 20, 40, 100, 400, π / 2, 0, "right")
end

# ╔═╡ b67d3d5b-00cf-4474-aa68-e8341a9b0513
begin
    left_spectrum = spectrum_oa(left, material; N_inc=72, N_sca=72)
    right_spectrum = spectrum_oa(right, material; N_inc=72, N_sca=72)
    @assert all(isfinite, left_spectrum.dichroism.extinction)
    @assert all(isfinite, right_spectrum.dichroism.extinction)
    @assert isapprox(left_spectrum.average.extinction, right_spectrum.average.extinction;
        rtol=1e-8)
    @assert isapprox(left_spectrum.dichroism.extinction, -right_spectrum.dichroism.extinction;
        rtol=1e-8)
end

# ╔═╡ 40bd48f9-119a-4b56-8d35-a732f778907a
let
    fig = Figure(size=(800, 350))
    average = Axis(fig[1, 1], xlabel="Wavelength / nm", ylabel="Extinction / nm^2")
    cd = Axis(fig[1, 2], xlabel="Wavelength / nm", ylabel="Circular dichroism / nm^2")
    for (spectrum, label) in ((left_spectrum, "left"), (right_spectrum, "right"))
        lines!(average, wavelengths, spectrum.average.extinction; label)
        lines!(cd, wavelengths, spectrum.dichroism.extinction; label)
    end
    axislegend(cd)
    fig
end

# ╔═╡ Cell order:
# ╠═04e43804-4264-4364-bc36-92fbba5366be
# ╟─b4056d58-3c11-4dab-aa68-d7022cb4279d
# ╠═2893c465-d8bc-41f0-a2de-dbeef2e3de27
# ╠═b67d3d5b-00cf-4474-aa68-e8341a9b0513
# ╠═40bd48f9-119a-4b56-8d35-a732f778907a
