at.load.file_input#

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

Functions

set_argparser(argparser)

Decorator which adds an "argparser" attribute to a function

skip_class(classname, baseclass, **kwargs)

Generate a class for skipped elements.

ignore_class(classname, baseclass, **kwargs)

Generate a class for ignored elements.

skip_names(namespace, baseclass, classnames)

Add classes for ignored elements in the given namespace.

ignore_names(namespace, baseclass, classnames)

Add classes for ignored elements in the given namespace.

Classes

AnyDescr(*args, **kwargs)

Base class for source object descriptors

ElementDescr(*args[, origin])

Simple representation of an element as a dict

SequenceDescr(*args, **kwargs)

Simple representation of a sequence of elements as a list

BaseParser(env, *args[, strict, always_force])

Generic file parser

UnorderedParser(env, *args, **kwargs)

Parser allowing definitions in any order

LowerCaseParser(env, *args[, strict, ...])

Case independent parser

UpperCaseParser(env, *args[, strict, ...])

Case independent parser

DictNoDot(*args[, verbose])

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

Bases: object

Base class for source object descriptors

classmethod argparser(parser, argcount, argstr)[source]#

Specialised argument parser

expand(parser)[source]#

Iterator on the generated AT elements

inverted(copy=False)[source]#

Return a reversed element or line

update(*args, **kwargs)[source]#
bool_attr = ()#

list of names of bool attributes

pos_args = ()#

list of names of positional arguments

str_attr = ()#

list of names of str attributes

class BaseParser(env, *args, strict=True, always_force=True, **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

  • verbose – If True, print detail on the processing

  • strict (bool) – If False, assign 0 to undefined variables

  • *args – dict initializer

  • **kwargs – dict initializer

clear()[source]#

Clear the database: remove all parameters and objects

evaluate(expr)[source]#

Evaluate the right side of an expression

Parameters:

expr (str) – expression to evaluate

Returns:

value – evaluated expression

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 sequence or line containing the desired lattice. Default: ring

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

  • particle (Particle) – Circulating particle. Default: Particle(“relativistic”)

  • energy (float) – Energy of the lattice [eV]. Default: 1.0 GeV

  • 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

property ignored#

Set of ignored commands

property missing#

Set of missing definitions

property sequences#

List of available sequences or lines

class DictNoDot(*args, verbose=False, **kwargs)[source]#

Bases: dict

get(key, *args)[source]#

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

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

Bases: AnyDescr, dict

Simple representation of an element as a dict

static attr_format(value)[source]#
expand(parser)[source]#

Iterator on the generated AT elements

classmethod from_at(kwargs)[source]#
static meval(params)[source]#

Evaluation of superfluous parameters

to_at(*args, **params)[source]#

Generate the AT element. Must be overloaded for each specific element

array_fmt = {40: 123, 41: 125, 91: 123, 93: 125}#
at2mad = {'Length': 'L'}#
bool_fmt = None#
property length: float#

Element length

class LowerCaseParser(env, *args, strict=True, always_force=True, **kwargs)[source]#

Bases: BaseParser

Case independent parser

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

  • verbose – If True, print detail on the processing

  • strict (bool) – If False, assign 0 to undefined variables

  • *args – dict initializer

  • **kwargs – dict initializer

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

Bases: AnyDescr, list

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

  • verbose – If True, print detail on the processing

  • *args – dict initializer

  • **kwargs – dict initializer

class UpperCaseParser(env, *args, strict=True, always_force=True, **kwargs)[source]#

Bases: BaseParser

Case independent parser

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

  • verbose – If True, print detail on the processing

  • strict (bool) – If False, assign 0 to undefined variables

  • *args – dict initializer

  • **kwargs – dict initializer

ignore_class(classname, baseclass, **kwargs)[source]#

Generate a class for ignored elements.

Parameters:
  • classname (str) – Name of the generated class

  • baseclass (type[ElementDescr]) – Base class, must be a subclass of ElementDescr

  • **kwargs – dictionary of additional attributes and methods. See type().

Returns:

cls – Element class, converted to Marker or Drift when generating AT elements

ignore_names(namespace, baseclass, classnames)[source]#

Add classes for ignored elements in the given namespace.

Parameters:
set_argparser(argparser)[source]#

Decorator which adds an “argparser” attribute to a function

skip_class(classname, baseclass, **kwargs)[source]#

Generate a class for skipped elements.

Parameters:
  • classname (str) – Name of the generated class

  • baseclass (type[ElementDescr]) – Base class, must be a subclass of ElementDescr

  • **kwargs – dictionary of additional attributes and methods. See type().

Returns:

cls – Element class, skipped when generating AT elements

skip_names(namespace, baseclass, classnames)[source]#

Add classes for ignored elements in the given namespace.

Parameters: