In [1]:
import sys
# Path to McStasScript pythoon file
sys.path.append('/home/docker/McStasScript')
from mcstasscript.interface import instr, plotter, functions
# Creating the instance of the class, insert path to mcrun and to mcstas root directory
Instr = instr.McStas_instr("jupyter_demo")
In [2]:
Instr.show_components() # Shows available McStas component categories in current installation
In [3]:
Instr.show_components("sources") # Display all McStas source components
In [4]:
Instr.component_help("Source_simple") # Displays help on the Source_simple component
In [5]:
source = Instr.add_component("Source","Source_simple") # Adds an instance of Source_simple
In [6]:
# Lets add a parameter to the instrument to control the wavelength of the source
Instr.add_parameter("double", "wavelength", value=3,
comment="[AA] Wavelength emmited from source")
source.xwidth = 0.06; source.yheight = 0.08;
source.dist = 2; source.focus_xw = 0.05; source.focus_yh = 0.05
source.lambda0 = "wavelength"; source.dlambda = 0.05; source.flux = 1E8
In [7]:
source.print_long() # Verify that the information is correct
In [8]:
guide = Instr.add_component("Guide", "Guide_gravity", AT=[0,0,2], RELATIVE="Source")
guide.set_comment="Beam extraction and first guide piece"
In [9]:
guide.show_parameters() # Lets view the parameters available in our guide component
In [10]:
guide.set_parameters({"w1" : 0.05, "w2" : 0.05, "h1" : 0.05, "h2" : 0.05,
"l" : 8, "m" : 3.5, "G" : -9.2})
In [11]:
guide.print_long() # Verify the information on this component is correct
In [12]:
# Add a sample to the instrument
sample = Instr.add_component("sample", "PowderN", AT=[0, 0, 9], RELATIVE="Guide")
In [13]:
# Set parameters corresponding to a copper cylinder
sample.radius = 0.015; sample.yheight = 0.05; sample.reflections = "\"Cu.laz\""
In [14]:
Instr.show_components("monitors") # Monitors are needed to record information
In [15]:
# Add 4PI detector to detect all neutrons
sphere = Instr.add_component("PSD_4PI", "PSD_monitor_4PI", RELATIVE="sample")
In [16]:
sphere.nx = 300; sphere.ny = 300
sphere.radius = 1; sphere.restore_neutron = 1
sphere.filename = "\"PSD_4PI.dat\"" # filenames need printed quotes, use \"
sphere.print_long() # Verify that monitors have filenames that are strings when printed
In [17]:
# Add PSD monitor to see the direct beam after the sample
PSD = Instr.add_component("PSD", "PSD_monitor", AT=[0,0,1], RELATIVE="sample")
PSD.xwidth = 0.1; PSD.yheight = 0.1; PSD.nx = 200; PSD.ny = 200
PSD.filename = "\"PSD.dat\""; PSD.restore_neutron = 1
In [18]:
L_mon = Instr.add_component("L_mon", "L_monitor", RELATIVE="PSD")
In [19]:
# Since the wavelength is an instrument parameter, it can be used when setting parameters
L_mon.Lmin = "wavelength - 0.1"; L_mon.Lmax = "wavelength + 0.1"; L_mon.nL = 150
L_mon.xwidth = 0.1; L_mon.yheight = 0.1
L_mon.filename = "\"wave.dat\""; L_mon.restore_neutron = 1
L_mon.comment = "Wavelength monitor for narrow range"
In [20]:
L_mon.print_long()
In [21]:
Instr.print_components() # Lets get an overview of the instrument so far
In [22]:
Instr.show_parameters()
In [23]:
# With increment_folder_name enabled, a new folder with incremented number is created
data = Instr.run_full_instrument(foldername="jupyter_demo",
parameters={"wavelength" : 1.5},
mpi=2, ncount=2E7,
increment_folder_name = True)
In [24]:
wavelength_data = functions.name_search("L_mon", data)
wavelength_intensity = wavelength_data.Intensity
wavelength_xaxis = wavelength_data.xaxis
for index in range(70,75):
print([wavelength_xaxis[index], wavelength_intensity[index]])
In [25]:
# Adjusting PSD_4PI plot
functions.name_plot_options("PSD_4PI", data, log=1, colormap="hot", orders_of_mag=5)
plot = plotter.make_sub_plot(data) # Making subplot of our monitors