Skip to content

Element Selection Syntax #26

@ax3l

Description

@ax3l

I designed and then vibe-coded an implementation of a element selection syntax that I like in: BLAST-ImpactX/impactx#1182, BLAST-ImpactX/impactx#1183 and follow-ups.

lattice = [...]  # your PALS lattice, e.g., read from a file or generated by a function

# Filter by element type
drift_elements = lattice.select(kind="Drift")
quad_elements = lattice.select(kind=elements.Quad)

# Filter by regex pattern
all_quads = lattice.select(kind=r".*Quad")  # matches Quad, ChrQuad, ExactQuad

# Filter by name
specific_elements = lattice.select(name="quad1")

# Chain filters (AND logic)
drift_named_d1 = lattice.select(kind="Drift").select(name="drift1")

# Position filtering (overlap logic)
early_elements = lattice.select(s=(None, 2.0))  # Elements overlapping s <= 2.0

# Chaining: s always calculated from original lattice
drift_then_early = lattice.select(kind="Drift").select(s=(1.0, 3.0))  # Drift AND overlapping s=[1.0,3.0]

# Modify original elements through references
drift_elements[0].ds = 2.0  # modifies original lattice

We could and should add something like this to PALS Python to make this library user-friendly for lattice manipulations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    element kindsbeamline elements & segments/lineselement parameterselement parameters (properties, attributes)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions