def _fuse_particles(self): """ This functions adds all particles to a pcf object (pcf_field). If a particle contains a multiplier field that number of particles are created with indexes appended to the particle's unique identifier. If the quasiparticle has a parent, that parent is added to all particles in the quasiparticle. Finally link_particles is called on the pcf_field. """ for particle in self.member_particles: if not particle.get("pcf_name"): particle["pcf_name"] = self.name multiplier = particle.get("multiplier", False) base_particle_config = particle.get("base_particle_config", False) if base_particle_config: particle = self.update_particle_definition( particle, self.pcf_field.get_particle_from_pcf_id( particle["flavor"] + ":" + base_particle_config)) # when there is no multiplier add quasiparticle parents to particle and add particle to pcf field if not multiplier: if self.particle_definition.get("parents"): particle = self.add_parents_to_particle(particle) self.pcf_field.load_particle_definition(particle) # when there is a multiplier get the unique identifers, index them, add quasiparticle parents, and then add all particles to the pcf field else: particle_name = particle["pcf_name"] unique_identifier_list = pcf_util.get_particle_unique_identifiers( particle['flavor']) unqiue_value_dict = dict([ (x, pcf_util.find_nested_dict_value(particle, x.split('.'))) for x in unique_identifier_list ]) for i in range(multiplier): particle_multiple = deepcopy(particle) particle_multiple["pcf_name"] = particle_name + "-" + str( i) # appends the correct index to each item in particle definition that is unique particle_multiple = functools.reduce( (lambda d, l: pcf_util.replace_value_nested_dict( d, l.split('.'), unqiue_value_dict.get(l) + '-' + str(i))), unique_identifier_list, particle_multiple) if self.particle_definition.get("parents"): particle_multiple = self.add_parents_to_particle( particle_multiple) self.pcf_field.load_particle_definition(particle_multiple) self.pcf_field.link_particles(self.pcf_field.particles)
def validate_unique_id(self): """ Throws an error if particle flavor or any unique identifiers are missing """ flavor_name = self.particle_definition.get("flavor") if not flavor_name: raise pcf_exceptions.FlavorMissingException try: # get list from UNIQUE_KEYS unique_identifier_list = pcf_util.get_particle_unique_identifiers( flavor_name) for uid in unique_identifier_list: if not pcf_util.find_nested_dict_value( self.particle_definition, uid.split('.')): raise pcf_exceptions.InvalidUniqueKeysException except AttributeError: # UNIQUE_KEYS list does not exist - disregard and move on (Only when UNIQUE_KEYS is not defined in a class) pass