def _reindexing(mod, sel, verbose=False): isel = sel.iselection() ra = reindexing_array(len(sel), flex.size_t(isel).as_int()) atoms = mod.get_atoms() for i_seq in isel: atoms[ra[i_seq]].tmp = i_seq if verbose: for atom in mod.get_atoms(): print(atom.quote(), atom.i_seq, atom.tmp) return mod
def reindex_h_parameterization(self, selection, iselection_original, n_atoms, h_para): iselection = selection.iselection().as_int() r_a = list(reindexing_array(n_atoms, iselection)) reindexing_dict = {} for index, i_seq in enumerate(iselection_original): reindexing_dict[iselection_original[index]] = r_a[index] # Change h_parameterization (contains i_seq --> have to be updated) new_h_parameterization = [] for index, rc in enumerate(h_para): key = iselection_original[index] # No entry for non-selected atoms (H or non-H) if reindexing_dict[key] == n_atoms: continue # Non-H atoms (if included in selection) have entry None if rc is None: new_h_parameterization.append(None) continue # For other entries: 2 possibilities # a) update all i_seqs according to reindexing dictionary # b) if any neighbors of H is not in selection --> change this # entry to None (because if neighbor is missing, H cannot be built) if reindexing_dict[rc.ih] != n_atoms: rc.ih = reindexing_dict[rc.ih] else: new_h_parameterization.append(None) continue if reindexing_dict[rc.a0] != n_atoms: rc.a0 = reindexing_dict[rc.a0] else: new_h_parameterization.append(None) continue if reindexing_dict[rc.a1] != n_atoms: rc.a1 = reindexing_dict[rc.a1] else: new_h_parameterization.append(None) continue if reindexing_dict[rc.a2] != n_atoms: rc.a2 = reindexing_dict[rc.a2] else: new_h_parameterization.append(None) continue # a3 only exists for htype "3neigbs" if rc.a3 != -1: if reindexing_dict[rc.a3] != n_atoms: rc.a3 = reindexing_dict[rc.a3] else: new_h_parameterization.append(None) continue new_h_parameterization.append(rc) return new_h_parameterization