mcstasscript.interface.instr.McXtrace_instr
mcstasscript.interface.instr.McXtrace_instr¶
- class mcstasscript.interface.instr.McXtrace_instr(name, **kwargs)¶
Main class for writing a McXtrace instrument using McStasScript
Initialization of McXtrace_instr sets the name of the instrument file and its methods are used to add all aspects of the instrument file. The class also holds methods for writing the finished instrument file to disk and to run the simulation.
- name¶
name of instrument file
- Type
str
- author¶
name of user of McStasScript, written to the file
- Type
str, default “Python Instrument Generator”
- origin¶
origin of instrument file (affiliation)
- Type
str, default “ESS DMSC”
- input_path¶
directory in which simulation is executed, uses components found there
- Type
str, default “.”
- output_path¶
directory in which the data is written
- Type
str
- executable_path¶
absolute path of mcrun command, or empty if it is in path
- Type
str
- parameters¶
contains all input parameters to be written to file
- Type
ParameterContainer
- declare_list¶
contains all declare parrameters to be written to file
- Type
list of DeclareVariable instances
- initialize_section¶
string containing entire initialize section to be written
- Type
str
- trace_section¶
string containing trace section (OBSOLETE)
- Type
str
- finally_section¶
string containing entire finally section to be written
- Type
str
- component_list¶
list of components in the instrument
- Type
list of component instances
- component_class_lib¶
dict of custom Component classes made at run time
- Type
dict
- component_reader¶
ComponentReader instance for reading component files
- Type
- package_path¶
Path to mccode package containing component folders
- Type
str
- run_settings¶
Dict of options set with settings
- Type
dict
- data¶
List of McStasData objects produced by last run
- Type
list
- add_parameter(*args, \*\*kwargs)¶
Adds input parameter to the define section
- add_declare_var(type, name)¶
Add declared variable called name of given type to the declare section
- append_declare(string)¶
Appends to the declare section
- append_initialize(string)¶
Appends a string to the initialize section, then adds new line
- append_initialize_no_new_line(string)¶
Appends a string to the initialize section
- append_finally(string)¶
Appends a string to finally section, then adds new line
- append_finally_no_new_line(string)¶
Appends a string to finally section
- append_trace(string)¶
Obsolete method, add components instead (used in write_c_files)
- append_trace_no_new_line(string)¶
Obsolete method, add components instead (used in write_c_files)
- available_components(string)¶
Shows available components in given category
- component_help(name)¶
Shows help on component of given name
- add_component(instance_name, component_name, \*\*kwargs)¶
Add a component to the instrument file
- copy_component(new_component_name, original_component, \*\*kwargs)¶
Makes a copy of original_component with new_component_name
- get_component(instance_name)¶
Returns component instance with name instance_name
- get_last_component()¶
Returns component instance of last component
- print_component(instance_name)¶
Prints an overview of current state of named component
- print_component_short(instance_name)¶
Prints short overview of current state of named component
- show_components()¶
Prints overview of postion / rotation of all components
- write_c_files()¶
Writes c files for %include in generated_includes folder
- write_full_instrument()¶
Writes full instrument file to current directory
- show_instrument()¶
Shows instrument using mcdisplay
- set_parameters(dict)¶
Inherited from libpyvinyl BaseCalculator
- settings(**kwargs)¶
Sets settings for performing simulation
- backengine()¶
Performs simulation, saves in data attribute
- run_full_instrument(**kwargs)¶
Deprecated method for performing the simulation
- interface()¶
Shows interface with jupyter notebook widgets
- get_interface_data()¶
Returns data set from latest simulation in widget
- __init__(name, **kwargs)¶
Initialization of McXtrace Instrument
- Parameters
name (str) – Name of project, instrument file will be name + “.instr”
arguments (keyword) –
- parametersParameterContainer or CalculatorParameters
Parameters for this instrument
- dumpfile: str
File path to dump file to be loaded
- authorstr
Name of author, written in instrument file
- originstr
Affiliation of author, written in instrument file
- executable_pathstr
Absolute path of mcrun or empty if already in path
- input_pathstr
Work directory, will load components from this folder
Methods
__init__
(name, **kwargs)Initialization of McXtrace Instrument
add_component
(name[, component_name, ...])Method for adding a new Component instance to the instrument
add_declare_var
(*args, **kwargs)Method for adding declared variable to instrument
add_parameter
(*args, **kwargs)Method for adding input parameter to instrument
add_search
(statement[, SHELL])Adds a search statement to the instrument
add_user_var
(*args, **kwargs)Method for adding user variable to instrument
append_declare
(string)Method for appending code to the declare section directly
append_finally
(string)Method for appending code to the finally section of instrument
append_finally_no_new_line
(string)Method for appending code to the finally section of instrument
append_initialize
(string)Method for appending code to the initialize section
append_initialize_no_new_line
(string)Method for appending code to the initialize section, no new line
append_trace
(string)Appends code to trace section, only used in write_c_files
append_trace_no_new_line
(string)Appends code to trace section, only used in write_c_files
available_components
(*args)Helper method that shows available components to the user
Runs instrument with McStas / McXtrace, saves data in data attribute
check_for_errors
()Methods that checks for common McStas errors
check_for_relative_errors
([start_ref, ...])Method for checking if RELATIVE locations does not contain unknown references
clear_search
()Clears the instrument of all search statements
component_help
(name, **kwargs)Method for showing parameters for a component before adding it to the instrument
copy_component
(name[, original_component, ...])Method for adding a copy of a Component instance to the instrument
dump
([fname])Dump class instance to file.
from_dump
(dumpfile)Load a dill dump from a dumpfile.
get_component
(name)Get the component instance of component with specified name
get_component_subset_index_range
([...])Provides start and end index for components in run_from to run_to range
Get the component instance of last component in the instrument
has_errors
()Method that returns true if errors are found in instrument
init_parameters
()Create empty ParameterContainer for new instrument
make_component_subset
()Uses run_from and run_to specifications to extract subset of components
move_component
(name[, before, after])Moves component with given name to before or after
move_user_vars_to_declare
()Moves all uservars to declare for compatibility with McStas 2.X
print_component
(name)Method for printing summary of contents in named component
print_component_short
(name)Method for printing summary of contents in named component
print_components
([line_length])Obsolete method, use show_components instead
read_instrument_file
()Reads current instrument file if it exists, otherwise creates one first
remove_component
(name)Removes component with given name from instrument
reset_parameters
(value)Resets the calculator parameters
reset_run_points
()Reset run_from and run_to points to the full instrument
run_from
(component_ref[, run_name, tag])Set limit for instrument, only run from given component, load MCPL ot start
run_full_instrument
(**kwargs)Runs McStas instrument described by this class, returns list of McStasData
run_to
(component_ref[, run_name, comment])Set limit for instrument, only run to given component, save MCPL there
saveH5
(filename[, openpmd])Not relevant, but required from BaseCalculator, will be removed
set_calculator_base_dir
(value)Set the calculator base directory
set_dependency
(string)Sets the DEPENDENCY line of instruments, expanding its system search
set_input
(value)Set the calculator input data.
set_instrument_base_dir
(value)Set the instrument base directory
set_output_data_types
(value)Set the calculator output data type.
set_output_filenames
(value)Set the calculator output filenames.
set_output_keys
(value)Set the calculator output keys.
set_parameters
([args_as_dict])Sets parameters contained in this calculator using dict or kwargs
settings
([ncount, mpi, seed, force_compile, ...])Sets settings for McStas run performed with backengine
settings_string
()Returns a string describing settings stored in this instrument object
show_analysis
([variable])show_components
([line_length])Method for printing overview of all components in instrument
show_diagram
([analysis, variable, limits])Shows diagram of component connections in insrument
show_dump
(point[, run_name, tag])show_dumps
()show_instrument
([format, width, height, new_tab])Uses mcdisplay to show the instrument in web browser
show_instrument_file
([line_numbers])Displays the current instrument file
show_parameters
([line_length])Method for displaying current instrument parameters
show_run_subset
()Shows current subset of instrument selected with run_from and run_to methods
show_search
()Shows all search statements on instrument level
show_settings
()Prints settings stored in this instrument object
show_variables
()Shows declared variables in instrument
subset_check
(start_ref, end_ref)Checks that when the instrument is broken into subsets, it is still valid
Obsolete method for writing instrument parts to c files
Method for writing full instrument file to disk
Attributes
base_dir
The base path for the output files of this calculator in consideration of instrument_base_dir and calculator_base_dir
calculator_base_dir
The alias of output.
input
instrument_base_dir
output
The output of this calculator
output_data_types
output_file_paths
The final output file paths considering base_dir
output_filenames
output_keys
- classmethod from_dump(dumpfile: str)¶
Load a dill dump from a dumpfile.
Overwrites a libpyvinyl method to load McStas components
- Parameters
dumpfile (str) – The file name of the dumpfile.
- Returns
The calculator object restored from the dumpfile.
- Return type
CalcualtorClass