Skip to content

source_simple -> mcstas-pygen -> mcstasscript -> exception #2175

@tkittel

Description

@tkittel

In a very simple instrument file with a Source_simple :

COMPONENT source = Source_simple(
    lambda0=lambda,
    dlambda=0.001,
    focus_yh=0.01,
    focus_xw=0.01
)
AT (0, 0, 0) RELATIVE PREVIOUS

I tried to export via the PyLab button in mcgui and run in mcstasscript. It mostly works, but when using

instr.show_diagram(analysis=True)

I end up with an exception:

 /opt/miniforge/envs/ESS/lib/python3.12/site-packages/mcstasscript/instrument_diagnostics/diagnostics_instrument.py:107, in DiagnosticsInstrument.correct_target_index(self)
    103 # Only here if target_index is used, correct it in modified instr
    104 
    105 # Find original index and the name of the original target
    106 original_comp_index = original_comp_names.index(comp.name)
--> 107 comp_target_name = original_comp_names[original_comp_index + int(comp.target_index)]
    109 # Find index of the original and target in modified instrument
    110 modified_comp_index = modified_comp_names.index(comp.name)

ValueError: invalid literal for int() with base 10: '+ 1'

It turns out that this is caused by the default value of a Source_simple parameter having a target_index=+1 as default value, which apparently gets converted to python as:

    # Comp instance source, placement and parameters
    source = instr.add_component('source','Source_simple', AT=['0', '0', '0'], AT_RELATIVE='origin', ROTATED=['0.0', '0.0', '0.0'], ROTATED_RELATIVE='origin')
    
    source.radius = '0.1'
    source.yheight = '0'
    source.xwidth = '0'
    source.dist = '0'
    source.focus_xw = '0.01'
    source.focus_yh = '0.01'
    source.E0 = '0'
    source.dE = '0'
    source.lambda0 = 'lambda'
    source.dlambda = '0.001'
    source.flux = '1'
    source.gauss = '0'
    source.target_index = '+ 1'

And apparently the space in between + and 1 in the last line gives issues.

Metadata

Metadata

Labels

McStasscriptIssues relating directly to using McStas from within McStasscriptpygen

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions