Commit 605c121e authored by Stephanie Radel's avatar Stephanie Radel
Browse files

Full change in xml2astra. Rewritten project in up-to-date style of xml2optr.

parent 02459ddb
xml2astra
#-----------#
# xml2astra #
#-----------#
To use xml2astra the file 'xml2astra.py' from the 'xml2astra'-project (collected with other programs in acc-utilities) has to be called in python. Astra was initially designed for linear accelerator and dipoles were included later. Thus the number of dipoles in the converting beamline define the number of output files. If the defined beam passes a dipole the particles are bended. The bended particle distribution can not be used for the next part of the beamline without any further process. To rotate the distribution back into the initial direction use 'rotate.py'.
To call this python script:
'python /acc-utilities/xml2astra/xml2astra.py <desired xml-path>'
\ No newline at end of file
To use xml2astra the file 'run-xml2astra' from the 'xml2astra'-project (collected with other programs in
acc-utilities) has to be called in python. A virtual environment is recommended for all necessary packages.
Astra was initially designed for linear accelerator and dipoles were included later. Thus the number of dipoles
in the converting beamline define the number of output files. If the defined beam passes a dipole the particles
are bended. The bended particle distribution can not be used for the next part of the beamline without any further
process. To rotate the distribution back into the initial direction use 'rotate.py'.
Here is an example to call this python script:
'python run-xml2astra -t <desired_xml_tune_ref.xml> -f <path_of_your_desired_file.xml>'
To work with xml2astra the virtual environment needs the following requierments:
asteval==0.9.14
beautifulsoup4==4.7.1
accpy==0.0.3
asteval==0.9.21
beautifulsoup4==4.9.3
bs4==0.0.1
lxml==4.3.4
certifi==2020.12.5
chardet==4.0.0
gitdb==4.0.5
GitPython==3.1.12
idna==2.10
lxml==4.6.2
mpmath==1.1.0
numpy==1.16.4
numpy==1.19.5
pkg-resources==0.0.0
six==1.12.0
soupsieve==1.9.2
sympy==1.4
requests==2.25.1
six==1.15.0
smmap==3.0.5
soupsieve==2.1
sympy==1.7.1
urllib3==1.26.3
xmltodict==0.12.0
(lxml>=4.2.5
numpy>=1.15.4)
\ No newline at end of file
#!/usr/bin/python
import os
import sys
import argparse
from lxml import etree
from accpy.acxml import get_root
from accpy import accBaseDir
import xml2astra
#: parsing arguments using library argparse
parser = argparse.ArgumentParser(
description='''Script to convert an acc/*/path XML file into TRANSOPTR input files.''',
epilog="""If you find a bug or want to make a suggestion, create an issue on gitlab.triumf.ca/hla/acc.""")
parser.add_argument('path', type=str, default='', help='ACC path name or XML path file')
parser.add_argument('-f', '--file', action='store_true', help='Pass XML path file instead of a path name, a tune is required')
parser.add_argument('-t', '--tune', type=str, default='', help='ACC tune name')
parser.add_argument('-tf', '--tunefile', type=str, default='', help='XML tune file')
parser.add_argument('-o', '--outdir', type=str, default='', help='Directory to output optr files')
args = parser.parse_args()
parser = etree.XMLParser(remove_blank_text=True)
# Load the path file
if args.file:
xml_root = etree.parse(args.path, parser)
xml_root.xinclude()
else:
xml_root = get_root(path=args.path)
# Load the tune file
if args.tune:
tune_file = args.tune
tune_root = get_root(tune=tune_file)
elif args.tunefile:
tune_root = etree.parse(args.tunefile, parser)
for elem in tune_root.iterfind('//*[@href]'):
elem.attrib['href'] = os.path.join(accBaseDir,elem.attrib['href'])
tune_root.xinclude()
tune_file = os.path.basename(args.tunefile)
elif args.file:
raise ValueError("Error: no tune provided.")
else:
tune_file = os.path.basename(args.path).split('.', 1)[0]+'_ref'
tune_root = get_root(tune=tune_file)
# Construct proper source file names for printing useful errors
if not tune_file.endswith(".xml"):
tune_source = tune_file+".xml"
else:
tune_source = tune_file
if args.file:
xml_source = args.path
else:
xml_source = args.path + ".xml"
output_dir = args.outdir if args.outdir else os.getcwd()
xml2astra.export_simulation(xml_root, tune_root, output_dir, xml_root_source=xml_source, tune_root_source=tune_source)
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment