Tutorial : ElegantRun class - Basic¶
[1]:
import pandas as pd
import numpy as np
from pyelegantsdds.elegantrun import ElegantRun
from pyelegantsdds.sdds import SDDS
from matplotlib import pyplot as plt
%matplotlib notebook
[2]:
# path to singularity container with parallel elegant installed
sif = "PATH_TO_SIF_ELEGANT"
Generate FODO lattice to use in examples¶
[3]:
# lattice element definitions
elements ={
"QF": {"type" : "KQUAD", "L": 0.342, "K1": 0.4900, "N_KICKS": 16},
"QD": {"type" : "KQUAD", "L": 0.668, "K1": -0.4999, "N_KICKS": 16},
"D": {"type" : "DRIF" , "L": 3.5805},
"W1": {"type" : "WATCH", "filename":"\"%s-%03ld.w1\"","mode": "coordinates"}
}
FODOstr = "! FODO cell.\n\n"
stringlist = ["{:6}: {}".format(k,", ".join(["{}={:15.12f}".format(kk,vv)
if not isinstance(vv,str)
else "{}={}".format(kk,vv)
if kk!="type" else "{}".format(vv) for kk,vv in v.items()]))
for k,v in elements.items()]
line = ["W1","QF","D","QD","D","QF"]
linestr = "{:6}: LINE=({})".format("FODO",",".join(line))
FODOstr += "\n".join(stringlist)
FODOstr += "\n\n"
FODOstr += linestr
print(FODOstr)
with open("FODO.lte","w") as f:
f.write(FODOstr)
# set lattice for the rest of the tutorial
lattice = "FODO.lte"
! FODO cell.
QF : KQUAD, L= 0.342000000000, K1= 0.490000000000, N_KICKS=16.000000000000
QD : KQUAD, L= 0.668000000000, K1=-0.499900000000, N_KICKS=16.000000000000
D : DRIF, L= 3.580500000000
W1 : WATCH, filename="%s-%03ld.w1", mode=coordinates
FODO : LINE=(W1,QF,D,QD,D,QF)
ElegantRun¶
The ElegantRun class is used to setup, control and run the Elegant simulations.
[4]:
# load Elegant similator
er = ElegantRun(sif,lattice, parallel=True, use_beamline="FODO", energy=1700.00)
The kwargs argument is used to extract the settings for the simulations and building of the Elegant command file (temp.ele) - minimum required arguments are: * use_beamline * energy
Most command have default argument that can be changed by use of the kwargs, in this way simple simulations can be set up quickly and in just a few lines of python code. More complicated examples, using kwargs can be found in the advanced tutorials.
[5]:
er.kwargs
[5]:
{'use_beamline': 'FODO', 'energy': 1700.0}
The parallel argument allows to choose between running serial or parallel Elegant.
[6]:
er.parallel
[6]:
True
The latticefile used in the simulations is saved in the lattice property.
[7]:
er.lattice
[7]:
'FODO.lte'
Properties¶
[8]:
er.__dict__
[8]:
{'sif': '/home/mti/gitlab-hzb/containers/bin/pelegant.sif',
'lattice': 'FODO.lte',
'parallel': True,
'kwargs': {'use_beamline': 'FODO', 'energy': 1700.0},
'commandfile': <pyelegantsdds.elegant_command.ElegantCommandFile at 0x7f640117f9d0>,
'pelegant': 'run_pelegant.sh',
'exec': 'bash run_pelegant.sh'}
The class contains a property commandfile that is an instance of the ElegantCommandFile class (see the specific tutorial for more details on this class).
Methods¶
[9]:
from types import FunctionType
[x for x, y in ElegantRun.__dict__.items() if (type(y) == FunctionType) and not x.startswith('_')]
[9]:
['check',
'clearCommands',
'clearCommandHistory',
'clearAll',
'run',
'add_basic_setup',
'add_basic_twiss',
'add_vary_element',
'add_vary_element_from_file',
'add_basic_controls',
'add_watch',
'add_watch_at_start',
'add_fma_command',
'add_DA_command',
'findtwiss',
'find_matrices',
'generate_sdds_particle_inputfile',
'simple_single_particle_track',
'track_simple',
'track_vary',
'fma',
'dynap',
'dynapmom',
'table_scan']
Commands - Basic¶
Most commands are designed to generate template command files that can be used by a single simulation command by providing a minimal of arguments through the kwargs argument.
[10]:
# should always be used first
er.add_basic_setup()
er.commandfile.commandlist, er.commandfile.history
[10]:
([{'NAME': 'run_setup',
'NOTE': '',
'lattice': 'FODO.lte',
'use_beamline': 'FODO',
'p_central_mev': 1700.0,
'default_order': 1,
'concat_order': 3,
'rootname': 'temp',
'parameters': '%s.params',
'semaphore_file': '%s.done',
'magnets': '%s.mag'}],
{})
Let us add now some basic twiss.
[11]:
er.add_basic_twiss()
er.commandfile.commandlist, er.commandfile.history
[11]:
([{'NAME': 'run_setup',
'NOTE': '',
'lattice': 'FODO.lte',
'use_beamline': 'FODO',
'p_central_mev': 1700.0,
'default_order': 1,
'concat_order': 3,
'rootname': 'temp',
'parameters': '%s.params',
'semaphore_file': '%s.done',
'magnets': '%s.mag'},
{'NAME': 'twiss_output',
'NOTE': '',
'filename': '%s.twi',
'matched': 1,
'radiation_integrals': 1}],
{})
And a watchpoint at the start.
[12]:
er.add_watch_at_start()
er.commandfile.commandlist, er.commandfile.history
[12]:
([{'NAME': 'run_setup',
'NOTE': '',
'lattice': 'FODO.lte',
'use_beamline': 'FODO',
'p_central_mev': 1700.0,
'default_order': 1,
'concat_order': 3,
'rootname': 'temp',
'parameters': '%s.params',
'semaphore_file': '%s.done',
'magnets': '%s.mag'},
{'NAME': 'twiss_output',
'NOTE': '',
'filename': '%s.twi',
'matched': 1,
'radiation_integrals': 1},
{'NAME': 'insert_elements',
'NOTE': '',
'name': 'W',
's_start': -1,
's_end': -1,
'skip': 1,
'insert_before': 0,
'add_at_end': 0,
'add_at_start': 1,
'element_def': '"W: WATCH, FILENAME=\\"%s-%03ld.wq\\", mode=\\"coordinates\\""'}],
{})
And finish of by adding basic controls.
[13]:
er.add_basic_controls()
er.commandfile.commandlist ,er.commandfile.history
[13]:
([{'NAME': 'run_setup',
'NOTE': '',
'lattice': 'FODO.lte',
'use_beamline': 'FODO',
'p_central_mev': 1700.0,
'default_order': 1,
'concat_order': 3,
'rootname': 'temp',
'parameters': '%s.params',
'semaphore_file': '%s.done',
'magnets': '%s.mag'},
{'NAME': 'twiss_output',
'NOTE': '',
'filename': '%s.twi',
'matched': 1,
'radiation_integrals': 1},
{'NAME': 'insert_elements',
'NOTE': '',
'name': 'W',
's_start': -1,
's_end': -1,
'skip': 1,
'insert_before': 0,
'add_at_end': 0,
'add_at_start': 1,
'element_def': '"W: WATCH, FILENAME=\\"%s-%03ld.wq\\", mode=\\"coordinates\\""'},
{'NAME': 'run_control', 'NOTE': ''},
{'NAME': 'bunched_beam', 'NOTE': ''},
{'NAME': 'track', 'NOTE': ''}],
{})
[14]:
# as example write to ele file and print
er.commandfile.write('basic.ele')
with open('basic.ele', 'r') as f:
cmd = f.read()
print(cmd)
&run_setup
lattice = FODO.lte,
use_beamline = FODO,
p_central_mev = 1700.0,
default_order = 1,
concat_order = 3,
rootname = temp,
parameters = %s.params,
semaphore_file = %s.done,
magnets = %s.mag,
&end
&twiss_output
filename = %s.twi,
matched = 1,
radiation_integrals = 1,
&end
&insert_elements
name = W,
s_start = -1,
s_end = -1,
skip = 1,
insert_before = 0,
add_at_end = 0,
add_at_start = 1,
element_def = "W: WATCH, FILENAME=\"%s-%03ld.wq\", mode=\"coordinates\"",
&end
&run_control
&end
&bunched_beam
&end
&track
&end
Clearing
[15]:
er.clearAll()
er.commandfile.commandlist ,er.commandfile.history
[15]:
([], {})
Below are a few more examples of basic commands that can be used as building blocks for generating composite templates.
[16]:
er.add_watch(type='KQUAD',insert_before=1,
element_def = '"WQ: WATCH, FILENAME=\\"%s-%03ld.wq\\", mode=\\"coordinates\\""')
er.commandfile.commandlist
[16]:
[{'NAME': 'insert_elements',
'NOTE': '',
'type': 'KQUAD',
's_start': -1,
's_end': -1,
'skip': 1,
'insert_before': 1,
'add_at_end': 0,
'add_at_start': 0,
'element_def': '"WQ: WATCH, FILENAME=\\"%s-%03ld.wq\\", mode=\\"coordinates\\""'}]
[17]:
er.clearAll()
er.add_vary_element_from_file(enumeration_file='scan.sdds')
er.commandfile.commandlist
[17]:
[{'NAME': 'vary_element',
'NOTE': '',
'name': '*',
'item': 'L',
'index_number': 0,
'index_limit': 1,
'enumeration_file': 'scan.sdds',
'enumeration_column': None}]
[18]:
er.clearAll()
Templates - Basic¶
Twiss¶
[19]:
# load Elegant similator
er = ElegantRun(sif,lattice, parallel=True, use_beamline="FODO", energy=1700.00)
# twiss
twidata, twipar = er.findtwiss()
# for example
print("Nux : {:12.6f}".format(twipar.nux))
print("Nuy : {:12.6f}".format(twipar.nuy))
print("dNux / dp : {:12.6f}".format(twipar['dnux/dp']))
print("dNuy / dp : {:12.6f}".format(twipar['dnuy/dp']))
Nux : 0.235726
Nuy : 0.234332
dNux / dp : -0.000000
dNuy / dp : -0.000000
[20]:
# twiss data is returned as dataframe
twidata.head()
[20]:
| s | betax | alphax | psix | etax | etaxp | xAperture | betay | alphay | psiy | ... | pCentral0 | ElementName | ElementOccurence | ElementType | ChamberShape | dI1 | dI2 | dI3 | dI4 | dI5 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.0000 | 14.018177 | 0.000000 | 0.000000 | 0.0 | 0.0 | 10.0 | 2.856023 | 9.761713e-17 | 0.000000 | ... | 3326.816296 | _BEG_ | 1 | MARK | NaN | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 1 | 0.0000 | 14.018177 | 0.000000 | 0.000000 | 0.0 | 0.0 | 10.0 | 2.856023 | 9.761713e-17 | 0.000000 | ... | 3326.816296 | W1 | 1 | WATCH | ? | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 2 | 0.3420 | 13.238180 | 2.236957 | 0.024869 | 0.0 | 0.0 | 10.0 | 3.064602 | -6.214851e-01 | 0.116974 | ... | 3326.816296 | QF | 1 | KQUAD | ? | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 3 | 3.9225 | 3.033641 | 0.613075 | 0.625301 | 0.0 | 0.0 | 10.0 | 13.314053 | -2.241090e+00 | 0.712004 | ... | 3326.816296 | D | 1 | DRIF | ? | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 4 | 4.5905 | 3.033641 | -0.613075 | 0.855812 | 0.0 | 0.0 | 10.0 | 13.314053 | 2.241090e+00 | 0.760351 | ... | 3326.816296 | QD | 1 | KQUAD | ? | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
5 rows × 23 columns
[21]:
from pprint import pprint
[22]:
print(twipar.to_dict())
{'Step': 0.0, 'nux': 0.2357264, 'dnux/dp': -0.0, 'dnux/dp2': 0.0, 'dnux/dp3': 0.0, 'Ax': 0.0, 'AxLocation': -1.797693e+308, 'nuy': 0.2343325, 'dnuy/dp': -0.0, 'dnuy/dp2': 0.0, 'dnuy/dp3': 0.0, 'Ay': 0.0, 'AyLocation': -1.797693e+308, 'deltaHalfRange': 0.0, 'nuxChromUpper': 0.2357264, 'nuxChromLower': 0.2357264, 'nuyChromUpper': 0.2343325, 'nuyChromLower': 0.2343325, 'pCentral': 3326.816, 'dbetax/dp': 0.0, 'dbetay/dp': 0.0, 'dalphax/dp': 0.0, 'dalphay/dp': 0.0, 'etax2': 0.0, 'etay2': 0.0, 'etax3': 0.0, 'etay3': 0.0, 'etaxp2': 0.0, 'etayp2': 0.0, 'etaxp3': 0.0, 'etayp3': 0.0, 'betaxMin': 3.033641, 'betaxAve': 8.176835, 'betaxMax': 14.01818, 'betayMin': 2.856023, 'betayAve': 8.171316, 'betayMax': 13.31405, 'etaxMax': 0.0, 'etayMax': 0.0, 'waistsx': 0.0, 'waistsy': 2.0, 'dnux/dAx': 0.0, 'dnux/dAy': 0.0, 'dnuy/dAx': 0.0, 'dnuy/dAy': 0.0, 'dnux/dAx2': 0.0, 'dnux/dAy2': 0.0, 'dnux/dAxAy': 0.0, 'dnuy/dAx2': 0.0, 'dnuy/dAy2': 0.0, 'dnuy/dAxAy': 0.0, 'nuxTswaLower': 0.0, 'nuxTswaUpper': 0.0, 'nuyTswaLower': 0.0, 'nuyTswaUpper': 0.0, 'couplingIntegral': 0.0, 'couplingDelta': 0.001393925, 'emittanceRatio': 0.0, 'alphac2': 0.0, 'alphac': 0.0, 'I1': 0.0, 'I2': 0.0, 'I3': 0.0, 'I4': 0.0, 'I5': 0.0, 'ex0': nan, 'enx0': nan, 'taux': nan, 'Jx': nan, 'tauy': inf, 'Jy': 1.0, 'Sdelta0': nan, 'taudelta': nan, 'Jdelta': nan, 'U0': 0.0, 'length': 8.513}
Find Matrices¶
[23]:
er = ElegantRun(sif,lattice, parallel=True, use_beamline="FODO", energy=1700.00)
tup = er.find_matrices(SDDS_output_order=3)
[24]:
print(tup[0])
[[0. ]
[0. ]
[0. ]
[0. ]
[8.513]
[0. ]]
[25]:
print(tup[1])
[[ 0.97148042 0.33874254 0. 0. 0. 0. ]
[-0.16598385 0.97148042 0. 0. 0. 0. ]
[ 0. 0. 1.0287933 0.34527618 0. 0. ]
[ 0. 0. 0.16918533 1.0287933 0. 0. ]
[ 0. 0. 0. 0. 1. 0. ]
[ 0. 0. 0. 0. 0. 1. ]]
[26]:
tup[2].head()
[26]:
| s | ElementName | ElementOccurence | ElementType | C1 | C2 | C3 | C4 | C5 | C6 | ... | U6652 | U6653 | U6654 | U6655 | U6661 | U6662 | U6663 | U6664 | U6665 | U6666 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.0000 | _BEG_ | 1 | MARK | 0.0 | 0.0 | 0.0 | 0.0 | 0.0000 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 1 | 0.0000 | W1 | 1 | WATCH | 0.0 | 0.0 | 0.0 | 0.0 | 0.0000 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 2 | 0.3420 | QF | 1 | KQUAD | 0.0 | 0.0 | 0.0 | 0.0 | 0.3420 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 3 | 3.9225 | D | 1 | DRIF | 0.0 | 0.0 | 0.0 | 0.0 | 3.5805 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 4 | 4.5905 | QD | 1 | KQUAD | 0.0 | 0.0 | 0.0 | 0.0 | 0.6680 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
5 rows × 508 columns
[27]:
print(tup[3])
{'T111': 0.0, 'T121': 0.0, 'T122': 0.0, 'T131': 0.0, 'T132': 0.0, 'T133': 0.0, 'T141': 0.0, 'T142': 0.0, 'T143': 0.0, 'T144': 0.0, 'T151': 0.0, 'T152': 0.0, 'T153': 0.0, 'T154': 0.0, 'T155': 0.0, 'T161': 0.0, 'T162': 0.0, 'T163': 0.0, 'T164': 0.0, 'T165': 0.0, 'T166': 0.0, 'T211': 0.0, 'T221': 0.0, 'T222': 0.0, 'T231': 0.0, 'T232': 0.0, 'T233': 0.0, 'T241': 0.0, 'T242': 0.0, 'T243': 0.0, 'T244': 0.0, 'T251': 0.0, 'T252': 0.0, 'T253': 0.0, 'T254': 0.0, 'T255': 0.0, 'T261': 0.0, 'T262': 0.0, 'T263': 0.0, 'T264': 0.0, 'T265': 0.0, 'T266': 0.0, 'T311': 0.0, 'T321': 0.0, 'T322': 0.0, 'T331': 0.0, 'T332': 0.0, 'T333': 0.0, 'T341': 0.0, 'T342': 0.0, 'T343': 0.0, 'T344': 0.0, 'T351': 0.0, 'T352': 0.0, 'T353': 0.0, 'T354': 0.0, 'T355': 0.0, 'T361': 0.0, 'T362': 0.0, 'T363': 0.0, 'T364': 0.0, 'T365': 0.0, 'T366': 0.0, 'T411': 0.0, 'T421': 0.0, 'T422': 0.0, 'T431': 0.0, 'T432': 0.0, 'T433': 0.0, 'T441': 0.0, 'T442': 0.0, 'T443': 0.0, 'T444': 0.0, 'T451': 0.0, 'T452': 0.0, 'T453': 0.0, 'T454': 0.0, 'T455': 0.0, 'T461': 0.0, 'T462': 0.0, 'T463': 0.0, 'T464': 0.0, 'T465': 0.0, 'T466': 0.0, 'T511': 0.0, 'T521': 0.0, 'T522': 0.0, 'T531': 0.0, 'T532': 0.0, 'T533': 0.0, 'T541': 0.0, 'T542': 0.0, 'T543': 0.0, 'T544': 0.0, 'T551': 0.0, 'T552': 0.0, 'T553': 0.0, 'T554': 0.0, 'T555': 0.0, 'T561': 0.0, 'T562': 0.0, 'T563': 0.0, 'T564': 0.0, 'T565': 0.0, 'T566': 0.0, 'T611': 0.0, 'T621': 0.0, 'T622': 0.0, 'T631': 0.0, 'T632': 0.0, 'T633': 0.0, 'T641': 0.0, 'T642': 0.0, 'T643': 0.0, 'T644': 0.0, 'T651': 0.0, 'T652': 0.0, 'T653': 0.0, 'T654': 0.0, 'T655': 0.0, 'T661': 0.0, 'T662': 0.0, 'T663': 0.0, 'T664': 0.0, 'T665': 0.0, 'T666': 0.0}
[28]:
print(tup[4])
{'Q1111': 0.0, 'Q1211': 0.0, 'Q1221': 0.0, 'Q1222': 0.0, 'Q1311': 0.0, 'Q1321': 0.0, 'Q1322': 0.0, 'Q1331': 0.0, 'Q1332': 0.0, 'Q1333': 0.0, 'Q1411': 0.0, 'Q1421': 0.0, 'Q1422': 0.0, 'Q1431': 0.0, 'Q1432': 0.0, 'Q1433': 0.0, 'Q1441': 0.0, 'Q1442': 0.0, 'Q1443': 0.0, 'Q1444': 0.0, 'Q1511': 0.0, 'Q1521': 0.0, 'Q1522': 0.0, 'Q1531': 0.0, 'Q1532': 0.0, 'Q1533': 0.0, 'Q1541': 0.0, 'Q1542': 0.0, 'Q1543': 0.0, 'Q1544': 0.0, 'Q1551': 0.0, 'Q1552': 0.0, 'Q1553': 0.0, 'Q1554': 0.0, 'Q1555': 0.0, 'Q1611': 0.0, 'Q1621': 0.0, 'Q1622': 0.0, 'Q1631': 0.0, 'Q1632': 0.0, 'Q1633': 0.0, 'Q1641': 0.0, 'Q1642': 0.0, 'Q1643': 0.0, 'Q1644': 0.0, 'Q1651': 0.0, 'Q1652': 0.0, 'Q1653': 0.0, 'Q1654': 0.0, 'Q1655': 0.0, 'Q1661': 0.0, 'Q1662': 0.0, 'Q1663': 0.0, 'Q1664': 0.0, 'Q1665': 0.0, 'Q1666': 0.0, 'Q2111': 0.0, 'Q2211': 0.0, 'Q2221': 0.0, 'Q2222': 0.0, 'Q2311': 0.0, 'Q2321': 0.0, 'Q2322': 0.0, 'Q2331': 0.0, 'Q2332': 0.0, 'Q2333': 0.0, 'Q2411': 0.0, 'Q2421': 0.0, 'Q2422': 0.0, 'Q2431': 0.0, 'Q2432': 0.0, 'Q2433': 0.0, 'Q2441': 0.0, 'Q2442': 0.0, 'Q2443': 0.0, 'Q2444': 0.0, 'Q2511': 0.0, 'Q2521': 0.0, 'Q2522': 0.0, 'Q2531': 0.0, 'Q2532': 0.0, 'Q2533': 0.0, 'Q2541': 0.0, 'Q2542': 0.0, 'Q2543': 0.0, 'Q2544': 0.0, 'Q2551': 0.0, 'Q2552': 0.0, 'Q2553': 0.0, 'Q2554': 0.0, 'Q2555': 0.0, 'Q2611': 0.0, 'Q2621': 0.0, 'Q2622': 0.0, 'Q2631': 0.0, 'Q2632': 0.0, 'Q2633': 0.0, 'Q2641': 0.0, 'Q2642': 0.0, 'Q2643': 0.0, 'Q2644': 0.0, 'Q2651': 0.0, 'Q2652': 0.0, 'Q2653': 0.0, 'Q2654': 0.0, 'Q2655': 0.0, 'Q2661': 0.0, 'Q2662': 0.0, 'Q2663': 0.0, 'Q2664': 0.0, 'Q2665': 0.0, 'Q2666': 0.0, 'Q3111': 0.0, 'Q3211': 0.0, 'Q3221': 0.0, 'Q3222': 0.0, 'Q3311': 0.0, 'Q3321': 0.0, 'Q3322': 0.0, 'Q3331': 0.0, 'Q3332': 0.0, 'Q3333': 0.0, 'Q3411': 0.0, 'Q3421': 0.0, 'Q3422': 0.0, 'Q3431': 0.0, 'Q3432': 0.0, 'Q3433': 0.0, 'Q3441': 0.0, 'Q3442': 0.0, 'Q3443': 0.0, 'Q3444': 0.0, 'Q3511': 0.0, 'Q3521': 0.0, 'Q3522': 0.0, 'Q3531': 0.0, 'Q3532': 0.0, 'Q3533': 0.0, 'Q3541': 0.0, 'Q3542': 0.0, 'Q3543': 0.0, 'Q3544': 0.0, 'Q3551': 0.0, 'Q3552': 0.0, 'Q3553': 0.0, 'Q3554': 0.0, 'Q3555': 0.0, 'Q3611': 0.0, 'Q3621': 0.0, 'Q3622': 0.0, 'Q3631': 0.0, 'Q3632': 0.0, 'Q3633': 0.0, 'Q3641': 0.0, 'Q3642': 0.0, 'Q3643': 0.0, 'Q3644': 0.0, 'Q3651': 0.0, 'Q3652': 0.0, 'Q3653': 0.0, 'Q3654': 0.0, 'Q3655': 0.0, 'Q3661': 0.0, 'Q3662': 0.0, 'Q3663': 0.0, 'Q3664': 0.0, 'Q3665': 0.0, 'Q3666': 0.0, 'Q4111': 0.0, 'Q4211': 0.0, 'Q4221': 0.0, 'Q4222': 0.0, 'Q4311': 0.0, 'Q4321': 0.0, 'Q4322': 0.0, 'Q4331': 0.0, 'Q4332': 0.0, 'Q4333': 0.0, 'Q4411': 0.0, 'Q4421': 0.0, 'Q4422': 0.0, 'Q4431': 0.0, 'Q4432': 0.0, 'Q4433': 0.0, 'Q4441': 0.0, 'Q4442': 0.0, 'Q4443': 0.0, 'Q4444': 0.0, 'Q4511': 0.0, 'Q4521': 0.0, 'Q4522': 0.0, 'Q4531': 0.0, 'Q4532': 0.0, 'Q4533': 0.0, 'Q4541': 0.0, 'Q4542': 0.0, 'Q4543': 0.0, 'Q4544': 0.0, 'Q4551': 0.0, 'Q4552': 0.0, 'Q4553': 0.0, 'Q4554': 0.0, 'Q4555': 0.0, 'Q4611': 0.0, 'Q4621': 0.0, 'Q4622': 0.0, 'Q4631': 0.0, 'Q4632': 0.0, 'Q4633': 0.0, 'Q4641': 0.0, 'Q4642': 0.0, 'Q4643': 0.0, 'Q4644': 0.0, 'Q4651': 0.0, 'Q4652': 0.0, 'Q4653': 0.0, 'Q4654': 0.0, 'Q4655': 0.0, 'Q4661': 0.0, 'Q4662': 0.0, 'Q4663': 0.0, 'Q4664': 0.0, 'Q4665': 0.0, 'Q4666': 0.0, 'Q5111': 0.0, 'Q5211': 0.0, 'Q5221': 0.0, 'Q5222': 0.0, 'Q5311': 0.0, 'Q5321': 0.0, 'Q5322': 0.0, 'Q5331': 0.0, 'Q5332': 0.0, 'Q5333': 0.0, 'Q5411': 0.0, 'Q5421': 0.0, 'Q5422': 0.0, 'Q5431': 0.0, 'Q5432': 0.0, 'Q5433': 0.0, 'Q5441': 0.0, 'Q5442': 0.0, 'Q5443': 0.0, 'Q5444': 0.0, 'Q5511': 0.0, 'Q5521': 0.0, 'Q5522': 0.0, 'Q5531': 0.0, 'Q5532': 0.0, 'Q5533': 0.0, 'Q5541': 0.0, 'Q5542': 0.0, 'Q5543': 0.0, 'Q5544': 0.0, 'Q5551': 0.0, 'Q5552': 0.0, 'Q5553': 0.0, 'Q5554': 0.0, 'Q5555': 0.0, 'Q5611': 0.0, 'Q5621': 0.0, 'Q5622': 0.0, 'Q5631': 0.0, 'Q5632': 0.0, 'Q5633': 0.0, 'Q5641': 0.0, 'Q5642': 0.0, 'Q5643': 0.0, 'Q5644': 0.0, 'Q5651': 0.0, 'Q5652': 0.0, 'Q5653': 0.0, 'Q5654': 0.0, 'Q5655': 0.0, 'Q5661': 0.0, 'Q5662': 0.0, 'Q5663': 0.0, 'Q5664': 0.0, 'Q5665': 0.0, 'Q5666': 0.0, 'Q6111': 0.0, 'Q6211': 0.0, 'Q6221': 0.0, 'Q6222': 0.0, 'Q6311': 0.0, 'Q6321': 0.0, 'Q6322': 0.0, 'Q6331': 0.0, 'Q6332': 0.0, 'Q6333': 0.0, 'Q6411': 0.0, 'Q6421': 0.0, 'Q6422': 0.0, 'Q6431': 0.0, 'Q6432': 0.0, 'Q6433': 0.0, 'Q6441': 0.0, 'Q6442': 0.0, 'Q6443': 0.0, 'Q6444': 0.0, 'Q6511': 0.0, 'Q6521': 0.0, 'Q6522': 0.0, 'Q6531': 0.0, 'Q6532': 0.0, 'Q6533': 0.0, 'Q6541': 0.0, 'Q6542': 0.0, 'Q6543': 0.0, 'Q6544': 0.0, 'Q6551': 0.0, 'Q6552': 0.0, 'Q6553': 0.0, 'Q6554': 0.0, 'Q6555': 0.0, 'Q6611': 0.0, 'Q6621': 0.0, 'Q6622': 0.0, 'Q6631': 0.0, 'Q6632': 0.0, 'Q6633': 0.0, 'Q6641': 0.0, 'Q6642': 0.0, 'Q6643': 0.0, 'Q6644': 0.0, 'Q6651': 0.0, 'Q6652': 0.0, 'Q6653': 0.0, 'Q6654': 0.0, 'Q6655': 0.0, 'Q6661': 0.0, 'Q6662': 0.0, 'Q6663': 0.0, 'Q6664': 0.0, 'Q6665': 0.0, 'Q6666': 0.0}
Generate initial coordinates¶
Hypercube¶
[29]:
# generate rectangular coordinate input file - auto
# if pcentralmev is not given the energy value in er.kwargs will be used
er.generate_sdds_particle_inputfile(grid_type='rectangular', p_min=1e-6, p_max=1e-2,
pcentralmev=er.kwargs.get('energy'),
NPOINTS=7
)
Shape: (16807, 6) - Number of paritcles: 16807
Running command /home/mti/gitlab-hzb/containers/bin/pelegant.sif plaindata2sdds temp_plain_particles.dat temp_particles_input.bin -inputMode=ascii -outputMode=binary "-separator= " -column=x,double,units=m -column=xp,double -column=y,double,units=m -column=yp,double -column=t,double,units=s -column=p,double,units="m$be$nc" -columns=particleID,long -noRowCount
[30]:
# read the data using SDDS class - see specific tutorial for more details
sddsp = SDDS(sif,"temp_particles_input.bin",0)
df = sddsp.readParticleData()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(df.x,df.xp,df.y,s=1)
# labels
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$p_x$')
ax.set_zlabel(r'$y$')
# padding
ax.xaxis.labelpad=15
ax.yaxis.labelpad=15
ax.zaxis.labelpad=15
plt.tight_layout()
plt.show()
Warning - auto filename set
Changed from temp_particles_input.bin to temp_particles_input.bin.txt
Warning - auto filetype set
Changed from 0 to 1
Hyperspheres¶
[31]:
# generate rectangular coordinate input file - auto
# if pcentralmev is not given the energy value in er.kwargs will be used
er = ElegantRun(sif,lattice, parallel=True, use_beamline="FODO", energy=1700.00)
er.generate_sdds_particle_inputfile(grid_type='spherical',
dim=6,
rmin=1e-6,
rmax=1e-4,
rsteps=5,
phisteps=10,
half=True, # False gives full spheres
pcentralmev=er.kwargs.get('energy'),
)
sddsp = SDDS(sif,"temp_particles_input.bin",0)
df = sddsp.readParticleData()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.xaxis.labelpad=15
ax.yaxis.labelpad=15
ax.zaxis.labelpad=15
ax.scatter(df.x,df.xp,df.y,s=1)
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$p_x$')
ax.set_zlabel(r'$y$')
plt.tight_layout()
plt.show()
Shape: (5000, 6) - Number of paritcles: 5000
Running command /home/mti/gitlab-hzb/containers/bin/pelegant.sif plaindata2sdds temp_plain_particles.dat temp_particles_input.bin -inputMode=ascii -outputMode=binary "-separator= " -column=x,double,units=m -column=xp,double -column=y,double,units=m -column=yp,double -column=t,double,units=s -column=p,double,units="m$be$nc" -columns=particleID,long -noRowCount
Warning - auto filename set
Changed from temp_particles_input.bin to temp_particles_input.bin.txt
Warning - auto filetype set
Changed from 0 to 1
[32]:
# generate rectangular coordinate input file - auto
# if pcentralmev is not given the energy value in er.kwargs will be used
er = ElegantRun(sif,lattice, parallel=True, use_beamline="FODO", energy=1700.00)
er.generate_sdds_particle_inputfile(grid_type='spherical',
dim=6,
rmin=1e-6,
rmax=1e-4,
rsteps=5,
phisteps=10,
half=False, # False gives full spheres
pcentralmev=er.kwargs.get('energy'),
)
sddsp = SDDS(sif,"temp_particles_input.bin",0)
df = sddsp.readParticleData()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.xaxis.labelpad=15
ax.yaxis.labelpad=15
ax.zaxis.labelpad=15
ax.scatter(df.x,df.xp,df.y,s=1)
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$p_x$')
ax.set_zlabel(r'$y$')
plt.tight_layout()
plt.show()
Shape: (5000, 6) - Number of paritcles: 5000
Running command /home/mti/gitlab-hzb/containers/bin/pelegant.sif plaindata2sdds temp_plain_particles.dat temp_particles_input.bin -inputMode=ascii -outputMode=binary "-separator= " -column=x,double,units=m -column=xp,double -column=y,double,units=m -column=yp,double -column=t,double,units=s -column=p,double,units="m$be$nc" -columns=particleID,long -noRowCount
Warning - auto filename set
Changed from temp_particles_input.bin to temp_particles_input.bin.txt
Warning - auto filetype set
Changed from 0 to 1