Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dea69fa
- Updated schema.json to include marker
tomerten May 26, 2020
929b570
Automated Code Formatting using Black
felix-andreas May 26, 2020
e554b78
add newline to end of file
felix-andreas May 26, 2020
7ef86a5
Merge branch 'master' into add-markers-tom
felix-andreas May 28, 2020
b0e15da
add space to end of file
felix-andreas Jul 2, 2020
c83d039
Merge branch 'add-markers-tom' of https://github.com/nobeam/latticejs…
tomerten Jul 2, 2020
4fdc191
- updated example.json in test to include monitor
tomerten Jul 2, 2020
4f06242
Delete README.txt
felix-andreas Jul 2, 2020
3799c08
- added Monitor
Jul 2, 2020
aa9d286
- added marker to tests
Jul 2, 2020
b7f1751
- updated version number in examplewq
tomerten Jul 2, 2020
6bf5031
- added Hcor and Vcor
Jul 2, 2020
03f5c82
- corrected typo in schema.json
Jul 2, 2020
327d0b1
- corrected Kick to kick in hcor and vcor
Jul 2, 2020
f1279c0
Automated Code Formatting using Black
felix-andreas Jul 3, 2020
71d7c6a
- added kicker (non linear kicker in lattice)
Jul 3, 2020
9188328
Merge branch 'add-markers-tom' of https://github.com/nobeam/latticejs…
Jul 3, 2020
739de83
- cavity removed voltage from being required both madx and elegant have
Jul 3, 2020
bcca405
Merge branch 'add-markers-tom' of https://github.com/nobeam/latticejs…
Jul 3, 2020
9eaeabe
- Working version
Jul 3, 2020
5deb2f6
- added k1 to dipoles in order to be able to convert Ji-Gwuang his
Jul 3, 2020
6b69c50
Automated Code Formatting using Black
felix-andreas Jul 3, 2020
589fba7
* updated schema to include multipole for converting maxiv lattice
Jul 3, 2020
5b9c651
- moved array to madx transformer
Jul 3, 2020
b9ac171
Merge branch 'add-markers-tom' of https://github.com/nobeam/latticejs…
Jul 3, 2020
37da071
added various attrs for dipole kicker and cavity
Jul 16, 2020
4fc9b2d
Automated Code Formatting using Black
felix-andreas Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions b2_std_user_beamports_latest.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions latticejson/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Dict, List
from warnings import warn

from termcolor import colored

from .exceptions import UnknownAttributeWarning, UnknownElementTypeWarning
from .parse import parse_elegant, parse_madx
from .utils import sort_lattices
Expand Down Expand Up @@ -44,16 +46,26 @@ def from_madx(string):
def _map_names(lattice_data: dict, name_map: dict):
elements = {}
for name, (other_type, other_attributes) in lattice_data["elements"].items():

# print(colored(other_type, "red"))
# print(colored(other_attributes, "red"))
# print(colored(name_map, "green"))

latticejson_type = name_map.get(other_type)

# print(latticejson_type)
if latticejson_type is None:
elements[name] = ["Drift", {"length": other_attributes.get("L", 0)}]
warn(UnknownElementTypeWarning(name, other_type))
continue

attributes = {}
elements[name] = [latticejson_type, attributes]

for other_key, value in other_attributes.items():
# print(other_key, value)
latticejson_key = name_map.get(other_key)
# print(latticejson_key)
if latticejson_key is not None:
attributes[latticejson_key] = value
else:
Expand Down Expand Up @@ -108,7 +120,9 @@ def to_madx(latticejson: dict) -> str:
strings = [f"TITLE, \"{latticejson['title']}\";"]
element_template = "{}: {}, {};".format
# TODO: check if equivalent type exists in madx

for name, (type_, attributes) in elements.items():
print(name, "boeeee")
attrs = ", ".join(f"{TO_MADX[k]}={v}" for k, v in attributes.items())
elegant_type = TO_MADX[type_]
strings.append(element_template(name, elegant_type, attrs))
Expand Down
4 changes: 3 additions & 1 deletion latticejson/madx.lark
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ start : (_statement ";")*
_statement : element | lattice | command | assignment

element : word ":" [word] ("," attribute)* ","?
attribute : word ("=" | ":=") (expr | string)
attribute : word ("=" | ":=") (expr | string )


lattice : word ":" "LINE"i "=" arrangement
Expand All @@ -34,6 +34,8 @@ command : word ("," (word | string | attribute))*
assignment : word ("=" | ":=") expr -> assignment
?expr : item
| "{" expr ("," expr)* ","? "}" -> array
| function
!function : expr("atan")
?item : term
| expr "+" term -> add
| expr "-" term -> sub
Expand Down
319 changes: 301 additions & 18 deletions latticejson/map.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,305 @@
{
"description": "LatticeJSON, elegant, MADX",
"map": [
["Drift", ["DRIF", "DRIFT"], ["DRIFT"], ["DRIFT"]],
["Dipole", ["CSBEND", "SBEND", "BEND"], ["SBEND", "RBEND"]],
["Quadrupole", ["KQUAD", "QUAD", "QUADRUPOLE"], ["QUADRUPOLE"]],
["Sextupole", ["KSEXT", "SEXT", "SEXTUPOLE"], ["SEXTUPOLE"]],
["Octupole", ["KOCT", "OCTU"], ["OCTUPOLE"]],
["Cavity", ["RFCA"], ["RFCAVITY"]],
["Lattice", ["LINE"], ["LINE"]],
["length", ["L"], ["L"]],
["angle", ["ANGLE"], ["ANGLE"]],
["e1", ["E1"], ["E1"]],
["e2", ["E2"], ["E2"]],
["k1", ["K1"], ["K1"]],
["k2", ["K2"], ["K2"]],
["k3", ["K3"], ["K3"]],
["voltage", ["VOLT"], ["VOLT"]],
["frequency", ["FREQ"], ["FREQ"]],
["phase", ["PHASE"], ["LAG"]]
[
"Monitor",
[
"MONI"
],
[
"MONITOR"
]
],
[
"Marker",
[
"MARK"
],
[
"MARKER"
]
],
[
"Hcor",
[
"HKICK"
],
[
"HKICKER"
]
],
[
"Vcor",
[
"VKICK"
],
[
"VKICKER"
]
],
[
"Kicker",
[
"KICKER"
],
[
"KICKER"
]
],
[
"Drift",
[
"DRIF",
"DRIFT"
],
[
"DRIFT"
],
[
"DRIFT"
]
],
[
"Dipole",
[
"CSBEND",
"SBEND",
"BEND"
],
[
"SBEND",
"RBEND"
]
],
[
"Quadrupole",
[
"KQUAD",
"QUAD",
"QUADRUPOLE"
],
[
"QUADRUPOLE"
]
],
[
"Sextupole",
[
"KSEXT",
"SEXT",
"SEXTUPOLE"
],
[
"SEXTUPOLE"
]
],
[
"Octupole",
[
"KOCT",
"OCTU"
],
[
"OCTUPOLE"
]
],
[
"Multipole",
[
"MULT"
],
[
"MULTIPOLE"
]
],
[
"Cavity",
[
"RFCA"
],
[
"RFCAVITY"
]
],
[
"Lattice",
[
"LINE"
],
[
"LINE"
]
],
[
"length",
[
"L"
],
[
"L"
]
],
[
"angle",
[
"ANGLE"
],
[
"ANGLE"
]
],
[
"e1",
[
"E1"
],
[
"E1"
]
],
[
"e2",
[
"E2"
],
[
"E2"
]
],
[
"k1",
[
"K1"
],
[
"K1"
]
],
[
"k2",
[
"K2"
],
[
"K2"
]
],
[
"k3",
[
"K3"
],
[
"K3"
]
],
[
"voltage",
[
"VOLT"
],
[
"VOLT"
]
],
[
"frequency",
[
"FREQ"
],
[
"FREQ"
]
],
[
"phase",
[
"PHASE"
],
[
"LAG"
]
],
[
"knl",
[
"KNL"
],
[
"KNL"
]
],
[
"k1s",
[
"K1S"
],
[
"K1S"
]
],
[
"kick",
[
"KICK"
],
[
"KICK"
]
],
[
"order",
[
"ORDER"
],
[
"BOE"
]
],
[
"harmon",
[
""
],
[
"HARMON"
]
],
[
"no_cavity_totalpath",
[
""
],
[
"NO_CAVITY_TOTALPATH"
]
],
[
"h",
[
""
],
[
"H"
]
],
[
"hgap",
[
"HGAP"
],
[
"HGAP"
]
],
[
"fint",
[
"FINT"
],
[
"FINT"
]
]
]
}
}
Loading