Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lattice definition with line syntax raises an error #23

Closed
Landau1908 opened this issue Jul 17, 2015 · 3 comments
Closed

lattice definition with line syntax raises an error #23

Landau1908 opened this issue Jul 17, 2015 · 3 comments

Comments

@Landau1908
Copy link

Hi, Thomas

When I run my sequence under cpymad, a KeyError occurs as follows:

elements = madx.sequences['MYRING'].elements
Traceback (most recent call last):

  File "<ipython-input-45-c1560b76e813>", line 1, in <module>
    elements = madx.sequences['MYRING'].elements

  File "C:\Python27\lib\site-packages\cpymad-0.10.6-py2.7-win32.egg\cpymad\madx.py", line 531, in __getitem__
    raise KeyError

My python code is below:

from cpymad.madx import Madx
madx = Madx(command_log="HIMM_log.madx")
print(madx.version) 
madx.command.call(file="HIMM.txt")
twiss = madx.twiss(sequence='MYRING',columns=['s','x','y','betx','bety','Dx','Dy'])
elements = madx.sequences['MYRING'].elements

My sequence definition is below:

! ring definition----------------------------------------------------

  CELL1:Line=(D11,Q11,D12,HB11,D13,PU11,D14,CY11,D15,
              SR11,D16,Q12,D17,CX11,D18,SH11,D16,Q13,
              D12,HB12,D19,PU12,D1a);

  CELL2:Line=(CY22,D21,SV21,D22,HB22,D23,Q23,D24,SR21,
              D25,Q22,D26,C21,D27,PU21,D28,HB21,D23,
              Q21,D29);

  CELL3:Line=(D31,PU31,D32,CX31,D33,Q31,D34,HB31,D35,
              PU32,D32,CY31,D36,SR31,D37,Q32,D3c,CX32,D3b,SH31,
              D37,Q33,D34,HB32,D39,CY32,D3a,PU33);

  CELL4:Line=(D41,SV41,D42,HB42,D43,Q43,D44,SR41,D4b,CX42,D4c,
              Q42,D46,CY41,D47,PU42,D48,HB41,D43,Q41,
              D44,S41,D49,CX41,D49,PU41,D4a);

  MYRING: Line=(CELL1,CELL2,CELL3,CELL4);

  BEAM, particle = proton, energy = 150;

  USE SEQUENCE = MYRING;

!--------------------------------------------------------------------

However, when I run a sequence with sequence syntax definition not a line definition, no KeyError occurs. I think if the line definition is the source of this error.

@coldfix
Copy link
Member

coldfix commented Jul 18, 2015

Hey, try print(list(madx.sequences.keys())) to get a list of available sequence names. My guess is that the sequence name is converted to lower case by MAD-X (which is generally the case for pretty much everything that isn't quoted).

In general, you should only use lower-case names / columns / etc from inside cpymad.

@coldfix
Copy link
Member

coldfix commented Jul 18, 2015

Also note that there is a syntax error in your sequence definition: you forgot the comma after USE.

@Landau1908
Copy link
Author

Yes, lower case works well.

Your analysis is very accuracy. Thanks a lot.

@coldfix coldfix closed this as completed Jul 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants