def symmetry(poscar,attr,sympre): """ argument: poscar, the path of your initial POSCAR attr, the attribute you want to get Example: pyvasp symmetry space POSCAR # get space_group pyvasp symmetry equivalent POSCAR # get equivalent_atoms pyvasp symmetry primitive POSCAR # get primitive cell """ c = read_vasp(poscar) if 'space' in attr or 'group' in attr: print('Space group: ', c.get_spacegroup(sympre)) elif 'equiv' in attr: equ_atom = c.get_symmetry(sympre)['equivalent_atoms'] atom_type = np.unique(equ_atom) atom_species,k = {},1 for ii in atom_type: atom_species[k] = np.where(equ_atom==ii)[0]+1 k += 1 for key, val in atom_species.items(): print(key,val) elif 'primi' in attr: if c.is_primitive(): click.echo('This poscar is a primitive cell, or you can decrease symprec to try to get a primitive cell') return pc = c.get_primitive_cell(sympre) write_vasp(pc,'primitive_cell')
def wirite_poscar(cell, purity_atom='', folder='.', idx=0): if purity_atom == '': filename = 'POSCAR-idx-' + str(idx) else: comment = 'POSCAR-' + purity_atom + '-defect' filename = '{:s}_id{:d}'.format(comment, idx) file = path.join('./' + folder, filename) write_vasp(cell, file)
def _export_supercell(pcell, comment, dimension, v, symprec, comprec, verbose): cells = cells_nonredundant( pcell, v, dimension, symprec=symprec, comprec=comprec) for idx, c in enumerate(cells): if verbose: print(" " + "No.{:d}: Processing".format(idx)) filename = '{:s}_v{:d}_id{:d}'.format(comment, v, idx) write_vasp(c, filename)
def extend_spec_direc(pcell_filename, volume): """ First parameter: filename, the path of your initial POSCAR Sencond parameter: volume, the volume you want to extend Example: pyvasp extend_spec_direc -v 2 2 2 POSCAR """ pcell = read_vasp(pcell_filename) supcell = pcell.extend(np.diag(volume)) write_vasp(supcell, 'supcell')
def cell(pcell_filename, volume): """ First parameter: pcell_filename, the path of your initial POSCAR Sencond parameter: volume, the volume you want to extend Example: module load sagar #load the necessay package pyvasp.py cell -v 2 2 2 POSCAR """ pcell = read_vasp(pcell_filename) supcell = pcell.extend(np.diag(volume)) write_vasp(supcell, 'supcell')
def symmetry(poscar, attr, sympre): """ argument: poscar, the path of your initial POSCAR attr, the attribute you want to get Example: module load sagar #load the necessay package pyvasp.py symmetry -a space POSCAR # get space_group pyvasp.py symmetry -a translations POSCAR # get translations symmetry pyvasp.py symmetry -a rotations POSCAR # get rotations symmetry pyvasp.py symmetry -a equivalent POSCAR # get equivalent_atoms pyvasp.py symmetry -a primitive POSCAR # get primitive cell """ c = read_vasp(poscar) if 'space' in attr or 'group' in attr: print('Space group: ', c.get_spacegroup(sympre)) elif 'symme' in attr: print('Symmetry: ', c.get_symmetry(sympre)) elif 'trans' in attr: print('Translations Symmetry: ', c.get_symmetry(sympre)['translations']) elif 'rotat' in attr: print('Rotations Symmetry: ', c.get_symmetry(sympre)['rotations']) elif 'equiv' in attr: equ_atom = c.get_symmetry(sympre)['equivalent_atoms'] atom_type = np.unique(equ_atom) atom_species, k = {}, 1 for ii in atom_type: atom_species[k] = np.where(equ_atom == ii)[0] + 1 k += 1 for key, val in atom_species.items(): print(key, val) elif 'primi' in attr: pc = c.get_primitive_cell(sympre) write_vasp(pc, 'primitive_cell')
def cell(pcell_filename, volume): pcell = read_vasp(pcell_filename) supcell = pcell.extend(np.diag(volume)) write_vasp(supcell, 'supcell')
def conf(cell_filename, comment, pmode, cmode, dimension, volume, element, substitutes, number, symprec, comprec, verbose): """ <parent_cell_file> is the parent cell to generating configurations by sites disorder.\n The non-primitive cell can only used as argument when '--pmode=sc'.\n Command line tool only provide configurations generator for elements disorder, for more flexible usage such as specific site disorder, please see document http:// , or use python library directly. """ cell = read_vasp(cell_filename) cg = ConfigurationGenerator(cell, symprec) if pmode == 'varv' and cmode == 'vc': click.secho("Expanding and generating configurations: ") click.secho("(may take much time)", blink=True, bold=True, bg='magenta', fg='white') spinner = Spinner() spinner.start() (min_v, max_v) = volume if min_v == -1: min_v = 1 sites = _get_sites(list(cell.atoms), element, substitutes) confs = cg.cons_max_volume(sites, max_v, min_volume=min_v, dimension=dimension, symprec=symprec) for idx, c in enumerate(confs): c = c.get_primitive_cell() filename = '{:s}_id{:d}'.format(comment, idx) write_vasp(c, filename) spinner.stop() click.secho("DONE", bold=True, bg='green', fg='white') elif pmode == 'svc' and cmode == 'vc': click.secho("Expanding and generating configurations: ") click.secho("(may take much time)", blink=True, bold=True, bg='magenta', fg='white') spinner = Spinner() spinner.start() (min_v, max_v) = volume sites = _get_sites(list(cell.atoms), element, substitutes) confs = cg.cons_specific_volume(sites, volume=max_v, e_num=None, dimension=dimension, symprec=symprec) f_deg = open('deg.txt', 'a') for idx, (c, d) in enumerate(confs): filename = '{:s}_id{:d}'.format(comment, idx) write_vasp(c, filename) deg_line = filename + '{:10d}'.format(d) + '\n' f_deg.write(deg_line) f_deg.close() spinner.stop() click.secho("DONE", bold=True, bg='green', fg='white') elif pmode == 'svc' and cmode == 'cc': click.secho("Expanding and generating configurations: ") click.secho("(may take much time)", blink=True, bold=True, bg='magenta', fg='white') spinner = Spinner() spinner.start() (min_v, max_v) = volume l_atoms = cell.atoms.tolist() sites = _get_sites(l_atoms, element, substitutes) # number to enum ele_n = s2n(element) e_total = l_atoms.count(ele_n) * max_v e_n = e_total - sum(number) # 第一个元素的数量 e_num = [e_n] + list(number) # 各个元素的数量 confs = cg.cons_specific_volume(sites, volume=max_v, e_num=e_num, dimension=dimension, symprec=symprec) f_deg = open('deg.txt', 'a') for idx, (c, d) in enumerate(confs): filename = '{:s}_id{:d}'.format(comment, idx) write_vasp(c, filename) deg_line = filename + '{:10d}'.format(d) + '\n' f_deg.write(deg_line) f_deg.close() spinner.stop() click.secho("DONE", bold=True, bg='green', fg='white') elif pmode == 'sc' and cmode == 'vc': click.secho("Generating configurations: ") click.secho("(may take much time)", blink=True, bold=True, bg='magenta', fg='white') spinner = Spinner() spinner.start() l_atoms = cell.atoms.tolist() sites = _get_sites(l_atoms, element, substitutes) confs = cg.cons_specific_cell(sites, None, symprec=symprec) f_deg = open('deg.txt', 'a') for idx, (c, d) in enumerate(confs): filename = '{:s}_id{:d}'.format(comment, idx) write_vasp(c, filename) # import pdb; pdb.set_trace() deg_line = filename + '{:10d}'.format(d) + '\n' f_deg.write(deg_line) f_deg.close() spinner.stop() click.secho("DONE", bold=True, bg='green', fg='white') elif pmode == 'sc' and cmode == 'cc': click.secho("Generating configurations: ") click.secho("(may take much time)", blink=True, bold=True, bg='magenta', fg='white') spinner = Spinner() spinner.start() l_atoms = cell.atoms.tolist() sites = _get_sites(l_atoms, element, substitutes) # number to enum ele_n = s2n(element) e_total = l_atoms.count(ele_n) e_n = e_total - sum(number) # 第一个元素的数量 e_num = [e_n] + list(number) # 各个元素的数量 confs = cg.cons_specific_cell(sites, e_num, symprec=symprec) f_deg = open('deg.txt', 'a') # TODO f.close() for idx, (c, d) in enumerate(confs): filename = '{:s}_id{:d}'.format(comment, idx) write_vasp(c, filename) deg_line = filename + '{:10d}'.format(d) + '\n' f_deg.write(deg_line) f_deg.close() spinner.stop() click.secho("DONE", bold=True, bg='green', fg='white') else: click.secho("ERROR: --pmode={:s} --cmode={:s} not supported.".format( pmode, cmode), bold=True, bg='red', fg='white')
def wirite_poscar(cell, purity_atom, folder, idx): comment = 'POSCAR-' + purity_atom + '-defect' filename = '{:s}_id{:d}'.format(comment, idx) file = path.join('./' + folder, filename) write_vasp(cell, file)
neig_list = np.zeros((n, 6)) for ii in range(pos.shape[0]): d = np.linalg.norm(pos[ii] - extend_pos, axis=1) idx = np.where(abs(d - d[np.argsort(d)[1]]) < 0.01)[0] neig_list[ii] = idx % n pos = np.dot(pos, np.linalg.inv(latt)) vac_str = [np.array([0])] for vac in range(2, 6): last_vac_str = vac_str[-1] tmp_vac_str = [] n_prev = last_vac_str.shape[0] for i in range(n_prev): each_str = last_vac_str[i] idx = np.setdiff1d(np.setdiff1d(range(n), each_str), neig_list[each_str][:]) for ii in idx: tmp_vac_str.append(get_min_serial(perms, np.hstack( (each_str, ii)))) vac_str.append(np.unique(tmp_vac_str, axis=0)) idx = 0 os.makedirs('vac-' + str(vac)) for _str in vac_str[-1]: _pos = pos[np.setdiff1d(range(n), _str), :] _latt, _atoms = latt, np.ones((n - vac, )) * 5 write_vasp(Cell(_latt, _pos, _atoms), 'vac-' + str(vac) + '/POSCAR' + str(idx)) idx += 1 print(vac_str[-1].shape)
def write_poscar(cell, folder='.', idx=0, comment=""): filename = '{:s}{:d}'.format('POSCAR' + comment, idx) file = path.join(folder, filename) write_vasp(cell, file, suffix='')