Skip to content

parser

converter.converter.topas.parser

TopasParser

Bases: Parser

A simple placeholder parser that parses energy and number of particles.

Source code in yaptide/converter/converter/topas/parser.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class TopasParser(Parser):
    """A simple placeholder parser that parses energy and number of particles."""

    def __init__(self) -> None:
        super().__init__()
        self.info['simulator'] = 'topas'
        self.config = Config()

    def parse_configs(self, json: dict) -> None:
        """Basicaly do nothing since we work on defaults in this parser."""
        self.config.energy = json["beam"]["energy"]
        self.config.num_histories = json["beam"].get("numberOfParticles", self.config.num_histories)

    def get_configs_json(self) -> dict:
        """
        Return a dict representation of the config files. Each element has
        the config files name as key and its content as value.
        """
        configs_json = super().get_configs_json()
        configs_json["topas_config.txt"] = str(self.config)

        return configs_json

config instance-attribute

config = Config()

__init__

__init__()
Source code in yaptide/converter/converter/topas/parser.py
 8
 9
10
11
def __init__(self) -> None:
    super().__init__()
    self.info['simulator'] = 'topas'
    self.config = Config()

get_configs_json

get_configs_json()

Return a dict representation of the config files. Each element has the config files name as key and its content as value.

Source code in yaptide/converter/converter/topas/parser.py
18
19
20
21
22
23
24
25
26
def get_configs_json(self) -> dict:
    """
    Return a dict representation of the config files. Each element has
    the config files name as key and its content as value.
    """
    configs_json = super().get_configs_json()
    configs_json["topas_config.txt"] = str(self.config)

    return configs_json

parse_configs

parse_configs(json)

Basicaly do nothing since we work on defaults in this parser.

Source code in yaptide/converter/converter/topas/parser.py
13
14
15
16
def parse_configs(self, json: dict) -> None:
    """Basicaly do nothing since we work on defaults in this parser."""
    self.config.energy = json["beam"]["energy"]
    self.config.num_histories = json["beam"].get("numberOfParticles", self.config.num_histories)