Line helpers

xtrack_tools.line.resolve_element_name(line, element_name)[source]

Return the line’s canonical name for element_name (case-insensitive).

Element names in the xsuite line are lower case, while callers commonly use the upper-case MAD-X convention (e.g. MKQA.6L4.B1). Match on a case-insensitive basis and return the actual name stored in the line.

Parameters:
  • line (xt.Line)

  • element_name (str)

Return type:

str

xtrack_tools.line.get_element_s_centre(line, element_name, table=None)[source]

Return the longitudinal position of an element in a line.

Parameters:
  • line (xt.Line)

  • element_name (str)

  • table (Any | None)

Return type:

float

xtrack_tools.line.get_explicit_element_s_centre(line, element_name)[source]

Return the source-resolved centre position when the line retains one.

MAD-X sequence import preserves placement definitions in the line composer. Once materialised, a line stores intervening drifts and its table reconstructs s by summation, which can differ by a few ulps from the source-resolved coordinate. This uses the composer’s own resolver rather than inspecting placement implementation details. A line without a composer has no retained source-placement result, so callers must use get_element_s_centre() instead.

Parameters:
  • line (xt.Line)

  • element_name (str)

Return type:

float | None

xtrack_tools.line.next_available_element_name(line, base_name)[source]

Return an element name that is unused in both the line and its environment.

Parameters:
  • line (xt.Line)

  • base_name (str)

Return type:

str

xtrack_tools.line.make_element_thin(line, element_name, length_tol=1e-12)[source]

Collapse a thick element to a zero-length marker at its centre, in place.

The thick body is preserved as an equal-length drift so the lattice length and downstream optics are unchanged, while a zero-length xt.Marker keeps the original element name and sits at the element centre. This pins the element’s Twiss row to its centre, which is where point-like insertions (a single-turn kick, an AC dipole) actually act — reading optics from the original thick element’s entry row would otherwise be off by half its length.

The element’s own transfer map is discarded (replaced by a drift), so this is intended for passive position markers such as tkickers and AC-dipole markers that carry no active strength in the optics. Elements already thin (within length_tol) are left untouched.

Parameters:
  • line (xt.Line) – Line to modify in place.

  • element_name (str) – Name of the element to thin (case-insensitive).

  • length_tol (float) – Elements with absolute length at or below this threshold are treated as already thin and returned unchanged.

Returns:

The canonical (line) name of the now-thin element.

Raises:

ValueError – If element_name is not present in the line.

Return type:

str