at.lattice.elements.element_object#

Base Element object

Classes

Element(family_name, **kwargs)

Base class for AT elements

class Element(family_name, **kwargs)[source]#

Bases: object

Base class for AT elements

Parameters:

family_name (str) – Name of the element

All keywords will be set as attributes of the element

classmethod get_subclasses()[source]#

Iterator over the subclasses of this element

Because of multiple inheritance, some classes may appear several times

static from_dict(elem_dict, index=None, check=True, quiet=False)#

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

copy()[source]#

Return a shallow copy of the element

deepcopy()[source]#

Return a deep copy of the element

divide(frac)[source]#

split the element in len(frac) pieces whose length is frac[i]*self.Length

Parameters:

frac – length of each slice expressed as a fraction of the initial length. sum(frac) may differ from 1.

Returns:

elem_list – a list of elements equivalent to the original.

Example

>>> Drift("dr", 0.5).divide([0.2, 0.6, 0.2])
[Drift('dr', 0.1), Drift('dr', 0.3), Drift('dr', 0.1)]
equals(other)[source]#

Whether an element is equivalent to another.

This implementation was found to be too slow for the generic __eq__ method when comparing lattices.

is_compatible(other)[source]#

Checks if another Element can be merged

items()[source]#

Iterates through the data members

merge(other)[source]#

Merge another element

swap_faces(copy=False)[source]#

Swap the faces of an element, alignment errors are ignored

to_dict(encoder=<function _no_encoder>)#

Convert a Element to a dict

Parameters:
Returns:

dct (dict) – Dictionary of Element attributes

track(r_in, in_place=False, **kwargs)#

element_track() tracks particles through one element of a calling the element-specific tracking function specified in the Element’s PassMethod field

Usage:
>>> element_track(element, r_in)
>>> element.track(r_in)
Parameters:
  • element (Element) – element to track through

  • r_in – (6, N) array: input coordinates of N particles. For the best efficiency, r_in should be given as F_CONTIGUOUS numpy array.

Keyword Arguments:
  • in_place (bool) – If True r_in is modified in-place and reports the coordinates at the end of the element. (default: False)

  • omp_num_threads (int) – Number of OpenMP threads (default: automatic)

  • particle (Optional[Particle]) – circulating particle. Default: lattice.particle if existing, otherwise Particle('relativistic')

  • energy (Optiona[float]) – lattice energy. Default 0.

Returns:

r_out – (6, N, R, T) array containing output coordinates of N particles at R reference points for T turns

transform(reference=ReferencePoint.CENTRE, dx=None, dy=None, dz=None, tilt=None, pitch=None, yaw=None, *, relative=False)#

Set the translations and rotations of an Element.

The tilt is a rotation around the s-axis, the pitch is a rotation around the x-axis, and the yaw is a rotation around the y-axis.

A positive angle represents a clockwise rotation when looking in the direction of the rotation axis.

The transformations are not all commutative. The translations are applied before the rotations. The rotations are applied in the order Z -> Y -> X (tilt -> yaw -> pitch). The element is rotated around its mid-point. The mid-point can either be the element entrance or its centre (axis joining the entry and exit points of the element).

If relative is True, the previous translations and angles are rebuilt from the r3d matrix and incremented by the input arguments.

PyAT describes the ultra-relativistic beam dynamics in 6D phase space coordinates, which differ from 3D spatial angles in an expansion with respect to the energy to first order by a factor \((1 + \delta)\), where \(\delta\) is the relative momentum deviation. This introduces spurious dispersion (angle proportional to \(\delta\)).

The implementation follows the one described in: https://doi.org/10.1016/j.nima.2022.167487 All the comments featuring ‘Eq’ point to the paper’s equations.

Parameters:
  • elem (Element) – Element to be transformed.

  • reference (ReferencePoint) – Transformation reference, either ReferencePoint.CENTRE or ReferencePoint.ENTRANCE.

  • dx (float | None) – Horizontal shift [m]. Default: no change.

  • dy (float | None) – Vertical shift [m]. Default: no change.

  • dz (float | None) – Longitudinal shift [m]. Default: no change.

  • tilt (float | None) – Tilt angle [rad]. Default: no change.

  • pitch (float | None) – Pitch angle [rad]. Default: no change.

  • yaw (float | None) – Yaw angle [rad]. Default: no change

  • relative (bool) – If True, the input values are added to the previous ones.

Attention

When combining several transformations by using multiple calls to transform_elem(), the reference argument must be identical for all. Otherwise, the result is unpredictable.

See also

get_offsets_rotations()

update(**kwargs)[source]#
update(mapping, **kwargs) None
update(iterable, **kwargs) None

Update the element attributes with the given arguments

property definition: tuple[str, tuple, dict]#

tuple (class_name, args, kwargs) defining the element

property dx: float#

Horizontal element shift

property dy: float#

Vertical element shift

property dz: float#

Longitudinal element shift

property is_collective: bool#

True if the element involves collective effects

property longt_motion: bool#

True if the element affects the longitudinal motion

property tilt: float#

Element tilt