forked from ax3l/pydantic-mad
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
element kindsbeamline elements & segments/linesbeamline elements & segments/lineselement parameterselement parameters (properties, attributes)element parameters (properties, attributes)
Description
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 latticeWe could and should add something like this to PALS Python to make this library user-friendly for lattice manipulations.
Metadata
Metadata
Assignees
Labels
element kindsbeamline elements & segments/linesbeamline elements & segments/lineselement parameterselement parameters (properties, attributes)element parameters (properties, attributes)