at.load.utils#

Conversion utilities for creating pyat elements.

Functions

element_from_dict(elem_dict[, index, quiet])

Builds an Element from a dictionary of attributes.

element_to_dict(el[, encoder])

find_class(elem, *[, index, quiet])

Deduce the class of an element from its attributes.

keep_attributes(ring)

Remove Lattice attributes which must not be saved on file.

keep_elements(ring)

Remove the 'RingParam' Marker.

protect(string[, fence, placeholder])

restore(replmatch, *parts)

show_under(key)

Restore leading underscores in attribute names.

split_ignoring_parentheses(string[, ...])

Split a string while keeping protected expressions intact.

Classes

RingParam(FamName, Energy, Periodicity, **kwargs)

Private class for Matlab RingParam element.

element_from_dict(elem_dict, index=None, quiet=False)[source]#

Builds an Element from a dictionary of attributes.

Parameters:
  • elem_dict (dict) – Dictionary of element attributes

  • index (int | None) – Element index in the lattice

  • quiet (bool) – Suppress the warning for undefined classes

Returns:

elem (Element) – new Element

element_to_dict(el, encoder=<function <lambda>>)[source]#
find_class(elem, *, index=None, quiet=False)[source]#

Deduce the class of an element from its attributes.

find_class tries to deduce the class from “FamName”, from “PassMethod”, and finally form the element contents.

Parameters:
  • elem (dict) – Dictionary of element attributes.

  • quiet (bool) – Suppress the warning for non-standard classes

  • index (int | None) – Element index in the lattice

Returns:

element_class – The guessed Class name

keep_attributes(ring)[source]#

Remove Lattice attributes which must not be saved on file.

keep_elements(ring)[source]#

Remove the ‘RingParam’ Marker.

protect(string, fence=('"', '"'), *, placeholder='placeholder')[source]#
restore(replmatch, *parts)[source]#
show_under(key)[source]#

Restore leading underscores in attribute names.

split_ignoring_parentheses(string, delimiter=',', fence=('\\(', '\\)'), maxsplit=-1)[source]#

Split a string while keeping protected expressions intact.

Example: “l=0,hom(4,0.0,0)” -> [“l=0”, “hom(4,0.0,0)”]