Skip to main content

Convert PALS lattice files to COSY INFINITY FOX code

Project description

pals2cosy

Convert PALS lattice files to COSY INFINITY FOX 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pals2cosy-0.4.0.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pals2cosy-0.4.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file pals2cosy-0.4.0.tar.gz.

File metadata

  • Download URL: pals2cosy-0.4.0.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pals2cosy-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b0ac898cb11beb989baa7068ed8209d3f7567756f994facda883bb70f76f671d
MD5 a0bd97f4313b45eb7e3a2069ad405570
BLAKE2b-256 da9699bfb26e6ce954697dedcee4af896806b4cc6c1cea3fd3dc34f2bd0426fb

See more details on using hashes here.

File details

Details for the file pals2cosy-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pals2cosy-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pals2cosy-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd5c6f96ae8e3de58dade1f346104e48b11f112fbd09c85cf2b3aed4f251c812
MD5 84e0d416ea687b06e50a1e521675beeb
BLAKE2b-256 efd9ed5aa33f2034a1f59c3f39e0f4447cad5ed3066d4be4943b894b32cdf7c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page