def _generate_parameters_file(data): _validate_data(data, _SCHEMA) res, v = template_common.generate_parameters_file(data) util = LatticeUtil(data, _SCHEMA) v.update({ 'lattice': _generate_lattice(data, util), 'use_beamline': util.select_beamline().name.lower(), 'bunchFileName': OUTPUT_FILE.bunchReport, 'diagnosticFilename': OUTPUT_FILE.beamEvolutionAnimation, 'twissFileName': OUTPUT_FILE.twissReport, }) if data.models.bunch.distribution == 'file': v.bunchFile = _SIM_DATA.lib_file_name_with_model_field('bunch', 'particleFile', data.models.bunch.particleFile) v.bunch = template_common.render_jinja(SIM_TYPE, v, 'bunch.py') res += template_common.render_jinja(SIM_TYPE, v, 'base.py') report = data.report if 'report' in data else '' if 'bunchReport' in report or 'twissReport' in report: res += template_common.render_jinja(SIM_TYPE, v, 'twiss.py') if 'bunchReport' in report: res += template_common.render_jinja(SIM_TYPE, v, 'bunch-report.py') else: res += template_common.render_jinja(SIM_TYPE, v, 'parameters.py') return res
def import_file(text, data=None): models = elegant_lattice_parser.parse_file( text, _SIM_DATA.elegant_max_id(data) if data else 0) name_to_id, default_beamline_id = _create_name_map(models) if 'default_beamline_name' in models and models[ 'default_beamline_name'] in name_to_id: default_beamline_id = name_to_id[models['default_beamline_name']] element_names = PKDict() rpn_cache = PKDict() for el in models['elements']: el['type'] = _validate_type(el, element_names) element_names[el['name'].upper()] = el validate_fields(el, rpn_cache, models['rpnVariables']) for bl in models['beamlines']: bl['items'] = _validate_beamline(bl, name_to_id, element_names) if len(models['elements']) == 0 or len(models['beamlines']) == 0: raise IOError('no beamline elements found in file') if not data: data = simulation_db.default_data(elegant_common.SIM_TYPE) data['models']['elements'] = models['elements'] data['models']['beamlines'] = models['beamlines'] data['models']['rpnVariables'] = models['rpnVariables'] LatticeUtil(data, _SCHEMA).sort_elements_and_beamlines() if default_beamline_id: data['models']['simulation']['activeBeamlineId'] = default_beamline_id data['models']['simulation'][ 'visualizationBeamlineId'] = default_beamline_id # used by synergia app to get values for rpn expressions data['models']['rpnCache'] = rpn_cache return data
def _generate_parameters_file(data): res, v = template_common.generate_parameters_file(data) util = LatticeUtil(data, _SCHEMA) cv = code_var(data.models.rpnVariables) report = data.get('report', '') if 'bunchReport' in report: # keep only first distribution and beam in command list beam = LatticeUtil.find_first_command(data, 'beam') distribution = LatticeUtil.find_first_command(data, 'distribution') v.beamName = beam.name v.distributionName = distribution.name # these need to get set to default or distribution won't generate in 1 step # for emitted distributions distribution.nbin = 0 distribution.emissionsteps = 1 distribution.offsetz = 0 data.models.commands = [ LatticeUtil.find_first_command(data, 'option'), beam, distribution, ] else: beamline_id = LatticeUtil.find_first_command( util.data, 'track').line or util.select_beamline().id v.lattice = _generate_lattice(util, cv, beamline_id) v.use_beamline = util.select_beamline().name v.update( dict( variables=cv.generate_variables(_generate_variable), header_commands=_generate_commands(util, True), commands=_generate_commands(util, False), )) if 'bunchReport' in report: return template_common.render_jinja(SIM_TYPE, v, 'bunch.in') return template_common.render_jinja(SIM_TYPE, v, 'parameters.in')
def _build_filename_map(data): return _build_filename_map_from_util(LatticeUtil(data, _SCHEMA))
def webcon_generate_lattice(data): # Used by Webcon util = LatticeUtil(data, _SCHEMA) return _generate_lattice(_build_filename_map_from_util(util), util)
def _lib_file_basenames(cls, data): return LatticeUtil(data, cls.schema()).iterate_models( lattice.InputFileIterator(cls)).result
def util(self): if not self._util: self._util = LatticeUtil(self.data, _SCHEMA) return self._util
def util(self): from sirepo.template.lattice import LatticeUtil if not hasattr(self, '_util'): self._util = LatticeUtil(self.data, self._schema) return self._util