File: ncrystal_union.py

package info (click to toggle)
python-mcstasscript 0.0.46%2Bgit20250402111921.bfa5a26-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,440 kB
  • sloc: python: 13,421; makefile: 14
file content (18 lines) | stat: -rw-r--r-- 785 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def add_ncrystal_union_material(instrument, name, cfgstr, split=False):
    try:
        import NCrystal.mcstasutils as NCms
    except ImportError or ModuleNotFoundError:
        raise RuntimeError("Install NCrystal to use this feature in McStasScript.")

    abs_info, ncrystal_processes = NCms.cfgstr_2_unioncfg(cfgstr=cfgstr, split_by_physics=split)

    process_names = []
    for process in ncrystal_processes:
        process_name = name + "_" + process[1]
        process_names.append(process_name)
        comp = instrument.add_component(process_name, "NCrystal_process")
        comp.cfg = '"' + process[0] + '"'

    comp = instrument.add_component(name, "Union_make_material")
    comp.my_absorption = abs_info
    comp.process_string = '"' + ",".join(process_names) + '"'