at.load.utils#

Conversion utilities for creating pyat elements

Functions

element_classes()

Build a set of all Element subclasses

element_from_dict(elem_dict[, index, check, ...])

Builds an Element from a dictionary of attributes

element_to_dict(elem[, encoder])

Convert a Element to a dict

find_class(elem_dict[, quiet, index])

Deduce the class of an element from its attributes

keep_elements(ring)

Remove the 'RingParam' Marker

keep_attributes(ring)

Remove Lattice attributes which must not be saved on file

split_ignoring_parentheses(string[, ...])

Split a string while keeping protected expressions intact

protect(string[, fence])

restore(matches, *parts)

Classes

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

Private class for Matlab RingParam element

element_classes()[source]#

Build a set of all Element subclasses

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

Builds an Element from a dictionary of attributes

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

  • index (int | None) – Element index

  • check (bool) – Check the compatibility of class and PassMethod

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

Returns:

elem (Element) – new Element

element_to_dict(elem, encoder=<function _no_encoder>)[source]#

Convert a Element to a dict

Parameters:
Returns:

dct (dict) – Dictionary of Element attributes

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

Deduce the class of an element from its attributes

find_class looks first at the “Class” field, if existing. It then tries to deduce the class from “FamName”, from “PassMethod”, and finally form the element contents.

Parameters:
  • elem_dict (dict) – The dictionary of keyword arguments passed to the Element constructor.

  • 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=('"', '"'))[source]#
restore(matches, *parts)[source]#
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)”]