ChristopherMayes / lume-astra

Python wrapper for Astra (A Space Charge Tracking Algorithm, DESY) for eventual use in LUME https://christophermayes.github.io/lume-astra/
https://christophermayes.github.io/lume-astra/
Apache License 2.0
14 stars 9 forks source link

file name of the input file for lume-astra #26

Open thuzz08 opened 8 months ago

thuzz08 commented 8 months ago

I found the name of the template input file for Astra has to be "astra.in". In the code below, the distgen.yaml and gun.in are from the DC gun in the examples. I changed the name of input file from 'astra.in' to gun.in. With this change, A1.run will have the error "Input not found". Changing the file name back to "astra.in" will solve this error.

from distgen import Generator
from astra import Astra
from pmd_beamphysics import ParticleGroup
from pmd_beamphysics.plot import marginal_plot
import os

# Get an input file
distgen_in1 = 'test/distgen.yaml'
D1 = Generator(distgen_in1, verbose=True)
# Change something
D1['n_particle'] = 10000
D1.run()
P1 = D1.particles
ASTRA_IN1 = 'test/gun.in'
A1 = Astra(input_file=ASTRA_IN1, initial_particles=P1)
A1.run()

I think the error message might be from this section in astra.py:

    def write_input_file(self, path=None, make_symlinks=True):
        if path is None:
            path = self.path
            input_file = self.input_file
        else:
            input_file = os.path.join(path, 'astra.in')

        writers.write_namelists(self.input, input_file, make_symlinks=make_symlinks, verbose=self.verbose)

If the path is set, for example a tmp folder, this function will save the input file to there with input file name "astra.in". But the self.input_file is the name of the template file. So if the template's name is not "astra.in", Astra cannot find it in the tmp folder.