PALSParserJ

PALSParserJ is a Julia parser for the Particle Accelerator Lattice Standard (PALS). It reads PALS-format lattice files, performs lattice expansion, and translates lattices into SciBmad, Bmad and MAD-X formats.

Under the hood, the package is a thin Julia wrapper around the C library built by PALSParserCpp (a rapidyaml backend). A parsed document is a tree of YAMLNode values that you index and mutate with familiar Julia idioms (node["key"], node[i], haskey, keys, length, iteration).

What it does

  1. Parse PALS-format YAML into a YAMLNode tree, or build one from scratch — see Parsing and writing YAML.

  2. Expand a lattice — read a lattice file, resolve its includes, and expand the line into an ordered list of elements — see Reading and expanding lattices.

  3. Evaluate the mathematical expressions in the expanded lattice to numbers — see Evaluating expressions.

  4. Translate a PALS lattice to SciBmad, Bmad or MAD-X format — see Translating to SciBmad, Bmad and MAD-X.

The complete docstring reference is in the API Reference (linked in the sidebar).

Quick example

import PALSParserJ as pj

# Read a lattice file and expand it.
lat = pj.parse_and_expand_pals("ex.pals.yaml")

println(pj.to_yaml_string(lat.full_expanded))  # the expanded root lattice as YAML
println(pj.to_yaml_string(lat.adjunct))       # everything else in the document

# Build a document from scratch and write it out.
root = pj.create_empty_tree()
server = pj.add_map!(root; key = "server")
server["host"] = "localhost"
server["port"] = "8080"

pj.write_yaml(root, "config.pals.yaml")