Coverage for yaptide/converter/converter/fluka/parser.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-07-01 12:55 +0000

1from converter.common import Parser 

2from converter.fluka.helper_parsers.beam_parser import parse_beam 

3from converter.fluka.helper_parsers.figure_parser import parse_figures 

4from converter.fluka.helper_parsers.region_parser import parse_regions 

5from converter.fluka.helper_parsers.scoring_parser import parse_scorings 

6from converter.fluka.helper_parsers.material_parser import ( 

7 parse_materials, 

8 assign_materials_to_regions, 

9 set_custom_ionisation_potential, 

10) 

11from converter.fluka.input import Input 

12 

13 

14class FlukaParser(Parser): 

15 """ 

16 A simple parser that parses only some of the parameters, such as geometry data and beam energy, 

17 and returns hardcoded values for other parameters 

18 """ 

19 

20 def __init__(self) -> None: 

21 super().__init__() 

22 self.info["simulator"] = "fluka" 

23 self.info["version"] = "unknown" 

24 self.input = Input() 

25 

26 def parse_configs(self, json: dict) -> None: 

27 """Parse energy and number of particles from json.""" 

28 self.input.number_of_particles = json["beam"]["numberOfParticles"] 

29 self.input.figures = parse_figures(json["figureManager"].get("figures")) 

30 regions, world_figures = parse_regions(json["zoneManager"], self.input.figures) 

31 self.input.scorings = parse_scorings(json["detectorManager"], json["scoringManager"]) 

32 self.input.regions = list(regions.values()) 

33 self.input.figures.extend(world_figures) 

34 materials, compounds, self.input.lowmats = parse_materials(json["materialManager"]["materials"], 

35 json["zoneManager"]) 

36 self.input.materials = [ 

37 material for material in materials.values() if material.fluka_name.startswith(("MAT", "COM")) 

38 ] 

39 self.input.compounds = [compound for compound in compounds.values() if compound.fluka_name.startswith("COM")] 

40 self.input.assignmats = assign_materials_to_regions(materials, regions, json["zoneManager"]) 

41 self.input.matprops = set_custom_ionisation_potential(materials, json["zoneManager"], 

42 json["materialManager"]["materials"]) 

43 self.input.beam = parse_beam(json["beam"]) 

44 

45 def get_configs_json(self) -> dict: 

46 """ 

47 Return a dict representation of the config files. Each element has 

48 the config files name as key and its content as value. 

49 """ 

50 configs_json = super().get_configs_json() 

51 configs_json["fl_sim.inp"] = str(self.input) 

52 

53 return configs_json