def refine_cell(structure, symprec=1e-5, angle_tolerance=-1.0): """ Return refined cell """ # Atomic positions have to be specified by scaled positions for spglib. num_atom = len(structure.sites) cell = structure.cell.T.copy() coords = np.zeros((num_atom * 4, 3), dtype='double') coords[:num_atom] = structure.site_coords.copy() comps = structure.site_compositions numbers = [comps.index(c) for c in comps] numbers = np.array(numbers * 4, dtype='intc') num_atom_bravais = spg.refine_cell(cell, coords, numbers, num_atom, symprec, angle_tolerance) coords = wrap(coords) comps = [comps[i] for i in numbers] if num_atom_bravais > 0: structure.cell = cell.T structure.set_nsites(num_atom_bravais) structure.site_coords = coords[:num_atom_bravais] structure.site_compositions = comps[:num_atom_bravais] return structure else: return structure
def refine_cell(structure, symprec=1e-5, angle_tolerance=-1.0): """ Return refined cell """ # Atomic positions have to be specified by scaled positions for spglib. num_atom = len(structure.sites) cell = structure.cell.T.copy() coords = np.zeros((num_atom * 4, 3), dtype='double') coords[:num_atom] = structure.site_coords.copy() comps = structure.site_compositions numbers = [ comps.index(c) for c in comps ] numbers = np.array(numbers*4, dtype='intc') num_atom_bravais = spg.refine_cell(cell, coords, numbers, num_atom, symprec, angle_tolerance) coords = wrap(coords) comps = [ comps[i] for i in numbers ] if num_atom_bravais > 0: structure.cell = cell.T structure.set_nsites(num_atom_bravais) structure.site_coords = coords[:num_atom_bravais] structure.site_compositions = comps[:num_atom_bravais] return structure else: return structure
def refine_cell(bulk, symprec=1e-5, angle_tolerance=-1.0): """ Return refined cell """ # Atomic positions have to be specified by scaled positions for spglib. num_atom = bulk.get_number_of_atoms() lattice = bulk.get_cell().T.copy() pos = np.zeros((num_atom * 4, 3), dtype='double') pos[:num_atom] = bulk.get_scaled_positions() numbers = np.zeros(num_atom * 4, dtype='intc') numbers[:num_atom] = np.intc(bulk.get_atomic_numbers()) num_atom_bravais = spg.refine_cell(lattice, pos, numbers, num_atom, symprec, angle_tolerance) return (lattice.T.copy(), pos[:num_atom_bravais].copy(), numbers[:num_atom_bravais].copy())
def refine_cell(bulk, symprec=1e-5, angle_tolerance=-1.0): """ Return refined cell """ # Atomic positions have to be specified by scaled positions for spglib. num_atom = bulk.get_number_of_atoms() lattice = np.array(bulk.get_cell().T, dtype='double', order='C') pos = np.zeros((num_atom * 4, 3), dtype='double') pos[:num_atom] = bulk.get_scaled_positions() numbers = np.zeros(num_atom * 4, dtype='intc') numbers[:num_atom] = np.array(bulk.get_atomic_numbers(), dtype='intc') num_atom_std = spg.refine_cell(lattice, pos, numbers, num_atom, symprec, angle_tolerance) return (np.array(lattice.T, dtype='double', order='C'), np.array(pos[:num_atom_std], dtype='double', order='C'), np.array(numbers[:num_atom_std], dtype='intc'))
def get_refined_structure(self): """ Return refined Structure """ # Atomic positions have to be specified by scaled positions for spglib. num_atom = self._structure.num_sites lattice = self._lattice.T.copy() pos = np.zeros((num_atom * 4, 3), dtype=float) pos[:num_atom] = self._positions.copy() numbers = np.zeros(num_atom * 4, dtype=int) numbers[:num_atom] = self._numbers.copy() num_atom_bravais = spg.refine_cell(lattice, pos, numbers, num_atom, self._symprec, self._angle_tol) zs = numbers[:num_atom_bravais] species = [self._unique_species[i - 1] for i in zs] return Structure(lattice.T.copy(), species, pos[:num_atom_bravais])
def refine_cell(bulk, symprec=1e-5, angle_tolerance=-1.0): """ Return refined cell """ # Atomic positions have to be specified by scaled positions for spglib. num_atom = bulk.get_number_of_atoms() lattice = np.array(bulk.get_cell().T, dtype='double', order='C') pos = np.zeros((num_atom * 4, 3), dtype='double') pos[:num_atom] = bulk.get_scaled_positions() numbers = np.zeros(num_atom * 4, dtype='intc') numbers[:num_atom] = np.array(bulk.get_atomic_numbers(), dtype='intc') num_atom_bravais = spg.refine_cell(lattice, pos, numbers, num_atom, symprec, angle_tolerance) return (np.array(lattice.T, dtype='double', order='C'), np.array(pos[:num_atom_bravais], dtype='double', order='C'), np.array(numbers[:num_atom_bravais], dtype='intc'))
def refine_cell(self): """ get refined data from symmetry finding """ if self.sym: # Temporary storage of structure info _lattice = self._lattice.T.copy() _scaled_coords = self._scaled_coords.copy() _symprec = self._symprec _angle_tol = self._angle_tol _numbers = self._numbers.copy() keys = ('number', 'international', 'hall', 'transformation_matrix', 'origin_shift', 'rotations', 'translations', 'wyckoffs', 'equivalent_atoms') dataset = {} dataset['number'] = 0 while dataset['number'] == 0: # refine cell num_atom = len(_scaled_coords) ref_lattice = _lattice.copy() ref_pos = np.zeros((num_atom * 4, 3), dtype=float) ref_pos[:num_atom] = _scaled_coords.copy() ref_numbers = np.zeros(num_atom * 4, dtype=int) ref_numbers[:num_atom] = _numbers.copy() num_atom_bravais = spg.refine_cell(ref_lattice, ref_pos, ref_numbers, num_atom, _symprec, _angle_tol) for key, data in zip(keys, spg.dataset(ref_lattice.copy(), ref_pos[:num_atom_bravais].copy(), ref_numbers[:num_atom_bravais].copy(), _symprec, _angle_tol)): dataset[key] = data _symprec = _symprec * 0.5 # an error occured with met9, org1, org9 whereby no # symmetry info was being printed for some reason. # thus a check is done after refining the structure. if dataset['number'] == 0: warning("WARNING - Bad Symmetry found!") self.sym = False else: self.dataset['number'] = dataset['number'] self.dataset['international'] = dataset['international'].strip() self.dataset['hall'] = dataset['hall'].strip() self.dataset['transformation_matrix'] = np.array(dataset['transformation_matrix']) self.dataset['origin_shift'] = np.array(dataset['origin_shift']) self.dataset['rotations'] = np.array(dataset['rotations']) self.dataset['translations'] = np.array(dataset['translations']) letters = "abcdefghijklmnopqrstuvwxyz" self.dataset['wyckoffs'] = [letters[x] for x in dataset['wyckoffs']] self.dataset['equivalent_atoms'] = np.array(dataset['equivalent_atoms']) self._lattice = ref_lattice.T.copy() self._scaled_coords = ref_pos[:num_atom_bravais].copy() self._numbers = ref_numbers[:num_atom_bravais].copy() self._element_symbols = [ATOMIC_NUMBER[i] for i in ref_numbers[:num_atom_bravais]]