def expressAtomsInCoordinates(atoms, vectors): positions = convertToBasis(atoms.get_positions(), vectors) unit_cell = convertToBasis(atoms.get_cell(), vectors) new_atoms = atoms.copy() new_atoms.set_positions(positions) new_atoms.set_cell(unit_cell) return new_atoms
def groupAtoms(atoms, order=(2,), tolerance=1e-2): atoms = atoms.copy() del atoms.constraints pbc = atoms.get_pbc() atoms.set_pbc([True]*3) cell = atoms.get_cell() positions, remainder = convertToBasis(atoms.get_positions(), cell) atoms.set_positions(positions) tolerance1 = convertToBasis(np.array([1,1,1])*tolerance, cell)[0][0] tolerance2 = convertToBasis(np.array([-1,1,-1])*tolerance, cell)[0][0] tolerance1 = map(abs, tolerance1) tolerance2 = map(abs, tolerance2) tolerance = np.max((tolerance1, tolerance2), 0) indices = np.arange(len(atoms)) groups = [(atoms, indices)] for i in order: new_groups = [] for atoms, indices in groups: while len(atoms) > 0: positions = atoms.get_positions() min_value = np.min(positions[:, i]) group_mask = abs(positions[:, i] - min_value) < tolerance[i] atom_group = atoms[group_mask] indices_group = indices[group_mask] atoms = atoms[np.logical_not(group_mask)] indices = indices[np.logical_not(group_mask)] new_groups.append((atom_group, indices_group)) groups = new_groups for atoms, indices in groups: positions = convertFromBasis(atoms.get_positions(), cell) atoms.set_positions(positions) atoms.set_cell(cell) return groups
def findPeriodicallyEqualAtoms(atoms, other_atoms): center = atoms.positions.mean(axis=0) center, remain = convertToBasis(center, other_atoms.cell) center = (np.array([.5, .5, .5]) - center)[0] other_atoms = wrap(other_atoms, center=center) cell = other_atoms.get_cell() pbc = atoms.get_pbc() cell = atoms.cell[pbc] group = -np.ones(len(other_atoms), dtype=np.int) for i, atom in enumerate(atoms): diff = other_atoms.get_positions() - atom.position pos = minimalDistance(diff, cell) mask = vectorLength(pos, 1) < 1e-5 indices = np.arange(len(other_atoms))[mask] group[indices] = i return group