def crystalAtoms(self, start_layer=0, end_layer=1, coordinates='orth_surface', vectors=((1,0),(0,1)), sub_layers=False, minimal=True, ): sl = slice(start_layer, end_layer) if minimal: unit_cell = self.minimalCell('crystal') else: unit_cell = self.cell('crystal') catoms = self.crystal().atoms() catoms.purgeTags() atoms = makeSlabWithVectors(catoms, unit_cell, sl.stop) atoms = self.change(atoms, to=coordinates, fro='orth_crystal') unit_cell = self.crystal().change(unit_cell, to='orth_crystal', fro='crystal', difference=True,)[:2] unit_cell = self.change(unit_cell, to='orth_surface', fro='orth_crystal') if len(atoms)==0: return atoms if minimal: vectors = unit_cell else: vectors = np.array(vectors) vectors = np.dot(unit_cell.transpose(), vectors.transpose()).transpose() repeats = fitBoxIntoBox(unit_cell, vectors) atoms = atoms.repeat(list(repeats) + [1]) out_vector = atoms.cell[2] out_vector[:2] = 0 vectors = np.array([vectors[0], vectors[1], out_vector]) atoms.set_cell(vectors) atoms.set_pbc([True, True, False]) atoms = removeCopies(atoms) atoms.wrap() atoms = orderAtoms(atoms, (2, 1, 0)) if sub_layers: groups = groupAtoms(atoms)[sl] if len(groups) == 0: return Atoms([], cell=atoms.get_cell(), pbc=atoms.get_pbc()) atoms, indices = groups[0] for atoms_group, indices in groups[1:]: atoms += atoms_group return atoms
def makeSlabWithVectors(atoms, vectors, n_layers): unit_cell = atoms.get_cell() vectors[2] *= -1 vectors = numpy.dot(unit_cell.transpose(), vectors.transpose()).transpose() repeats = fitBoxIntoBox(unit_cell, vectors) atoms = atoms.repeat(repeats) atoms.set_cell(vectors) atoms = wrap(atoms) atoms = removeCopies(atoms) atoms = atoms.repeat((1,1,n_layers)) return atoms