def make_super_cell_pymatgen (jdata) : make_unit_cell(jdata) out_dir = jdata['out_dir'] path_uc = os.path.join(out_dir, global_dirname_02) from_path = path_uc from_file = os.path.join(from_path, 'POSCAR.unit') ss = Structure.from_file(from_file) all_millers = jdata['millers'] path_sc = os.path.join(out_dir, global_dirname_02) z_min = jdata['z_min'] super_cell = jdata['super_cell'] cwd = os.getcwd() path_work = (path_sc) path_work = os.path.abspath(path_work) pcpy_cmd = os.path.join(cwd, 'tools') pcpy_cmd = os.path.join(pcpy_cmd, 'poscar_copy.py') os.chdir(path_work) for miller in all_millers: miller_str="" for ii in miller : miller_str += str(ii) path_cur_surf = create_path('surf-'+miller_str) os.chdir(path_cur_surf) slabgen = SlabGenerator(ss, miller, z_min, 1e-3) all_slabs = slabgen.get_slabs() print("Miller %s: The slab has %s termination, use the first one" %(str(miller), len(all_slabs))) all_slabs[0].to('POSCAR', 'POSCAR') if super_cell[0] > 1 or super_cell[1] > 1 : sp.check_call(pcpy_cmd + ' -n %d %d %d POSCAR POSCAR ' % (super_cell[0], super_cell[1], 1), shell = True) os.chdir(path_work) os.chdir(cwd)
def make_super_cell_pymatgen(jdata): make_unit_cell(jdata) out_dir = jdata['out_dir'] path_uc = os.path.join(out_dir, global_dirname_02) from_path = path_uc from_file = os.path.join(from_path, 'POSCAR.unit') ss = Structure.from_file(from_file) # ase only support X type element for i in range(len(ss)): ss[i] = 'X' ss = AseAtomsAdaptor.get_atoms(ss) all_millers = jdata['millers'] path_sc = os.path.join(out_dir, global_dirname_02) #z_min = jdata['z_min'] layer_numb = jdata['layer_numb'] super_cell = jdata['super_cell'] cwd = os.getcwd() path_work = (path_sc) path_work = os.path.abspath(path_work) os.chdir(path_work) for miller in all_millers: miller_str = "" for ii in miller: miller_str += str(ii) path_cur_surf = create_path('surf-' + miller_str) os.chdir(path_cur_surf) #slabgen = SlabGenerator(ss, miller, z_min, 1e-3) slab = general_surface.surface(ss, indices=miller, vacuum=1e-3, layers=layer_numb) #all_slabs = slabgen.get_slabs() dlog.info(os.getcwd()) #dlog.info("Miller %s: The slab has %s termination, use the first one" %(str(miller), len(all_slabs))) #all_slabs[0].to('POSCAR', 'POSCAR') slab.write('POSCAR', vasp5=True) if super_cell[0] > 1 or super_cell[1] > 1: st = Structure.from_file('POSCAR') st.make_supercell([super_cell[0], super_cell[1], 1]) st.to('POSCAR', 'POSCAR') os.chdir(path_work) os.chdir(cwd)
def make_surface(file, facet=(1, 1, 1), verbose=True): # read in structure st = Structure.from_file(file) # generate slabs with the given facet slabgen = SlabGenerator(st, facet, 6, 16, center_slab=True) all_slabs = slabgen.get_slabs(symmetrize=True) if verbose: print("The slab has %s termination." % (len(all_slabs))) # save surfaces for i, slab in enumerate(all_slabs): slab.to('POSCAR', 'POSCAR_SURF_' + str(i).zfill(2))
def make_super_cell_pymatgen(jdata): make_unit_cell(jdata) out_dir = jdata['out_dir'] path_uc = os.path.join(out_dir, global_dirname_02) from_path = path_uc from_file = os.path.join(from_path, 'POSCAR.unit') ss = Structure.from_file(from_file) all_millers = jdata['millers'] path_sc = os.path.join(out_dir, global_dirname_02) z_min = jdata['z_min'] super_cell = jdata['super_cell'] cwd = os.getcwd() path_work = (path_sc) path_work = os.path.abspath(path_work) os.chdir(path_work) for miller in all_millers: miller_str = "" for ii in miller: miller_str += str(ii) path_cur_surf = create_path('surf-' + miller_str) os.chdir(path_cur_surf) slabgen = SlabGenerator(ss, miller, z_min, 1e-3) all_slabs = slabgen.get_slabs() dlog.info(os.getcwd()) dlog.info("Miller %s: The slab has %s termination, use the first one" % (str(miller), len(all_slabs))) all_slabs[0].to('POSCAR', 'POSCAR') if super_cell[0] > 1 or super_cell[1] > 1: st = Structure.from_file('POSCAR') st.make_supercell([super_cell[0], super_cell[1], 1]) st.to('POSCAR', 'POSCAR') os.chdir(path_work) os.chdir(cwd)
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, max_miller = 2, static = False, relax_box = False, task_name = 'wrong-task') : 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] 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_deepmd, deepmd_models_name) else : fc = lammps.make_lammps_equi('conf.lmp', ntypes, lammps.inter_deepmd, deepmd_models_name, 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'] + deepmd_models_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', deepmd_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(deepmd_models, deepmd_models_name) : os.symlink(os.path.relpath(ii), jj) cwd = os.getcwd()
# Import the neccesary tools to generate surfaces from pymatgen.core.surface import SlabGenerator, generate_all_slabs, Structure, Lattice # Import the neccesary tools for making a Wulff shape from pymatgen.analysis.wulff import WulffShape import os lattice = Lattice.cubic(3.508) Ni = Structure(lattice, ["Ni", "Ni", "Ni", "Ni"], [[0, 0, 0], [0, 0.5, 0], [0.5, 0, 0], [0, 0, 0.5]]) slabgen = SlabGenerator(Ni, (1, 1, 1), 10, 10) lattice = Lattice.cubic(5.46873) Si = Structure(lattice, ["Si", "Si", "Si", "Si", "Si", "Si", "Si", "Si"], [[0.00000, 0.00000, 0.50000], [0.75000, 0.75000, 0.75000], [0.00000, 0.50000, 0.00000], [0.75000, 0.25000, 0.25000], [0.50000, 0.00000, 0.00000], [0.25000, 0.75000, 0.25000], [0.50000, 0.50000, 0.50000], [0.25000, 0.25000, 0.75000]]) slabgen = SlabGenerator(Si, (1, 1, 1), 10, 10) print("Notice now there are actually now %s terminations that can be \ generated in the (111) direction for diamond Si" % (len(slabgen.get_slabs())))
} Adsorbant_1 = { 'M': 24, 'X': 48, 'Y': 2, 'Area': 77.14, 'Energy': -609.24, 'Label': '1 Species' } data = [Adsorbant_1] Surface_111_1 = wulff.calculate_surface_energy(stoich, data, SE, adsorbant, thermochem, 298, 0) #Declare the lattic paramter lattice = Lattice.cubic(5.411) ceo = Structure(lattice, ["Ce", "O"], [[0, 0, 0], [0.25, 0.25, 0.25]]) surface_energies_ceo = { (1, 1, 1): np.amin(Surface_111_1), (1, 1, 0): np.amin(Surface_110_1), (1, 0, 0): np.amin(Surface_100_1) } miller_list = surface_energies_ceo.keys() e_surf_list = surface_energies_ceo.values() # We can now construct a Wulff shape with an accuracy up to a max Miller index of 3 wulffshape = WulffShape(ceo.lattice, miller_list, e_surf_list) # Let's get some useful information from our wulffshape object print("shape factor: %.3f, anisotropy: \ %.3f, weighted surface energy: %.3f J/m^2" %
# Input parameters, following behavior of SlabGenerator in pymatgen filname = sys.argv[1] outname = filname.split('.') outname = outname[0].split('/') outname = outname[-1:] print("Reading atomic coordinates from: ", filname) # remaining input parameters miller = sys.argv[2].split(',') slabsize = int(sys.argv[3]) vacsize = int(sys.argv[4]) # Read structure from PWscf file, xsf format structure = Structure.from_file(filname) # make slab if len(miller) == 3: miller = tuple(map(int, miller)) # no list in py2 slabgen = SlabGenerator(structure, miller, slabsize, vacsize, center_slab=True) slabs = slabgen.get_slabs() print("Generated %d slabs in %s direction" % ( len(slabs), str(miller), ))