Converting instrument files

Converting instrument files#

The .instr suffix is shared by McStas and McXtrace, so select the appropriate conversion function explicitly. For McStas, use the mcstas-pygen command supplied with McStas:

import mcstasscript as ms

instrument = ms.mcstas_pygen("my_instrument.instr")

For McXtrace, use the corresponding mcxtrace-pygen command:

instrument = ms.mcxtrace_pygen("my_instrument.instr")

The generated file is written next to the input file as my_instrument_generated.py. Use destination to choose a generated Python file or an existing destination directory:

instrument = ms.mcstas_pygen(
    "my_instrument.instr",
    destination="generated/my_instrument.py",
)

The optional input_path is passed to the generated make function and sets the work directory used by the returned instrument:

instrument = ms.mcstas_pygen(
    "my_instrument.instr",
    input_path="path/to/components",
)

The input directory must exist, as must the parent directory of a custom destination. The selected McStas or McXtrace installation must provide its corresponding *-pygen executable on the system PATH.

mcstasscript.mcstas_pygen(filename: str | PathLike, destination: str | PathLike | None = None, input_path: str | PathLike | None = None) → Any#

Generate and return a McStas instrument from a .instr file.

This uses the mcstas-pygen executable and returns the McStas instrument generated by that command.

destination selects the generated Python file, or an existing directory in which <instrument>_generated.py is written. input_path is passed to the generated make function and must name an existing directory.

mcstasscript.mcxtrace_pygen(filename: str | PathLike, destination: str | PathLike | None = None, input_path: str | PathLike | None = None) → Any#

Generate and return a McXtrace instrument from a .instr file.

This uses the mcxtrace-pygen executable and returns the McXtrace instrument generated by that command.

destination selects the generated Python file, or an existing directory in which <instrument>_generated.py is written. input_path is passed to the generated make function and must name an existing directory.