at.load.file_input#

Generic text parsers for conversion of lattices in different formats to AT

Classes

AnyDescr(*args, **kwargs)

Base class for source object descriptors

ElementDescr(*args, **kwargs)

Simple representation of an element as a dict

SequenceDescr(*args, **kwargs)

Simple representation of a sequence of elements as a list

BaseParser(env, *args[, delimiter, ...])

Generic file parser

UnorderedParser(env, *args, **kwargs)

parser allowing definitions in any order

DictNoDot

class AnyDescr(*args, **kwargs)[source]#

Bases: ABC

Base class for source object descriptors

abstract expand(parser)[source]#

Iterator on the possibly inverted sequence of elements

inverted(copy=False)[source]#

Return a reversed element or line

update(*args, **kwargs)[source]#
class BaseParser(env, *args, delimiter=None, continuation='\\', linecomment='#', blockcomment=None, endfile=None, verbose=False, **kwargs)[source]#

Bases: DictNoDot

Generic file parser

Analyses files with the following MAD-like format:

variable = value

label : command [,attribute=value] [,attribute=value]...

The parser builds a database of all the defined objects

Parameters:
  • env (dict) – global namespace used for evaluating commands

  • delimiter (str | None) – command delimiter

  • continuation (str) – command continuation character

  • linecomment (str | tuple[str] | None) – Line comment character

  • blockcomment (tuple[str, str] | None) – Block comment delimiter

  • endfile (str | None) – “End of input” marker

  • verbose (bool) – If True, print detail on the processing

  • *args – dict initializer

  • **kwargs – dict initializer

clear()[source]#

Clean the database

evaluate(expr)[source]#

Evaluate an expression using self as local namespace

expand(key)[source]#

iterator over AT objects generated by a source object

lattice(use='ring', **kwargs)[source]#

Create a lattice from the selected sequence

Parameters:

use – Name of the MADX sequence or line containing the desired lattice. Default: ring

Keyword Arguments:
  • name (str) – Name of the lattice. Default: MADX sequence name.

  • particle (Particle) – Circulating particle. Default: from MADX

  • energy (float) – Energy of the lattice [eV], Default: from MADX

  • periodicity (int) – Number of periods. Default: 1

  • * – All other keywords will be set as Lattice attributes

parse_files(*filenames, final=True, prolog=None, epilog=None, **kwargs)[source]#

Process files and fill the database

Parameters:
  • *filenames (str) – Files to process

  • final (bool) – If True, signals that the undefined variables may be set to the default value

  • prolog (None | int | Callable[..., None])

  • epilog (Callable[..., None] | None)

  • **kwargs – Initial variable definitions

parse_lines(lines, final=True, **kwargs)[source]#

Process input lines and fill the database

Parameters:
  • lines (Iterable[str]) – Iterable of input lines

  • final (bool) – If True, signals that the undefined variables may be set to the default value

  • **kwargs – Initial variable definitions

class DictNoDot[source]#

Bases: dict

get(key, *args)[source]#

Return the value for key if key is in the dictionary, else default.

class ElementDescr(*args, **kwargs)[source]#

Bases: AnyDescr, dict

Simple representation of an element as a dict

static convert(name, *args, **params)[source]#

Generate the AT element, Most be overloaded for each specific element

expand(parser)[source]#

Iterator on the possibly inverted sequence of elements

property length: float#

Element length

class SequenceDescr(*args, **kwargs)[source]#

Bases: AnyDescr, list, ABC

Simple representation of a sequence of elements as a list

property length: float#
class UnorderedParser(env, *args, **kwargs)[source]#

Bases: BaseParser

parser allowing definitions in any order

This is done by storing the failed statements in a queue and iteratively trying to execute them after all input statements have been processed, until the number of failures is constant (hopefully zero)

Parameters:
  • env (dict) – global namespace

  • delimiter – command delimiter

  • continuation – command continuation character

  • linecomment – Line comment character

  • blockcomment – Block comment delimiter

  • endfile – End of input marker

  • verbose – If True, print detail on the processing

  • *args – dict initializer

  • **kwargs – dict initializer

clear()[source]#

Clean the database

property missing#

Set of missing definitions