at.load.mad8#

Using MAD8 files with PyAT#

Using MAD8 files is similar to using MAD-X files: see the MAD-X documentation

Functions

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

Create a Lattice from MAD8 files

save_mad8(ring[, filename])

Save a Lattice as a MAD8 file

Classes

Mad8Parser(**kwargs)

MAD-X specific parser

class Mad8Parser(**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.Mad8Parser()
>>> 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 – If False, assign 0 to undefined variables

  • verbose – If True, print details on the processing

  • **kwargs – Initial variable definitions

clear()#

Clear the database: remove all parameters and objects

evaluate(expr)#

Evaluate the right side of an expression

Parameters:

expr (str) – expression to evaluate

Returns:

value – evaluated expression

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

Set of ignored commands

property missing#

Set of missing definitions

property sequences#

List of available sequences or lines

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

Create a Lattice from MAD8 files

  • The energy and particle of the generated lattice are taken from the MAD8 BEAM object, using the MAD8 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 MAD8 files

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

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

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

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

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

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

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

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

Returns:

lattice (Lattice) – New Lattice object

save_mad8(ring, filename=None, **kwargs)[source]#

Save a Lattice as a MAD8 file

Parameters:
  • ring (Lattice) – lattice

  • filename (str | None) – file to be created. If None, write to sys.stdout

Keyword Arguments:
  • use (str | None) – name of the created SEQUENCE of LINE. Default: name of the PyAT lattice

  • use_line (bool) – If True, use a MAD “LINE” format. Otherwise, use a MAD “SEQUENCE”