py4sci

Previous topic

Model example

Next topic

API Reference

This Page

Madx exampleΒΆ

Several users have been most interested in having direct access to MAD-X inside Python instead of using models.

from cern.cpymad.madx import Madx
from matplotlib import pyplot as plt

m = Madx()

m.call('my-sequences.seq')
m.call('my-strengths.str')

m.command.beam(sequence='myseq1', particle='PROTON')
# you can also just put an arbitrary MAD-X command string here:
m.command('beam, sequence=myseq1, particle=PROTON')

table = m.twiss('myseq1')
columns = table.columns

plt.plot(columns['s'], columns['betx'])
plt.show()

Most of this should be self-explanatory.

Note, that many Madx instances can be constructed independently without side-effects on each other.