1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
%global _empty_manifest_terminate_build 0
Name: python-McStasScript
Version: 0.0.58
Release: 1
Summary: A python scripting interface for McStas
License: GNU General Public License (GPL)
URL: https://github.com/PaNOSC-ViNYL/McStasScript
Source0: https://mirrors.aliyun.com/pypi/web/packages/01/c3/505dbc8bb610063208da052e87e60e96980f40ee6b3184826aff4645952b/McStasScript-0.0.58.tar.gz
BuildArch: noarch
%description
The parameters of the source can be adjusted directly as attributes of the python object
my_source.xwidth = 0.12
my_source.yheight = 0.12
my_source.lambda0 = 3
my_source.dlambda = 2.2
my_source.focus_xw = 0.05
my_source.focus_yh = 0.05
A monitor is added as well to get data out of the simulation (few bins so it is easy to print the results)
PSD = my_instrument.add_component("PSD", "PSD_monitor", AT=[0,0,1], RELATIVE="source")
PSD.xwidth = 0.1
PSD.yheight = 0.1
PSD.nx = 5
PSD.ny = 5
PSD.filename = '"PSD.dat"'
Settings for the simulation can be adjusted with the *settings* method, an output_path for the data is needed.
my_instrument.settings(output_path="first_run", ncount=1E7)
The simulatiuon is performed with the *backengine* method. This returns the data generated from the simulation.
data = my_instrument.backengine()
Results from the monitors would be stored as a list of McStasData objects in the returned data. The counts are stored as numpy arrays. We can read and change the intensity directly and manipulate the data before plotting.
data[0].Intensity
In a python terminal this would display the data directly:
array([[0. , 0. , 0. , 0. , 0. ],
[0. , 0.1422463 , 0.19018485, 0.14156196, 0. ],
[0. , 0.18930076, 0.25112956, 0.18897898, 0. ],
[0. , 0.14121589, 0.18952508, 0.14098576, 0. ],
[0. , 0. , 0. , 0. , 0. ]])
Plotting is usually done in a subplot of all monitors recorded.
plot = ms.make_sub_plot(data)
## Widgets in Jupyter Notebooks
When using McStasScript in a jupyter notebook, it is possible to plot the data with a widget system instead. To do so, import the jupyter notebook widget interface and use show.
import mcstasscript.jb_interface as ms_widget
ms_widget.show(data)
There is also a widget solution for performing the simulation which works as an alternative to *backengine*, this method is also included in the jb_interface show command, just provide an instrument object instead of data. This interface includes setting parameters, simulation options and plotting of the resulting data.
ms_widget.show(instr)
If one wants to have access to the data generated in the widget, the widget needs to be created as an object with SimInterface. The resulting object will have a *show_interface* method to display the interface, and a *get_data* method to retrieve the latest generated dataset.
sim_widget = ms_widget.SimInterface(instr)
sim_widget.show_interface()
data = sim_widget.get_data()
## Use in existing project
If one wish to work on existing projects using McStasScript, there is a reader included that will read a McStas Instrument file and write the corresponding McStasScript python instrument to disk. Here is an example where the PSI_DMC.instr example is converted:
Reader = ms.McStas_file("PSI_DMC.instr")
Reader.write_python_file("PSI_DMC_generated.py")
It is highly advised to run a check between the output of the generated file and the original to ensure the process was sucessful.
## Method overview
Here is a quick overview of the available methods of the main classes in the project. Most have more options from keyword arguments that are explained in the manual, but also in python help. To get more information on for example the show_components method of the McStas_instr class, one can use the python help command help(instr.McStas_instr.show_components). Many methods take a reference to a component, that can either be a string with the component name or a component object, here written as Cref in type hint.
instr
└── McStas_instr(str instr_name) # Returns McStas instrument object on initialize
├── show_parameters() # Prints list of parameters
├── show_settings() # Prints current instrument settings
├── show_variables() # Prints list of declare variables and user vars
├── show_components() # Prints list of components and their location
├── show_instrument() # Shows instrument drawing with current parameters
├── show_instr_file() # Prints the current instrument file
├── show_diagram() # Show figure describing the instrument object
├── set_parameters() # Sets instrument parameters as keyword arguments
├── available_components(str category_name) # Show available components in given category
├── component_help(Cref component_name) # Prints component parameters for given component name
├── add_component(str name, str component_name) # Adds component to instrument and returns object
├── copy_component(str name, Cref original_name) # Copies a component to instrument and returns object
├── remove_component(Cref name) # Removes component
├── move_component(str name, Cref before / after, ) # Moves component to either before or after another
├── get_component(str name) # Gets component object
├── get_last_component() # Gets last component object
├── add_parameter(str name) # Adds instrument parameter with name
├── add_declare_var(str type, str name) # Adds declared variable with type and name
├── add_user_var(str type, str name) # Adds user var with type and name
├── append_declare(str string) # Appends a line to declare section (c syntax)
├── append_initialize(str string) # Appends a line to initialize (c syntax)
├── append_finally(str string) # Appends a line to finally (c syntax)
├── write_full_instrument() # Writes instrument to disk with given name + ".instr"
├── settings(kwargs) Settings as keyword arguments.
└── backengine() # Runs simulation.
component # returned by add_component
├── set_AT(list at_list) # Sets component position (list of x,y,z positions in [m])
├── set_ROTATED(list rotated_list) # Sets component rotation (list of x,y,z rotations in [deg])
├── set_RELATIVE(str component_name) # Sets relative to other component name
├── set_parameters(dict input) # Set parameters using dict input
├── set_comment(str string) # Set comment explaining something about the component
└── print_long() # Prints currently contained information on component
mcstasscript functions
├── name_search(str name, list McStasData) # Returns data set with given name from McStasData list
├── name_plot_options(str name, list McStasData, kwargs) # Sends kwargs to dataset with given name
├── load_data(str foldername) # Loads data from folder with McStas data as McStasData list
└── Configurator()
├── set_mcrun_path(str path) # sets mcrun path
├── set_mcstas_path(str path) # sets mcstas path
└── set_line_length(int length) # sets maximum line length
mcstasscript plotter
├── make_plot(list McStasData) # Plots each data set individually
├── make_sub_plot(list McStasData) # Plots data as subplot
└── interface(list McStasData) # Shows plotting interface in jupyter notebook
mcstasscript reader
└── McStas_file(str filename) # Returns a reader that can extract information from given instr file
InstrumentReader # returned by McStas_file
├── generate_python_file(str filename) # Writes python file with information contaiend in isntrument
└── add_to_instr(McStas_instr Instr) # Adds information from instrument to McStasScirpt instrument
%package -n python3-McStasScript
Summary: A python scripting interface for McStas
Provides: python-McStasScript
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-McStasScript
The parameters of the source can be adjusted directly as attributes of the python object
my_source.xwidth = 0.12
my_source.yheight = 0.12
my_source.lambda0 = 3
my_source.dlambda = 2.2
my_source.focus_xw = 0.05
my_source.focus_yh = 0.05
A monitor is added as well to get data out of the simulation (few bins so it is easy to print the results)
PSD = my_instrument.add_component("PSD", "PSD_monitor", AT=[0,0,1], RELATIVE="source")
PSD.xwidth = 0.1
PSD.yheight = 0.1
PSD.nx = 5
PSD.ny = 5
PSD.filename = '"PSD.dat"'
Settings for the simulation can be adjusted with the *settings* method, an output_path for the data is needed.
my_instrument.settings(output_path="first_run", ncount=1E7)
The simulatiuon is performed with the *backengine* method. This returns the data generated from the simulation.
data = my_instrument.backengine()
Results from the monitors would be stored as a list of McStasData objects in the returned data. The counts are stored as numpy arrays. We can read and change the intensity directly and manipulate the data before plotting.
data[0].Intensity
In a python terminal this would display the data directly:
array([[0. , 0. , 0. , 0. , 0. ],
[0. , 0.1422463 , 0.19018485, 0.14156196, 0. ],
[0. , 0.18930076, 0.25112956, 0.18897898, 0. ],
[0. , 0.14121589, 0.18952508, 0.14098576, 0. ],
[0. , 0. , 0. , 0. , 0. ]])
Plotting is usually done in a subplot of all monitors recorded.
plot = ms.make_sub_plot(data)
## Widgets in Jupyter Notebooks
When using McStasScript in a jupyter notebook, it is possible to plot the data with a widget system instead. To do so, import the jupyter notebook widget interface and use show.
import mcstasscript.jb_interface as ms_widget
ms_widget.show(data)
There is also a widget solution for performing the simulation which works as an alternative to *backengine*, this method is also included in the jb_interface show command, just provide an instrument object instead of data. This interface includes setting parameters, simulation options and plotting of the resulting data.
ms_widget.show(instr)
If one wants to have access to the data generated in the widget, the widget needs to be created as an object with SimInterface. The resulting object will have a *show_interface* method to display the interface, and a *get_data* method to retrieve the latest generated dataset.
sim_widget = ms_widget.SimInterface(instr)
sim_widget.show_interface()
data = sim_widget.get_data()
## Use in existing project
If one wish to work on existing projects using McStasScript, there is a reader included that will read a McStas Instrument file and write the corresponding McStasScript python instrument to disk. Here is an example where the PSI_DMC.instr example is converted:
Reader = ms.McStas_file("PSI_DMC.instr")
Reader.write_python_file("PSI_DMC_generated.py")
It is highly advised to run a check between the output of the generated file and the original to ensure the process was sucessful.
## Method overview
Here is a quick overview of the available methods of the main classes in the project. Most have more options from keyword arguments that are explained in the manual, but also in python help. To get more information on for example the show_components method of the McStas_instr class, one can use the python help command help(instr.McStas_instr.show_components). Many methods take a reference to a component, that can either be a string with the component name or a component object, here written as Cref in type hint.
instr
└── McStas_instr(str instr_name) # Returns McStas instrument object on initialize
├── show_parameters() # Prints list of parameters
├── show_settings() # Prints current instrument settings
├── show_variables() # Prints list of declare variables and user vars
├── show_components() # Prints list of components and their location
├── show_instrument() # Shows instrument drawing with current parameters
├── show_instr_file() # Prints the current instrument file
├── show_diagram() # Show figure describing the instrument object
├── set_parameters() # Sets instrument parameters as keyword arguments
├── available_components(str category_name) # Show available components in given category
├── component_help(Cref component_name) # Prints component parameters for given component name
├── add_component(str name, str component_name) # Adds component to instrument and returns object
├── copy_component(str name, Cref original_name) # Copies a component to instrument and returns object
├── remove_component(Cref name) # Removes component
├── move_component(str name, Cref before / after, ) # Moves component to either before or after another
├── get_component(str name) # Gets component object
├── get_last_component() # Gets last component object
├── add_parameter(str name) # Adds instrument parameter with name
├── add_declare_var(str type, str name) # Adds declared variable with type and name
├── add_user_var(str type, str name) # Adds user var with type and name
├── append_declare(str string) # Appends a line to declare section (c syntax)
├── append_initialize(str string) # Appends a line to initialize (c syntax)
├── append_finally(str string) # Appends a line to finally (c syntax)
├── write_full_instrument() # Writes instrument to disk with given name + ".instr"
├── settings(kwargs) Settings as keyword arguments.
└── backengine() # Runs simulation.
component # returned by add_component
├── set_AT(list at_list) # Sets component position (list of x,y,z positions in [m])
├── set_ROTATED(list rotated_list) # Sets component rotation (list of x,y,z rotations in [deg])
├── set_RELATIVE(str component_name) # Sets relative to other component name
├── set_parameters(dict input) # Set parameters using dict input
├── set_comment(str string) # Set comment explaining something about the component
└── print_long() # Prints currently contained information on component
mcstasscript functions
├── name_search(str name, list McStasData) # Returns data set with given name from McStasData list
├── name_plot_options(str name, list McStasData, kwargs) # Sends kwargs to dataset with given name
├── load_data(str foldername) # Loads data from folder with McStas data as McStasData list
└── Configurator()
├── set_mcrun_path(str path) # sets mcrun path
├── set_mcstas_path(str path) # sets mcstas path
└── set_line_length(int length) # sets maximum line length
mcstasscript plotter
├── make_plot(list McStasData) # Plots each data set individually
├── make_sub_plot(list McStasData) # Plots data as subplot
└── interface(list McStasData) # Shows plotting interface in jupyter notebook
mcstasscript reader
└── McStas_file(str filename) # Returns a reader that can extract information from given instr file
InstrumentReader # returned by McStas_file
├── generate_python_file(str filename) # Writes python file with information contaiend in isntrument
└── add_to_instr(McStas_instr Instr) # Adds information from instrument to McStasScirpt instrument
%package help
Summary: Development documents and examples for McStasScript
Provides: python3-McStasScript-doc
%description help
The parameters of the source can be adjusted directly as attributes of the python object
my_source.xwidth = 0.12
my_source.yheight = 0.12
my_source.lambda0 = 3
my_source.dlambda = 2.2
my_source.focus_xw = 0.05
my_source.focus_yh = 0.05
A monitor is added as well to get data out of the simulation (few bins so it is easy to print the results)
PSD = my_instrument.add_component("PSD", "PSD_monitor", AT=[0,0,1], RELATIVE="source")
PSD.xwidth = 0.1
PSD.yheight = 0.1
PSD.nx = 5
PSD.ny = 5
PSD.filename = '"PSD.dat"'
Settings for the simulation can be adjusted with the *settings* method, an output_path for the data is needed.
my_instrument.settings(output_path="first_run", ncount=1E7)
The simulatiuon is performed with the *backengine* method. This returns the data generated from the simulation.
data = my_instrument.backengine()
Results from the monitors would be stored as a list of McStasData objects in the returned data. The counts are stored as numpy arrays. We can read and change the intensity directly and manipulate the data before plotting.
data[0].Intensity
In a python terminal this would display the data directly:
array([[0. , 0. , 0. , 0. , 0. ],
[0. , 0.1422463 , 0.19018485, 0.14156196, 0. ],
[0. , 0.18930076, 0.25112956, 0.18897898, 0. ],
[0. , 0.14121589, 0.18952508, 0.14098576, 0. ],
[0. , 0. , 0. , 0. , 0. ]])
Plotting is usually done in a subplot of all monitors recorded.
plot = ms.make_sub_plot(data)
## Widgets in Jupyter Notebooks
When using McStasScript in a jupyter notebook, it is possible to plot the data with a widget system instead. To do so, import the jupyter notebook widget interface and use show.
import mcstasscript.jb_interface as ms_widget
ms_widget.show(data)
There is also a widget solution for performing the simulation which works as an alternative to *backengine*, this method is also included in the jb_interface show command, just provide an instrument object instead of data. This interface includes setting parameters, simulation options and plotting of the resulting data.
ms_widget.show(instr)
If one wants to have access to the data generated in the widget, the widget needs to be created as an object with SimInterface. The resulting object will have a *show_interface* method to display the interface, and a *get_data* method to retrieve the latest generated dataset.
sim_widget = ms_widget.SimInterface(instr)
sim_widget.show_interface()
data = sim_widget.get_data()
## Use in existing project
If one wish to work on existing projects using McStasScript, there is a reader included that will read a McStas Instrument file and write the corresponding McStasScript python instrument to disk. Here is an example where the PSI_DMC.instr example is converted:
Reader = ms.McStas_file("PSI_DMC.instr")
Reader.write_python_file("PSI_DMC_generated.py")
It is highly advised to run a check between the output of the generated file and the original to ensure the process was sucessful.
## Method overview
Here is a quick overview of the available methods of the main classes in the project. Most have more options from keyword arguments that are explained in the manual, but also in python help. To get more information on for example the show_components method of the McStas_instr class, one can use the python help command help(instr.McStas_instr.show_components). Many methods take a reference to a component, that can either be a string with the component name or a component object, here written as Cref in type hint.
instr
└── McStas_instr(str instr_name) # Returns McStas instrument object on initialize
├── show_parameters() # Prints list of parameters
├── show_settings() # Prints current instrument settings
├── show_variables() # Prints list of declare variables and user vars
├── show_components() # Prints list of components and their location
├── show_instrument() # Shows instrument drawing with current parameters
├── show_instr_file() # Prints the current instrument file
├── show_diagram() # Show figure describing the instrument object
├── set_parameters() # Sets instrument parameters as keyword arguments
├── available_components(str category_name) # Show available components in given category
├── component_help(Cref component_name) # Prints component parameters for given component name
├── add_component(str name, str component_name) # Adds component to instrument and returns object
├── copy_component(str name, Cref original_name) # Copies a component to instrument and returns object
├── remove_component(Cref name) # Removes component
├── move_component(str name, Cref before / after, ) # Moves component to either before or after another
├── get_component(str name) # Gets component object
├── get_last_component() # Gets last component object
├── add_parameter(str name) # Adds instrument parameter with name
├── add_declare_var(str type, str name) # Adds declared variable with type and name
├── add_user_var(str type, str name) # Adds user var with type and name
├── append_declare(str string) # Appends a line to declare section (c syntax)
├── append_initialize(str string) # Appends a line to initialize (c syntax)
├── append_finally(str string) # Appends a line to finally (c syntax)
├── write_full_instrument() # Writes instrument to disk with given name + ".instr"
├── settings(kwargs) Settings as keyword arguments.
└── backengine() # Runs simulation.
component # returned by add_component
├── set_AT(list at_list) # Sets component position (list of x,y,z positions in [m])
├── set_ROTATED(list rotated_list) # Sets component rotation (list of x,y,z rotations in [deg])
├── set_RELATIVE(str component_name) # Sets relative to other component name
├── set_parameters(dict input) # Set parameters using dict input
├── set_comment(str string) # Set comment explaining something about the component
└── print_long() # Prints currently contained information on component
mcstasscript functions
├── name_search(str name, list McStasData) # Returns data set with given name from McStasData list
├── name_plot_options(str name, list McStasData, kwargs) # Sends kwargs to dataset with given name
├── load_data(str foldername) # Loads data from folder with McStas data as McStasData list
└── Configurator()
├── set_mcrun_path(str path) # sets mcrun path
├── set_mcstas_path(str path) # sets mcstas path
└── set_line_length(int length) # sets maximum line length
mcstasscript plotter
├── make_plot(list McStasData) # Plots each data set individually
├── make_sub_plot(list McStasData) # Plots data as subplot
└── interface(list McStasData) # Shows plotting interface in jupyter notebook
mcstasscript reader
└── McStas_file(str filename) # Returns a reader that can extract information from given instr file
InstrumentReader # returned by McStas_file
├── generate_python_file(str filename) # Writes python file with information contaiend in isntrument
└── add_to_instr(McStas_instr Instr) # Adds information from instrument to McStasScirpt instrument
%prep
%autosetup -n McStasScript-0.0.58
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-McStasScript -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Thu Jun 08 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.58-1
- Package Spec generated
|