def make_vasp(jdata, conf_dir): fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] conf_path = os.path.abspath(conf_dir) equi_path = re.sub('confs', global_task_name, conf_path) os.makedirs(equi_path, exist_ok=True) cwd = os.getcwd() from_poscar = os.path.join(conf_path, 'POSCAR') to_poscar = os.path.join(equi_path, 'POSCAR') if os.path.exists(to_poscar): assert (filecmp.cmp(from_poscar, to_poscar)) else: os.chdir(equi_path) os.symlink(os.path.relpath(from_poscar), 'POSCAR') os.chdir(cwd) is_alloy = \ os.path.exists( os.path.join( os.path.join(conf_path, '..'), 'alloy' ) ) vasp_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing) os.makedirs(vasp_path, exist_ok=True) os.chdir(vasp_path) print(vasp_path) # gen incar if is_alloy: fc = vasp.make_vasp_relax_incar(ecut, ediff, True, True, True, npar, kpar, kspacing, kgamma) else: fc = vasp.make_vasp_relax_incar(ecut, ediff, False, True, True, npar, kpar, kspacing, kgamma) with open('INCAR', 'w') as fp: fp.write(fc) # gen poscar if os.path.exists('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(to_poscar), 'POSCAR') # gen potcar with open('POSCAR', 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list: assert (os.path.exists(potcar_map[ii])) potcar_list.append(potcar_map[ii]) with open('POTCAR', 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) os.chdir(cwd)
def make_vasp(jdata, conf_dir) : fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] vol_start = jdata['vol_start'] vol_end = jdata['vol_end'] vol_step = jdata['vol_step'] conf_path = os.path.abspath(conf_dir) task_path = re.sub('confs', global_task_name, conf_path) os.makedirs(task_path, exist_ok = True) cwd = os.getcwd() from_poscar = os.path.join(conf_path, 'POSCAR') to_poscar = os.path.join(task_path, 'POSCAR') if os.path.exists(to_poscar) : assert(filecmp.cmp(from_poscar, to_poscar)) else : os.chdir(task_path) os.symlink(os.path.relpath(from_poscar), 'POSCAR') os.chdir(cwd) vol_to_poscar = vasp.poscar_vol(to_poscar) / vasp.poscar_natoms(to_poscar) # print(to_poscar, vol_to_poscar) is_alloy = \ os.path.exists( os.path.join( os.path.join(conf_path, '..'), 'alloy' ) ) vasp_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing) os.makedirs(vasp_path, exist_ok = True) os.chdir(vasp_path) # gen incar if is_alloy : fc = vasp.make_vasp_relax_incar(ecut, ediff, True, True, False, npar, kpar, kspacing, kgamma) else : fc = vasp.make_vasp_relax_incar(ecut, ediff, False, True, False, npar, kpar, kspacing, kgamma) with open('INCAR', 'w') as fp : fp.write(fc) # gen potcar with open(to_poscar,'r') as fp : lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list : assert(os.path.exists(potcar_map[ii])) potcar_list.append(potcar_map[ii]) with open('POTCAR', 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # loop over volumes for vol in np.arange(vol_start, vol_end, vol_step) : vol_path = os.path.join(vasp_path, 'vol-%.2f' % vol) os.makedirs(vol_path, exist_ok = True) os.chdir(vol_path) print(vol_path) for ii in ['INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR'] : if os.path.exists(ii) : os.remove(ii) # link incar, potcar os.symlink(os.path.relpath(os.path.join(vasp_path, 'INCAR')), 'INCAR') os.symlink(os.path.relpath(os.path.join(vasp_path, 'POTCAR')), 'POTCAR') # gen poscar os.symlink(os.path.relpath(to_poscar), 'POSCAR.orig') scale = (vol / vol_to_poscar) ** (1./3.) # print(scale) vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale) # print(vol_path, vasp.poscar_vol('POSCAR') / vasp.poscar_natoms('POSCAR')) os.chdir(cwd)
def _make_vasp(jdata, conf_dir, supercell, insert_ele): fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] conf_path = os.path.abspath(conf_dir) conf_poscar = os.path.join(conf_path, 'POSCAR') # get equi poscar equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing) equi_contcar = os.path.join(equi_path, 'CONTCAR') assert os.path.exists( equi_contcar), "Please compute the equilibrium state using vasp first" task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing) os.makedirs(task_path, exist_ok=True) cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') os.chdir(cwd) task_poscar = os.path.join(task_path, 'POSCAR') # gen strcture print("task poscar: ", task_poscar) ss = Structure.from_file(task_poscar) # gen defects vds = InterstitialGenerator(ss, insert_ele) dss = [] for jj in vds: dss.append(jj.generate_defect_structure(supercell)) # gen incar fc = vasp.make_vasp_relax_incar(ecut, ediff, True, True, True, npar=npar, kpar=kpar, kspacing=kspacing, kgamma=kgamma) with open(os.path.join(task_path, 'INCAR'), 'w') as fp: fp.write(fc) # gen tasks copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2]) cwd = os.getcwd() for ii in range(len(dss)): struct_path = os.path.join( task_path, 'struct-%s-%s-%03d' % (insert_ele, copy_str, ii)) print('# generate %s' % (struct_path)) os.makedirs(struct_path, exist_ok=True) os.chdir(struct_path) for jj in ['POSCAR', 'POTCAR', 'INCAR']: if os.path.isfile(jj): os.remove(jj) # make conf dss[ii].to('POSCAR', 'POSCAR') # gen potcar with open('POSCAR', 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() os.chdir(cwd) potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list: assert os.path.exists(os.path.abspath( potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii) potcar_list.append(os.path.abspath(potcar_map[ii])) os.chdir(struct_path) with open('POTCAR', 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # link incar os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') # save supercell np.savetxt('supercell.out', supercell, fmt='%d') os.chdir(cwd)
def make_vasp(jdata, conf_dir, norm_def = 2e-3, shear_def = 5e-3) : norm_def = jdata['norm_deform'] shear_def = jdata['shear_deform'] conf_path = os.path.abspath(conf_dir) conf_poscar = os.path.join(conf_path, 'POSCAR') # get equi poscar if 'relax_incar' in jdata.keys(): vasp_str='vasp-relax_incar' else: kspacing = jdata['vasp_params']['kspacing'] vasp_str='vasp-k%.2f' % kspacing equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, vasp_str) equi_contcar = os.path.join(equi_path, 'CONTCAR') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, vasp_str) os.makedirs(task_path, exist_ok=True) cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR') : os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') os.chdir(cwd) task_poscar = os.path.join(task_path, 'POSCAR') # stress equi_outcar = os.path.join(equi_path, 'OUTCAR') stress = vasp.get_stress(equi_outcar) np.savetxt(os.path.join(task_path, 'equi.stress.out'), stress) # gen strcture ss = Structure.from_file(task_poscar) # gen defomations norm_strains = [-norm_def, -0.5*norm_def, 0.5*norm_def, norm_def] shear_strains = [-shear_def, -0.5*shear_def, 0.5*shear_def, shear_def] dfm_ss = DeformedStructureSet(ss, symmetry = False, norm_strains = norm_strains, shear_strains = shear_strains) n_dfm = len(dfm_ss) # gen incar if 'relax_incar' in jdata.keys(): relax_incar_path = jdata['relax_incar'] assert(os.path.exists(relax_incar_path)) relax_incar_path = os.path.abspath(relax_incar_path) fc = open(relax_incar_path).read() kspacing =float(re.findall((r"KSPACING(.+?)\n"),fc)[0].replace('=','')) kgamma =('T' in re.findall((r"KGAMMA(.+?)\n"),fc)[0]) else : fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] fc = vasp.make_vasp_relax_incar(ecut, ediff, True, False, False, npar=npar,kpar=kpar, kspacing = kspacing, kgamma = kgamma) with open(os.path.join(task_path, 'INCAR'), 'w') as fp : fp.write(fc) # gen potcar with open(task_poscar,'r') as fp : lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list : assert os.path.exists(os.path.abspath(potcar_map[ii])),"No POTCAR in the potcar_map of %s"%(ii) potcar_list.append(os.path.abspath(potcar_map[ii])) with open(os.path.join(task_path,'POTCAR'), 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # gen kpoints fc = vasp.make_kspacing_kpoints(task_poscar, kspacing, kgamma) with open(os.path.join(task_path,'KPOINTS'), 'w') as fp: fp.write(fc) # gen tasks cwd = os.getcwd() for ii in range(n_dfm) : # make dir dfm_path = os.path.join(task_path, 'dfm-%03d' % ii) os.makedirs(dfm_path, exist_ok=True) os.chdir(dfm_path) for jj in ['POSCAR', 'POTCAR', 'INCAR', 'KPOINTS'] : if os.path.isfile(jj): os.remove(jj) # make conf dfm_ss.deformed_structures[ii].to('POSCAR', 'POSCAR') # record strain strain = Strain.from_deformation(dfm_ss.deformations[ii]) np.savetxt('strain.out', strain) # link incar, potcar, kpoints os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'KPOINTS')), 'KPOINTS') cwd = os.getcwd()
def make_vasp(jdata, conf_dir, norm_def=2e-3, shear_def=5e-3): fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] strain_start = jdata['strain_start'] strain_end = jdata['strain_end'] strain_step = jdata['strain_step'] strain_direct = jdata['strain_direct'] conf_path = os.path.abspath(conf_dir) conf_poscar = os.path.join(conf_path, 'POSCAR') # get equi poscar equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing) equi_contcar = os.path.join(equi_path, 'CONTCAR') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing) os.makedirs(task_path, exist_ok=True) cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') os.chdir(cwd) task_poscar = os.path.join(task_path, 'POSCAR') # stress equi_outcar = os.path.join(equi_path, 'OUTCAR') stress = vasp.get_stress(equi_outcar) np.savetxt(os.path.join(task_path, 'equi.stress.out'), stress) # gen strcture ss = Structure.from_file(task_poscar) # gen defomations norm_strains = np.arange(strain_start, strain_end, strain_step) print('gen with norm ' + str(norm_strains)) deformations = [] for ii in norm_strains: strain = Strain.from_index_amount(strain_direct, ii) deformations.append(strain.get_deformation_matrix()) deformed_structures = [ defo.apply_to_structure(ss) for defo in deformations ] n_dfm = len(deformed_structures) # gen incar fc = vasp.make_vasp_relax_incar(ecut, ediff, True, False, False, npar=npar, kpar=kpar, kspacing=None, kgamma=None) with open(os.path.join(task_path, 'INCAR'), 'w') as fp: fp.write(fc) # gen potcar with open(task_poscar, 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list: assert (os.path.exists(potcar_map[ii])) potcar_list.append(potcar_map[ii]) with open(os.path.join(task_path, 'POTCAR'), 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # gen kpoints fc = vasp.make_kspacing_kpoints(task_poscar, kspacing, kgamma) with open(os.path.join(task_path, 'KPOINTS'), 'w') as fp: fp.write(fc) # gen tasks cwd = os.getcwd() for ii in range(n_dfm): # make dir dfm_path = os.path.join(task_path, 'dfm-%03d' % ii) os.makedirs(dfm_path, exist_ok=True) os.chdir(dfm_path) for jj in ['POSCAR', 'POTCAR', 'INCAR', 'KPOINTS']: if os.path.isfile(jj): os.remove(jj) # make conf deformed_structures[ii].to('POSCAR', 'POSCAR') # record strain strain = Strain.from_deformation(deformations[ii]) np.savetxt('strain.out', strain) # link incar, potcar, kpoints os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'KPOINTS')), 'KPOINTS') cwd = os.getcwd()
def make_vasp(jdata, conf_dir, max_miller=2, relax_box=False, static=False): fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] min_slab_size = jdata['min_slab_size'] min_vacuum_size = jdata['min_vacuum_size'] pert_xz = jdata['pert_xz'] # get conf poscar # conf_path = os.path.abspath(conf_dir) # conf_poscar = os.path.join(conf_path, 'POSCAR') equi_path = re.sub('confs', global_equi_name, conf_dir) equi_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing) equi_path = os.path.abspath(equi_path) equi_contcar = os.path.join(equi_path, 'CONTCAR') assert os.path.exists( equi_contcar), "Please compute the equilibrium state using vasp first" task_path = re.sub('confs', global_task_name, conf_dir) task_path = os.path.abspath(task_path) if static: task_path = os.path.join(task_path, 'vasp-static-k%.2f' % kspacing) else: task_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing) os.makedirs(task_path, exist_ok=True) cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') os.chdir(cwd) task_poscar = os.path.join(task_path, 'POSCAR') ptypes = vasp.get_poscar_types(task_poscar) # gen strcture ss = Structure.from_file(task_poscar) # gen slabs all_slabs = generate_all_slabs(ss, max_miller, min_slab_size, min_vacuum_size) # gen incar if static: fc = vasp.make_vasp_static_incar(ecut, ediff, npar=npar, kpar=kpar, kspacing=kspacing, kgamma=kgamma) else: fc = vasp.make_vasp_relax_incar(ecut, ediff, True, relax_box, False, npar=npar, kpar=kpar, kspacing=kspacing, kgamma=kgamma) with open(os.path.join(task_path, 'INCAR'), 'w') as fp: fp.write(fc) # gen potcar with open(task_poscar, 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list: assert os.path.exists(os.path.abspath( potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii) potcar_list.append(os.path.abspath(potcar_map[ii])) with open(os.path.join(task_path, 'POTCAR'), 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # gen tasks cwd = os.getcwd() for ii in range(len(all_slabs)): slab = all_slabs[ii] miller_str = "m%d.%d.%dm" % ( slab.miller_index[0], slab.miller_index[1], slab.miller_index[2]) # make dir struct_path = os.path.join(task_path, 'struct-%03d-%s' % (ii, miller_str)) os.makedirs(struct_path, exist_ok=True) os.chdir(struct_path) for jj in ['POSCAR', 'POTCAR', 'INCAR']: if os.path.isfile(jj): os.remove(jj) print("# %03d generate " % ii, struct_path, " \t %d atoms" % len(slab.sites)) # make conf slab.to('POSCAR', 'POSCAR.tmp') vasp.regulate_poscar('POSCAR.tmp', 'POSCAR') vasp.sort_poscar('POSCAR', 'POSCAR', ptypes) vasp.perturb_xz('POSCAR', 'POSCAR', pert_xz) # record miller np.savetxt('miller.out', slab.miller_index, fmt='%d') # link incar, potcar, kpoints os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR') cwd = os.getcwd()
def _make_vasp(jdata, conf_dir, supercell, insert_ele): fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] conf_path = os.path.abspath(conf_dir) conf_poscar = os.path.join(conf_path, 'POSCAR') # get equi poscar equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing) equi_contcar = os.path.join(equi_path, 'CONTCAR') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing) os.makedirs(task_path, exist_ok=True) cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') os.chdir(cwd) task_poscar = os.path.join(task_path, 'POSCAR') # gen strcture print("task poscar: ", task_poscar) ss = Structure.from_file(task_poscar) # gen defects vds = InterstitialGenerator(ss, insert_ele) dss = [] for jj in vds: dss.append(jj.generate_defect_structure(supercell)) # gen incar fc = vasp.make_vasp_relax_incar(ecut, ediff, True, True, True, 1, 1, kspacing=kspacing, kgamma=kgamma) with open(os.path.join(task_path, 'INCAR'), 'w') as fp: fp.write(fc) # gen tasks copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2]) cwd = os.getcwd() for ii in range(len(dss)): struct_path = os.path.join( task_path, 'struct-%s-%s-%03d' % (insert_ele, copy_str, ii)) print('# generate %s' % (struct_path)) os.makedirs(struct_path, exist_ok=True) os.chdir(struct_path) for jj in ['POSCAR', 'POTCAR', 'INCAR']: if os.path.isfile(jj): os.remove(jj) # make conf dss[ii].to('POSCAR', 'POSCAR') # gen potcar _gen_potcar(jdata, 'POSCAR', 'POTCAR') # link incar os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') # save supercell np.savetxt('supercell.out', supercell, fmt='%d') os.chdir(cwd)
def make_vasp(jdata, conf_dir, supercell = [1,1,1]) : fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] conf_path = os.path.abspath(conf_dir) conf_poscar = os.path.join(conf_path, 'POSCAR') # get equi poscar equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing) equi_contcar = os.path.join(equi_path, 'CONTCAR') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing) os.makedirs(task_path, exist_ok=True) cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR') : os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') os.chdir(cwd) task_poscar = os.path.join(task_path, 'POSCAR') # gen structure from equi poscar edge = Structure.from_file(task_poscar) edge.make_supercell([supercell[0],supercell[1],1]) center=int(supercell[0]*int(supercell[1]/2)+supercell[0]/2) s=[center+supercell[0]*ii for ii in range(int(supercell[1]/2+1))] # gen edge dislocation edge.remove_sites(s) edge.make_supercell([1,1,supercell[2]]) # gen screw dislocation screw = Structure.from_file(task_poscar) screw.make_supercell([supercell[0], supercell[1], supercell[2]],to_unit_cell=False) c=[] for jj in range(math.ceil(supercell[0]/2)): for ii in range(supercell[2]): c.append(ii+jj*supercell[2]) v0 = np.asarray(screw._sites[0].coords, float) - np.asarray(screw._sites[1].coords, float) for kk in range(math.ceil(supercell[1]/2)): dc=[ii+kk*supercell[0]*supercell[2] for ii in c] v=(math.ceil(supercell[1]/2)-kk)/math.ceil(supercell[1]/2)*v0 screw.translate_sites(dc, vector=v, frac_coords=False, to_unit_cell=False) dss = [] dss.append(edge) dss.append(screw) # gen incar fc = vasp.make_vasp_relax_incar(ecut, ediff, True, True, True, npar, kpar, kspacing = kspacing, kgamma = kgamma) with open(os.path.join(task_path, 'INCAR'), 'w') as fp : fp.write(fc) # gen potcar with open(task_poscar,'r') as fp : lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list : assert(os.path.exists(potcar_map[ii])) potcar_list.append(potcar_map[ii]) with open(os.path.join(task_path,'POTCAR'), 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # gen tasks copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2]) cwd = os.getcwd() for ii in range(len(dss)) : struct_path = os.path.join(task_path, 'struct-%s-%s' % (copy_str,task_dict[ii])) print('# generate %s' % (struct_path)) os.makedirs(struct_path, exist_ok=True) os.chdir(struct_path) for jj in ['POSCAR', 'POTCAR', 'INCAR'] : if os.path.isfile(jj): os.remove(jj) # make conf dss[ii].to('POSCAR', 'POSCAR') # link incar, potcar, kpoints os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR') # save supercell np.savetxt('supercell.out', supercell, fmt='%d') os.chdir(cwd)
def make_vasp(jdata, conf_dir) : vol_start = jdata['vol_start'] vol_end = jdata['vol_end'] vol_step = jdata['vol_step'] eos_relax_cell_shape = jdata.get('eos_relax_cell_shape', True) conf_path = os.path.abspath(conf_dir) conf_poscar = os.path.join(conf_path, 'POSCAR') if 'relax_incar' in jdata.keys(): vasp_str='vasp-relax_incar' else: kspacing = jdata['vasp_params']['kspacing'] vasp_str='vasp-k%.2f' % kspacing # get equi poscar equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, vasp_str) equi_contcar = os.path.join(equi_path, 'CONTCAR') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, vasp_str) os.makedirs(task_path, exist_ok = True) # link poscar cwd = os.getcwd() from_poscar = os.path.join(equi_contcar) to_poscar = os.path.join(task_path, 'POSCAR') if os.path.exists(to_poscar) : assert(filecmp.cmp(from_poscar, to_poscar)) else : os.chdir(task_path) os.symlink(os.path.relpath(from_poscar), 'POSCAR') os.chdir(cwd) vol_to_poscar = vasp.poscar_vol(to_poscar) / vasp.poscar_natoms(to_poscar) # print(to_poscar, vol_to_poscar) is_alloy = \ os.path.exists( os.path.join( os.path.join(conf_path, '..'), 'alloy' ) ) # read potcar with open(to_poscar,'r') as fp : lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list : assert os.path.exists(os.path.abspath(potcar_map[ii])),"No POTCAR in the potcar_map of %s"%(ii) potcar_list.append(os.path.abspath(potcar_map[ii])) # gen incar if 'relax_incar' in jdata.keys(): relax_incar_path = jdata['relax_incar'] assert(os.path.exists(relax_incar_path)) relax_incar_path = os.path.abspath(relax_incar_path) incar = incar_upper(Incar.from_file(relax_incar_path)) if eos_relax_cell_shape: isif = 4 else: isif = 2 if incar.get('ISIF') != isif: dlog.info("%s:%s setting ISIF to %d" % (__file__, make_vasp.__name__, isif)) incar['ISIF'] = isif fc = incar.get_string() kspacing = incar['KSPACING'] kgamma = incar['KGAMMA'] else : fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] fc = vasp.make_vasp_relax_incar(ecut, ediff, is_alloy, True, False, npar, kpar, kspacing, kgamma) os.chdir(task_path) with open('INCAR', 'w') as fp : fp.write(fc) # gen potcar with open('POTCAR', 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # loop over volumes for vol in np.arange(vol_start, vol_end, vol_step) : vol_path = os.path.join(task_path, 'vol-%.2f' % vol) os.makedirs(vol_path, exist_ok = True) os.chdir(vol_path) for ii in ['INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR'] : if os.path.exists(ii) : os.remove(ii) # link incar, potcar os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR') # gen poscar os.symlink(os.path.relpath(to_poscar), 'POSCAR.orig') scale = (vol / vol_to_poscar) ** (1./3.) # print(scale) vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale) # print(vol_path, vasp.poscar_vol('POSCAR') / vasp.poscar_natoms('POSCAR')) # gen kpoints fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma) with open('KPOINTS', 'w') as fp: fp.write(fc) #copy cvasp if ('cvasp' in jdata) and (jdata['cvasp'] == True): shutil.copyfile(cvasp_file, os.path.join(vol_path,'cvasp.py')) os.chdir(cwd)
def make_vasp(jdata, conf_dir): conf_path = os.path.abspath(conf_dir) equi_path = re.sub('confs', global_task_name, conf_path) os.makedirs(equi_path, exist_ok=True) cwd = os.getcwd() from_poscar = os.path.join(conf_path, 'POSCAR') to_poscar = os.path.join(equi_path, 'POSCAR') if os.path.exists(to_poscar): assert (filecmp.cmp(from_poscar, to_poscar)) else: os.chdir(equi_path) os.symlink(os.path.relpath(from_poscar), 'POSCAR') os.chdir(cwd) is_alloy = \ os.path.exists( os.path.join( os.path.join(conf_path, '..'), 'alloy' ) ) # read potcar with open(to_poscar, 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list: assert os.path.exists(os.path.abspath( potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii) potcar_list.append(os.path.abspath(potcar_map[ii])) # gen incar if 'relax_incar' in jdata.keys(): relax_incar_path = jdata['relax_incar'] assert (os.path.exists(relax_incar_path)) relax_incar_path = os.path.abspath(relax_incar_path) incar = incar_upper(Incar.from_file(relax_incar_path)) isif = 3 if incar.get('ISIF') != isif: dlog.info("%s:%s setting ISIF to %d" % (__file__, make_vasp.__name__, isif)) incar['ISIF'] = isif fc = incar.get_string() kspacing = incar['KSPACING'] kgamma = incar['KGAMMA'] vasp_path = os.path.join(equi_path, 'vasp-relax_incar') else: fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] fc = vasp.make_vasp_relax_incar(ecut, ediff, is_alloy, True, True, npar, kpar, kspacing, kgamma) vasp_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing) os.makedirs(vasp_path, exist_ok=True) os.chdir(vasp_path) # write incar with open('INCAR', 'w') as fp: fp.write(fc) # gen poscar if os.path.exists('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(to_poscar), 'POSCAR') # gen kpoints fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma) with open('KPOINTS', 'w') as fp: fp.write(fc) #copy cvasp if ('cvasp' in jdata) and (jdata['cvasp'] == True): shutil.copyfile(cvasp_file, 'cvasp.py') # gen potcar with open('POTCAR', 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) os.chdir(cwd)
def make_vasp(jdata, conf_dir, supercell=[1, 1, 1]): conf_path = os.path.abspath(conf_dir) conf_poscar = os.path.join(conf_path, 'POSCAR') # get equi poscar if 'relax_incar' in jdata.keys(): vasp_str = 'vasp-relax_incar' else: kspacing = jdata['vasp_params']['kspacing'] vasp_str = 'vasp-k%.2f' % kspacing equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, vasp_str) equi_contcar = os.path.join(equi_path, 'CONTCAR') assert os.path.exists( equi_contcar), "Please compute the equilibrium state using vasp first" task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, vasp_str) os.makedirs(task_path, exist_ok=True) cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') os.chdir(cwd) task_poscar = os.path.join(task_path, 'POSCAR') # gen strcture ss = Structure.from_file(task_poscar) # gen defects vds = VacancyGenerator(ss) dss = [] for jj in vds: dss.append(jj.generate_defect_structure(supercell)) # gen incar if 'relax_incar' in jdata.keys(): relax_incar_path = jdata['relax_incar'] assert (os.path.exists(relax_incar_path)) relax_incar_path = os.path.abspath(relax_incar_path) incar = incar_upper(Incar.from_file(relax_incar_path)) fc = incar.get_string() kspacing = incar['KSPACING'] kgamma = incar['KGAMMA'] else: fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] fc = vasp.make_vasp_relax_incar(ecut, ediff, True, True, True, npar=npar, kpar=kpar, kspacing=kspacing, kgamma=kgamma) with open(os.path.join(task_path, 'INCAR'), 'w') as fp: fp.write(fc) # gen potcar with open(task_poscar, 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list: assert os.path.exists(os.path.abspath( potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii) potcar_list.append(os.path.abspath(potcar_map[ii])) with open(os.path.join(task_path, 'POTCAR'), 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # gen tasks copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2]) cwd = os.getcwd() for ii in range(len(dss)): struct_path = os.path.join(task_path, 'struct-%s-%03d' % (copy_str, ii)) print('# generate %s' % (struct_path)) os.makedirs(struct_path, exist_ok=True) os.chdir(struct_path) for jj in ['POSCAR', 'POTCAR', 'INCAR']: if os.path.isfile(jj): os.remove(jj) # make conf dss[ii].to('POSCAR', 'POSCAR') # link incar, potcar, kpoints os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR') # save supercell np.savetxt('supercell.out', supercell, fmt='%d') # write kp fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma) with open('KPOINTS', 'w') as fp: fp.write(fc) #copy cvasp if ('cvasp' in jdata) and (jdata['cvasp'] == True): shutil.copyfile(cvasp_file, os.path.join(struct_path, 'cvasp.py')) os.chdir(cwd)
def make_vasp(jdata, conf_dir): default_norm_def = 2e-3 default_shear_def = 5e-3 norm_def = jdata.get('norm_deform', default_norm_def) shear_def = jdata.get('shear_deform', default_shear_def) conf_path = os.path.abspath(conf_dir) conf_poscar = os.path.join(conf_path, 'POSCAR') if 'relax_incar' in jdata.keys(): vasp_str = 'vasp-relax_incar' else: kspacing = jdata['vasp_params']['kspacing'] vasp_str = 'vasp-k%.2f' % kspacing # get equi poscar equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, vasp_str) equi_contcar = os.path.join(equi_path, 'CONTCAR') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, vasp_str) os.makedirs(task_path, exist_ok=True) cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') os.chdir(cwd) task_poscar = os.path.join(task_path, 'POSCAR') # stress equi_outcar = os.path.join(equi_path, 'OUTCAR') stress = vasp.get_stress(equi_outcar) np.savetxt(os.path.join(task_path, 'equi.stress.out'), stress) # gen strcture ss = Structure.from_file(task_poscar) # gen defomations norm_strains = [-norm_def, -0.5 * norm_def, 0.5 * norm_def, norm_def] shear_strains = [-shear_def, -0.5 * shear_def, 0.5 * shear_def, shear_def] dfm_ss = DeformedStructureSet(ss, symmetry=False, norm_strains=norm_strains, shear_strains=shear_strains) n_dfm = len(dfm_ss) # gen incar if 'relax_incar' in jdata.keys(): relax_incar_path = jdata['relax_incar'] assert (os.path.exists(relax_incar_path)) relax_incar_path = os.path.abspath(relax_incar_path) incar = incar_upper(Incar.from_file(relax_incar_path)) if incar.get('ISIF') != 2: dlog.info("%s:%s setting ISIF to 2" % (__file__, make_vasp.__name__)) incar['ISIF'] = 2 fc = incar.get_string() kspacing = incar['KSPACING'] kgamma = incar['KGAMMA'] else: fp_params = jdata['vasp_params'] ecut = fp_params['ecut'] ediff = fp_params['ediff'] npar = fp_params['npar'] kpar = fp_params['kpar'] kspacing = fp_params['kspacing'] kgamma = fp_params['kgamma'] fc = vasp.make_vasp_relax_incar(ecut, ediff, True, False, False, npar=npar, kpar=kpar, kspacing=kspacing, kgamma=kgamma) with open(os.path.join(task_path, 'INCAR'), 'w') as fp: fp.write(fc) # gen potcar with open(task_poscar, 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() potcar_map = jdata['potcar_map'] potcar_list = [] for ii in ele_list: assert os.path.exists(os.path.abspath( potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii) potcar_list.append(os.path.abspath(potcar_map[ii])) with open(os.path.join(task_path, 'POTCAR'), 'w') as outfile: for fname in potcar_list: with open(fname) as infile: outfile.write(infile.read()) # gen kpoints fc = vasp.make_kspacing_kpoints(task_poscar, kspacing, kgamma) with open(os.path.join(task_path, 'KPOINTS'), 'w') as fp: fp.write(fc) # gen tasks cwd = os.getcwd() for ii in range(n_dfm): # make dir dfm_path = os.path.join(task_path, 'dfm-%03d' % ii) os.makedirs(dfm_path, exist_ok=True) os.chdir(dfm_path) for jj in ['POSCAR', 'POTCAR', 'INCAR', 'KPOINTS']: if os.path.isfile(jj): os.remove(jj) # make conf dfm_ss.deformed_structures[ii].to('POSCAR', 'POSCAR') # record strain strain = Strain.from_deformation(dfm_ss.deformations[ii]) np.savetxt('strain.out', strain) # link incar, potcar, kpoints os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR') os.symlink(os.path.relpath(os.path.join(task_path, 'KPOINTS')), 'KPOINTS') #copy cvasp if ('cvasp' in jdata) and (jdata['cvasp'] == True): shutil.copyfile(cvasp_file, os.path.join(dfm_path, 'cvasp.py')) os.chdir(cwd)