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) cwd = os.getcwd() task_list = [] if refine: task_list = make_refine( self.parameter['init_from_suffix'], self.parameter['output_suffix'], path_to_work, (self.vol_end - self.vol_start) / self.vol_step) 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: equi_contcar = os.path.join(path_to_equi, 'CONTCAR') if not os.path.exists(equi_contcar): raise RuntimeError("please do relaxation first") vol_to_poscar = vasp.poscar_vol(equi_contcar) / vasp.poscar_natoms( equi_contcar) for vol in np.arange(self.vol_start, self.vol_end, self.vol_step): task_num = (vol - self.vol_start) / self.vol_step output_task = os.path.join(path_to_work, 'task.%06d' % task_num) os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for ii in [ 'INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR', 'conf.lmp', 'in.lammps' ]: if os.path.exists(ii): os.remove(ii) task_list.append(output_task) os.symlink(os.path.relpath(equi_contcar), 'POSCAR.orig') scale = (vol / vol_to_poscar)**(1. / 3.) self.parameter['scale2equi'] = scale # 06/14 vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale) os.chdir(cwd) return task_list
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_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_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_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')) cwd = os.getcwd() task_list = [] if self.reprod: print('eos 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('eos refine starts') task_list = make_refine(self.parameter['init_from_suffix'], self.parameter['output_suffix'], path_to_work) os.chdir(cwd) 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('eos.json'): os.remove('eos.json') if os.path.islink('eos.json'): os.remove('eos.json') os.symlink( os.path.relpath( os.path.join(init_from_task, 'eos.json')), 'eos.json') os.chdir(cwd) else: print('gen eos from ' + str(self.vol_start) + ' to ' + str(self.vol_end) + ' by every ' + str(self.vol_step)) equi_contcar = os.path.join(path_to_equi, 'CONTCAR') if not os.path.exists(equi_contcar): raise RuntimeError("please do relaxation first") vol_to_poscar = vasp.poscar_vol( equi_contcar) / vasp.poscar_natoms(equi_contcar) self.parameter['scale2equi'] = [] task_num = 0 while self.vol_start + self.vol_step * task_num < self.vol_end: # for vol in np.arange(int(self.vol_start * 100), int(self.vol_end * 100), int(self.vol_step * 100)): # vol = vol / 100.0 vol = self.vol_start + task_num * self.vol_step #task_num = int((vol - self.vol_start) / self.vol_step) output_task = os.path.join(path_to_work, 'task.%06d' % task_num) os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for ii in [ 'INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR', 'conf.lmp', 'in.lammps' ]: if os.path.exists(ii): os.remove(ii) task_list.append(output_task) os.symlink(os.path.relpath(equi_contcar), 'POSCAR.orig') # scale = (vol / vol_to_poscar) ** (1. / 3.) scale = vol**(1. / 3.) eos_params = { 'volume': vol * vol_to_poscar, 'scale': scale } dumpfn(eos_params, 'eos.json', indent=4) self.parameter['scale2equi'].append(scale) # 06/22 vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale) task_num += 1 os.chdir(cwd) return task_list
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_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)