core.elements.element module

Define base Element, declined in Drift, FieldMap, etc.

Todo

clean the patch for the ‘name’. my has and get methods do not work with @property

class Element(line: list[str], dat_idx: int, name: str | None = None, **kwargs: str)

Bases: Instruction

Generic element.

base_name

Short name for the element according to TraceWin. Should be overriden. The default is "ELT".

Type:

str, optional

increment_elt_idx

If the element should be considered when counting the elements. If False, elt_idx will keep its default value of -1. The default is True. As for now, there is no element with this attribute set to False.

Type:

bool, optional

increment_lattice_idx

If the element should be considered when determining the lattice. Should be True for physical elements, such as DRIFT, and False for other elements such as DIAGNOSTIC. The default is True.

Type:

bool, optional

__init__(line: list[str], dat_idx: int, name: str | None = None, **kwargs: str) None

Init parameters common to all elements.

Parameters:
  • line (list[str]) – A line of the .dat file. If the element was given a name, it must not appear in line but rather in name. First element of the list must be in IMPLEMENTED_ELEMENTS.

  • dat_idx (int) – Position in the .dat file.

  • name (str | None, optional) – Non-default name of the element, as given in the .dat file. The default is None, in which case an automatic name will be given later.

_abc_impl = <_abc._abc_data object>
base_name = 'ELT'
property can_be_retuned: bool

Tell if we can modify the element’s tuning.

Will return False by default.

get(*keys: str, to_numpy: bool = True, **kwargs: bool | str | None) Any

Shorthand to get attributes from this class or its attributes.

Parameters:
  • *keys (str) – Name of the desired attributes.

  • to_numpy (bool, optional) – If you want the list output to be converted to a np.ndarray. The default is True.

  • **kwargs (bool | str | None) – Other arguments passed to recursive getter.

Returns:

out – Attribute(s) value(s).

Return type:

Any

has(key: str) bool

Tell if the required attribute is in this class.

increment_elt_idx = True
increment_lattice_idx = True
property is_accelerating: bool

Say if this element is accelerating or not.

Will return False by default.

is_implemented: bool = True
keep_cavity_settings(cavity_settings: CavitySettings) None

Save data calculated by BeamCalculator.run_with_this().

keep_rf_field(*args, **kwargs) None

Save data calculated by BeamCalculator.run_with_this().

Deprecated since version 0.6.16: Prefer keep_cavity_settings()

update_status(new_status: str) None

Change the status of the element. To override.