def get_lmto_structure(cell): lattice = cell.get_cell() (num_atoms, symbols, scaled_positions, sort_list) = sort_positions_by_symbols(cell.get_chemical_symbols(), cell.get_scaled_positions()) lines = '%% site-data vn=3.0 xpos fast io=62 nbas=%d' % sum(num_atoms) lines += ' alat=1.0 plat=' + ('%.6f ' * 9 + '\n') % tuple(lattice.ravel()) lines += '# pos ' lines += 'vel eula ' lines += 'vshft PL rlx\n' atom_species = [] for i, j in zip(symbols, num_atoms): atom_species.append([i]*j) for x, y in zip(sum(atom_species, []), scaled_positions): lines += ' %s' % x lines += ' %.7f %.7f %.7f' % tuple(y) lines += ' %.7f %.7f %.7f %.7f %.7f %.7f %.7f' % tuple([0.0] * 7) lines += ' 0 111\n' return lines
def get_elk_structure(cell, sp_filenames=None): """Return Elk structure in text.""" lattice = cell.get_cell() (num_atoms, symbols, scaled_positions, sort_list) = sort_positions_by_symbols(cell.get_chemical_symbols(), cell.get_scaled_positions()) if sp_filenames is None: spfnames = [s + ".in" for s in symbols] else: spfnames = sp_filenames lines = "" lines += "avec\n" lines += ((" %21.16f" * 3 + "\n") * 3) % tuple(lattice.ravel()) lines += "atoms\n" n_pos = 0 lines += " %d\n" % len(num_atoms) for i, (n, s) in enumerate(zip(num_atoms, spfnames)): lines += " '%s'\n" % s lines += " %d\n" % n lines += get_scaled_positions_lines(scaled_positions[n_pos:(n_pos + n)]) if i < len(num_atoms) - 1: lines += "\n" n_pos += n return lines
def get_fleur_structure(cell, speci, N, restlines): lattice = cell.get_cell() (num_atoms, symbols, scaled_positions, sort_list) = sort_positions_by_symbols(cell.get_chemical_symbols(), cell.get_scaled_positions()) specilong = list( itertools.chain.from_iterable(itertools.repeat(x, N) for x in speci)) lines = restlines[0] + "\n" lines += ((" %21.16f" * 3 + "\n") * 3) % tuple(lattice.ravel()) lines += '1.0 \n' lines += '1.0 1.0 1.0 \n \n' lines += str(sum(num_atoms)) + '\n' for i in range(sum(num_atoms)): lines += specilong[i].ljust(6) currentpos = str(scaled_positions[i]).replace("[", "") currentpos = currentpos.replace("]", "").split() for j in range(3): lines += ' ' + "{:.10f}".format(float(currentpos[j])) if i < sum(num_atoms) - 1: lines += "\n" for x in range(1, len(restlines)): if len(restlines[x]) == 0: lines += "\n" continue lines += restlines[x] if x != len(restlines) - 1: lines += "\n" return lines
def get_elk_structure(cell, sp_filenames=None): lattice = cell.get_cell() (num_atoms, symbols, scaled_positions, sort_list) = sort_positions_by_symbols(cell.get_chemical_symbols(), cell.get_scaled_positions()) if sp_filenames is None: spfnames = [s + ".in" for s in symbols] else: spfnames = sp_filenames lines = "" lines += "avec\n" lines += ((" %21.16f" * 3 + "\n") * 3) % tuple(lattice.ravel()) lines += "atoms\n" n_pos = 0 lines += " %d\n" % len(num_atoms) for i, (n, s) in enumerate(zip(num_atoms, spfnames)): lines += " \'%s\'\n" % s lines += " %d\n" % n lines += get_scaled_positions_lines(scaled_positions[n_pos:(n_pos + n)]) if i < len(num_atoms) - 1: lines += "\n" n_pos += n return lines
def write_magnetic_moments(cell, sort_by_elements=False): magmoms = cell.magnetic_moments if magmoms is not None: if sort_by_elements: (_, _, _, sort_list) = sort_positions_by_symbols(cell.symbols, cell.scaled_positions) else: sort_list = range(cell.get_number_of_atoms()) with open("MAGMOM", 'w') as w: w.write(" MAGMOM = ") for i in sort_list: w.write("%f " % magmoms[i]) w.write("\n") w.close()
def get_standardized_cell(self, to_primitive: bool, no_idealize: bool, symprec: float = 1e-5, no_sort: bool = False, get_sort_list: list = False): """ Get stadandardized cell. Args: to_primitive (bool): True => primitive, False => conventional. no_idealize (bool): True => not rotate crystal body, False => rotate crystal body symprec (float): symmetry tolerance, for more detail see spglib documentation no_sort (bool): does not change atoms order get_sort_list (bool): When no_sort=True, return sort list Returns: tuple: If get_sort_list=False, return cell. If get_sort_list=True, return (cell, sort_list). """ spg_cell = spglib.standardize_cell(self._cell_for_spglib, to_primitive=to_primitive, no_idealize=no_idealize, symprec=symprec) symbols = get_symbols_from_numbers(spg_cell[2]) std_cell = (spg_cell[0], spg_cell[1], symbols) if no_sort: return std_cell num_atoms, unique_symbols, scaled_positions, sort_list = \ sort_positions_by_symbols( symbols=std_cell[2], positions=std_cell[1]) symbols = [] for num, symbol in zip(num_atoms, unique_symbols): symbols.extend([symbol] * num) sort_std_cell = (std_cell[0], scaled_positions, symbols) if get_sort_list: return (sort_std_cell, sort_list) return sort_std_cell
def get_lmto_structure(cell): lattice = cell.get_cell() (num_atoms, symbols, scaled_positions, sort_list) = sort_positions_by_symbols(cell.get_chemical_symbols(), cell.get_scaled_positions()) lines = '%% site-data vn=3.0 xpos fast io=62 nbas=%d' % sum(num_atoms) lines += ' alat=1.0 plat=' + ('%.6f ' * 9 + '\n') % tuple(lattice.ravel()) lines += '# pos ' lines += 'vel eula ' lines += 'vshft PL rlx\n' atom_species = [] for i, j in zip(symbols, num_atoms): atom_species.append([i] * j) for x, y in zip(sum(atom_species, []), scaled_positions): lines += ' %s' % x lines += ' %.7f %.7f %.7f' % tuple(y) lines += ' %.7f %.7f %.7f %.7f %.7f %.7f %.7f' % tuple( [0.0] * 7) lines += ' 0 111\n' return lines