def make_confs(self, path_to_work, path_to_equi, refine=False): path_to_work = os.path.abspath(path_to_work) if os.path.exists(path_to_work): dlog.warning('%s already exists' % path_to_work) else: os.makedirs(path_to_work) path_to_equi = os.path.abspath(path_to_equi) if 'start_confs_path' in self.parameter and os.path.exists(self.parameter['start_confs_path']): init_path_list = glob.glob(os.path.join(self.parameter['start_confs_path'], '*')) struct_init_name_list = [] for ii in init_path_list: struct_init_name_list.append(ii.split('/')[-1]) struct_output_name = path_to_work.split('/')[-2] assert struct_output_name in struct_init_name_list path_to_equi = os.path.abspath(os.path.join(self.parameter['start_confs_path'], struct_output_name, 'relaxation', 'relax_task')) task_list = [] cwd = os.getcwd() if self.reprod: print('surface reproduce starts') if 'init_data_path' not in self.parameter: raise RuntimeError("please provide the initial data path to reproduce") init_data_path = os.path.abspath(self.parameter['init_data_path']) task_list = make_repro(init_data_path, self.init_from_suffix, path_to_work, self.parameter.get('reprod_last_frame', True)) os.chdir(cwd) else: if refine: print('surface refine starts') task_list = make_refine(self.parameter['init_from_suffix'], self.parameter['output_suffix'], path_to_work) os.chdir(cwd) # record miller init_from_path = re.sub(self.parameter['output_suffix'][::-1], self.parameter['init_from_suffix'][::-1], path_to_work[::-1], count=1)[::-1] task_list_basename = list(map(os.path.basename, task_list)) for ii in task_list_basename: init_from_task = os.path.join(init_from_path, ii) output_task = os.path.join(path_to_work, ii) os.chdir(output_task) if os.path.isfile('miller.json'): os.remove('miller.json') if os.path.islink('miller.json'): os.remove('miller.json') os.symlink(os.path.relpath(os.path.join(init_from_task, 'miller.json')), 'miller.json') os.chdir(cwd) else: equi_contcar = os.path.join(path_to_equi, 'CONTCAR') if not os.path.exists(equi_contcar): raise RuntimeError("please do relaxation first") ptypes = vasp.get_poscar_types(equi_contcar) # gen structure ss = Structure.from_file(equi_contcar) # gen slabs all_slabs = generate_all_slabs(ss, self.miller, self.min_slab_size, self.min_vacuum_size) os.chdir(path_to_work) if os.path.isfile('POSCAR'): os.remove('POSCAR') if os.path.islink('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') # task_poscar = os.path.join(output, 'POSCAR') for ii in range(len(all_slabs)): output_task = os.path.join(path_to_work, 'task.%06d' % ii) os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for jj in ['INCAR', 'POTCAR', 'POSCAR', 'conf.lmp', 'in.lammps']: if os.path.exists(jj): os.remove(jj) task_list.append(output_task) print("# %03d generate " % ii, output_task, " \t %d atoms" % len(all_slabs[ii].sites)) # make confs all_slabs[ii].to('POSCAR', 'POSCAR.tmp') vasp.regulate_poscar('POSCAR.tmp', 'POSCAR') vasp.sort_poscar('POSCAR', 'POSCAR', ptypes) vasp.perturb_xz('POSCAR', 'POSCAR', self.pert_xz) # record miller dumpfn(all_slabs[ii].miller_index, 'miller.json') os.chdir(cwd) return task_list
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_confs(self, path_to_work, path_to_equi, refine=False): path_to_work = os.path.abspath(path_to_work) path_to_equi = os.path.abspath(path_to_equi) task_list = [] cwd = os.getcwd() equi_contcar = os.path.join(path_to_equi, 'CONTCAR') ptypes = vasp.get_poscar_types(equi_contcar) if not os.path.exists(equi_contcar): raise RuntimeError("please do relaxation first") # gen structure ss = Structure.from_file(equi_contcar) # gen slabs all_slabs = generate_all_slabs(ss, self.max_miller, self.min_slab_size, self.min_vacuum_size) if refine: task_list = make_refine(self.parameter['init_from_suffix'], self.parameter['output_suffix'], path_to_work, len(all_slabs)) # record miller for ii in range(len(task_list)): os.chdir(task_list[ii]) np.savetxt('miller.out', all_slabs[ii].miller_index, fmt='%d') os.chdir(cwd) if self.reprod: if 'vasp_path' not in self.parameter: raise RuntimeError( "please provide the vasp_path for reproduction") vasp_path = os.path.abspath(self.parameter['vasp_path']) task_list = reproduce.make_repro(vasp_path, path_to_work) os.chdir(cwd) else: os.chdir(path_to_work) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') # task_poscar = os.path.join(output, 'POSCAR') for ii in range(len(all_slabs)): output_task = os.path.join(path_to_work, 'task.%06d' % ii) os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for jj in [ 'INCAR', 'POTCAR', 'POSCAR', 'conf.lmp', 'in.lammps' ]: if os.path.exists(jj): os.remove(jj) task_list.append(output_task) print("# %03d generate " % ii, output_task, " \t %d atoms" % len(all_slabs[ii].sites)) # make confs all_slabs[ii].to('POSCAR', 'POSCAR.tmp') vasp.regulate_poscar('POSCAR.tmp', 'POSCAR') vasp.sort_poscar('POSCAR', 'POSCAR', ptypes) vasp.perturb_xz('POSCAR', 'POSCAR', self.pert_xz) # record miller np.savetxt('miller.out', all_slabs[ii].miller_index, fmt='%d') os.chdir(cwd) return task_list