def comput_vasp_nev(jdata, conf_dir, write_stable=False): kspacing = jdata['vasp_params']['kspacing'] conf_path = re.sub('confs', global_equi_name, conf_dir) conf_path = os.path.abspath(conf_path) poscar = os.path.join(conf_path, 'POSCAR') if write_stable: ele_types = vasp.get_poscar_types(poscar) if len(ele_types) > 1: raise RuntimeError( 'stable energy and volume only for one element, current you have %s from POSCAR' % str(ele_types)) ener_shift = comput_e_shift(poscar, 'vasp-k%.2f' % kspacing) vasp_path = os.path.join(conf_path, 'vasp-k%.2f' % kspacing) outcar = os.path.join(vasp_path, 'OUTCAR') # tag_fin = os.path.join(vasp_path, 'tag_finished') if not os.path.isfile(outcar): warnings.warn("cannot find OUTCAR in " + vasp_path + " skip") elif not vasp.check_finished(outcar): warnings.warn("incomplete job " + vasp_path + " use the last frame") if os.path.isfile(outcar): natoms, epa, vpa = vasp.get_nev(outcar) epa = (epa * natoms - ener_shift) / natoms if write_stable: stable_dir = 'stables' os.makedirs(stable_dir, exist_ok=True) name_prefix = os.path.join( stable_dir, '%s.vasp-k%.2f' % (ele_types[0], kspacing)) open(name_prefix + '.e', 'w').write('%.16f\n' % (epa)) open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa)) return natoms, epa, vpa else: return None, None, None
def comput_lmp_nev(conf_dir, task_name, write_stable=False): conf_path = re.sub('confs', global_equi_name, conf_dir) conf_path = os.path.abspath(conf_path) poscar = os.path.join(conf_path, 'POSCAR') if write_stable: ele_types = vasp.get_poscar_types(poscar) if len(ele_types) > 1: raise RuntimeError( 'stable energy and volume only for one element, current you have %s from POSCAR' % str(ele_types)) ener_shift = comput_e_shift(poscar, task_name) lmp_path = os.path.join(conf_path, task_name) log_lammps = os.path.join(lmp_path, 'log.lammps') if os.path.isfile(log_lammps): natoms, epa, vpa = lammps.get_nev(log_lammps) epa = (epa * natoms - ener_shift) / natoms if write_stable: stable_dir = 'stables' os.makedirs(stable_dir, exist_ok=True) name_prefix = os.path.join(stable_dir, '%s.%s' % (ele_types[0], task_name)) open(name_prefix + '.e', 'w').write('%.16f\n' % (epa)) open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa)) return natoms, epa, vpa else: return None, None, None
def make_lammps(jdata, conf_dir, task_type): fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name = fp_params['model_name'] deepmd_version = fp_params.get("deepmd_version", "0.12") if not model_name and task_type == 'deepmd': models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] assert len(model_name) > 0, "No deepmd model in the model_dir" else: models = [os.path.join(model_dir, ii) for ii in model_name] model_param = { 'model_name': model_name, 'param_type': fp_params['model_param_type'], 'deepmd_version': deepmd_version } ntypes = len(type_map) 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) # lmp path lmp_path = os.path.join(equi_path, task_type) os.makedirs(lmp_path, exist_ok=True) print(lmp_path) # lmp conf conf_file = os.path.join(lmp_path, 'conf.lmp') lammps.cvt_lammps_conf(to_poscar, os.path.relpath(conf_file)) ptypes = vasp.get_poscar_types(to_poscar) lammps.apply_type_map(conf_file, type_map, ptypes) # lmp input if task_type == 'deepmd': fc = lammps.make_lammps_equi(os.path.basename(conf_file), ntypes, lammps.inter_deepmd, model_param) elif task_type == 'meam': fc = lammps.make_lammps_equi(os.path.basename(conf_file), ntypes, lammps.inter_meam, model_param) with open(os.path.join(lmp_path, 'lammps.in'), 'w') as fp: fp.write(fc) # link models os.chdir(lmp_path) for ii in model_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(models, model_name): os.symlink(os.path.relpath(ii), jj) os.chdir(cwd)
def comput_e_shift(poscar, task_name) : a_types = vasp.get_poscar_types(poscar) a_natoms = vasp.get_poscar_natoms(poscar) ener_shift = 0 if not os.path.isdir('stables') : raise RuntimeError('no dir "stable". Stable energy and volume of components should be computed before calculating formation energy of an alloy') for ii in range(len(a_types)) : ref_e_file = a_types[ii] + '.' + task_name + '.e' ref_e_file = os.path.join('stables', ref_e_file) ener = float(open(ref_e_file).read()) ener_shift += a_natoms[ii] * ener return ener_shift
def make_meam_lammps(jdata, conf_dir): meam_potfile_dir = jdata['meam_potfile_dir'] meam_potfile_dir = os.path.abspath(meam_potfile_dir) meam_potfile = jdata['meam_potfile'] meam_potfile = [os.path.join(meam_potfile_dir, ii) for ii in meam_potfile] meam_potfile_name = jdata['meam_potfile'] type_map = jdata['meam_type_map'] ntypes = len(type_map) meam_param = { 'meam_potfile': jdata['meam_potfile'], 'meam_type': jdata['meam_param_type'] } 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) # lmp path lmp_path = os.path.join(equi_path, 'meam') os.makedirs(lmp_path, exist_ok=True) print(lmp_path) # lmp conf conf_file = os.path.join(lmp_path, 'conf.lmp') lammps.cvt_lammps_conf(to_poscar, os.path.relpath(conf_file)) ptypes = vasp.get_poscar_types(to_poscar) lammps.apply_type_map(conf_file, type_map, ptypes) # lmp input fc = lammps.make_lammps_equi(os.path.basename(conf_file), ntypes, lammps.inter_meam, meam_param) with open(os.path.join(lmp_path, 'lammps.in'), 'w') as fp: fp.write(fc) # link models os.chdir(lmp_path) for ii in meam_potfile_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(meam_potfile, meam_potfile_name): os.symlink(os.path.relpath(ii), jj) os.chdir(cwd)
def make_deepmd_lammps(jdata, conf_dir): deepmd_model_dir = jdata['deepmd_model_dir'] deepmd_type_map = jdata['deepmd_type_map'] ntypes = len(deepmd_type_map) deepmd_model_dir = os.path.abspath(deepmd_model_dir) deepmd_models = glob.glob(os.path.join(deepmd_model_dir, '*pb')) deepmd_models_name = [os.path.basename(ii) for ii in deepmd_models] 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) # lmp path lmp_path = os.path.join(equi_path, 'deepmd') os.makedirs(lmp_path, exist_ok=True) print(lmp_path) # lmp conf conf_file = os.path.join(lmp_path, 'conf.lmp') lammps.cvt_lammps_conf(to_poscar, os.path.relpath(conf_file)) ptypes = vasp.get_poscar_types(to_poscar) lammps.apply_type_map(conf_file, deepmd_type_map, ptypes) # lmp input fc = lammps.make_lammps_equi(os.path.basename(conf_file), ntypes, lammps.inter_deepmd, deepmd_models_name) with open(os.path.join(lmp_path, 'lammps.in'), 'w') as fp: fp.write(fc) # link models os.chdir(lmp_path) for ii in deepmd_models_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(deepmd_models, deepmd_models_name): os.symlink(os.path.relpath(ii), jj) os.chdir(cwd)
def comput_vasp_nev(jdata, conf_dir, write_shift=False): conf_path = re.sub('confs', global_equi_name, conf_dir) conf_path = os.path.abspath(conf_path) poscar = os.path.join(conf_path, 'POSCAR') ele_types = vasp.get_poscar_types(poscar) if 'relax_incar' in jdata.keys(): vasp_str = 'vasp-relax_incar' else: kspacing = jdata['vasp_params']['kspacing'] vasp_str = 'vasp-k%.2f' % kspacing vasp_path = os.path.join(conf_path, vasp_str) outcar = os.path.join(vasp_path, 'OUTCAR') # tag_fin = os.path.join(vasp_path, 'tag_finished') if not os.path.isfile(outcar): warnings.warn("cannot find OUTCAR in " + vasp_path + " skip") elif not vasp.check_finished(outcar): warnings.warn("incomplete job " + vasp_path + " use the last frame") if os.path.isfile(outcar): natoms, epa, vpa = vasp.get_nev(outcar) if write_shift and len(ele_types) > 1: ener_shift = comput_e_shift(poscar, vasp_str) shift = (epa * natoms - ener_shift) / natoms return natoms, epa, vpa, shift if len(ele_types) == 1: stable_dir = 'stables' os.makedirs(stable_dir, exist_ok=True) name_prefix = os.path.join(stable_dir, '%s.' % (ele_types[0]) + vasp_str) open(name_prefix + '.e', 'w').write('%.16f\n' % (epa)) open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa)) return natoms, epa, vpa, None else: return None, None, None, None
def comput_lmp_nev(conf_dir, task_name, write_shift=False): conf_path = re.sub('confs', global_equi_name, conf_dir) conf_path = os.path.abspath(conf_path) poscar = os.path.join(conf_path, 'POSCAR') ele_types = vasp.get_poscar_types(poscar) lmp_path = os.path.join(conf_path, task_name) log_lammps = os.path.join(lmp_path, 'log.lammps') if os.path.isfile(log_lammps): natoms, epa, vpa = lammps.get_nev(log_lammps) if write_shift and len(ele_types) > 1: ener_shift = comput_e_shift(poscar, task_name) shift = (epa * natoms - ener_shift) / natoms return natoms, epa, vpa, shift if len(ele_types) == 1: stable_dir = 'stables' os.makedirs(stable_dir, exist_ok=True) name_prefix = os.path.join(stable_dir, '%s.%s' % (ele_types[0], task_name)) open(name_prefix + '.e', 'w').write('%.16f\n' % (epa)) open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa)) return natoms, epa, vpa, None else: return None, None, None, None
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_lammps(jdata, conf_dir, max_miller=2, static=False, relax_box=False, task_type='wrong-task'): kspacing = jdata['vasp_params']['kspacing'] fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name = fp_params['model_name'] if not model_name and task_type == 'deepmd': models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] assert len(model_name) > 0, "No deepmd model in the model_dir" else: models = [os.path.join(model_dir, ii) for ii in model_name] model_param = { 'model_name': fp_params['model_name'], 'param_type': fp_params['model_param_type'] } ntypes = len(type_map) min_slab_size = jdata['min_slab_size'] min_vacuum_size = jdata['min_vacuum_size'] # get equi 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, task_type + '-static') else: task_path = os.path.join(task_path, task_type) 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 slabs all_slabs = generate_all_slabs(ss, max_miller, min_slab_size, min_vacuum_size) # make lammps.in if task_type == 'deepmd': if static: fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_deepmd, model_name) else: fc = lammps.make_lammps_equi('conf.lmp', ntypes, lammps.inter_deepmd, model_name, change_box=relax_box) elif task_type == 'meam': if static: fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_meam, model_param) else: fc = lammps.make_lammps_equi('conf.lmp', ntypes, lammps.inter_meam, model_param, change_box=relax_box) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp: fp.write(fc) cwd = os.getcwd() if task_type == 'deepmd': os.chdir(task_path) for ii in model_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(models, model_name): os.symlink(os.path.relpath(ii), jj) share_models = glob.glob(os.path.join(task_path, '*pb')) else: share_models = models 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 ['conf.lmp', 'lammps.in'] + model_name: 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') vasp.regulate_poscar('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # record miller np.savetxt('miller.out', slab.miller_index, fmt='%d') # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii, jj) in zip(share_models, model_name): os.symlink(os.path.relpath(ii), jj) cwd = os.getcwd()
def make_deepmd_lammps(jdata, conf_dir): deepmd_model_dir = jdata['deepmd_model_dir'] deepmd_type_map = jdata['deepmd_type_map'] ntypes = len(deepmd_type_map) deepmd_model_dir = os.path.abspath(deepmd_model_dir) deepmd_models = glob.glob(os.path.join(deepmd_model_dir, '*pb')) deepmd_models_name = [os.path.basename(ii) for ii in deepmd_models] supercell_matrix = jdata['supercell_matrix'] band_path = jdata['band'] 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, 'deepmd') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, 'deepmd') os.makedirs(task_path, exist_ok=True) task_poscar = os.path.join(task_path, 'POSCAR') cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(conf_poscar), 'POSCAR') os.chdir(cwd) with open(task_poscar, 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() print(task_path) # make conf.lmp conf_file = os.path.join(task_path, 'conf.lmp') lammps.cvt_lammps_conf(task_poscar, os.path.relpath(conf_file)) ptypes = vasp.get_poscar_types(task_poscar) lammps.apply_type_map(conf_file, deepmd_type_map, ptypes) # make lammps.in ntypes = len(ele_list) unitcell = PhonopyAtoms(symbols=ele_list, cell=(np.eye(3)), scaled_positions=np.zeros((ntypes, 3))) fc = lammps.make_lammps_phonon('conf.lmp', unitcell.masses, lammps.inter_deepmd, deepmd_models_name) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp: fp.write(fc) cwd = os.getcwd() # link models os.chdir(task_path) for ii in deepmd_models_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(deepmd_models, deepmd_models_name): os.symlink(os.path.relpath(ii), jj) # gen band.conf os.chdir(task_path) with open('band.conf', 'w') as fp: fp.write('ATOM_NAME = ') for ii in ele_list: fp.write(ii) fp.write(' ') fp.write('\n') fp.write( 'DIM = %d %d %d\n' % (supercell_matrix[0], supercell_matrix[1], supercell_matrix[2])) fp.write('BAND = %s\n' % band_path) fp.write('FORCE_CONSTANTS=READ') # gen task ''' phlammps = Phonolammps('lammps.in',supercell_matrix=supercell_matrix) unitcell = phlammps.get_unitcell() phonon = Phonopy(unitcell,supercell_matrix) phonon.save(filename='phonopy_disp.yaml') with open('phonopy_disp.yaml', 'r') as f: temp = yaml.load(f.read()) with open('POSCAR-unitcell', 'w') as fp: for ii in ele_list: fp.write(ii) fp.write(' ') fp.write('\n') data=open('POSCAR', 'r') next(data) fp.write(data.readline()) for ii in temp['unit_cell']['lattice']: fp.write(str(ii).replace(',', '').replace('[', '').replace(']','\n')) for ii in ele_list: fp.write(str(str(temp['unit_cell']['points']).count(ii))) fp.write(' ') fp.write('\n') fp.write('Direct\n') for ii in temp['unit_cell']['points']: fp.write(str(ii['coordinates']).replace(',', '').replace('[', '').replace(']', '\n')) ''' os.system('phonolammps lammps.in --dim %d %d %d -c POSCAR-unitcell' % (supercell_matrix[0], supercell_matrix[1], supercell_matrix[2]))
def _make_meam_lammps(jdata, conf_dir, supercell, insert_ele, task_name): meam_potfile_dir = jdata['meam_potfile_dir'] meam_potfile_dir = os.path.abspath(meam_potfile_dir) meam_potfile = jdata['meam_potfile'] meam_potfile = [os.path.join(meam_potfile_dir, ii) for ii in meam_potfile] meam_potfile_name = jdata['meam_potfile'] type_map = jdata['meam_type_map'] ntypes = len(type_map) meam_param = { 'meam_potfile': jdata['meam_potfile'], 'meam_type': jdata['meam_param_type'] } 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, task_name) equi_dump = os.path.join(equi_path, 'dump.relax') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, task_name) os.makedirs(task_path, exist_ok=True) task_poscar = os.path.join(task_path, 'POSCAR') cwd = os.getcwd() os.chdir(task_path) lammps.poscar_from_last_dump(equi_dump, task_poscar, type_map) os.chdir(cwd) # gen structure from equi 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 tasks cwd = os.getcwd() # make lammps.in, relax at 0 bar (scale = 1) fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, 1, lammps.inter_meam, meam_param) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, '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 ['conf.lmp', 'lammps.in'] + meam_potfile_name: if os.path.isfile(jj): os.remove(jj) # make conf dss[ii].to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii, jj) in zip(meam_potfile, meam_potfile_name): os.symlink(os.path.relpath(ii), jj) # save supercell np.savetxt('supercell.out', supercell, fmt='%d') os.chdir(cwd)
def make_lammps(jdata, conf_dir, supercell,task_type) : kspacing = jdata['vasp_params']['kspacing'] fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name =fp_params['model_name'] if not model_name : models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] else: models = [os.path.join(model_dir,ii) for ii in model_name] model_param = {'model_name' : fp_params['model_name'], 'param_type': fp_params['model_param_type']} ntypes = len(type_map) 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') # equi_path = re.sub('confs', global_equi_name, conf_path) # equi_path = os.path.join(equi_path, 'lmp') # equi_dump = os.path.join(equi_path, 'dump.relax') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, task_type) os.makedirs(task_path, exist_ok=True) # gen task poscar task_poscar = os.path.join(task_path, 'POSCAR') # lammps.poscar_from_last_dump(equi_dump, task_poscar, deepmd_type_map) 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) # 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 tasks cwd = os.getcwd() # make lammps.in, relax at 0 bar (scale = 1) if task_type=='deepmd': fc = lammps.make_lammps_elastic('conf.lmp', ntypes, lammps.inter_deepmd, model_name) elif task_type =='meam': fc = lammps.make_lammps_elastic('conf.lmp', ntypes, lammps.inter_meam, model_param) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp : fp.write(fc) # gen tasks copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2]) cwd = os.getcwd() if task_type=='deepmd': os.chdir(task_path) for ii in model_name : if os.path.exists(ii) : os.remove(ii) for (ii,jj) in zip(models, model_name) : os.symlink(os.path.relpath(ii), jj) share_models = glob.glob(os.path.join(task_path, '*pb')) else : share_models=models 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 ['conf.lmp', 'lammps.in'] + model_name : if os.path.isfile(jj): os.remove(jj) # make conf dss[ii].to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii,jj) in zip(share_models, model_name) : os.symlink(os.path.relpath(ii), jj) # save supercell np.savetxt('supercell.out', supercell, fmt='%d') os.chdir(cwd)
def make_lammps_fixv (jdata, conf_dir,task_type) : fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name =fp_params['model_name'] deepmd_version = fp_params.get("deepmd_version", "0.12") if not model_name and task_type =='deepmd': models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] else: models = [os.path.join(model_dir,ii) for ii in model_name] model_param = {'model_name' : model_name, 'param_type': fp_params['model_param_type'], 'deepmd_version' : deepmd_version} ntypes = len(type_map) vol_start = jdata['vol_start'] vol_end = jdata['vol_end'] vol_step = jdata['vol_step'] # get equi props equi_path = re.sub('confs', global_equi_name, conf_dir) task_path = re.sub('confs', global_task_name, conf_dir) equi_path = os.path.join(equi_path, task_type) task_path = os.path.join(task_path, task_type) equi_path = os.path.abspath(equi_path) task_path = os.path.abspath(task_path) equi_dump = os.path.join(equi_path, 'dump.relax') os.makedirs(task_path, exist_ok = True) task_poscar = os.path.join(task_path, 'POSCAR') lammps.poscar_from_last_dump(equi_dump, task_poscar, type_map) cwd = os.getcwd() volume = vasp.poscar_vol(task_poscar) natoms = vasp.poscar_natoms(task_poscar) vpa = volume / natoms # structrure ss = Structure.from_file(task_poscar) # make lammps.in if task_type=='deepmd': fc = lammps.make_lammps_equi('conf.lmp', ntypes, lammps.inter_deepmd, model_param, change_box = False) elif task_type=='meam': fc = lammps.make_lammps_equi('conf.lmp', ntypes, lammps.inter_meam, model_param, change_box = False) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp : fp.write(fc) os.chdir(task_path) for ii in model_name : if os.path.exists(ii) : os.remove(ii) for (ii,jj) in zip(models, model_name) : os.symlink(os.path.relpath(ii), jj) share_models = [os.path.join(task_path,ii) for ii in model_name] # make vols for vol in np.arange(vol_start, vol_end, vol_step) : vol_path = os.path.join(task_path, 'vol-%.2f' % vol) print('# generate %s' % (vol_path)) os.makedirs(vol_path, exist_ok = True) os.chdir(vol_path) for ii in ['conf.lmp', 'conf.lmp', 'lammps.in'] + model_name : if os.path.exists(ii) : os.remove(ii) # make conf scale_ss = ss.copy() scale_ss.scale_lattice(vol * natoms) scale_ss.to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii,jj) in zip(share_models,model_name) : os.symlink(os.path.relpath(ii), jj) # make lammps input os.chdir(cwd)
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
def make_meam_lammps_fixv (jdata, conf_dir) : meam_potfile_dir = jdata['meam_potfile_dir'] meam_potfile_dir = os.path.abspath(meam_potfile_dir) meam_potfile = jdata['meam_potfile'] meam_potfile = [os.path.join(meam_potfile_dir,ii) for ii in meam_potfile] meam_potfile_name = jdata['meam_potfile'] type_map = jdata['meam_type_map'] ntypes = len(type_map) meam_param = {'meam_potfile' : jdata['meam_potfile'], 'meam_type': jdata['meam_param_type']} vol_start = jdata['vol_start'] vol_end = jdata['vol_end'] vol_step = jdata['vol_step'] # get equi props equi_path = re.sub('confs', global_equi_name, conf_dir) task_path = re.sub('confs', global_task_name, conf_dir) equi_path = os.path.join(equi_path, 'meam') task_path = os.path.join(task_path, 'meam') equi_path = os.path.abspath(equi_path) task_path = os.path.abspath(task_path) equi_log = os.path.join(equi_path, 'log.lammps') equi_dump = os.path.join(equi_path, 'dump.relax') os.makedirs(task_path, exist_ok = True) task_poscar = os.path.join(task_path, 'POSCAR') lammps.poscar_from_last_dump(equi_dump, task_poscar, type_map) cwd = os.getcwd() volume = vasp.poscar_vol(task_poscar) natoms = vasp.poscar_natoms(task_poscar) vpa = volume / natoms # structrure ss = Structure.from_file(task_poscar) # make lammps.in fc = lammps.make_lammps_equi('conf.lmp', ntypes, lammps.inter_meam, meam_param, change_box = False) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp : fp.write(fc) # make vols for vol in np.arange(vol_start, vol_end, vol_step) : vol_path = os.path.join(task_path, 'vol-%.2f' % vol) print('# generate %s' % (vol_path)) os.makedirs(vol_path, exist_ok = True) os.chdir(vol_path) for ii in ['conf.lmp', 'conf.lmp', 'lammps.in'] + meam_potfile_name : if os.path.exists(ii) : os.remove(ii) # make conf scale_ss = ss.copy() scale_ss.scale_lattice(vol * natoms) scale_ss.to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii,jj) in zip(meam_potfile, meam_potfile_name) : os.symlink(os.path.relpath(ii), jj) # make lammps input os.chdir(cwd)
def _make_reprod_traj(jdata, conf_dir, supercell, insert_ele, task_type): kspacing = jdata['vasp_params']['kspacing'] fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name = fp_params['model_name'] if not model_name and task_type == 'deepmd': models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] assert len(model_name) > 0, "No deepmd model in the model_dir" else: models = [os.path.join(model_dir, ii) for ii in model_name] model_param = { 'model_name': fp_params['model_name'], 'param_type': fp_params['model_param_type'] } ntypes = len(type_map) conf_path = os.path.abspath(conf_dir) task_path = re.sub('confs', global_task_name, conf_path) vasp_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing) lmps_path = os.path.join(task_path, task_type + '-reprod-k%.2f' % kspacing) os.makedirs(lmps_path, exist_ok=True) copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2]) struct_widecard = os.path.join(vasp_path, 'struct-%s-%s-*' % (insert_ele, copy_str)) vasp_struct = glob.glob(struct_widecard) vasp_struct.sort() cwd = os.getcwd() # make lammps.in if task_type == 'deepmd': fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_deepmd, model_name) elif task_type == 'meam': fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_meam, model_param) f_lammps_in = os.path.join(lmps_path, 'lammps.in') with open(f_lammps_in, 'w') as fp: fp.write(fc) for vs in vasp_struct: # get vasp energy outcar = os.path.join(vs, 'OUTCAR') energies = vasp.get_energies(outcar) # get xdat xdatcar = os.path.join(vs, 'XDATCAR') struct_basename = os.path.basename(vs) ls = os.path.join(lmps_path, struct_basename) print(ls) os.makedirs(ls, exist_ok=True) os.chdir(ls) if os.path.exists('XDATCAR'): os.remove('XDATCAR') os.symlink(os.path.relpath(xdatcar), 'XDATCAR') xdat_lines = open('XDATCAR', 'r').read().split('\n') natoms = vasp.poscar_natoms('XDATCAR') xdat_secsize = natoms + 8 xdat_nframes = len(xdat_lines) // xdat_secsize if xdat_nframes > len(energies): warnings.warn( 'nframes %d in xdat is larger than energy %d, use the last %d frames' % (xdat_nframes, len(energies), len(energies))) xdat_nlines = len(energies) * xdat_secsize xdat_lines = xdat_lines[xdat_nlines:] xdat_nframes = len(xdat_lines) // xdat_secsize print(xdat_nframes, len(energies)) #link lammps.in and model for jj in ['lammps.in'] + model_name: if os.path.islink(jj): os.unlink(jj) os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') if task_type == 'deepmd': for ii in model_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(models, model_name): os.symlink(os.path.relpath(ii), jj) share_models = glob.glob(os.path.join(ls, '*pb')) else: share_models = models # loop over frames for ii in range(xdat_nframes): frame_path = 'frame.%06d' % ii os.makedirs(frame_path, exist_ok=True) os.chdir(frame_path) # clear dir for jj in ['conf.lmp']: if os.path.isfile(jj): os.remove(jj) for jj in ['lammps.in'] + model_name: if os.path.islink(jj): os.unlink(jj) # link lammps in os.symlink(os.path.relpath('../lammps.in'), 'lammps.in') # make conf with open('POSCAR', 'w') as fp: fp.write('\n'.join(xdat_lines[ii * xdat_secsize:(ii + 1) * xdat_secsize])) lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # link models for (kk, ll) in zip(share_models, model_name): os.symlink(os.path.relpath(kk), ll) os.chdir(ls) os.chdir(cwd)
def make_lammps(jdata, conf_dir, task_type): fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name = fp_params['model_name'] if not model_name: models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] else: models = [os.path.join(model_dir, ii) for ii in model_name] model_param = { 'model_name': fp_params['model_name'], 'param_type': fp_params['model_param_type'] } ntypes = len(type_map) 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, task_type) equi_dump = os.path.join(equi_path, 'dump.relax') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, task_type) os.makedirs(task_path, exist_ok=True) task_poscar = os.path.join(task_path, 'POSCAR') lammps.poscar_from_last_dump(equi_dump, task_poscar, type_map) # get equi stress equi_log = os.path.join(equi_path, 'log.lammps') stress = lammps.get_stress(equi_log) 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 tasks cwd = os.getcwd() # make lammps.in if task_type == 'deepmd': fc = lammps.make_lammps_elastic('conf.lmp', ntypes, lammps.inter_deepmd, model_name) elif task_type == 'meam': fc = lammps.make_lammps_elastic('conf.lmp', ntypes, lammps.inter_meam, model_param) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp: fp.write(fc) cwd = os.getcwd() if task_type == 'deepmd': os.chdir(task_path) for ii in model_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(models, model_name): os.symlink(os.path.relpath(ii), jj) share_models = glob.glob(os.path.join(task_path, '*pb')) else: share_models = models 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 ['conf.lmp', 'lammps.in'] + model_name: if os.path.isfile(jj): os.remove(jj) # make conf deformed_structures[ii].to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # record strain strain = Strain.from_deformation(deformations[ii]) np.savetxt('strain.out', strain) # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii, jj) in zip(share_models, model_name): os.symlink(os.path.relpath(ii), jj) cwd = os.getcwd()
def make_lammps(jdata, conf_dir, task_type): fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name = fp_params['model_name'] if not model_name: models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] else: models = [os.path.join(model_dir, ii) for ii in model_name] model_param = { 'model_name': fp_params['model_name'], 'param_type': fp_params['model_param_type'] } supercell_matrix = jdata['supercell_matrix'] band_path = jdata['band'] 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, task_type) task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, task_type) os.makedirs(task_path, exist_ok=True) task_poscar = os.path.join(task_path, 'POSCAR') cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(conf_poscar), 'POSCAR') os.chdir(cwd) with open(task_poscar, 'r') as fp: lines = fp.read().split('\n') ele_list = lines[5].split() print(task_path) # make conf.lmp conf_file = os.path.join(task_path, 'conf.lmp') lammps.cvt_lammps_conf(task_poscar, os.path.relpath(conf_file)) ptypes = vasp.get_poscar_types(task_poscar) lammps.apply_type_map(conf_file, type_map, ptypes) # make lammps.in ntypes = len(ele_list) unitcell = get_structure_from_poscar(task_poscar) if task_type == 'deepmd': fc = lammps.make_lammps_phonon('conf.lmp', unitcell.masses, lammps.inter_deepmd, model_name) if task_type == 'meam': fc = lammps.make_lammps_phonon('conf.lmp', unitcell.masses, lammps.inter_meam, model_param) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp: fp.write(fc) cwd = os.getcwd() # link models os.chdir(task_path) for ii in model_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(models, model_name): os.symlink(os.path.relpath(ii), jj) # gen band.conf os.chdir(task_path) with open('band.conf', 'w') as fp: fp.write('ATOM_NAME = ') for ii in ele_list: fp.write(ii) fp.write(' ') fp.write('\n') fp.write( 'DIM = %d %d %d\n' % (supercell_matrix[0], supercell_matrix[1], supercell_matrix[2])) fp.write('BAND = %s\n' % band_path) fp.write('FORCE_CONSTANTS=READ\n') os.system('phonolammps lammps.in --dim %d %d %d -c POSCAR' % (supercell_matrix[0], supercell_matrix[1], supercell_matrix[2]))
def make_lammps(jdata, conf_dir,task_type) : fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name =fp_params['model_name'] if not model_name and task_type =='deepmd': models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] assert len(model_name)>0,"No deepmd model in the model_dir" else: models = [os.path.join(model_dir,ii) for ii in model_name] model_param = {'model_name' : fp_params['model_name'], 'param_type': fp_params['model_param_type']} ntypes = len(type_map) 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 equi_path = re.sub('confs', global_equi_name, conf_path) equi_path = os.path.join(equi_path, task_type) equi_dump = os.path.join(equi_path, 'dump.relax') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, task_type) os.makedirs(task_path, exist_ok=True) task_poscar = os.path.join(task_path, 'POSCAR') lammps.poscar_from_last_dump(equi_dump, task_poscar, type_map) # get equi stress equi_log = os.path.join(equi_path, 'log.lammps') stress = lammps.get_stress(equi_log) np.savetxt(os.path.join(task_path, 'equi.stress.out'), stress) # gen strcture # ss = Structure.from_file(conf_poscar) # print(ss) # ss = ss.from_file(task_poscar) # print(ss) 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] print('gen with norm '+str(norm_strains)) print('gen with shear '+str(shear_strains)) dfm_ss = DeformedStructureSet(ss, symmetry = False, norm_strains = norm_strains, shear_strains = shear_strains) n_dfm = len(dfm_ss) # gen tasks cwd = os.getcwd() # make lammps.in if task_type=='deepmd': fc = lammps.make_lammps_elastic('conf.lmp', ntypes, lammps.inter_deepmd, model_name) elif task_type=='meam': fc = lammps.make_lammps_elastic('conf.lmp', ntypes, lammps.inter_meam, model_param) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp : fp.write(fc) cwd = os.getcwd() os.chdir(task_path) for ii in model_name : if os.path.exists(ii) : os.remove(ii) for (ii,jj) in zip(models, model_name) : os.symlink(os.path.relpath(ii), jj) share_models = [os.path.join(task_path,ii) for ii in model_name] 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 ['conf.lmp', 'lammps.in'] + model_name : if os.path.isfile(jj): os.remove(jj) # make conf dfm_ss.deformed_structures[ii].to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # record strain strain = Strain.from_deformation(dfm_ss.deformations[ii]) np.savetxt('strain.out', strain) # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii,jj) in zip(share_models, model_name) : os.symlink(os.path.relpath(ii), jj) cwd = os.getcwd()
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_lammps(jdata, conf_dir, supercell, insert_ele, task_type): fp_params = jdata['vasp_params'] kspacing = fp_params['kspacing'] fp_params = jdata['lammps_params'] model_dir = fp_params['model_dir'] type_map = fp_params['type_map'] model_dir = os.path.abspath(model_dir) model_name = fp_params['model_name'] if not model_name and task_type == 'deepmd': models = glob.glob(os.path.join(model_dir, '*pb')) model_name = [os.path.basename(ii) for ii in models] assert len(model_name) > 0, "No deepmd model in the model_dir" else: models = [os.path.join(model_dir, ii) for ii in model_name] model_param = { 'model_name': fp_params['model_name'], 'param_type': fp_params['model_param_type'] } ntypes = len(type_map) 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') #equi_path = os.path.join(equi_path, task_type) #equi_dump = os.path.join(equi_path, 'dump.relax') 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, task_type) os.makedirs(task_path, exist_ok=True) task_poscar = os.path.join(task_path, 'POSCAR') cwd = os.getcwd() os.chdir(task_path) if os.path.isfile('POSCAR'): os.remove('POSCAR') os.symlink(os.path.relpath(equi_contcar), 'POSCAR') #lammps.poscar_from_last_dump(equi_dump, task_poscar, type_map) os.chdir(cwd) # gen structure from equi poscar 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 tasks cwd = os.getcwd() # make lammps.in, relax at 0 bar (scale = 1) if task_type == 'deepmd': fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, 1, lammps.inter_deepmd, model_name) elif task_type == 'meam': fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, 1, lammps.inter_meam, model_param) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp: fp.write(fc) # gen tasks copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2]) cwd = os.getcwd() if task_type == 'deepmd': os.chdir(task_path) for ii in model_name: if os.path.exists(ii): os.remove(ii) for (ii, jj) in zip(models, model_name): os.symlink(os.path.relpath(ii), jj) share_models = glob.glob(os.path.join(task_path, '*pb')) else: share_models = models 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 ['conf.lmp', 'lammps.in'] + model_name: if os.path.isfile(jj): os.remove(jj) # make conf dss[ii].to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii, jj) in zip(share_models, model_name): os.symlink(os.path.relpath(ii), jj) # save supercell np.savetxt('supercell.out', supercell, fmt='%d') os.chdir(cwd)
def make_meam_lammps(jdata, conf_dir, max_miller=2, static=False, relax_box=False, task_name='wrong-task'): fp_params = jdata['vasp_params'] kspacing = fp_params['kspacing'] meam_potfile_dir = jdata['meam_potfile_dir'] meam_potfile_dir = os.path.abspath(meam_potfile_dir) meam_potfile = jdata['meam_potfile'] meam_potfile = [os.path.join(meam_potfile_dir, ii) for ii in meam_potfile] meam_potfile_name = jdata['meam_potfile'] type_map = jdata['meam_type_map'] ntypes = len(type_map) meam_param = { 'meam_potfile': jdata['meam_potfile'], 'meam_type': jdata['meam_param_type'] } min_slab_size = jdata['min_slab_size'] min_vacuum_size = jdata['min_vacuum_size'] # get equi 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') task_path = re.sub('confs', global_task_name, conf_dir) task_path = os.path.abspath(task_path) task_path = os.path.join(task_path, task_name) 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 slabs all_slabs = generate_all_slabs(ss, max_miller, min_slab_size, min_vacuum_size) # make lammps.in if static: fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_meam, meam_param) else: fc = lammps.make_lammps_equi('conf.lmp', ntypes, lammps.inter_meam, meam_param, change_box=relax_box) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp: fp.write(fc) 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 ['conf.lmp', 'lammps.in'] + meam_potfile_name: 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') vasp.regulate_poscar('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', type_map, ptypes) # record miller np.savetxt('miller.out', slab.miller_index, fmt='%d') # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii, jj) in zip(meam_potfile, meam_potfile_name): os.symlink(os.path.relpath(ii), jj) cwd = os.getcwd()
def make_deepmd_lammps (jdata, conf_dir) : deepmd_model_dir = jdata['deepmd_model_dir'] deepmd_type_map = jdata['deepmd_type_map'] ntypes = len(deepmd_type_map) deepmd_model_dir = os.path.abspath(deepmd_model_dir) deepmd_models = glob.glob(os.path.join(deepmd_model_dir, '*pb')) deepmd_models_name = [os.path.basename(ii) for ii in deepmd_models] vol_start = jdata['vol_start'] vol_end = jdata['vol_end'] vol_step = jdata['vol_step'] # # get equi props # equi_path = re.sub('confs', global_equi_name, conf_path) # equi_path = os.path.join(equi_path, 'lmp') # equi_log = os.path.join(equi_path, 'log.lammps') # if not os.path.isfile(equi_log) : # raise RuntimeError("the system should be equilibriated first") # natoms, epa, vpa = lammps.get_nev(equi_log) # task path task_path = re.sub('confs', global_task_name, conf_dir) task_path = os.path.abspath(task_path) os.makedirs(task_path, exist_ok = True) cwd = os.getcwd() conf_path = os.path.abspath(conf_dir) 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) volume = vasp.poscar_vol(to_poscar) natoms = vasp.poscar_natoms(to_poscar) vpa = volume / natoms # structrure ss = Structure.from_file(to_poscar) # lmp path lmp_path = os.path.join(task_path, 'deepmd') os.makedirs(lmp_path, exist_ok = True) # # lmp conf # conf_file = os.path.join(lmp_path, 'conf.lmp') # lammps.cvt_lammps_conf(to_poscar, conf_file) # ptypes = vasp.get_poscar_types(to_poscar) # lammps.apply_type_map(conf_file, deepmd_type_map, ptypes) os.chdir(lmp_path) for ii in deepmd_models_name : if os.path.exists(ii) : os.remove(ii) for (ii,jj) in zip(deepmd_models, deepmd_models_name) : os.symlink(os.path.relpath(ii), jj) share_models = glob.glob(os.path.join(lmp_path, '*pb')) for vol in np.arange(vol_start, vol_end, vol_step) : vol_path = os.path.join(lmp_path, 'vol-%.2f' % vol) print('# generate %s' % (vol_path)) os.makedirs(vol_path, exist_ok = True) os.chdir(vol_path) #print(vol_path) for ii in ['conf.lmp', 'conf.lmp'] + deepmd_models_name : if os.path.exists(ii) : os.remove(ii) # # link conf # os.symlink(os.path.relpath(conf_file), 'conf.lmp') # make conf scale_ss = ss.copy() scale_ss.scale_lattice(vol * natoms) scale_ss.to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', deepmd_type_map, ptypes) # link models for (ii,jj) in zip(share_models, deepmd_models_name) : os.symlink(os.path.relpath(ii), jj) # make lammps input scale = (vol / vpa) ** (1./3.) fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, scale,lammps.inter_deepmd, deepmd_models_name) with open(os.path.join(vol_path, 'lammps.in'), 'w') as fp : fp.write(fc) os.chdir(cwd)
def make_deepmd_lammps(jdata, conf_dir, supercell) : fp_params = jdata['vasp_params'] kspacing = fp_params['kspacing'] deepmd_model_dir = jdata['deepmd_model_dir'] deepmd_type_map = jdata['deepmd_type_map'] ntypes = len(deepmd_type_map) deepmd_model_dir = os.path.abspath(deepmd_model_dir) deepmd_models = glob.glob(os.path.join(deepmd_model_dir, '*pb')) deepmd_models_name = [os.path.basename(ii) for ii in deepmd_models] 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') # equi_path = re.sub('confs', global_equi_name, conf_path) # equi_path = os.path.join(equi_path, 'lmp') # equi_dump = os.path.join(equi_path, 'dump.relax') task_path = re.sub('confs', global_task_name, conf_path) task_path = os.path.join(task_path, 'deepmd') os.makedirs(task_path, exist_ok=True) # gen task poscar task_poscar = os.path.join(task_path, 'POSCAR') # lammps.poscar_from_last_dump(equi_dump, task_poscar, deepmd_type_map) 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) # gen structure from equi poscar ss = Structure.from_file(task_poscar) # gen defects vds = VacancyGenerator(ss) dss = [] for jj in vds : dss.append(jj.generate_defect_structure(supercell)) # gen tasks cwd = os.getcwd() # make lammps.in, relax at 0 bar (scale = 1) fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, 1, lammps.inter_deepmd, deepmd_models_name) f_lammps_in = os.path.join(task_path, 'lammps.in') with open(f_lammps_in, 'w') as fp : fp.write(fc) # gen tasks copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2]) cwd = os.getcwd() os.chdir(task_path) for ii in deepmd_models_name : if os.path.exists(ii) : os.remove(ii) for (ii,jj) in zip(deepmd_models, deepmd_models_name) : os.symlink(os.path.relpath(ii), jj) share_models = glob.glob(os.path.join(task_path, '*pb')) 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 ['conf.lmp', 'lammps.in'] + deepmd_models_name : if os.path.isfile(jj): os.remove(jj) # make conf dss[ii].to('POSCAR', 'POSCAR') lammps.cvt_lammps_conf('POSCAR', 'conf.lmp') ptypes = vasp.get_poscar_types('POSCAR') lammps.apply_type_map('conf.lmp', deepmd_type_map, ptypes) # link lammps.in os.symlink(os.path.relpath(f_lammps_in), 'lammps.in') # link models for (ii,jj) in zip(share_models, deepmd_models_name) : os.symlink(os.path.relpath(ii), jj) # save supercell np.savetxt('supercell.out', supercell, fmt='%d') os.chdir(cwd)