#!/usr/bin/env python3"""
Basic example of specular reflectometry simulation with BornAgain.
The sample consists of 20 alternating Ti and Ni layers.
"""frombornagainimportba_plotasbp,std_samples,std_simulationsdefget_sample():returnstd_samples.alternating_layers()defget_simulation(sample):n=bp.simargs['n']returnstd_simulations.specular(sample,n)if__name__=='__main__':bp.parse_args(sim_n=500)sample=get_sample()simulation=get_simulation(sample)result=simulation.simulate()bp.plot_simulation_result(result)
defines the function get_simulation that)
imports the BornAgain submodule std_simulations,
and returns a standard setup to simulate a specular reflectivity scan.
The clause
if__name__=='__main__':
ensures that the following statements are only executed
if the script is called directly, as a “main” program.
This precaution is required by the GUI, where scripts can be imported without
being immediately executed.
In the main block, the statement
ba_plot.run_and_plot(simulation)
runs the previously defined simulation, and calls MatPlotLib to display the results.
The function run_and_plot is implemented in the module
ba_plot.