#!/usr/bin/env python3
"""
Plot an SLD profile for a sample with a sliced particle layer.
"""

import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, nm, sample_tools
import numpy as np


def get_sample():
    # materials
    vacuum = ba.Vacuum()
    particle_color = (0.86, 0.24, 0.18)
    particle_mat = ba.SLDMaterial("Particle", particle_color, 5e-6, 0)
    substrate_color = (0.28, 0.57, 0.82)
    substrate_mat = ba.SLDMaterial("SiSubstrate", substrate_color, 2.0704e-06, 0)

    # layers
    ambient_layer = ba.Layer(vacuum)
    substrate_layer = ba.Layer(substrate_mat)

    # particle layout
    ff = ba.Cone(5*nm, 10*nm, 75*deg)
    particle = ba.Particle(particle_mat, ff)

    layout = ba.Crystal2D(particle, ba.SquareLattice2D(10*nm, 0))
    ambient_layer.deposit2D(layout)
    ambient_layer.setNumberOfSlices(20)

    # sample
    sample = ba.Sample()
    sample.addLayer(ambient_layer)
    sample.addLayer(substrate_layer)

    return sample


if __name__ == '__main__':
    sample = get_sample()
    zpoints, slds = sample_tools.materialProfile(sample, 400)

    bp.plt.figure()
    bp.plt.plot(zpoints, np.real(slds))
