Skip to content
Open
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
461 commits
Select commit Hold shift + click to select a range
1371ab6
Added name and on condition.
Jan 6, 2022
0ff6b6d
Getting indentation right
Jan 6, 2022
2e42a3a
Added colon
Jan 6, 2022
d3f1b65
Small changes to syntax
Jan 6, 2022
f8497f9
removed name
Jan 6, 2022
e0e1402
Removed mmap from requirements as its a default package
Jan 6, 2022
4e985b6
Removed demo
Jan 6, 2022
4d18f08
installed pytest
Jan 6, 2022
55bafda
Show file structure to ensure all folders are present
Jan 6, 2022
a8c7b7d
Updated show_categories so that their output is in alphabetic order.
Jan 6, 2022
de8cc83
Missed a file in last commit.
Jan 6, 2022
ab45030
Attempting to add windows to the text matrix
Jan 6, 2022
3591506
Fixed unit test that would fail on windows due to hardcoded slash
Jan 6, 2022
7452ebd
Fixed mistake in workflow that caused unix part not to run.
Jan 6, 2022
f054b10
Added macos and cache system to unittest workflow
Jan 6, 2022
fef8518
Moved to find instead of tree to show files to ensure compatability
Jan 6, 2022
5c01de8
tree . on windows and unix
Jan 6, 2022
38976a4
reorder lines for if
Jan 6, 2022
ce06820
made comparisons strings
Jan 6, 2022
d29a866
Changed to one workflow per operating system.
Jan 6, 2022
6f8d282
Merge pull request #41 from PaNOSC-ViNYL/github_actions
mads-bertelsen Jan 6, 2022
dd02d25
Merge branch 'master' into mcstasscript_on_libpyvinyl
mads-bertelsen Jan 6, 2022
40c8304
Checking checkout of libpyvinyl on workflow
Jan 6, 2022
609942d
Trying libpyvinyl build first, then mcstasscript
Jan 6, 2022
33f98e9
Forgot checkout of libpyvinyl
Jan 6, 2022
1587455
All workflows now get libpyvinyl develop from github.
Jan 6, 2022
f3e094c
Fix of indentation error on ubuntu workflow
Jan 6, 2022
c86c020
Added note on unused threading.
Jan 6, 2022
0925b95
Updates to test workflows so developer version of libpyvinyl is used
Jan 6, 2022
04f53df
Removed cache from libpyvinyl install
Jan 6, 2022
da974e5
setting up a path for each library.
Jan 6, 2022
69dad37
Trying to cd into libpyvinyl and mcstasscript folders
Jan 6, 2022
9c753b7
Changed directory structure of workflows.
Jan 6, 2022
e915fb4
Changed directory to avoid python setup getting requirements
Jan 6, 2022
8de9af1
Started sphinx documentation
Jan 12, 2022
b703622
Updates to documentation, including longer run lengths.
Mar 15, 2022
74fdc15
First version of McStasScript working with something very close to
Mar 21, 2022
919c61e
Change libpyvinyl version in github workflows.
Mar 21, 2022
7b1eee3
Update of documentation to reflect that backengine now returns
Mar 21, 2022
0af03de
Updates to documentation. Bug in reading union_histories fixed.
Mar 22, 2022
24467e5
Included link to documentation in warning.
Mar 22, 2022
aa11b56
Changed version system so it can be found by mcstasscript.
Mar 22, 2022
257d557
First version of mcstasscript init.
Mar 22, 2022
867c232
Added configurator to __init__
Mar 22, 2022
64c36ae
Update to documentation, now uses simple import.
Mar 22, 2022
12ffb83
Updating tests to run python 3.7 to 3.9
Mar 22, 2022
a447c26
Fixed bug in version pickup in setup.py
Mar 22, 2022
5589a73
removed pickle from requirements (its built in, so can't be found)
Mar 22, 2022
325ca51
Update of readme
Mar 22, 2022
9587cba
Removed pdf documentation, outdated and not useful anymore.
Mar 22, 2022
3c9d256
Merge branch 'master' into mcstasscript_on_libpyvinyl
mads-bertelsen Mar 22, 2022
382f1b6
Merge pull request #40 from PaNOSC-ViNYL/mcstasscript_on_libpyvinyl
mads-bertelsen Mar 22, 2022
aae9cd3
Small typo in setup script.
Mar 22, 2022
ed60a10
Small typo in setup.py
Mar 22, 2022
9f81219
Update of examples and tutorial.
Mar 22, 2022
e1d82b6
Bump of version number.
Mar 22, 2022
1a12a3f
Cryostat builder and example notebook added.
Mar 22, 2022
58598be
cleared cryostat notebook.
Mar 22, 2022
e21b7a9
Small fixes from Shervin review.
Mar 23, 2022
d246873
Small documentation fixes from Celine. Thanks!
Mar 23, 2022
00263ca
Update of cryostat_builder: sample -> origin to clarify that it is a …
Mar 23, 2022
39a4444
Fix of issue where libpyvinyl parameters provided to McStasScript
Apr 22, 2022
2e78111
Added unit test on case where libpyvinyl parameters given at
Apr 22, 2022
52e4130
Updated doc strings for new functions
Apr 22, 2022
042cef8
Merge pull request #43 from PaNOSC-ViNYL/libpyvinyl_par_fix
mads-bertelsen Apr 22, 2022
1f070ca
Fixed a bug where components with definition parameters that have double
Apr 25, 2022
01904a1
Added simple tool for generating NCrystal Union materials.
Apr 25, 2022
d527725
Fixed lack of suppress_output in settings.
May 5, 2022
2d5bf4d
Added suppress_output to instrument initialization.
May 5, 2022
db0535a
Version bump
May 5, 2022
34fd657
Merge pull request #44 from PaNOSC-ViNYL/ncrystal_union_tool
mads-bertelsen May 6, 2022
ad79d65
Update including fix of setting mpi to None and including gravity in …
May 6, 2022
86e9b4f
Incremented version number, now have mpi and gravity fix.
May 6, 2022
76a12ca
Renamed show_components to available_components as it displays
May 10, 2022
25c5d3f
Removed kwargs in instrument initialization.
May 10, 2022
b1de666
Removed kwargs in show_parameters and print_short on Component.
May 11, 2022
6d81b9c
Removed methods on instrument for manipulating components.
May 11, 2022
142f31d
Removed widget interface from base McStasScript import to avoid
May 11, 2022
0dedcb5
Removed component_name_list attribute in instr. It introduced a
May 11, 2022
2397c51
Work in progress on changing component to not have RELATIVE in
May 11, 2022
1408e3c
Enabled an error check for references to other components in
May 11, 2022
4bb0ce0
Checks for RELATIVE errors and allows PREVIOUS keyword.
May 11, 2022
1d56660
Code for error checking and remove/move components.
May 12, 2022
37a6146
Clean up of examples, correcting bugs and improving use of syntax.
May 12, 2022
897bb65
Check of all doc notebooks for consitensy.
May 12, 2022
675e06f
making output_path a method of the class and not a member. It is now …
May 13, 2022
822fc59
Added feature that allows hiding the new tab from show_instrument
May 16, 2022
8348009
Version bump to 0.0.44
May 16, 2022
9971107
Final documentation pass before update 0.0.44.
May 16, 2022
e94caae
Merge pull request #46 from PaNOSC-ViNYL/syntax_cleanup
mads-bertelsen May 16, 2022
a44c51d
Merge pull request #45 from PaNOSC-ViNYL/using_basedir
mads-bertelsen May 18, 2022
2aa392e
Ensure default name for data depend on instrument name.
May 18, 2022
d81af52
First functional version of instrument diagram.
May 18, 2022
75cd967
Update of instrument diagram, now makes it as wide as it needs to
May 18, 2022
8aea22f
Finishing touches on instrument diagram.
May 18, 2022
ccc8ed4
version bump.
May 18, 2022
5b63b74
Missing line in doc string.
May 18, 2022
6a06f26
Merge pull request #47 from PaNOSC-ViNYL/instrument_diagram
mads-bertelsen May 18, 2022
8076695
New version of instrument diagram.
May 31, 2022
9370464
Refactor and fix of instrument diagram:
Jun 7, 2022
07b8a20
Introduced changes to box outline in diagram to show EXTEND and WHEN …
Jun 8, 2022
40452a6
Updates to documentation, including instrument diagram in tutorial.
Jun 8, 2022
45b0107
Improvements to diagram.
Jun 10, 2022
aa12242
Updates to documentation.
Jun 10, 2022
0f45056
Images for documentation.
Jun 10, 2022
29a0086
Adds quotes around executables to run even when there are spaces in p…
Jun 10, 2022
32cd28c
forgot __init__.py file for python module instrument_diagram.
Jun 13, 2022
b240099
version bump
Jun 13, 2022
febca28
Removed print from managed_mcrun.
Jun 16, 2022
345c06e
Adding support for USERVARS which is available in McStas 3.X.
Jun 17, 2022
2fe9730
Makes instrument reader handle USERVARS in 3.0 instruments.
Jun 20, 2022
c426b90
Fixed problem in connections allowing skipping both origin and
Jun 20, 2022
17d9a37
Version bump
Jun 20, 2022
d8ec33c
Updates to documentation for v 0.0.50
Jun 20, 2022
5f09666
Merge pull request #49 from PaNOSC-ViNYL/mcstas_3.0_support
mads-bertelsen Jun 20, 2022
9e768dc
Update of reader so it understands keywords in capital and lowercase …
Sep 8, 2022
7befe4e
First version of MCPL bridge.
Sep 27, 2022
d244081
If instrument file not found, it is generated even if force_compile=F…
Sep 27, 2022
3e40a5d
Merge branch 'PaNOSC-ViNYL:master' into master
willend Sep 28, 2022
b98e0af
Fixes to how the MCPL bridge feature is implemented.
Sep 28, 2022
8e0e44b
Changes to how dumps to and from MCPL work.
Sep 29, 2022
9edcd30
Updates for dump database.
Sep 30, 2022
ee93f4b
Migrated mcpl filenames to parameters to avoid recompiling
Sep 30, 2022
81cdcc0
Patch with McStas-compatible print (allows direct copy-pasting to ins…
willend Oct 4, 2022
562e071
Express AT and ROTATED via tuples, thanks @g5t.
willend Oct 4, 2022
7871013
Merge pull request #52 from PaNOSC-ViNYL/fix_forcecompile
mads-bertelsen Oct 10, 2022
2124be7
Merge pull request #55 from McStasMcXtrace/master
mads-bertelsen Oct 10, 2022
dda57c4
Cleanup of MCPL bridge system, including more doc strigns and checks.
Oct 13, 2022
9935121
Refactor of BeamDumpDatabase newest_at_point and
Oct 14, 2022
caa5bf3
Merge pull request #56 from PaNOSC-ViNYL/bridge_with_MCPL
mads-bertelsen Oct 14, 2022
2b50787
Fix of component print code and associated unittests.
Oct 14, 2022
72efbd1
Version bump, now version 0.0.51, updates to documentation for MCPL b…
Oct 17, 2022
4b58173
Small fixes:
Oct 25, 2022
f85d687
Initial implementation of debugging tool that place event monitors
Oct 26, 2022
786dd52
New feature, diagnostics tool can now plot intensity and ray evolution
Oct 27, 2022
22234ac
Update of diagnostics, common aspects of a diagnostics instrument
Oct 31, 2022
d90e55a
Fixed bug with GROUP label in diagrams, the last GROUP name was
Nov 1, 2022
0cefb15
mcpl file path added to output collection, mcpl input added to MCPL_i…
Oct 12, 2022
419ea25
make the mcpl methods for internal use only
Oct 12, 2022
5994ba7
data collection taking the name from the calculator name
Sep 7, 2022
69966db
Update of CI workflows for new version of libpyvinyl
Nov 4, 2022
5acff0f
Going to libpyvinyl master for CI builds.
Nov 4, 2022
a0f9977
Merge pull request #53 from PaNOSC-ViNYL/mcpl_input_output
mads-bertelsen Nov 4, 2022
06207e6
Update of diagnostics tools, they now support:
Nov 14, 2022
738eb8e
Update of data with ability to use flag info to set axis when
Nov 15, 2022
439a8f3
Update of CI workflows for new version of libpyvinyl
Nov 4, 2022
d2f7c7b
Going to libpyvinyl master for CI builds.
Nov 4, 2022
97b6531
Final update of diagnostics system. Now checks if McStas / McXtrace
Nov 17, 2022
e3d0099
Fix of index.rst typo.
Nov 17, 2022
9a4d5e1
Fixed tests for instrument that now have two subprocess runs, and
Nov 17, 2022
976c1f1
Merge pull request #57 from PaNOSC-ViNYL/instrument_diagnostics
mads-bertelsen Nov 17, 2022
30b2e86
Version bump to get fixed tests to pypi package.
Nov 17, 2022
48cf559
Update README.md
mads-bertelsen Nov 18, 2022
e0cf35d
Adding axis1_values and axis2_values to view which plots lines
Nov 22, 2022
ffc9ad1
[Fix] Determine base for C integer literals
g5t Feb 15, 2023
dc3f367
Merge pull request #59 from g5t/85-base-10-int
mads-bertelsen Feb 15, 2023
5e3c779
Small fix of component reader when finding vectors
Feb 17, 2023
04d609f
Update syntax for plotting
Apr 14, 2023
0d3ff4c
Update with McStas 3.x relevant syntax
Apr 14, 2023
956f926
Apply McStas 3.x syntax
Apr 14, 2023
4c0a42e
Update syntax to get plot outputs
Apr 14, 2023
b71e98e
Add Union_init and Union_stop for 3.x support
Apr 14, 2023
a858ee5
Updates for Union in McStas 3.x
Apr 14, 2023
8b2861d
Update that removes the need to provide a name in often used methods
Apr 14, 2023
63d16c5
Addition of ipympl as dependency to fix issues with jupyter notebook …
Apr 18, 2023
880cbe4
Merge pull request #63 from PaNOSC-ViNYL/implicit_naming
mads-bertelsen Apr 18, 2023
6618d45
Update of actions to new setup-python version and enabling manual dis…
Apr 18, 2023
0f39274
Update of syntax
Apr 18, 2023
5df9d75
Issue with syntax in github actions.
Apr 18, 2023
e7a649d
Updated duplicate name.
Apr 18, 2023
b423403
Merge pull request #64 from PaNOSC-ViNYL/actions_update
mads-bertelsen Apr 19, 2023
3902405
Update of integration tests to support McStas 2 and 3.
Apr 20, 2023
59fc55c
Added openacc and NeXus option to settings, including unit tests.
Apr 20, 2023
ec4a47a
Added search and dependency keywords.
Apr 25, 2023
1f4d8a4
Update of documentation and fix of bug in resetting dependency.
Apr 25, 2023
4d5b235
reset notebook.
Apr 25, 2023
1690c95
Merge pull request #62 from McStasMcXtrace/master
mads-bertelsen Apr 25, 2023
f51e80c
Small changes to readme.
Apr 25, 2023
932c59d
Updating checks of c variable names with regular expressions and
Apr 28, 2023
9251009
Updated version of component reader, now handles comments in paramete…
May 2, 2023
6397fb8
Fixed bugs that caused infinite loops.
May 2, 2023
b6fceea
Fixed spelling mistake in comment.
May 2, 2023
eeb29eb
Update version number as behavior changed.
May 2, 2023
abaad34
Merge pull request #69 from PaNOSC-ViNYL/comp_reader_improvements
mads-bertelsen May 2, 2023
2614d29
[Apply][Fix] On top of the up-to-date master
g5t Jun 8, 2023
4366b32
[Fix] white space issues for tests
g5t Jun 9, 2023
5c61a2e
Small bug pointed out by Kristine which prevented diagnostic output
Jun 15, 2023
76feb49
Small updates:
Aug 4, 2023
91124ca
Update that allows reading of nexus files with load functions.
Aug 29, 2023
6f6075a
Avoid plotting event data as the results are not meaningful and often…
Aug 30, 2023
f5964a0
Merge pull request #73 from PaNOSC-ViNYL/nexus_reader
mads-bertelsen Aug 30, 2023
f8e17f3
Added h5py to requirements to ensure users have the package for nexus…
Aug 30, 2023
d4dced8
Fixed issue with placement of plot in widget on newer ipywidget versi…
Dec 1, 2023
0e64e0e
Merge pull request #75 from PaNOSC-ViNYL/new_widget_layout
mads-bertelsen Dec 1, 2023
4efe99f
mcdisplay is now searched for in both exectuable path and package path.
Dec 1, 2023
c3cf1b4
Tight layout on all figures
Dec 1, 2023
9a87088
Bump of version.
Dec 1, 2023
c3485c9
Fixed called_with parameters in unittests for plotting.
Dec 1, 2023
65aa945
Merge pull request #76 from PaNOSC-ViNYL/show_instrument_fix
mads-bertelsen Dec 1, 2023
fd5bac9
Hotfix of mcdisplay path issue.
Dec 1, 2023
8c5396a
Hotfix of mcdisplay path issue.
Dec 1, 2023
9bf67c1
Improved reliability of reading NeXus data.
Dec 6, 2023
909e01d
Merge pull request #77 from PaNOSC-ViNYL/nexus_loading_improvements
mads-bertelsen Dec 7, 2023
811230d
Mocked datetime to avoid a flaky test when writing instrument code.
Dec 14, 2023
2f0a26e
Implement simple solution to auto-detect McStas and McXtrace paramete…
willend Feb 10, 2024
c6c3b31
Merge pull request #78 from willend/master
mads-bertelsen Feb 14, 2024
ffbac37
Fix of case where MCSTAS was not found in environ.
Feb 14, 2024
3cab00e
Allow McXtrace sessions to visualize using mxdisplay(-webgl/-pyqtgraph)
willend May 15, 2024
e8adc29
We should of course still use mcdisplay in the McStas case...
willend May 15, 2024
b6afee1
Merge pull request #80 from willend/master
mads-bertelsen Jul 24, 2024
99a5120
Increasing python version for workflows
mads-bertelsen Jul 24, 2024
1c79985
Added instrument checker.
mads-bertelsen Jul 24, 2024
c765c31
Updates to workflows.
mads-bertelsen Jul 24, 2024
aa4e228
Changed how python versions are specified
mads-bertelsen Jul 24, 2024
510010b
Shifted to libpyvinyl branch without Pint.
mads-bertelsen Jul 24, 2024
f23de3b
Further development of instrument_checker and version bump.
mads-bertelsen Jul 25, 2024
2fa3cc5
Updated search statements so McStasScript loads the appropriate folde…
mads-bertelsen Jul 29, 2024
6ec43bc
Added system that writes down all final values given to components fo…
mads-bertelsen Aug 9, 2024
6bbe6fa
Merge pull request #83 from PaNOSC-ViNYL/include_meta
mads-bertelsen Aug 9, 2024
076f3bd
fix bad escape sequence warning in python 3.11
nvaytet Aug 21, 2024
03ec6d9
Merge pull request #84 from nvaytet/fix-py-311
mads-bertelsen Sep 11, 2024
c544634
Version bump after merging pull request on python 3.11 compatability.
mads-bertelsen Sep 11, 2024
9bc85b1
Fixed issues with escape characters.
mads-bertelsen Sep 20, 2024
c8b3c78
Get instrument search object to be written before the first component…
mads-bertelsen Sep 20, 2024
6848eba
Bump version for SEARCH fix
mads-bertelsen Sep 20, 2024
721e421
Updated test for new SEARCH location.
mads-bertelsen Sep 20, 2024
e47ce37
Merge pull request #85 from PaNOSC-ViNYL/search_fix
mads-bertelsen Sep 20, 2024
b453308
fixed typos in Union tutorial docs
MilanKlausz Oct 17, 2024
89293de
fixed typos in Union tutorials
MilanKlausz Oct 18, 2024
8d6c829
Fixed bug where dependency line was read as additional parameters in …
mads-bertelsen Nov 8, 2024
2755c77
Included component made for unit test that lacks these sections and h…
mads-bertelsen Nov 8, 2024
046ca81
Added handling of damaged utf-8 strings and EQ for search statements.
mads-bertelsen Apr 2, 2025
caf273e
Change to how NeXus data is read.
mads-bertelsen Apr 2, 2025
bfa5a26
Merge pull request #91 from PaNOSC-ViNYL/nexus_improvement
mads-bertelsen Apr 2, 2025
79fa259
Let McStasScript default to use of webgl-classic vis.
willend Aug 12, 2025
cfa8210
Merge pull request #93 from willend/master
mads-bertelsen Aug 19, 2025
310b6d8
Update default instrument visualization to webgl-classic
mads-bertelsen Aug 19, 2025
358cba9
Add ':' consistently in Instrument: name header fields, prompt user t…
willend Oct 8, 2025
f6c1cd0
Add a missing newline, push parm table below %Parameters
willend Oct 8, 2025
51cdb4e
Partial generation of parameter list
willend Oct 8, 2025
1f2d1ef
Add missing +
willend Oct 8, 2025
989a1a7
Add param.comment as parameter description
willend Oct 8, 2025
af0b0f9
Drop (type) since this is part of the comment string already.
willend Oct 8, 2025
a9f3e27
Merge pull request #86 from MilanKlausz/master
mads-bertelsen Nov 24, 2025
bbda414
Merge pull request #95 from willend/master
mads-bertelsen Dec 3, 2025
de34c2d
Merge branch 'master' into fix-format-strings-on-master
mads-bertelsen Dec 3, 2025
8477dd6
Merge pull request #70 from g5t/fix-format-strings-on-master
mads-bertelsen Dec 3, 2025
e24634a
Updated tests after merging recent pull requests.
mads-bertelsen Dec 3, 2025
202cac6
Updated manifest to include test_input_folder in tests
mads-bertelsen Dec 3, 2025
423274e
Updated version
mads-bertelsen Dec 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python
python:
- "3.6"
- "3.7"

install:
- pip install -r requirements.txt
- pip install coverage

script:
- coverage run -m unittest discover mcstasscript/tests

after_success:
- bash <(curl -s https://codecov.io/bash)
11 changes: 11 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include McStasScript_documentation.pdf
include mcstasscript/configuration.yaml
include mcstasscript/tests/test_for_reading.comp
include mcstasscript/tests/test_instrument.instr
include mcstasscript/tests/Union_demonstration_test.instr
include mcstasscript/integration_tests/test_input_folder
include mcstasscript/integration_tests/test_input_folder/PSDlin_monitor.comp
graft mcstasscript/tests/dummy_mcstas
graft mcstasscript/tests/dummy_instrument_folder
graft mcstasscript/tests/test_data_set

Binary file added McStasScript_developer_documentation.pdf
Binary file not shown.
Binary file added McStasScript_documentation.pdf
Binary file not shown.
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# McStasScript
McStas API for creating and running McStas instruments from python scripting

Prototype for an API that allow interaction with McStas through an interface like Jupyter Notebooks created under WP5 of PaNOSC.

## Installation
McStasScript does not include the McStas installation, so McStas should be installed separately.
McStasScript can be installed using pip,

python3 -m pip install McStasScript --upgrade

After installation it is necessary to configure the package so the McStas installation can be found, here we show how the appropriate code for an Ubuntu system. The configuration is saved permanently, and only needs to be updated when McStas or McStasScript is updated. This has to be done from within python.

from mcstasscript.interface import functions
my_configurator = functions.Configurator()
my_configurator.set_mcrun_path("/usr/bin/")
my_configurator.set_mcstas_path("/usr/share/mcstas/2.5/")

### Notes on windows installation
McStasScript was tested on Windows 10 installed using this [guide](https://github.com/McStasMcXtrace/McCode/blob/master/INSTALL-McStas/Windows/README.md), it is necessary to include MPI using MSMpiSetup.exe and msmpisdk.msi located in the extras folder.

Open the McStas-shell cmd (shortcut should be available on desktop) and install McStasScript / jupyter notebook with these commands:

python -m pip install notebook
python -m pip install McStasScript --upgrade

Using the McStas-shell one can start a jupyter notebook server with this command:

jupyter notebook

For a standard McStas installation on Windows, the appropriate configuration can be set with these commands in a notebook:

from mcstasscript.interface import functions
my_configurator = functions.Configurator()
my_configurator.set_mcrun_path("\\mcstas-2.6\\bin\\")
my_configurator.set_mcstas_path("\\mcstas-2.6\\lib\\")

## Instructions for basic use
This section provides a quick way to get started, a more in depth tutorial using Jupyter Notebooks is available in the tutorial folder.

Import the interface

from mcstasscript.interface import instr, plotter, functions, reader

Now the package can be used. Start with creating a new instrument, just needs a name

my_instrument = instr.McStas_instr("my_instrument_file")

Then McStas components can be added, here we add a source

my_source = my_instrument.add_component("source", "Source_simple")
my_source.show_parameters() # Can be used to show available parameters for Source simple

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

PSD = my_instrument.add_component("PSD", "PSD_monitor", AT=[0,0,1], RELATIVE="source")
PSD.xwidth = 0.1
PSD.yheight = 0.1
PSD.nx = 200
PSD.ny = 200
PSD.filename = "\"PSD.dat\""

This simple simulation can be executed from the

data = my_instrument.run_full_instrument(foldername="first_run", increment_folder_name=True)

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

Plotting is usually done in a subplot of all monitors recorded.

plot = plotter.make_sub_plot(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 = reader.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, for example help(instr.McStas_instr.show_components).

instr
└── McStas_instr(str instr_name) # Returns McStas instrument object on initialize
├── show_components(str category_name) # Show available components in given category
├── component_help(str component_name) # Prints component parameters for given component name
├── add_component(str name, str component_name) # Adds component to instrument and returns object
├── add_parameter(str name) # Adds instrument parameter with name
├── add_declare_var(str type, str name) # Adds declared variable with type and name
├── append_initialize(str string) # Appends a line to initialize (c syntax)
├── print_components() # Prints list of components and their location
├── write_full_instrument() # Writes instrument to disk with given name + ".instr"
└── run_full_instrument() # Runs simulation. Options in keyword arguments. Returns list of McStasData

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

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

plotter
├── make_plot(list McStasData) # Plots each data set individually
└── make_sub_plot(list McStasData) # Plots data as subplot

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
Loading