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_input_file(self, output_dir, task_type, task_param): lammps.cvt_lammps_conf(os.path.join(output_dir, 'POSCAR'), 'conf.lmp') with open(os.path.join(output_dir, 'task.json'), 'w') as fp: json.dump(task_param, fp, indent=4) # lines in lammps.in related to model # line_model = "pair_style meam \n" # line_model += "pair_coeff * * %s " % (os.path.basename(self.model[0])) # for ii in self.type_map: # line_model += ii + ' ' # line_model += "%s " % (os.path.basename(self.model[1])) # for ii in self.type_map: # line_model += ii + ' ' # line_model += '\n' etol = 1e-12 ftol = 1e-6 maxiter = 5000 maxeval = 500000 change_box = True B0 = 70 bp = 0 scale2equi = 1 ntypes = len(self.type_map) reprod_opt = False static = False if 'etol' in task_param: etol = task_param['etol'] if 'ftol' in task_param: ftol = task_param['ftol'] if 'maxiter' in task_param: maxiter = task_param['maxiter'] if 'maxeval' in task_param: maxeval = task_param['maxeval'] if 'change_box' in task_param: change_box = task_param['change_box'] if 'scale2equi' in task_param: scale2equi = task_param['scale2equi'] if 'reprod_opt' in task_param: reprod_opt = task_param['reprod_opt'] if 'static-opt' in task_param: static = task_param['static-opt'] model_name = list(map(os.path.basename, self.model)) model_param = {'model_name': model_name, 'param_type': self.type_map} fc = '' if task_type == 'relaxation' \ or (task_type == 'eos' and not change_box) \ or (task_type == 'surface' and not static): fc = lammps.make_lammps_equi('conf.lmp', ntypes, lammps.inter_meam, model_param, etol, ftol, maxiter, maxeval, change_box) if task_type == 'static' \ or (task_type == 'surface' and static): fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_meam, model_param) if task_type == 'elastic': fc = lammps.make_lammps_elastic('conf.lmp', ntypes, lammps.inter_meam, model_param, etol, ftol, maxiter, maxeval) if task_type == 'vacancy' \ or (task_type == 'eos' and change_box) \ or (task_type == 'interstitial'): fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, scale2equi, lammps.inter_meam, model_param, B0, bp, etol, ftol, maxiter, maxeval) if reprod_opt: fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_meam, model_param) with open(os.path.join(output_dir, 'in.lammps'), 'w') as fp: fp.write(fc)
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, 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)