Working with MainInput¶
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 main input file¶
You can load Genesis4-format main input directly from a file by using from_file:
In [2]:
Copied!
input = g4.MainInput.from_file("data/basic4/cu_hxr.in")
input = g4.MainInput.from_file("data/basic4/cu_hxr.in")
In [3]:
Copied!
input.namelists
input.namelists
Out[3]:
[Setup( rootname='LCLS2_HXR_9keV', lattice='hxr.lat', beamline='HXR', gamma0=19174.0776, lambda0=1.3789244869952112e-10, delz=0.026, seed=84672, npart=1024, ), Time(slen=1.5e-05, sample=200), Field(dgrid=0.0001, ngrid=101, accumulate=True), ProfileFile( label='beamcurrent', xdata='beam_current.h5/s', ydata='beam_current.h5/current', ), ProfileFile(label='beamgamma', xdata='beam_gamma.h5/s', ydata='beam_gamma.h5/gamma'), Beam( gamma='@beamgamma', delgam=3.97848, current='@beamcurrent', ex=4e-07, ey=4e-07, betax=7.910909406464387, betay=16.881178621346898, alphax=-0.7393217413918415, alphay=1.3870723536888105, ), Track(zstop=10.0)]
This input object is a convenient dataclass which contains all of the namelists and offers some convenience methods.
We can see the Genesis 4 representation of a namelist by looking at namelist.to_genesis():
In [4]:
Copied!
print(input.setup.to_genesis())
print(input.setup.to_genesis())
&setup rootname = LCLS2_HXR_9keV lattice = hxr.lat beamline = HXR gamma0 = 19174.0776 lambda0 = 1.3789244869952112e-10 delz = 0.026 seed = 84672 npart = 1024 &end
The parser also works directly with strings if you prefer with .from_contents. Try the following:
In [5]:
Copied!
input = g4.MainInput.from_contents(
    """
&setup
  rootname = LCLS2_HXR_9keV
  lattice = hxr.lat
  beamline = HXR
  gamma0 = 19174.0776
  lambda0 = 1.3789244869952112e-10
  delz = 0.026
  seed = 84672
  npart = 1024
&end
"""
)
input = g4.MainInput.from_contents(
    """
&setup
  rootname = LCLS2_HXR_9keV
  lattice = hxr.lat
  beamline = HXR
  gamma0 = 19174.0776
  lambda0 = 1.3789244869952112e-10
  delz = 0.026
  seed = 84672
  npart = 1024
&end
"""
)
In [6]:
Copied!
input.setup
input.setup
Out[6]:
Setup( rootname='LCLS2_HXR_9keV', lattice='hxr.lat', beamline='HXR', gamma0=19174.0776, lambda0=1.3789244869952112e-10, delz=0.026, seed=84672, npart=1024, )
In [7]:
Copied!
input
input
Out[7]:
MainInput(
  namelists=[
    Setup(
      rootname='LCLS2_HXR_9keV',
      lattice='hxr.lat',
      beamline='HXR',
      gamma0=19174.0776,
      lambda0=1.3789244869952112e-10,
      delz=0.026,
      seed=84672,
      npart=1024,
    ),
  ],
  filename=pathlib.Path('unknown'),
)
You can see full descriptions of all parameters and values in a table format:
In [8]:
Copied!
input.to_table()
input.to_table()
Out[8]:
| Attribute | Value | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 
  |