def get_delete_atom_num(no_defect_poscar, one_defect_poscar): no_defect = read_vasp(no_defect_poscar) one_defect = read_vasp(one_defect_poscar) no_def_pos = no_defect.positions one_def_pos = one_defect.positions no_def_pos[abs(no_def_pos - 1) < 0.01] = 0 one_def_pos[abs(one_def_pos - 1) < 0.01] = 0 if len(no_defect.atoms) - 1 == len(one_defect.atoms): num = no_def_pos.shape[0] for ii in range(num): d = np.linalg.norm(no_def_pos[ii] - one_def_pos, axis=1) if min(d) > 0.1: break _no_def_pos = np.unique(np.delete(no_def_pos, ii, 0), axis=0) _one_def_pos = np.unique(one_def_pos, axis=0) d = 0 for i in _no_def_pos: d = d + min(np.linalg.norm(i - _one_def_pos, axis=1)) for key, val in ptd.items(): if val == no_defect.atoms[ii]: rm_atom = key break print('This is a vacancy defect', 'atom: \n', rm_atom, ii + 1, 'in the defect-free POSCAR has benn removed') with open('element-in-out', 'w') as f: f.writelines(str(rm_atom) + '=' + str(1) + '\n') f.writelines('Vacc=-1 \n') return ii, d elif len(no_defect.atoms) == len(one_defect.atoms): no_def_atoms, def_atoms = np.unique(no_defect.atoms), np.unique( one_defect.atoms) purity_atom = np.setdiff1d(def_atoms, no_def_atoms) idx = np.where(one_defect.atoms == purity_atom)[0] d = np.linalg.norm(one_def_pos[idx] - no_def_pos, axis=1) ii, d = np.argmin(d), np.min(d) for key, val in ptd.items(): if val == no_defect.atoms[ii]: rm_atom = key if val == purity_atom: in_atom = key print('This is a purity defect', 'atom: \n', rm_atom, ii + 1, 'in the defect-free POSCAR has benn dopped by', in_atom) with open('element-in-out', 'w') as f: f.writelines(str(rm_atom) + '=' + str(1) + '\n') f.writelines(str(in_atom) + '=' + str(-1) + '\n') return ii, d else: print('This kind of defect is not supported here right now')
def test_kpts(self,kw={}): start,end,step = kw.get('start'),kw.get('end'),kw.get('step') is_login_node,kw = run_vasp.clean_parse(kw,'is_login_node',False) kw.pop('start');kw.pop('end');kw.pop('step') kpts = Kpoints() kpts_list = set() kppa_list = [] for kppa in range(start,end,step): kpts.automatic_density(structure=read_vasp(self.poscar),kppa=kppa) if tuple(kpts.kpts[0]) not in kpts_list: kpts_list.add(tuple(kpts.kpts[0])) kppa_list.append(kppa) idx = 0 for kppa in kppa_list: _kw = kw.copy() if 'style' not in _kw: _kw.update({'kppa':kppa,'style':'auto','job_name':'test_kpts'+str(idx),'NSW':0}) prep_vasp.prep_single_vasp(poscar=self.poscar,kw=_kw) idx += 1 for i in range(idx): run_vasp.run_single_vasp(job_name='test_kpts'+str(i),is_login_node=is_login_node) kpts_res = [] for ii in range(len(kppa_list)): EV = ExtractValue(data_folder='test_kpts'+str(ii)) kpts_res.append([kppa_list[ii],EV.get_energy(),EV.get_cpu_time()]) with open('test_kpts.txt','w') as f: f.writelines('KPTS\tEnergy\tcpu_time\n') for line in kpts_res: f.writelines(str(line[0])+'\t'+str(line[1])+'\t'+str(line[2])+'\n')
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 __init__(self, no_defect='POSCAR', no_defect_string=''): # 初始化用 POSCAR路径? if no_defect_string: self.no_defect_cell = _read_string(no_defect_string) else: self.no_defect_cell = read_vasp(no_defect) self.lattice = self.no_defect_cell.lattice self.positions = self.no_defect_cell.positions self.atoms = self.no_defect_cell.atoms
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 diff_poscar(pri_pos,pos1,pos2,symprec=1e-3): ''' To compare two structures are the same or not ''' cell1,cell2 = read_vasp(pos1),read_vasp(pos2) if sum(sum((cell1.lattice-cell2.lattice)**2))>0.01: raise ValueError("Two POSCARs do not have the same lattice") if len(cell1.atoms) != len(cell2.atoms): raise ValueError("Two POSCARs do not have the same atoms number") if sum(np.sort(cell1.atoms)-np.sort(cell2.atoms))>0.001: raise ValueError("Two POSCARs do not have the same atoms") cell = read_vasp(pri_pos) if sum(sum((cell1.lattice-cell.lattice)**2))>0.01: raise ValueError("Two POSCAR do not have the same lattice with the primitive POSCAR") idx_1 = get_idx_in_pri_pos(cell.positions,cell1.positions) idx_2 = get_idx_in_pri_pos(cell.positions,cell2.positions) perms = get_perms(cell,symprec=symprec) serial_1 = _get_min_serial(perms,idx_1) serial_2 = _get_min_serial(perms,idx_2) if sum(serial_1-serial_2) <= 0.001: return True return False
def extend_specific_volume(pcell_filename, dimension, volume, symprec, comprec, verbose): """ <primitive_cell_file> Primitive cell structure file, now only vasp POSCAR version5 supported. """ pcell = read_vasp(pcell_filename) comment = 'cell' (min_v, max_v) = volume if min_v == -1: click.echo("Expanding primitive to volume {:d}".format(max_v)) _export_supercell(pcell, comment, dimension, max_v, symprec, comprec, verbose) else: for v in range(min_v, max_v + 1): click.echo("Expanding primitive to volume {:d}".format(v)) _export_supercell(pcell, comment, dimension, v, symprec, comprec, verbose)
def get_farther_atom_num(no_defect_poscar, one_defect_poscar): ''' Return: 1: atom number of the farther atom in defect system 2: atom number of the farther atom in defect-free system ''' all_basis = generate_all_basis(1, 1, 1) no_defect = read_vasp(no_defect_poscar) one_defect = read_vasp(one_defect_poscar) no_def_pos = no_defect.positions one_def_pos = one_defect.positions c = no_defect.lattice no_def_pos = np.dot(no_def_pos, c) one_def_pos = np.dot(one_def_pos, c) ii, d = get_delete_atom_num(no_defect_poscar, one_defect_poscar) defect_atom = no_def_pos[ii] extend_S = [] d, idx = np.zeros((no_def_pos.shape[0], 27)), 0 for basis in all_basis: i, j, k = basis d[:, idx] = np.linalg.norm( defect_atom - (no_def_pos + i * c[0] + j * c[1] + k * c[2]), axis=1) idx += 1 max_idx_no_def = np.argmax(np.min(d, axis=1)) #no-defect-farther-atom-number # import pdb;pdb.set_trace() d, idx = np.zeros((one_def_pos.shape[0], 27)), 0 for basis in all_basis: i, j, k = basis d[:, idx] = np.linalg.norm( defect_atom - (one_def_pos + i * c[0] + j * c[1] + k * c[2]), axis=1) idx += 1 max_idx_one_def = np.argmax(np.min(d, axis=1)) return max_idx_one_def + 1, max_idx_no_def + 1
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 read_doscar(wd): c = read_vasp(os.path.join(wd, 'POSCAR')) line6 = np.genfromtxt(os.path.join(wd, 'DOSCAR'), skip_header=5, max_rows=1) n_dos = int(line6[2]) sum_dos = np.genfromtxt(os.path.join(wd, 'DOSCAR'), skip_header=6, max_rows=n_dos) np.savetxt(os.path.join(wd, 'sum_dos.txt'), sum_dos, fmt="%.5f") incar = read_incar(os.path.join(wd, 'INCAR')) if 'LORBIT' not in incar: return if int(incar['LORBIT']) == 11: for ii in range(c.atoms.shape[0]): p_dos = np.genfromtxt(os.path.join(wd, 'DOSCAR'), skip_header=6 + (1 + n_dos) * (ii + 1), max_rows=n_dos) np.savetxt(os.path.join(wd, 'p_dos' + str(ii) + '.txt'), p_dos, fmt="%.5f")
def write_kpoints(poscar='POSCAR', kw={}): if not path.isfile(poscar): raise FileNotFoundError('Not found POSCAR') stru = read_vasp(poscar) style, kw = clean_parse(kw, 'style', 'auto') if not path.isfile('KPOINTS'): _kpts = Kpoints() if 'auto' in style.lower(): if 'kpts' not in kw: kppa, kw = clean_parse(kw, 'kppa', 3000) kppa = float(kppa) _kpts.automatic_density(structure=stru, kppa=kppa) _kpts.write_file('KPOINTS') else: kpts, kw = clean_parse(kw, 'kpts', (1, 1, 1)) shift, kw = clean_parse(kw, 'shift', (0, 0, 0)) _kpts.gamma_automatic(kpts=kpts, shift=shift) _kpts.write_file('KPOINTS') elif 'gamma' in style.lower() and 'kpts' not in kw: kppa, kw = clean_parse(kw, 'kppa', 3000) kppa = float(kppa) _kpts.automatic_gamma_density(structure=stru, kppa=kppa) _kpts.write_file('KPOINTS') elif 'gamma' in style.lower() and 'kpts' in kw: kpts, kw = clean_parse(kw, 'kpts', (1, 1, 1)) shift, kw = clean_parse(kw, 'shift', (0, 0, 0)) _kpts.gamma_automatic(kpts=kpts, shift=shift) _kpts.write_file('KPOINTS') elif 'monk' in style.lower() and 'kpts' in kw: kpts, kw = clean_parse(kw, 'kpts', (1, 1, 1)) shift, kw = clean_parse(kw, 'shift', (0, 0, 0)) _kpts.monkhorst_automatic(kpts=kpts, shift=shift) _kpts.write_file('KPOINTS') elif 'band' in style.lower() or 'line' in style.lower(): num_kpts, kw = clean_parse(kw, 'num_kpts', 16) _kpts.automatic_linemode(structure=stru, num_kpts=num_kpts) _kpts.write_file('KPOINTS') return kw
if dimension == 2: supercell = pcell.extend(h)._get_niggli_2D() else: supercell = pcell.extend(h)._get_niggli_3D() _sites = np.repeat(sites, volume, axis=0) for mol, _ in remove_redundant(supercell.positions, _sites, perms): c = Cell(supercell.lattice, mol[0], mol[1]) if c.is_primitive(symprec): yield c def get_identity_atoms(cell, symprec, style="crystal"): atom_number = cell.atoms if style == "crystal": equ_atom = cell.get_symmetry(symprec)['equivalent_atoms'] atom_uniq_type = np.unique(equ_atom) atom_type = np.zeros(np.shape(equ_atom)) for idx, ea in enumerate(equ_atom): atom_type[idx] = np.where(atom_uniq_type == ea)[0] return atom_type if __name__ == '__main__': cell = read_vasp("/home/hecc/Desktop/Al_prim.vasp") for idx, c in enumerate(get_max_volume(cell, [(13, 42)], 12, min_volume=2)): write_poscar(c, folder="/home/hecc/Desktop/fcc", idx=idx)
def __init__(self, poscar='POSCAR'): self.poscar = poscar if is_2d_structure(read_vasp(self.poscar)): self.dimen = 2 else: self.dimen = 3
def get_delete_atom_num(no_defect_poscar, one_defect_poscar): no_defect = read_vasp(no_defect_poscar) one_defect = read_vasp(one_defect_poscar) no_def_pos = no_defect.positions one_def_pos = one_defect.positions no_def_pos[abs(no_def_pos - 1) < 0.01] = 0 one_def_pos[abs(one_def_pos - 1) < 0.01] = 0 if len(no_defect.atoms) - 1 == len(one_defect.atoms): num = no_def_pos.shape[0] for ii in range(num): d = np.linalg.norm(no_def_pos[ii] - one_def_pos, axis=1) if min(d) > 0.1: break _no_def_pos = np.unique(np.delete(no_def_pos, ii, 0), axis=0) _one_def_pos = np.unique(one_def_pos, axis=0) d = 0 for i in _no_def_pos: d = d + min(np.linalg.norm(i - _one_def_pos, axis=1)) for key, val in ptd.items(): if val == no_defect.atoms[ii]: rm_atom = key break print('This is a vacancy defect', 'atom: \n', rm_atom, ii + 1, 'in the defect-free POSCAR has benn removed') with open('element-in-out', 'w') as f: f.writelines(str(rm_atom) + '=' + str(1) + '\n') f.writelines('Vacc=-1 \n') return ii, d elif len(no_defect.atoms) == len(one_defect.atoms): no_def_atoms, def_atoms = np.unique(no_defect.atoms), np.unique( one_defect.atoms) purity_atom = np.setdiff1d(def_atoms, no_def_atoms) if len(purity_atom) != 0: # introduce a new atom purity idx = np.where(one_defect.atoms == purity_atom)[0] d = np.linalg.norm(one_def_pos[idx] - no_def_pos, axis=1) ii, d = np.argmin(d), np.min(d) for key, val in ptd.items(): if val == no_defect.atoms[ii]: rm_atom = key if val == purity_atom: in_atom = key print('This is a purity defect', 'atom: \n', rm_atom, ii + 1, 'in the defect-free POSCAR has benn dopped by', in_atom) with open('element-in-out', 'w') as f: f.writelines(str(rm_atom) + '=' + str(1) + '\n') f.writelines(str(in_atom) + '=' + str(-1) + '\n') return ii, d else: purity_atom = [] for _atom in no_def_atoms: idx_num_1, idx_num_2 = len( np.where(_atom == no_defect.atoms)[0]), len( np.where(_atom == one_defect.atoms)[0]) if abs(idx_num_2 - idx_num_1) == 1: purity_atom.append(_atom) elif abs(idx_num_1 - idx_num_2) > 1: raise ValueError("The POSCAR has two or more defect atoms") if len(purity_atom) > 2: raise ValueError("The POSCAR has two or more defect atoms") no_def_pos_0 = no_def_pos[no_defect.atoms == purity_atom[0]] no_def_pos_1 = no_def_pos[no_defect.atoms == purity_atom[1]] one_def_pos_0 = one_def_pos[one_defect.atoms == purity_atom[0]] one_def_pos_1 = one_def_pos[one_defect.atoms == purity_atom[1]] if no_def_pos_0.shape[0] - one_def_pos_0.shape[0] == 1: purity_in = purity_atom[1] purity_out = purity_atom[0] d = [ min(np.linalg.norm(pos - one_def_pos_0, axis=1)) for pos in no_def_pos_0 ] ahead_num = np.where(no_defect.atoms == purity_out)[0][0] idx = np.argmax(d) for key, val in ptd.items(): if val == purity_out: rm_atom = key if val == purity_in: in_atom = key print('This is a purity defect', 'atom: \n', rm_atom, ahead_num + idx + 1, 'in the defect-free POSCAR has benn dopped by', in_atom) with open('element-in-out', 'w') as f: f.writelines(str(rm_atom) + '=' + str(1) + '\n') f.writelines(str(in_atom) + '=' + str(-1) + '\n') return ahead_num + idx, d[idx] else: purity_in = purity_atom[0] purity_out = purity_atom[1] d = [ min(np.linalg.norm(pos - one_def_pos_1, axis=1)) for pos in no_def_pos_1 ] idx = np.argmax(d) ahead_num = np.where(no_defect.atoms == purity_out)[0][0] # import pdb; pdb.set_trace() for key, val in ptd.items(): if val == purity_out: rm_atom = key if val == purity_in: in_atom = key print('This is a purity defect', 'atom: \n', rm_atom, ahead_num + idx + 1, 'in the defect-free POSCAR has benn dopped by', in_atom) with open('element-in-out', 'w') as f: f.writelines(str(rm_atom) + '=' + str(1) + '\n') f.writelines(str(in_atom) + '=' + str(-1) + '\n') return ahead_num + idx, d[idx] else: print('This kind of defect is not supported here right now')
if is_int_np_array(mat): mat = np.around(mat).astype('intc') else: print("cell:\n", lat_cell) print("primitive cell:\n", lat_pcell) raise ValueError( "cell lattice and its primitive cell lattice not convertable") hfpg = PG(pcell, mat) return hfpg.get_symmetry_perms(symprec) def get_min_serial(perms, num): return np.unique(np.sort(perms[:, num], axis=1), axis=0)[0].tolist() cell = read_vasp('POSCAR') perms = get_perms(cell) latt = cell.lattice pos = cell.positions pos = np.dot(pos, latt) n = pos.shape[0] basis = generate_all_basis(1, 1, 0) extend_pos = np.zeros((9 * n, 3)) idx = 0 for ii in basis: extend_pos[n * idx:n * (idx + 1), :] = (pos + ii[0] * latt[0] + ii[1] * latt[1] + ii[2] * latt[2]) idx += 1 neig_list = np.zeros((n, 6)) for ii in range(pos.shape[0]):
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 __init__(self, no_defect='POSCAR'): # 初始化用 POSCAR路径? self.no_defect_cell = read_vasp(no_defect) self.lattice = self.no_defect_cell.lattice self.positions = self.no_defect_cell.positions self.atoms = self.no_defect_cell.atoms
optional_paras = ["genvec1", "genvec2", "genvec3", "shift"] for para in optional_paras: if para in self.__dict__: d[para] = self.__dict__[para] d["@module"] = self.__class__.__module__ d["@class"] = self.__class__.__name__ return d @classmethod def from_dict(cls, d): comment = d.get("comment", "") generation_style = d.get("generation_style") kpts = d.get("kpoints", [[1, 1, 1]]) kpts_shift = d.get("usershift", [0, 0, 0]) num_kpts = d.get("nkpoints", 0) return cls(comment=comment, kpts=kpts, style=generation_style, kpts_shift=kpts_shift, num_kpts=num_kpts, kpts_weights=d.get("kpts_weights"), coord_type=d.get("coord_type"), labels=d.get("labels"), tet_number=d.get("tet_number", 0), tet_weight=d.get("tet_weight", 0), tet_connections=d.get("tet_connections")) if __name__ == '__main__': from sagar.io.vasp import read_vasp c = read_vasp('/home/hecc/Documents/python-package/Defect-Formation-Calculation/pyvaspflow/examples/POSCAR') kpoints = Kpoints() kpoints.automatic_density(structure=c,kppa=3000) kpoints.write_file()