at.load.madx#

Load a lattice from a MADX file (.seq).

Functions

load_madx(*files[, use, strict, verbose])

Create a Lattice from MAD-X files

Classes

MadxParser(*[, strict, verbose])

MAD-X specific parser

class MadxParser(*, strict=True, verbose=False, **kwargs)[source]#

Bases: _MadParser

MAD-X specific parser

The parser is a subclass of dict and is database containing all the MAD-X variables.

Example

Parse a 1st file:

>>> parser = at.MadxParser()
>>> parser.parse_file("file1")

Parse another file:

>>> parser.parse_file("file2")

Get the variable “vkick”

>>> parser["vkick"]
0.003

Define a new variable:

>>> parser["hkick"] = -0.0024

Get the “qf1” element

>>> parser["qf1"]
quadrupole(name=qf1, l=1.0, k1=0.5, tilt=0.001)

Generate an AT Lattice from the “ring” sequence

>>> ring = parser.lattice(use="ring")  # generate an AT Lattice
Parameters:
  • strict (bool) – If False, assign 0 to undefined variables

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

  • **kwargs – Initial variable definitions

clear()#

Clean the database

evaluate(expr)[source]#

Evaluate an expression using self as local namespace

expand(key)#

iterator over AT objects generated by a source object

lattice(use='ring', **kwargs)#

Create a lattice from the selected sequence

Parameters:

use (str) – Name of the MAD sequence or line containing the desired lattice. Default: ring

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

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

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

  • 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)#

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)#

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 missing#

Set of missing definitions

property sequences#

List of available sequences or lines

load_madx(*files, use='ring', strict=True, verbose=False, **kwargs)[source]#

Create a Lattice from MAD-X files

  • The energy and particle of the generated lattice are taken from the MAD-X BEAM object, using the MAD-X default parameters: positrons at 1 Gev. These parameters are overloaded by the value given in the energy and particle keyword arguments.

  • The radiation state is given by the RADIATE flag of the BEAM object, using the AT defaults: RF cavities active, synchrotron radiation in dipoles and quadrupoles.

  • Long elements are split according to the default AT value for NumIntSteps (10).

Parameters:
  • files (str) – Names of one or several MAD-X files

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

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

  • verbose – If True, print details on the processing

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

  • * – Other keywords will be used as initial variable definitions

Returns:

lattice (Lattice) – New Lattice object

See also

load_lattice() for a generic lattice-loading function.