Working with Lattices¶
In [1]:
Copied!
import genesis.version4 as g4
%config InlineBackend.figure_format = 'retina' # Nicer plots
import genesis.version4 as g4
%config InlineBackend.figure_format = 'retina' # Nicer plots
Load an existing lattice file¶
You can load an existing Genesis4-format Lattices input directly from a file by using from_file
:
In [2]:
Copied!
lat = g4.Lattice.from_file("data/basic4/hxr.lat")
lat = g4.Lattice.from_file("data/basic4/hxr.lat")
In [3]:
Copied!
lat.elements
lat.elements
Out[3]:
{'QHXH17': Quadrupole(L=0.101, k1=1.78), 'QHXH18': Quadrupole(L=0.101, k1=-1.78), 'QHXH19': Quadrupole(L=0.101, k1=1.78), 'QHXH20': Quadrupole(L=0.101, k1=-1.78), 'QHXH21': Quadrupole(L=0.101, k1=1.78), 'QHXH22': Quadrupole(L=0.101, k1=-1.78), 'QHXH23': Quadrupole(L=0.101, k1=1.78), 'QHXH24': Quadrupole(L=0.101, k1=-1.78), 'QHXH25': Quadrupole(L=0.101, k1=1.78), 'QHXH26': Quadrupole(L=0.101, k1=-1.78), 'QHXH27': Quadrupole(L=0.101, k1=1.78), 'QHXH28': Quadrupole(L=0.101, k1=-1.78), 'QHXH29': Quadrupole(L=0.101, k1=1.78), 'QHXH30': Quadrupole(L=0.101, k1=-1.78), 'QHXH31': Quadrupole(L=0.101, k1=1.78), 'QHXH32': Quadrupole(L=0.101, k1=-1.78), 'QHXH33': Quadrupole(L=0.101, k1=1.78), 'QHXH34': Quadrupole(L=0.101, k1=-1.78), 'QHXH35': Quadrupole(L=0.101, k1=1.78), 'QHXH36': Quadrupole(L=0.101, k1=-1.78), 'QHXH37': Quadrupole(L=0.101, k1=1.78), 'QHXH38': Quadrupole(L=0.101, k1=-1.78), 'QHXH39': Quadrupole(L=0.101, k1=1.78), 'QHXH40': Quadrupole(L=0.101, k1=-1.78), 'QHXH41': Quadrupole(L=0.101, k1=1.78), 'QHXH42': Quadrupole(L=0.101, k1=-1.78), 'QHXH43': Quadrupole(L=0.101, k1=1.78), 'QHXH44': Quadrupole(L=0.101, k1=-1.78), 'QHXH45': Quadrupole(L=0.101, k1=1.78), 'QHXH46': Quadrupole(L=0.101, k1=-1.78), 'QHXH47': Quadrupole(L=0.101, k1=1.78), 'QHXH48': Quadrupole(L=0.101, k1=-1.78), 'QHXH49': Quadrupole(L=0.101, k1=1.78), 'QHXH50': Quadrupole(L=0.101, k1=-1.78), 'UMAHXH17': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH18': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH19': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH20': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH21': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH22': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH23': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH25': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH26': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH27': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH28': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH29': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH30': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH31': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH33': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH34': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH35': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH36': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH37': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH38': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH39': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH40': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH41': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH42': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH43': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH44': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH45': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH46': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH47': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH48': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH49': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH50': Undulator(aw=1.7017, lambdau=0.026, nwig=130), 'CORR00': Corrector(L=0.001), 'CORR01': Corrector(L=0.001), 'CORR02': Corrector(L=0.001), 'CORR03': Corrector(L=0.001), 'CORR04': Corrector(L=0.001), 'CORR05': Corrector(L=0.001), 'CORR06': Corrector(L=0.001), 'CORR07': Corrector(L=0.001), 'CORR08': Corrector(L=0.001), 'CORR09': Corrector(L=0.001), 'CORR10': Corrector(L=0.001), 'CORR11': Corrector(L=0.001), 'CORR12': Corrector(L=0.001), 'CORR13': Corrector(L=0.001), 'CORR14': Corrector(L=0.001), 'CORR15': Corrector(L=0.001), 'CORR16': Corrector(L=0.001), 'CORR17': Corrector(L=0.001), 'CORR18': Corrector(L=0.001), 'CORR19': Corrector(L=0.001), 'CORR20': Corrector(L=0.001), 'CORR21': Corrector(L=0.001), 'CORR22': Corrector(L=0.001), 'CORR23': Corrector(L=0.001), 'CORR24': Corrector(L=0.001), 'CORR25': Corrector(L=0.001), 'CORR26': Corrector(L=0.001), 'CORR27': Corrector(L=0.001), 'CORR28': Corrector(L=0.001), 'CORR29': Corrector(L=0.001), 'CORR30': Corrector(L=0.001), 'CORR31': Corrector(L=0.001), 'CORR32': Corrector(L=0.001), 'CORR33': Corrector(L=0.001), 'D1': Drift(L=0.1335), 'D2': Drift(L=0.4615), 'D3': Drift(L=0.328), 'D4': Drift(L=3.4), 'HXRSS': Chicane(L=4.55, lb=0.1), 'HXR': Line( elements=[ 'D1', 'UMAHXH17', 'D2', 'QHXH17', 'CORR00', 'D3', 'D1', 'UMAHXH18', 'D2', 'QHXH18', 'CORR01', 'D3', 'D1', 'UMAHXH19', 'D2', 'QHXH19', 'CORR02', 'D3', 'D1', 'UMAHXH20', 'D2', 'QHXH20', 'CORR03', 'D3', 'D1', 'UMAHXH21', 'D2', 'QHXH21', 'CORR04', 'D3', 'D1', 'UMAHXH22', 'D2', 'QHXH22', 'CORR05', 'D3', 'D1', 'UMAHXH23', 'D2', 'QHXH23', 'CORR06', 'D3', 'D1', 'HXRSS', 'D2', 'QHXH24', 'CORR07', 'D3', 'D1', 'UMAHXH25', 'D2', 'QHXH25', 'CORR08', 'D3', 'D1', 'UMAHXH26', 'D2', 'QHXH26', 'CORR09', 'D3', 'D1', 'UMAHXH27', 'D2', 'QHXH27', 'CORR10', 'D3', 'D1', 'UMAHXH28', 'D2', 'QHXH28', 'CORR11', 'D3', 'D1', 'UMAHXH29', 'D2', 'QHXH29', 'CORR12', 'D3', 'D1', 'UMAHXH30', 'D2', 'QHXH30', 'CORR13', 'D3', 'D1', 'UMAHXH31', 'D2', 'QHXH31', 'CORR14', 'D3', 'D1', 'D4', 'D2', 'QHXH32', 'CORR15', 'D3', 'D1', 'UMAHXH33', 'D2', 'QHXH33', 'CORR16', 'D3', 'D1', 'UMAHXH34', 'D2', 'QHXH34', 'CORR17', 'D3', 'D1', 'UMAHXH35', 'D2', 'QHXH35', 'CORR18', 'D3', 'D1', 'UMAHXH36', 'D2', 'QHXH36', 'CORR19', 'D3', 'D1', 'UMAHXH37', 'D2', 'QHXH37', 'CORR20', 'D3', 'D1', 'UMAHXH38', 'D2', 'QHXH38', 'CORR21', 'D3', 'D1', 'UMAHXH39', 'D2', 'QHXH39', 'CORR22', 'D3', 'D1', 'UMAHXH40', 'D2', 'QHXH40', 'CORR23', 'D3', 'D1', 'UMAHXH41', 'D2', 'QHXH41', 'CORR24', 'D3', 'D1', 'UMAHXH42', 'D2', 'QHXH42', 'CORR25', 'D3', 'D1', 'UMAHXH43', 'D2', 'QHXH43', 'CORR26', 'D3', 'D1', 'UMAHXH44', 'D2', 'QHXH44', 'CORR27', 'D3', 'D1', 'UMAHXH45', 'D2', 'QHXH45', 'CORR28', 'D3', 'D1', 'UMAHXH46', 'D2', 'QHXH46', 'CORR29', 'D3', 'D1', 'UMAHXH47', 'D2', 'QHXH47', 'CORR30', 'D3', 'D1', 'UMAHXH48', 'D2', 'QHXH48', 'CORR31', 'D3', 'D1', 'UMAHXH49', 'D2', 'QHXH49', 'CORR32', 'D3', 'D1', 'UMAHXH50', 'D2', 'QHXH50', 'CORR33', 'D3', ], ), 'LCLS2_HXR_U1': Line( elements=[ 'D1', 'UMAHXH17', 'D2', 'QHXH17', 'CORR00', 'D3', 'D1', 'UMAHXH18', 'D2', 'QHXH18', 'CORR01', 'D3', 'D1', 'UMAHXH19', 'D2', 'QHXH19', 'CORR02', 'D3', 'D1', 'UMAHXH20', 'D2', 'QHXH20', 'CORR03', 'D3', 'D1', 'UMAHXH21', 'D2', 'QHXH21', 'CORR04', 'D3', 'D1', 'UMAHXH22', 'D2', 'QHXH22', 'CORR05', 'D3', 'D1', 'UMAHXH23', 'D2', 'QHXH23', 'CORR06', 'D3', ], ), 'LCLS2_HXR_U2': Line( elements=[ 'D1', 'UMAHXH25', 'D2', 'QHXH25', 'CORR08', 'D3', 'D1', 'UMAHXH26', 'D2', 'QHXH26', 'CORR09', 'D3', 'D1', 'UMAHXH27', 'D2', 'QHXH27', 'CORR10', 'D3', 'D1', 'UMAHXH28', 'D2', 'QHXH28', 'CORR11', 'D3', 'D1', 'UMAHXH29', 'D2', 'QHXH29', 'CORR12', 'D3', 'D1', 'UMAHXH30', 'D2', 'QHXH30', 'CORR13', 'D3', 'D1', 'UMAHXH31', 'D2', 'QHXH31', 'CORR14', 'D3', 'D1', 'D4', 'D2', 'QHXH32', 'CORR15', 'D3', 'D1', 'UMAHXH33', 'D2', 'QHXH33', 'CORR16', 'D3', 'D1', 'UMAHXH34', 'D2', 'QHXH34', 'CORR17', 'D3', 'D1', 'UMAHXH35', 'D2', 'QHXH35', 'CORR18', 'D3', 'D1', 'UMAHXH36', 'D2', 'QHXH36', 'CORR19', 'D3', 'D1', 'UMAHXH37', 'D2', 'QHXH37', 'CORR20', 'D3', 'D1', 'UMAHXH38', 'D2', 'QHXH38', 'CORR21', 'D3', 'D1', 'UMAHXH39', 'D2', 'QHXH39', 'CORR22', 'D3', 'D1', 'UMAHXH40', 'D2', 'QHXH40', 'CORR23', 'D3', 'D1', 'UMAHXH41', 'D2', 'QHXH41', 'CORR24', 'D3', 'D1', 'UMAHXH42', 'D2', 'QHXH42', 'CORR25', 'D3', 'D1', 'UMAHXH43', 'D2', 'QHXH43', 'CORR26', 'D3', 'D1', 'UMAHXH44', 'D2', 'QHXH44', 'CORR27', 'D3', 'D1', 'UMAHXH45', 'D2', 'QHXH45', 'CORR28', 'D3', 'D1', 'UMAHXH46', 'D2', 'QHXH46', 'CORR29', 'D3', 'D1', 'UMAHXH47', 'D2', 'QHXH47', 'CORR30', 'D3', 'D1', 'UMAHXH48', 'D2', 'QHXH48', 'CORR31', 'D3', 'D1', 'UMAHXH49', 'D2', 'QHXH49', 'CORR32', 'D3', 'D1', 'UMAHXH50', 'D2', 'QHXH50', 'CORR33', 'D3', ], )}
This input
object is a convenient dataclass which contains all of the beamline elements and offers some convenience methods.
See the Genesis4 format of the lattice¶
We can see the Genesis 4 representation by looking at lat.to_genesis()
:
In [4]:
Copied!
print(lat.to_genesis())
print(lat.to_genesis())
QHXH17: quadrupole = {l=0.101, k1=1.78}; QHXH18: quadrupole = {l=0.101, k1=-1.78}; QHXH19: quadrupole = {l=0.101, k1=1.78}; QHXH20: quadrupole = {l=0.101, k1=-1.78}; QHXH21: quadrupole = {l=0.101, k1=1.78}; QHXH22: quadrupole = {l=0.101, k1=-1.78}; QHXH23: quadrupole = {l=0.101, k1=1.78}; QHXH24: quadrupole = {l=0.101, k1=-1.78}; QHXH25: quadrupole = {l=0.101, k1=1.78}; QHXH26: quadrupole = {l=0.101, k1=-1.78}; QHXH27: quadrupole = {l=0.101, k1=1.78}; QHXH28: quadrupole = {l=0.101, k1=-1.78}; QHXH29: quadrupole = {l=0.101, k1=1.78}; QHXH30: quadrupole = {l=0.101, k1=-1.78}; QHXH31: quadrupole = {l=0.101, k1=1.78}; QHXH32: quadrupole = {l=0.101, k1=-1.78}; QHXH33: quadrupole = {l=0.101, k1=1.78}; QHXH34: quadrupole = {l=0.101, k1=-1.78}; QHXH35: quadrupole = {l=0.101, k1=1.78}; QHXH36: quadrupole = {l=0.101, k1=-1.78}; QHXH37: quadrupole = {l=0.101, k1=1.78}; QHXH38: quadrupole = {l=0.101, k1=-1.78}; QHXH39: quadrupole = {l=0.101, k1=1.78}; QHXH40: quadrupole = {l=0.101, k1=-1.78}; QHXH41: quadrupole = {l=0.101, k1=1.78}; QHXH42: quadrupole = {l=0.101, k1=-1.78}; QHXH43: quadrupole = {l=0.101, k1=1.78}; QHXH44: quadrupole = {l=0.101, k1=-1.78}; QHXH45: quadrupole = {l=0.101, k1=1.78}; QHXH46: quadrupole = {l=0.101, k1=-1.78}; QHXH47: quadrupole = {l=0.101, k1=1.78}; QHXH48: quadrupole = {l=0.101, k1=-1.78}; QHXH49: quadrupole = {l=0.101, k1=1.78}; QHXH50: quadrupole = {l=0.101, k1=-1.78}; UMAHXH17: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH18: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH19: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH20: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH21: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH22: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH23: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH25: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH26: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH27: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH28: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH29: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH30: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH31: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH33: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH34: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH35: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH36: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH37: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH38: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH39: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH40: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH41: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH42: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH43: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH44: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH45: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH46: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH47: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH48: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH49: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH50: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; CORR00: corrector = {l=0.001}; CORR01: corrector = {l=0.001}; CORR02: corrector = {l=0.001}; CORR03: corrector = {l=0.001}; CORR04: corrector = {l=0.001}; CORR05: corrector = {l=0.001}; CORR06: corrector = {l=0.001}; CORR07: corrector = {l=0.001}; CORR08: corrector = {l=0.001}; CORR09: corrector = {l=0.001}; CORR10: corrector = {l=0.001}; CORR11: corrector = {l=0.001}; CORR12: corrector = {l=0.001}; CORR13: corrector = {l=0.001}; CORR14: corrector = {l=0.001}; CORR15: corrector = {l=0.001}; CORR16: corrector = {l=0.001}; CORR17: corrector = {l=0.001}; CORR18: corrector = {l=0.001}; CORR19: corrector = {l=0.001}; CORR20: corrector = {l=0.001}; CORR21: corrector = {l=0.001}; CORR22: corrector = {l=0.001}; CORR23: corrector = {l=0.001}; CORR24: corrector = {l=0.001}; CORR25: corrector = {l=0.001}; CORR26: corrector = {l=0.001}; CORR27: corrector = {l=0.001}; CORR28: corrector = {l=0.001}; CORR29: corrector = {l=0.001}; CORR30: corrector = {l=0.001}; CORR31: corrector = {l=0.001}; CORR32: corrector = {l=0.001}; CORR33: corrector = {l=0.001}; D1: drift = {l=0.1335}; D2: drift = {l=0.4615}; D3: drift = {l=0.328}; D4: drift = {l=3.4}; HXRSS: chicane = {l=4.55, lb=0.1}; HXR: LINE = {D1, UMAHXH17, D2, QHXH17, CORR00, D3, D1, UMAHXH18, D2, QHXH18, CORR01, D3, D1, UMAHXH19, D2, QHXH19, CORR02, D3, D1, UMAHXH20, D2, QHXH20, CORR03, D3, D1, UMAHXH21, D2, QHXH21, CORR04, D3, D1, UMAHXH22, D2, QHXH22, CORR05, D3, D1, UMAHXH23, D2, QHXH23, CORR06, D3, D1, HXRSS, D2, QHXH24, CORR07, D3, D1, UMAHXH25, D2, QHXH25, CORR08, D3, D1, UMAHXH26, D2, QHXH26, CORR09, D3, D1, UMAHXH27, D2, QHXH27, CORR10, D3, D1, UMAHXH28, D2, QHXH28, CORR11, D3, D1, UMAHXH29, D2, QHXH29, CORR12, D3, D1, UMAHXH30, D2, QHXH30, CORR13, D3, D1, UMAHXH31, D2, QHXH31, CORR14, D3, D1, D4, D2, QHXH32, CORR15, D3, D1, UMAHXH33, D2, QHXH33, CORR16, D3, D1, UMAHXH34, D2, QHXH34, CORR17, D3, D1, UMAHXH35, D2, QHXH35, CORR18, D3, D1, UMAHXH36, D2, QHXH36, CORR19, D3, D1, UMAHXH37, D2, QHXH37, CORR20, D3, D1, UMAHXH38, D2, QHXH38, CORR21, D3, D1, UMAHXH39, D2, QHXH39, CORR22, D3, D1, UMAHXH40, D2, QHXH40, CORR23, D3, D1, UMAHXH41, D2, QHXH41, CORR24, D3, D1, UMAHXH42, D2, QHXH42, CORR25, D3, D1, UMAHXH43, D2, QHXH43, CORR26, D3, D1, UMAHXH44, D2, QHXH44, CORR27, D3, D1, UMAHXH45, D2, QHXH45, CORR28, D3, D1, UMAHXH46, D2, QHXH46, CORR29, D3, D1, UMAHXH47, D2, QHXH47, CORR30, D3, D1, UMAHXH48, D2, QHXH48, CORR31, D3, D1, UMAHXH49, D2, QHXH49, CORR32, D3, D1, UMAHXH50, D2, QHXH50, CORR33, D3}; LCLS2_HXR_U1: LINE = {D1, UMAHXH17, D2, QHXH17, CORR00, D3, D1, UMAHXH18, D2, QHXH18, CORR01, D3, D1, UMAHXH19, D2, QHXH19, CORR02, D3, D1, UMAHXH20, D2, QHXH20, CORR03, D3, D1, UMAHXH21, D2, QHXH21, CORR04, D3, D1, UMAHXH22, D2, QHXH22, CORR05, D3, D1, UMAHXH23, D2, QHXH23, CORR06, D3}; LCLS2_HXR_U2: LINE = {D1, UMAHXH25, D2, QHXH25, CORR08, D3, D1, UMAHXH26, D2, QHXH26, CORR09, D3, D1, UMAHXH27, D2, QHXH27, CORR10, D3, D1, UMAHXH28, D2, QHXH28, CORR11, D3, D1, UMAHXH29, D2, QHXH29, CORR12, D3, D1, UMAHXH30, D2, QHXH30, CORR13, D3, D1, UMAHXH31, D2, QHXH31, CORR14, D3, D1, D4, D2, QHXH32, CORR15, D3, D1, UMAHXH33, D2, QHXH33, CORR16, D3, D1, UMAHXH34, D2, QHXH34, CORR17, D3, D1, UMAHXH35, D2, QHXH35, CORR18, D3, D1, UMAHXH36, D2, QHXH36, CORR19, D3, D1, UMAHXH37, D2, QHXH37, CORR20, D3, D1, UMAHXH38, D2, QHXH38, CORR21, D3, D1, UMAHXH39, D2, QHXH39, CORR22, D3, D1, UMAHXH40, D2, QHXH40, CORR23, D3, D1, UMAHXH41, D2, QHXH41, CORR24, D3, D1, UMAHXH42, D2, QHXH42, CORR25, D3, D1, UMAHXH43, D2, QHXH43, CORR26, D3, D1, UMAHXH44, D2, QHXH44, CORR27, D3, D1, UMAHXH45, D2, QHXH45, CORR28, D3, D1, UMAHXH46, D2, QHXH46, CORR29, D3, D1, UMAHXH47, D2, QHXH47, CORR30, D3, D1, UMAHXH48, D2, QHXH48, CORR31, D3, D1, UMAHXH49, D2, QHXH49, CORR32, D3, D1, UMAHXH50, D2, QHXH50, CORR33, D3};
The lattice parser also works directly with strings if you prefer with .from_contents
. Try the following:
Create a lattice from a string¶
In [5]:
Copied!
lat = g4.Lattice.from_contents(
"""
CORR32: corrector = {l=0.001};
CORR33: corrector = {l=0.002};
"""
)
lat = g4.Lattice.from_contents(
"""
CORR32: corrector = {l=0.001};
CORR33: corrector = {l=0.002};
"""
)
In [6]:
Copied!
lat
lat
Out[6]:
Lattice( elements={'CORR32': Corrector(L=0.001), 'CORR33': Corrector(L=0.002)}, filename=pathlib.Path('unknown'), )
View the lattice in a table format:
In [7]:
Copied!
lat.to_table()
lat.to_table()
Out[7]:
Attribute | Value | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CORR32 |
| ||||||||||||||||||||||||||
CORR33 |
|
Access elements of a specific type easily¶
In [8]:
Copied!
lat.correctors
lat.correctors
Out[8]:
[Corrector(L=0.001), Corrector(L=0.002)]
Create a Lattice entirely in Python¶
In [9]:
Copied!
lat = g4.Lattice(
{
"D1": g4.Drift(L=0.44),
"D2": g4.Drift(L=0.24),
"FEL": g4.Line(elements=["FODO"] * 6),
"FODO": g4.Line(
elements=["UND", "D1", "QF", "D2", "UND", "D1", "QD", "D2"],
),
"QD": g4.Quadrupole(L=0.08, k1=-2.0),
"QF": g4.Quadrupole(L=0.08, k1=2.0),
"UND": g4.Undulator(aw=0.84853, lambdau=0.015, nwig=266, helical=True),
}
)
lat = g4.Lattice(
{
"D1": g4.Drift(L=0.44),
"D2": g4.Drift(L=0.24),
"FEL": g4.Line(elements=["FODO"] * 6),
"FODO": g4.Line(
elements=["UND", "D1", "QF", "D2", "UND", "D1", "QD", "D2"],
),
"QD": g4.Quadrupole(L=0.08, k1=-2.0),
"QF": g4.Quadrupole(L=0.08, k1=2.0),
"UND": g4.Undulator(aw=0.84853, lambdau=0.015, nwig=266, helical=True),
}
)
In [10]:
Copied!
print(lat.to_genesis())
print(lat.to_genesis())
D1: drift = {l=0.44}; D2: drift = {l=0.24}; FEL: LINE = {FODO, FODO, FODO, FODO, FODO, FODO}; FODO: LINE = {UND, D1, QF, D2, UND, D1, QD, D2}; QD: quadrupole = {l=0.08, k1=-2.0}; QF: quadrupole = {l=0.08, k1=2.0}; UND: undulator = {aw=0.84853, lambdau=0.015, nwig=266, helical=true};
You can also plot the lattice layout prior to running Genesis4:
In [11]:
Copied!
lat.plot("FODO")
lat.plot("FODO")
In [12]:
Copied!
lat.plot("FEL", figsize=(8, 4))
lat.plot("FEL", figsize=(8, 4))
View detailed information about a single lattice element¶
In [13]:
Copied!
lat.undulators[0].to_table()
lat.undulators[0].to_table()
Out[13]:
Attribute | Value | Type | Description |
---|---|---|---|
label | UND | str | |
type | undulator | str | |
aw | 0.84853 | float | The dimensionless rms undulator parameter. For planar undulator this value is smaller by a factor $1 / \sqrt{2}$ than its K-value, while for helical undulator rms and peak values are identical. |
lambdau | 0.015 | float | Undulator period length in meter. Default is 0 m. |
nwig | 266 | int | Number of periods. |
helical | True | bool | Boolean flag whether the undulator is planar or helical. A planar undulator has helical=`false`. Note that setting it to `true`, does not change the roll-off parameters for focusing. To be consistent they have to be set directly. |
kx | 0.0 | float | Roll-off parameter of the quadratic term of the undulator field in x. It is normalized with respect to $k_u^2$. |
ky | 1.0 | float | Roll-off parameter of the quadratic term of the undulator field in y. |
ax | 0.0 | float | Offset of the undulator module in $x$ in meter. |
ay | 0.0 | float | Offset of the undulator module in $y$ in meter. |
gradx | 0.0 | float | Relative transverse gradient of undulator field in $x$ $\equiv (1/a_w) \partial a_w/\partial x$. |
grady | 0.0 | float | Relative transverse gradient of undulator field in $y$ $\equiv (1/a_w) \partial a_w/\partial y$. |