#!/usr/bin/env python3
"""
Specular reflectometry of a Ti/Ni multilayer defined via scattering
length densities, including absorption.

10 bilayers of Ti (3.5 nm) and Ni (7 nm) on a Si substrate.
SLD values include the imaginary component (absorption) for all layers.
Compare AlternatingLayers1.py which uses lossless SLD materials.
"""
import bornagain as ba
from bornagain import ba_plot as bp, deg, nm, angstrom


def get_sample():
    vacuum = ba.Vacuum()
    si_color = (0.28, 0.57, 0.82)
    si_mat = ba.SLDMaterial("Si_substrate", si_color, 2.0704e-6, 2.3726e-11)
    ni_color = (0.93, 0.48, 0.14)
    ni_mat = ba.SLDMaterial("Ni", ni_color, 9.4245e-6, 1.1423e-9)
    ti_color = (0.05, 0.62, 0.55)
    ti_mat = ba.SLDMaterial("Ti", ti_color, -1.9493e-6, 9.6013e-10)

    vacuum_layer = ba.Layer(vacuum)
    ti_layer = ba.Layer(ti_mat, 3.5*nm)
    ni_layer = ba.Layer(ni_mat, 7*nm)
    substrate = ba.Layer(si_mat)

    n_repetitions = 10
    stack = ba.LayerStack(n_repetitions)
    stack.addLayer(ti_layer)
    stack.addLayer(ni_layer)

    sample = ba.Sample()
    sample.addLayer(vacuum_layer)
    sample.addStack(stack)
    sample.addLayer(substrate)
    return sample


def get_simulation(sample):
    n = 500
    scan = ba.AlphaScan(n, 2*deg/n, 2*deg)
    scan.setWavelength(1.54*angstrom)
    return ba.SpecularSimulation(scan, sample)


if __name__ == '__main__':
    sample = get_sample()
    simulation = get_simulation(sample)
    result = simulation.simulate()
    plotargs = bp.parse_commandline()
    bp.plot_datafield(result, **plotargs)
    bp.export(**plotargs)
