def element_to_bdsim(e):
"""Convert a pandas.Series representation onto a BDSim sequence element."""
bdsim = ""
if e.KEYWORD in ['MARKER', 'INSTRUMENT']:
bdsim = "{}: {};".format(e.name.replace('$', ''), "marker")
if e.KEYWORD in ['DRIFT', 'QUADRUPOLE', 'RBEND', 'SBEND']:
bdsim = "{}: {}, l={}*m".format(e.name.replace('$', ''), e.KEYWORD.lower(), e.L)
if e.get('BENDING_ANGLE') is not None and not np.isnan(e['BENDING_ANGLE']):
bdsim += f",angle=-{e['BENDING_ANGLE']}"
elif e.get('ANGLE') is not None and not np.isnan(e['ANGLE']):
bdsim += f",angle=-{e.get('ANGLE', 0)}"
else:
# Angle property not supported by the element or absent
bdsim += ""
#if pd.notnull(e['APERTYPE']):
# bdsim += ", aperture={}*m".format(str(e['APERTURE']).strip('[]'))
if pd.notnull(e.get('PLUG')) and pd.notnull(e.get('CIRCUIT')):
bdsim += ", {}={{{{ {} or '0.0' }}}}".format(e['PLUG'].lower(), e['CIRCUIT'])
bdsim += ';'
return bdsim
评论列表
文章目录