at.load.utils#

Conversion utilities for creating pyat elements

Functions

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

Builds an Element from a dictionary of attributes

element_from_m(line)

Builds an Element from a line in an m-file

element_from_string(elem_string)

Builds an Element from its python repr() string

element_to_dict(elem)

Builds the Matlab structure of an Element

element_to_m(elem)

Builds the Matlab-evaluable string for an Element

find_class(elem_dict[, quiet, index])

Identify the class of an element from its attributes

find_class_name(elem_dict[, quiet])

Derive the class name of an Element from its attributes

hasattrs(kwargs, *attributes)

Checks the presence of keys in a dict

split_ignoring_parentheses(string, delimiter)

Classes

RingParam(name, energy[, periodicity, particle])

Private class for Matlab RingParam element

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_from_m(line)[source]#

Builds an Element from a line in an m-file

Parameters:

line (str) – Matlab string representation of an Element

Returns:

elem (Element) – new Element

element_from_string(elem_string)[source]#

Builds an Element from its python repr() string

Parameters:

elem_string (str) – String representation of an Element

Returns:

elem (Element) – new Element

element_to_dict(elem)[source]#

Builds the Matlab structure of an Element

Parameters:

elem (Element) – Element

Returns:

dct (dict) – Dictionary of Element attributes

element_to_m(elem)[source]#

Builds the Matlab-evaluable string for an Element

Parameters:

elem (Element) – Element

Returns:

mstr (str) – Matlab string representation of the Element attributes

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

Identify the class of an element from its attributes

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

find_class_name(elem_dict, quiet=False)[source]#

Derive the class name of an Element from its attributes

hasattrs(kwargs, *attributes)[source]#

Checks the presence of keys in a dict

Returns True if any of the attributes is in kwargs

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

  • attributes – A list of strings, the attribute names to be checked.

Returns:

found (bool) – True if the element has any of the specified attributes.

split_ignoring_parentheses(string, delimiter)[source]#