Ejemplo n.º 1
0
def build_particle_collection(definition: dict,
                              validate: bool = True) -> ParticleCollection:
    if validate:
        validation.particle_list(definition)
    definition = definition["ParticleList"]
    particles = ParticleCollection()
    for name, particle_def in definition.items():
        particles.add(build_particle(name, particle_def))
    return particles
Ejemplo n.º 2
0
def _generate_particle_collection(
    graphs: List[StateTransitionGraph[ParticleWithSpin]],
) -> ParticleCollection:
    particles = ParticleCollection()
    for graph in graphs:
        for edge_props in map(graph.get_edge_props, graph.edges):
            particle_name = edge_props[0].name
            if particle_name not in particles:
                particles.add(edge_props[0])
    return particles
Ejemplo n.º 3
0
 def get_intermediate_particles(self) -> ParticleCollection:
     """Extract the names of the intermediate state particles."""
     intermediate_states = ParticleCollection()
     for graph in self.solutions:
         for edge_props in map(
             graph.get_edge_props, graph.get_intermediate_state_edge_ids()
         ):
             if edge_props:
                 particle, _ = edge_props
                 if particle not in intermediate_states:
                     intermediate_states.add(particle)
     return intermediate_states
Ejemplo n.º 4
0
def load_pdg() -> ParticleCollection:
    all_pdg_particles = PdgDatabase.findall(
        lambda item: item.charge is not None and item.charge.is_integer(
        )  # remove quarks
        and item.J is not None  # remove new physics and nuclei
        and abs(item.pdgid) < 1e9  # p and n as nucleus
        and item.name not in __skip_particles and not (
            item.mass is None and not item.name.startswith("nu")))
    particle_collection = ParticleCollection()
    for pdg_particle in all_pdg_particles:
        new_particle = __convert_pdg_instance(pdg_particle)
        particle_collection.add(new_particle)
    return particle_collection
Ejemplo n.º 5
0
def build_particle_collection(definition: dict) -> ParticleCollection:
    if isinstance(definition, dict):
        definition = definition.get("root", definition)
    if isinstance(definition, dict):
        definition = definition.get("ParticleList", definition)
    if isinstance(definition, dict):
        definition = definition.get("Particle", definition)
    if isinstance(definition, list):
        particle_list: Union[List[dict], ValuesView] = definition
    elif isinstance(definition, dict):
        particle_list = definition.values()
    else:
        raise ValueError(
            "The following definition cannot be converted to a ParticleCollection\n"
            f"{definition}")
    collection = ParticleCollection()
    for particle_def in particle_list:
        collection.add(build_particle(particle_def))
    return collection