def identify_chains(input_dictionary, chromophore_list): print("Identifying chain numbers...") # Create a lookup table `neighbour list' for all connected atoms called {bondedAtoms} bonded_atoms = hf.obtain_bonded_list(input_dictionary['bond']) molecule_list = [i for i in range(len(input_dictionary['type']))] # Recursively add all atoms in the neighbour list to this molecule for mol_ID in range(len(molecule_list)): molecule_list = update_molecule(mol_ID, molecule_list, bonded_atoms) # Create a dictionary of the molecule data molecule_data = {} for atom_ID in range(len(input_dictionary['type'])): if molecule_list[atom_ID] not in molecule_data: molecule_data[molecule_list[atom_ID]] = [atom_ID] else: molecule_data[molecule_list[atom_ID]].append(atom_ID) # Now map the AAID data back to the chromophores # Reverse the molecule_data dictionary reverse_lookup_dict = {value: key for key, val in molecule_data.items() for value in val} chromos_in_mol = {} for chromophore in chromophore_list: mol_no = reverse_lookup_dict[chromophore.AAIDs[0]] if mol_no not in chromos_in_mol.keys(): chromos_in_mol[mol_no] = [chromophore.ID] else: chromos_in_mol[mol_no] += [chromophore.ID] chromos_by_mol_list = [np.array(chromos_in_mol[index]) for index in sorted(chromos_in_mol.keys())] return chromos_by_mol_list
def split_molecules(self): # Split the full morphology into individual molecules molecule_AAIDs = [] molecule_lengths = [] # Create a lookup table `neighbour list' for all connected atoms called # {bonded_atoms} bonded_atoms = hf.obtain_bonded_list(self.CG_dictionary["bond"]) molecule_list = [i for i in range(len(self.CG_dictionary["type"]))] # Recursively add all atoms in the neighbour list to this molecule for mol_ID in range(len(molecule_list)): molecule_list = self.update_molecule( mol_ID, molecule_list, bonded_atoms ) # Create a dictionary of the molecule data molecule_data = {} for atom_ID in range(len(self.CG_dictionary["type"])): if molecule_list[atom_ID] not in molecule_data: molecule_data[molecule_list[atom_ID]] = [atom_ID] else: molecule_data[molecule_list[atom_ID]].append(atom_ID) # Return the list of AAIDs and the lengths of the molecules for molecule_ID in list(molecule_data.keys()): molecule_AAIDs.append(sorted(molecule_data[molecule_ID])) molecule_lengths.append(len(molecule_data[molecule_ID])) return molecule_AAIDs, molecule_lengths
def split_molecules(input_dictionary): # Split the full morphology into individual molecules # Create a lookup table `neighbour list' for all connected atoms called # {bondedAtoms} bonded_atoms = hf.obtain_bonded_list(input_dictionary["bond"]) molecule_list = [i for i in range(len(input_dictionary["type"]))] # Recursively add all atoms in the neighbour list to this molecule for mol_ID in range(len(molecule_list)): molecule_list = update_molecule(mol_ID, molecule_list, bonded_atoms) # Here we have a list of len(atoms) where each index gives the molID mol_ID_dict = {} for chromo in chromophore_list: AAID_to_check = chromo.AAIDs[0] mol_ID_dict[chromo.ID] = molecule_list[AAID_to_check] return mol_ID_dict
def calculate_chromophores_AA( CG_morphology_dict, AA_morphology_dict, CG_to_AAID_master, parameter_dict, sim_dims, rigid_bodies=None, ): # If rigid_bodies == None: # This function works in the same way as the coarse-grained version above, # except this one iterates through the AA bonds instead. This is FAR SLOWER # and so shouldn't be done, except in the case where the coarse-grained # morphology does not exist (because we started with an atomistic morphology # and are only interested in running KMC on it) # If rigid_bodies == AA_morphology_dict['body']: # This function uses the rigid bodies specified in # parameter_dict['AA_rigid_body_species'], and those which have not been # specified by iterating through the AA bond list, to determine the # chromophores in the system. This is the slowest way to calculate # chromophores, but is useful for systems such as BDT-TPD, where there are # multiple chromophores of differing species present in the same molecule. # As above, this code will only run if an atomistic morphology has been # input to MorphCT. If it is coarse-grained, the CG-based # "calculate_chromophore" function will be used, and will also be a lot # faster. # The parameter_dict['AA_rigid_body_species'] is a dictionary with two keys, # 'donor' or 'acceptor'. Each element in the value list corresponds to a new # chromophore. These aren't the only atoms that belong to this chromophore, # however - there might be a bunch of aliphatic/flexible atoms that are # connected, so we need to make sure that we add those too. print("Determining chromophores in the system...") bonded_atoms = hf.obtain_bonded_list(AA_morphology_dict["bond"]) chromophore_list = [i for i in range(len(AA_morphology_dict["type"]))] for AA_site_ID, chromophore_ID in enumerate(chromophore_list): AA_site_type = AA_morphology_dict["type"][AA_site_ID] chromophore_list = update_chromophores_AA( AA_site_ID, chromophore_list, bonded_atoms, parameter_dict, rigid_bodies, ) chromophore_data = {} for atom_ID, chromo_ID in enumerate(chromophore_list): if chromo_ID not in list(chromophore_data.keys()): chromophore_data[chromo_ID] = [atom_ID] else: chromophore_data[chromo_ID].append(atom_ID) # Now rename the chromophore IDs so that they increment sensibly (they will # be used later for the orca files) old_keys = sorted(chromophore_data.keys()) for new_key, old_key in enumerate(old_keys): chromophore_data[new_key] = chromophore_data.pop(old_key) print("{:d} chromophores successfully identified!".format( len(list(chromophore_data.keys())))) # Now let's create a list of all the chromophore instances which contain all # of the information we could ever want about them. chromophore_instances = [] for chromo_ID, chromophore_CG_sites in chromophore_data.items(): print( "\rCalculating properties of chromophore {:05d} of {:05d}...". format(chromo_ID, len(list(chromophore_data.keys())) - 1), end=" ", ) if sys.stdout is not None: sys.stdout.flush() chromophore_instances.append( chromophore( chromo_ID, chromophore_CG_sites, CG_morphology_dict, AA_morphology_dict, CG_to_AAID_master, parameter_dict, sim_dims, )) print("") return chromophore_instances
def calculate_chromophores( CG_morphology_dict, AA_morphology_dict, CG_to_AAID_master, parameter_dict, sim_dims, ): # We make the assumption that a chromophore consists of one of each of the # CG site types described by the same template file. For instance, if we # have 3 sites 'A', 'B' and 'C' described in one file and one site 'D' # described in another file then there are two chromophores species # described by A-B-C and D. This will be treated automatically because the # D's shouldn't be bonded to anything in the CGMorphologyDict if they are # small molecules. # Therefore, we need to assign each CG site in the morphology to a # particular chromophore, so first, it's important to generate a # `neighbour_list' of all bonded atoms print("Determining chromophores in the system...") bonded_atoms = hf.obtain_bonded_list(CG_morphology_dict["bond"]) chromophore_list = [i for i in range(len(CG_morphology_dict["type"]))] for CG_site_ID, chromophore_ID in enumerate(chromophore_list): CG_site_type = CG_morphology_dict["type"][CG_site_ID] types_in_this_chromophore = [CG_site_type] chromophore_list, types_in_this_chromophore = update_chromophores( CG_site_ID, chromophore_list, bonded_atoms, CG_morphology_dict["type"], types_in_this_chromophore, parameter_dict, ) chromophore_data = {} for atom_ID, chromo_ID in enumerate(chromophore_list): if chromo_ID not in list(chromophore_data.keys()): chromophore_data[chromo_ID] = [atom_ID] else: chromophore_data[chromo_ID].append(atom_ID) # Now rename the chromophore IDs so that they increment sensibly (they will # be used later for the orca files) old_keys = sorted(chromophore_data.keys()) for new_key, old_key in enumerate(old_keys): chromophore_data[new_key] = chromophore_data.pop(old_key) print("{:d} chromophores successfully identified!".format( len(list(chromophore_data.keys())))) # Now let's create a list of all the chromophore instances which contain all # of the information we could ever want about them. chromophore_instances = [] for chromo_ID, chromophore_CG_sites in chromophore_data.items(): print( "\rCalculating properties of chromophore {:05d} of {:05d}...". format(chromo_ID, len(list(chromophore_data.keys())) - 1), end=" ", ) if sys.stdout is not None: sys.stdout.flush() chromophore_instances.append( chromophore( chromo_ID, chromophore_CG_sites, CG_morphology_dict, AA_morphology_dict, CG_to_AAID_master, parameter_dict, sim_dims, )) print("") return chromophore_instances