Skip to main content

pals2cosy

Convert PALS lattice files to COSY INFINITY input code.

Supports the official PALS format (PALS: root with facility:/line: composition) with auto-detection from the root key. Also accepts a flat beamline: format with positioned elements.

Installation

pip install pals2cosy

Or for development:

pip install -e .

Requires Python 3.9+ and PyYAML (for YAML input).

Usage

# PALS FODO cell (auto-detected from PALS: root key)
pals2cosy examples/fodo.pals.yaml --ke 1000 --particle proton

# Write to file with fringe fields
pals2cosy beamline.pals.yaml -o output.fox --ke 40 --fr 1

# Select a specific BeamLine from the facility
pals2cosy lattice.pals.yaml --beamline fodo_cell --ke 1000

# Compute Twiss parameters (periodic lattices only)
pals2cosy lattice.pals.yaml --ke 1000 --particle proton --twiss

Options

Flag Default Description
-o FILE stdout Output FOX file
--ke FLOAT from lattice Kinetic energy (MeV)
--fr INT 0 Fringe field order (0=none, 1=Enge, 2=symplectic, 3=high-precision Enge)
--order INT 3 DA computation order
--dim INT 3 Phase-space dimensions (2 or 3)
--quad-aperture FLOAT 0.027 Quadrupole bore diameter (m)
--particle STR from lattice Particle type (see Supported particles)
--twiss off Append GT Twiss extraction (requires periodic lattice)
--mode STR auto Input format override
--beamline NAME last BeamLine to expand (official PALS only)
--no-comments off Omit element name comments in FOX output

Input format

PALS:
  version: null
  facility:
    - q1:
        kind: Quadrupole
        length: 1.0
        MagneticMultipoleP:
          Bn1: 1.0           # Pole-tip field (Tesla)
    - b1:
        kind: SBend
        length: 2.0
        BendP:
          g_ref: 0.5         # Bend strength (1/m)
          e1: 0.1            # Entrance edge angle (radians)
          e2: 0.2            # Exit edge angle (radians)
    - my_line:
        kind: BeamLine
        line:
          - q1
          - b1

See examples/fodo.pals.yaml for a complete FODO cell with inherit: and repeat:.

Element mapping

Input type FOX command Notes
Quadrupole (Bn1) MQ L Bn1 r ; Direct pole-tip field
Quadrupole (current) MQ L {±G·I·r} r ; Sign from polarity
Sextupole (Bn2) MH L Bn2 r ; Drift if Bn2 absent
Octupole (Bn3) MO L Bn3 r ; Drift if Bn3 absent
Multipole (Bn1–Bn5) M5 L BQ BH BO BD BZ r ; Up to dodecapole; drift if all absent
Solenoid (Bz) CMS Bz D L ; Drift if Bz absent
RFCavity RF V 0 W PHI D ; Drift if voltage/frequency absent
Wiggler/Undulator WI B K L D 0 0 0 ; Drift if field/period absent
SBend/RBend (no Enge) DIL L θ g/2 e₁ 0 e₂ 0 ;
SBend/RBend (with Enge) FC ..; DIL ..; FD ;
SBend (negative angle) CB ; DIL ..; CB ;
BPM/OTR/Corrector (skipped) Zero-length

Supported particles

Name FOX command Notes
electron RPE Preset
proton RPP Preset
muon, mu- RPMU μ⁻ preset
mu+, antimuon RP μ⁺ via generic RP (RPMU hardcodes charge −1)
pion+, pi+ RPPI E 1 Preset with charge
pion-, pi- RPPI E -1 Preset with charge
positron RP Generic
antiproton RP Generic
deuteron RP Generic
alpha RP Generic (⁴He²⁺)
carbon12 RP Generic (¹²C⁶⁺)

Known limitations

  • Drift fallback: All active elements fall back to drifts when their field parameters are absent.
  • Enge coefficients: Maximum 6 coefficients per fringe field (COSY INFINITY FC command limit). Longer coefficient lists are truncated with a warning.
  • Quad sign convention: The current-based quadrupole path (±G·I·r) uses an electron-specific sign convention (QPF→negative B, QPD→positive B). Proton beamlines should use Bn1 (pole-tip field) instead, which bypasses the sign logic.

Roadmap

pals2cosy implements provisional support for element types and parameters that are present in COSY INFINITY but not yet part of the official PALS specification, such as MagneticMultipoleP.Bn2Bn5, SolenoidP.Bz, and RFCavityP. As a documented PALS use case, these extensions may inform future PALS standardization. If PALS adopts a different parameterization, pals2cosy can be adjusted accordingly.

Planned extensions:

  • Combined-function magnets (dipole + multipole fields → COSY MC/MS)
  • Electrostatic deflectors (EC, ECL, ES)
  • Skew multipoles (MMS, EMS)
  • Particle tracking (SR + TR + PRAY/WRAY)
  • FIT optimization blocks

Acknowledgments

This work was supported in part by DOE EPSCoR Award DE-SC0025583. The converter is based in part on research performed on the University of Hawaiʻi free electron laser by the author.

Tests

pip install pytest
pytest tests/ -v

Release files for pals2cosy 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pals2cosy 0.4.2
File Size Uploaded
pals2cosy-0.4.2.tar.gz 34.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pals2cosy 0.4.2
File Interpreter ABI Platform
pals2cosy-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 54.7 kB

Release files / pals2cosy-0.4.2.tar.gz

Download URL pals2cosy-0.4.2.tar.gz
Size 34.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b2d272948a796f0923708657464e16e7dc167802ca2547e601cb9ed45a954262
BLAKE2b-256 checksum
How to use checksums
ccc1bcdd0d32b2e5384a3e8909e6bcc1dafe6b74d84d701183ad45bae9a21a89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / pals2cosy-0.4.2-py3-none-any.whl

Download URL pals2cosy-0.4.2-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10fe8f44a44c83be14d7184d29cff452b7d8dc7b2159832d989a1a4e08ae3a22
BLAKE2b-256 checksum
How to use checksums
83e0d1a67357f617f4ac065bad7c183db577fc1f90b4ced3887fbf6e7bac3579
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page