def apply_transformation(self, structure, return_ranked_list=False): """ :param structure: :param return_ranked_list (Logical or integer): Use big enough number to return all defect structures :return: scs: Supercells with one vacancy in each structure. """ if not return_ranked_list: raise ValueError( "VacancyTransformation has no single best structure" " output. Must use return_ranked_list.") try: num_to_return = int(return_ranked_list) except ValueError: num_to_return = 1 vac = Vacancy(structure, self.valences, self.radii) scs = vac.make_supercells_with_defects(self.supercell_dim, self.species, num_to_return) #if num_to_return < len(scs)-1: # raise ValueError("VacancyTransformation has no ordering of best " # "structure. Must increase return_ranked_list.") structures = [] for sc in scs[1:]: structures.append({'structure': sc}) return structures
def apply_transformation(self, structure, return_ranked_list=False): """ :param structure: :param return_ranked_list (Logical or integer): Use big enough number to return all defect structures :return: scs: Supercells with one vacancy in each structure. """ if not return_ranked_list: raise ValueError("VacancyTransformation has no single best structure" " output. Must use return_ranked_list.") try: num_to_return = int(return_ranked_list) except ValueError: num_to_return = 1 vac = Vacancy(structure,self.valences,self.radii) scs = vac.make_supercells_with_defects( self.supercell_dim,self.species, num_to_return) #if num_to_return < len(scs)-1: # raise ValueError("VacancyTransformation has no ordering of best " # "structure. Must increase return_ranked_list.") structures = [] for sc in scs[1:]: structures.append({'structure':sc}) return structures
def vac_intl(cellmax=2, mpid='', struct=None): """ Vacancy and interstitial generator Args: cellmax: maximum cell size struct: Structure object Returns: def_str: defect structures """ if struct == None: with MPRester() as mp: struct = mp.get_structure_by_material_id(mpid) if mpid == '': print("Provide structure") sg_mat = SpacegroupAnalyzer(struct) struct = sg_mat.get_conventional_standard_structure() def_str = [] count = 0 cell_arr = [cellmax, cellmax, cellmax] vac = Vacancy(struct, {}, {}) for el in list(struct.symbol_set): scs = vac.make_supercells_with_defects(cell_arr, el) for i in range(len(scs)): if i == 0: pos = Poscar(scs[i]) pos.comment = str('bulk') + str('.') + str('cellmax') + str( cellmax) if count == 0: def_str.append(pos) count = count + 1 else: pos = Poscar(scs[i]) pos.comment = str('vac') + str('cellmax') + str(cellmax) + str( '@') + str(vac.get_defectsite_multiplicity(i)) + str( 'Element') + str(el) if pos not in def_str: def_str.append(pos) struct_valrad_eval = ValenceIonicRadiusEvaluator(struct) val = struct_valrad_eval.valences rad = struct_valrad_eval.radii struct_val = val struct_rad = rad intl = Interstitial(struct, val, rad) for el in struct.composition.elements: scs = intl.make_supercells_with_defects(cell_arr, el) for i in range(1, len(scs)): pos = Poscar(scs[i]) pos.comment = str('intl') + str('cellmax') + str(cellmax) + str( '@') + str(intl.get_defectsite_coordination_number( i - 1)) + str('Element') + str(el) if pos not in def_str: def_str.append(pos) print(len(def_str)) return def_str
def apply_transformation(self, structure, return_ranked_list=False): """ :param structure: :param return_ranked_list (Logical or integer): Use big enough number to return all defect structures :return: scs: Supercells with one substitution defect in each structure. """ if not return_ranked_list: raise ValueError( "SubstitutionDefectTransformation has no single" "best structure output. Must use return_ranked_list.") try: num_to_return = int(return_ranked_list) except ValueError: num_to_return = 1 species = self._species_map.keys() vac = Vacancy(structure, self.valences, self.radii) scs = vac.make_supercells_with_defects(self.supercell_dim, species, num_to_return) blk_sc = scs[0] sub_scs = [] for i in range(1, len(scs)): vac_sc = scs[i] vac_site = list(set(blk_sc.sites) - set(vac_sc.sites))[0] if isinstance(vac_site.specie, Specie): site_specie = vac_site.specie.element.symbol elif isinstance(vac_site.specie, Element): site_specie = vac_site.specie.symbol if site_specie in self._species_map.keys(): substitute_specie = self._species_map[site_specie] vac_sc.append(substitute_specie, vac_site.frac_coords) sub_scs.append(vac_sc.get_sorted_structure()) #if num_to_return < len(sub_scs)-1: # raise ValueError("SubstitutionDefectTransformation has no ordering" # " of best structure. Must increase return_ranked_list.") num_to_return = min(num_to_return, len(sub_scs)) structures = [] if num_to_return: for sc in sub_scs[0:num_to_return]: structures.append({'structure': sc}) else: structures.append({'structure': scs[0]}) return structures
def apply_transformation(self, structure, return_ranked_list=False): """ :param structure: :param return_ranked_list (Logical or integer): Use big enough number to return all defect structures :return: scs: Supercells with one substitution defect in each structure. """ if not return_ranked_list: raise ValueError("SubstitutionDefectTransformation has no single" "best structure output. Must use return_ranked_list.") try: num_to_return = int(return_ranked_list) except ValueError: num_to_return = 1 species = self._species_map.keys() vac = Vacancy(structure,self.valences,self.radii) scs = vac.make_supercells_with_defects( self.supercell_dim,species,num_to_return) blk_sc = scs[0] sub_scs = [] for i in range(1,len(scs)): vac_sc = scs[i] vac_site = list(set(blk_sc.sites) - set(vac_sc.sites))[0] if isinstance(vac_site.specie,Specie): site_specie = vac_site.specie.element.symbol elif isinstance(vac_site.specie,Element): site_specie = vac_site.specie.symbol if site_specie in self._species_map.keys(): substitute_specie = self._species_map[site_specie] vac_sc.append(substitute_specie, vac_site.frac_coords) sub_scs.append(vac_sc.get_sorted_structure()) #if num_to_return < len(sub_scs)-1: # raise ValueError("SubstitutionDefectTransformation has no ordering" # " of best structure. Must increase return_ranked_list.") num_to_return = min(num_to_return, len(sub_scs)) structures = [] if num_to_return: for sc in sub_scs[0:num_to_return]: structures.append({'structure':sc}) else: structures.append({'structure':scs[0]}) return structures
def apply_transformation(self, structure, return_ranked_list=False): """ :param structure: :param return_ranked_list (Logical or integer): Use big enough number to return all defect structures :return: scs: Supercells with one antisite defect in each structure. """ if not return_ranked_list: raise ValueError("AntisiteDefectTransformation has no single best" "structure output. Must use return_ranked_list.") try: num_to_return = int(return_ranked_list) except ValueError: num_to_return = 1 vac = Vacancy(structure, self.valences, self.radii) scs = vac.make_supercells_with_defects(self.supercell_dim) blk_sc = scs[0] as_scs = [] struct_species = blk_sc.types_of_specie for i in range(1, len(scs)): vac_sc = scs[i] vac_site = list(set(blk_sc.sites) - set(vac_sc.sites))[0] for specie in set(struct_species) - set([vac_site.specie]): anti_struct = vac_sc.copy() anti_struct.append(specie, vac_site.frac_coords) as_scs.append(anti_struct.get_sorted_structure()) #if num_to_return < len(as_scs)-1: # raise ValueError("AntisiteDefectTransformation has no ordering " # "of best structures. Must increase return_ranked_list.") num_to_return = min(num_to_return, len(as_scs)) structures = [] for sc in as_scs[0:num_to_return]: structures.append({'structure': sc}) return structures
def apply_transformation(self, structure, return_ranked_list=False): """ :param structure: :param return_ranked_list (Logical or integer): Use big enough number to return all defect structures :return: scs: Supercells with one antisite defect in each structure. """ if not return_ranked_list: raise ValueError("AntisiteDefectTransformation has no single best" "structure output. Must use return_ranked_list.") try: num_to_return = int(return_ranked_list) except ValueError: num_to_return = 1 vac = Vacancy(structure,self.valences,self.radii) scs = vac.make_supercells_with_defects(self.supercell_dim) blk_sc = scs[0] as_scs = [] struct_species = blk_sc.types_of_specie for i in range(1,len(scs)): vac_sc = scs[i] vac_site = list(set(blk_sc.sites) - set(vac_sc.sites))[0] for specie in set(struct_species) - set([vac_site.specie]): anti_struct = vac_sc.copy() anti_struct.append(specie, vac_site.frac_coords) as_scs.append(anti_struct.get_sorted_structure()) #if num_to_return < len(as_scs)-1: # raise ValueError("AntisiteDefectTransformation has no ordering " # "of best structures. Must increase return_ranked_list.") num_to_return = min(num_to_return,len(as_scs)) structures = [] for sc in as_scs[0:num_to_return]: structures.append({'structure':sc}) return structures
def vac_antisite_def_struct_gen(c_size=15, mpid='', struct=None): def_str = [] if struct == None: with MPRester() as mp: struct = mp.get_structure_by_material_id(mpid) if mpid == '': print("Provide structure") dim1 = int((float(c_size) / float(max(abs(struct.lattice.matrix[0]))))) + 1 dim2 = int(float(c_size) / float(max(abs(struct.lattice.matrix[1])))) + 1 dim3 = int(float(c_size) / float(max(abs(struct.lattice.matrix[2])))) + 1 cellmax = max(dim1, dim2, dim3) prim_struct_sites = len(struct.sites) struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure() conv_struct_sites = len(struct.sites) conv_prim_rat = 1 + int(conv_struct_sites / prim_struct_sites) sc_scale = [dim1, dim2, dim3] print("sc_scale", sc_scale) struct_valrad_eval = ValenceIonicRadiusEvaluator(struct) val = struct_valrad_eval.valences rad = struct_valrad_eval.radii struct_val = val struct_rad = rad vac = Vacancy(struct, {}, {}) scs = vac.make_supercells_with_defects(sc_scale) #print ('scssssss',scs[0].make_supercell([1,1,1])) for i in range(len(scs)): sc = scs[i] mpvis = MPRelaxSet(sc) #VaspInputSet(struct) #print ('sccccc',sc,type(sc[0])) tmp = struct.copy() poscar = mpvis.poscar #kpoints = Kpoints.automatic_density(sc,kpoint_den) #incar = mpvis.get_incar(sc) #print ('big pos',poscar) interdir = mpid if not i: fin_dir = os.path.join(interdir, 'bulk') poscar.comment = str('bulk') + str('@') + str('cellmax') + str( cellmax) def_str.append(poscar) poscar.write_file('POSCAR-' + str('bulk') + str(".vasp")) else: blk_str_sites = set(scs[0].sites) vac_str_sites = set(sc.sites) vac_sites = blk_str_sites - vac_str_sites vac_site = list(vac_sites)[0] site_mult = int( vac.get_defectsite_multiplicity(i - 1) / conv_prim_rat) vac_site_specie = vac_site.specie vac_symbol = vac_site.specie.symbol vac_dir = 'vacancy_{}_mult-{}_sitespecie-{}'.format( str(i), site_mult, vac_symbol) fin_dir = os.path.join(interdir, vac_dir) try: poscar.comment = str(vac_dir) + str('@') + str( 'cellmax') + str(cellmax) except: pass pos = poscar def_str.append(pos) poscar.write_file('POSCAR-' + str(vac_dir) + str(".vasp")) struct_species = scs[0].types_of_specie for specie in set(struct_species) - set([vac_site_specie]): subspecie_symbol = specie.symbol anti_struct = sc.copy() anti_struct.append(specie, vac_site.frac_coords) mpvis = MPRelaxSet(anti_struct) #VaspInputSet(struct) print('anti_struct', anti_struct) poscar = mpvis.poscar as_dir = 'antisite_{}_mult-{}_sitespecie-{}_subspecie-{}'.format( str(i), site_mult, vac_symbol, subspecie_symbol) fin_dir = os.path.join(interdir, as_dir) poscar.comment = str(as_dir) + str('@') + str('cellmax') + str( cellmax) pos = poscar def_str.append(pos) poscar.write_file('POSCAR-' + str(as_dir) + str(".vasp")) return def_str
def vac_antisite_def_struct_gen(c_size=15, mpid='', struct=None, write_file=True): """ Vacancy, antisite generator Args: c_size: cell size struct: Structure object or mpid: materials project id Returns: def_str: defect structures in Poscar object format """ def_str = [] if struct == None: with MPRester() as mp: struct = mp.get_structure_by_material_id(mpid) if mpid == '': print("Provide structure") c_size = c_size dim1 = int((float(c_size) / float(max(abs(struct.lattice.matrix[0]))))) + 1 dim2 = int(float(c_size) / float(max(abs(struct.lattice.matrix[1])))) + 1 dim3 = int(float(c_size) / float(max(abs(struct.lattice.matrix[2])))) + 1 cellmax = max(dim1, dim2, dim3) prim_struct_sites = len(struct.sites) struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure() conv_struct_sites = len(struct.sites) conv_prim_rat = int(conv_struct_sites / prim_struct_sites) sc_scale = [dim1, dim2, dim3] print("sc_scale", sc_scale) struct_valrad_eval = ValenceIonicRadiusEvaluator(struct) val = struct_valrad_eval.valences rad = struct_valrad_eval.radii struct_val = val struct_rad = rad vac = Vacancy(struct, {}, {}) scs = vac.make_supercells_with_defects(sc_scale) for i in range(len(scs)): sc = scs[i] poscar = Poscar(sc) #mpvis.get_poscar(sc) interdir = mpid if not i: fin_dir = os.path.join(interdir, 'bulk') poscar.comment = str('bulk') + str('@') + str('cellmax') + str( cellmax) def_str.append(poscar) if write_file == True: poscar.write_file('POSCAR-' + str('bulk') + str(".vasp")) else: blk_str_sites = set(scs[0].sites) vac_str_sites = set(sc.sites) vac_sites = blk_str_sites - vac_str_sites vac_site = list(vac_sites)[0] site_mult = int( vac.get_defectsite_multiplicity(i - 1) / conv_prim_rat) vac_site_specie = vac_site.specie vac_symbol = vac_site.specie.symbol vac_dir = 'vacancy_{}_mult-{}_sitespecie-{}'.format( str(i), site_mult, vac_symbol) fin_dir = os.path.join(interdir, vac_dir) try: poscar.comment = str(vac_dir) + str('@') + str( 'cellmax') + str(cellmax) except: pass pos = poscar def_str.append(pos) if write_file == True: poscar.write_file('POSCAR-' + str(vac_dir) + str(".vasp")) struct_species = scs[0].types_of_specie for specie in set(struct_species) - set([vac_site_specie]): subspecie_symbol = specie.symbol anti_struct = sc.copy() anti_struct.append(specie, vac_site.frac_coords) poscar = Poscar(anti_struct) as_dir = 'antisite_{}_mult-{}_sitespecie-{}_subspecie-{}'.format( str(i), site_mult, vac_symbol, subspecie_symbol) fin_dir = os.path.join(interdir, as_dir) poscar.comment = str(as_dir) + str('@') + str('cellmax') + str( cellmax) pos = poscar def_str.append(pos) if write_file == True: poscar.write_file('POSCAR-' + str(as_dir) + str(".vasp")) return def_str
def vac_antisite_def_struct_gen(mpid, mapi_key, cellmax): if not mpid: print ("============\nERROR: Provide an mpid\n============") return if not mapi_key: with MPRester() as mp: struct = mp.get_structure_by_material_id(mpid) else: with MPRester(mapi_key) as mp: struct = mp.get_structure_by_material_id(mpid) prim_struct_sites = len(struct.sites) struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure() conv_struct_sites = len(struct.sites) conv_prim_rat = int(conv_struct_sites/prim_struct_sites) sc_scale = get_sc_scale(struct,cellmax) mpvis = MPGGAVaspInputSet() # Begin defaults: All default settings. blk_vasp_incar_param = {'IBRION':-1,'EDIFF':1e-4,'EDIFFG':0.001,'NSW':0,} def_vasp_incar_param = {'ISIF':2,'NELM':99,'IBRION':2,'EDIFF':1e-6, 'EDIFFG':0.001,'NSW':40,} kpoint_den = 6000 # End defaults ptcr_flag = True try: potcar = mpvis.get_potcar(struct) except: print ("VASP POTCAR folder not detected.\n" \ "Only INCAR, POSCAR, KPOINTS are generated.\n" \ "If you have VASP installed on this system, \n" \ "refer to pymatgen documentation for configuring the settings.") ptcr_flag = False vac = Vacancy(struct, {}, {}) scs = vac.make_supercells_with_defects(sc_scale) site_no = scs[0].num_sites if site_no > cellmax: max_sc_dim = max(sc_scale) i = sc_scale.index(max_sc_dim) sc_scale[i] -= 1 scs = vac.make_supercells_with_defects(sc_scale) for i in range(len(scs)): sc = scs[i] poscar = mpvis.get_poscar(sc) kpoints = Kpoints.automatic_density(sc,kpoint_den) incar = mpvis.get_incar(sc) if ptcr_flag: potcar = mpvis.get_potcar(sc) interdir = mpid if not i: fin_dir = os.path.join(interdir,'bulk') try: os.makedirs(fin_dir) except: pass incar.update(blk_vasp_incar_param) incar.write_file(os.path.join(fin_dir,'INCAR')) poscar.write_file(os.path.join(fin_dir,'POSCAR')) if ptcr_flag: potcar.write_file(os.path.join(fin_dir,'POTCAR')) kpoints.write_file(os.path.join(fin_dir,'KPOINTS')) else: blk_str_sites = set(scs[0].sites) vac_str_sites = set(sc.sites) vac_sites = blk_str_sites - vac_str_sites vac_site = list(vac_sites)[0] site_mult = int(vac.get_defectsite_multiplicity(i-1)/conv_prim_rat) vac_site_specie = vac_site.specie vac_symbol = vac_site.specie.symbol vac_dir ='vacancy_{}_mult-{}_sitespecie-{}'.format(str(i), site_mult, vac_symbol) fin_dir = os.path.join(interdir,vac_dir) try: os.makedirs(fin_dir) except: pass incar.update(def_vasp_incar_param) poscar.write_file(os.path.join(fin_dir,'POSCAR')) incar.write_file(os.path.join(fin_dir,'INCAR')) if ptcr_flag: potcar.write_file(os.path.join(fin_dir,'POTCAR')) kpoints.write_file(os.path.join(fin_dir,'KPOINTS')) # Antisite generation at all vacancy sites struct_species = scs[0].types_of_specie for specie in set(struct_species)-set([vac_site_specie]): subspecie_symbol = specie.symbol anti_struct = sc.copy() anti_struct.append(specie, vac_site.frac_coords) poscar = mpvis.get_poscar(anti_struct) incar = mpvis.get_incar(anti_struct) incar.update(def_vasp_incar_param) as_dir ='antisite_{}_mult-{}_sitespecie-{}_subspecie-{}'.format( str(i), site_mult, vac_symbol, subspecie_symbol) fin_dir = os.path.join(interdir,as_dir) try: os.makedirs(fin_dir) except: pass poscar.write_file(os.path.join(fin_dir,'POSCAR')) incar.write_file(os.path.join(fin_dir,'INCAR')) if ptcr_flag: potcar.write_file(os.path.join(fin_dir,'POTCAR')) kpoints.write_file(os.path.join(fin_dir,'KPOINTS'))
def substitute_def_struct_gen(args): mpid = args.mpid solute = args.solute mapi_key = args.mapi_key cellmax = args.cellmax if not mpid: print ("============\nERROR: Provide an mpid\n============") return if not solute: print ("============\nERROR: Provide solute atom\n============") return if not mapi_key: with MPRester() as mp: struct = mp.get_structure_by_material_id(mpid) else: with MPRester(mapi_key) as mp: struct = mp.get_structure_by_material_id(mpid) prim_struct_sites = len(struct.sites) struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure() conv_struct_sites = len(struct.sites) conv_prim_rat = int(conv_struct_sites/prim_struct_sites) mpvis = MPRelaxSet(struct, user_incar_settings={"LDAU": False}) # Begin defaults: All default settings. blk_vasp_incar_param = {'IBRION':-1,'EDIFF':1e-4,'EDIFFG':0.001,'NSW':0,} def_vasp_incar_param = {'ISIF':2,'NELM':99,'IBRION':2,'EDIFF':1e-6, 'EDIFFG':0.001,'NSW':40,} kpoint_den = 6000 # End defaults # Check if POTCAR file can be geneated ptcr_flag = True try: potcar = mpvis.potcar except: print ("VASP POTCAR folder not detected.\n" \ "Only INCAR, POSCAR, KPOINTS are generated.\n" \ "If you have VASP installed on this system, \n" \ "refer to pymatgen documentation for configuring the settings.") ptcr_flag = False vac = Vacancy(struct, {}, {}) sc_scale = get_sc_scale(struct,cellmax) scs = vac.make_supercells_with_defects(sc_scale) site_no = scs[0].num_sites if site_no > cellmax: max_sc_dim = max(sc_scale) i = sc_scale.index(max_sc_dim) sc_scale[i] -= 1 scs = vac.make_supercells_with_defects(sc_scale) interdir = mpid blk_str_sites = set(scs[0].sites) for i in range(1,len(scs)): sc = scs[i] vac_str_sites = set(sc.sites) vac_sites = blk_str_sites - vac_str_sites vac_site = list(vac_sites)[0] site_mult = int(vac.get_defectsite_multiplicity(i-1)/conv_prim_rat) vac_site_specie = vac_site.specie vac_specie = vac_site.specie.symbol # Solute substitution defect generation at all vacancy sites struct_species = scs[0].types_of_specie solute_struct = sc.copy() solute_struct.append(solute, vac_site.frac_coords) mpvis = MPRelaxSet(solute_struct, user_incar_settings={"LDAU": False}) incar = mpvis.incar incar.update(def_vasp_incar_param) poscar = mpvis.poscar kpoints = Kpoints.automatic_density(solute_struct,kpoint_den) if ptcr_flag: potcar = mpvis.potcar sub_def_dir ='solute_{}_mult-{}_sitespecie-{}_subspecie-{}'.format( str(i), site_mult, vac_specie, solute) fin_dir = os.path.join(interdir,sub_def_dir) try: os.makedirs(fin_dir) except: pass poscar.write_file(os.path.join(fin_dir,'POSCAR')) incar.write_file(os.path.join(fin_dir,'INCAR')) kpoints.write_file(os.path.join(fin_dir,'KPOINTS')) if ptcr_flag: potcar.write_file(os.path.join(fin_dir,'POTCAR'))
def vac_antisite_def_struct_gen(c_size=15,mpid='',struct=None): """ Vacancy, antisite generator Args: c_size: cell size struct: Structure object or mpid: materials project id Returns: def_str: defect structures in Poscar object format """ def_str=[] if struct ==None: with MPRester() as mp: struct = mp.get_structure_by_material_id(mpid) if mpid == '': print ("Provide structure") c_size=c_size dim1=int((float(c_size)/float( max(abs(struct.lattice.matrix[0])))))+1 dim2=int(float(c_size)/float( max(abs(struct.lattice.matrix[1]))))+1 dim3=int(float(c_size)/float( max(abs(struct.lattice.matrix[2]))))+1 cellmax=max(dim1,dim2,dim3) #print ("in vac_def cellmax=",cell prim_struct_sites = len(struct.sites) struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure() conv_struct_sites = len(struct.sites) conv_prim_rat = int(conv_struct_sites/prim_struct_sites) #sc_scale = get_sc_scale(struct,cellmax) sc_scale=[dim1,dim2,dim3] #sc_scale=[cellmax,cellmax,cellmax] print ("sc_scale",sc_scale) #mpvis = MITRelaxSet #MPGGAVaspInputSet() # Begin defaults: All default settings. #blk_vasp_incar_param = {'IBRION':-1,'EDIFF':1e-4,'EDIFFG':0.001,'NSW':0,} #def_vasp_incar_param = {'ISIF':2,'NELM':99,'IBRION':2,'EDIFF':1e-6, # 'EDIFFG':0.001,'NSW':40,} #kpoint_den = 6000 # End defaults #ptcr_flag = True #try: # potcar = mpvis.get_potcar(struct) #except: # print ("VASP POTCAR folder not detected.\n" \ # "Only INCAR, POSCAR, KPOINTS are generated.\n" \ # "If you have VASP installed on this system, \n" \ # "refer to pymatgen documentation for configuring the settings.") # ptcr_flag = False struct_valrad_eval = ValenceIonicRadiusEvaluator(struct) val = struct_valrad_eval.valences rad = struct_valrad_eval.radii struct_val = val struct_rad = rad vac = Vacancy(struct, {}, {}) scs = vac.make_supercells_with_defects(sc_scale) #site_no = scs[0].num_sites #if site_no > cellmax: # max_sc_dim = max(sc_scale) # i = sc_scale.index(max_sc_dim) # sc_scale[i] -= 1 # scs = vac.make_supercells_with_defects(sc_scale) #print ('struct',scs) for i in range(len(scs)): sc = scs[i] #print (type(sc)) poscar = Poscar(sc) #mpvis.get_poscar(sc) #kpoints = Kpoints.automatic_density(sc,kpoint_den) #incar = mpvis.get_incar(sc) #if ptcr_flag: # potcar = mpvis.get_potcar(sc) interdir = mpid if not i: fin_dir = os.path.join(interdir,'bulk') #try: # os.makedirs(fin_dir) #except: # pass #incar.update(blk_vasp_incar_param) #incar.write_file(os.path.join(fin_dir,'INCAR')) #poscar.write_file(os.path.join(fin_dir,'POSCAR')) poscar.comment=str('bulk')+str('@')+str('cellmax')+str(cellmax) def_str.append(poscar) poscar.write_file('POSCAR-'+str('bulk')+str(".vasp")) #if ptcr_flag: # potcar.write_file(os.path.join(fin_dir,'POTCAR')) #kpoints.write_file(os.path.join(fin_dir,'KPOINTS')) else: blk_str_sites = set(scs[0].sites) vac_str_sites = set(sc.sites) vac_sites = blk_str_sites - vac_str_sites vac_site = list(vac_sites)[0] site_mult = int(vac.get_defectsite_multiplicity(i-1)/conv_prim_rat) #try: # site_mult = int(vac.get_defectsite_multiplicity(i-1)/conv_prim_rat) #except: # site_mult=1 # pass vac_site_specie = vac_site.specie vac_symbol = vac_site.specie.symbol vac_dir ='vacancy_{}_mult-{}_sitespecie-{}'.format(str(i), site_mult, vac_symbol) fin_dir = os.path.join(interdir,vac_dir) #try: # os.makedirs(fin_dir) #except: # pass #incar.update(def_vasp_incar_param) try: poscar.comment=str(vac_dir)+str('@')+str('cellmax')+str(cellmax) except: pass pos=poscar #pos=poscar.structure def_str.append(pos) #poscar.write_file(os.path.join(fin_dir,'POSCAR')) poscar.write_file('POSCAR-'+str(vac_dir)+str(".vasp")) #incar.write_file(os.path.join(fin_dir,'INCAR')) #if ptcr_flag: # potcar.write_file(os.path.join(fin_dir,'POTCAR')) #kpoints.write_file(os.path.join(fin_dir,'KPOINTS')) # Antisite generation at all vacancy sites struct_species = scs[0].types_of_specie for specie in set(struct_species)-set([vac_site_specie]): subspecie_symbol = specie.symbol anti_struct = sc.copy() anti_struct.append(specie, vac_site.frac_coords) poscar = Poscar(anti_struct) #incar = mpvis.get_incar(anti_struct) #incar.update(def_vasp_incar_param) as_dir ='antisite_{}_mult-{}_sitespecie-{}_subspecie-{}'.format( str(i), site_mult, vac_symbol, subspecie_symbol) fin_dir = os.path.join(interdir,as_dir) #try: # os.makedirs(fin_dir) #except: # pass poscar.comment=str(as_dir)+str('@')+str('cellmax')+str(cellmax) pos=poscar #pos=poscar.structure def_str.append(pos) #poscar.write_file(os.path.join(fin_dir,'POSCAR')) poscar.write_file('POSCAR-'+str(as_dir)+str(".vasp")) #incar.write_file(os.path.join(fin_dir,'INCAR')) #if ptcr_flag: # potcar.write_file(os.path.join(fin_dir,'POTCAR')) #kpoints.write_file(os.path.join(fin_dir,'KPOINTS')) #try: # struct.make_supercell(sc_scale) # intl = Interstitial(struct, val, rad) # cell_arr=sc_scale # for el in struct.composition.elements: # scs = intl.make_supercells_with_defects(1,el) # #scs = intl.make_supercells_with_defects(cell_arr,el) # for i in range(1,len(scs)): # pos=Poscar(scs[i]) # pos.comment=str('intl_')+str('cellmax')+str(cellmax)+str('@')+str(intl.get_defectsite_coordination_number(i-1))+str('Element')+str(el) # def_str.append(pos) # pos.write_file('POSCAR-'+str('intl_')+str('cellmax')+str(cellmax)+str('@')+str(intl.get_defectsite_coordination_number(i-1))+str('Element')+str(el)) #except: # pass return def_str
def vac_antisite_def_struct_gen(mpid, mapi_key, cellmax): if not mpid: print("============\nERROR: Provide an mpid\n============") return if not mapi_key: with MPRester() as mp: struct = mp.get_structure_by_material_id(mpid) else: with MPRester(mapi_key) as mp: struct = mp.get_structure_by_material_id(mpid) prim_struct_sites = len(struct.sites) struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure() conv_struct_sites = len(struct.sites) conv_prim_rat = int(conv_struct_sites / prim_struct_sites) sc_scale = get_sc_scale(struct, cellmax) mpvis = MPGGAVaspInputSet() # Begin defaults: All default settings. blk_vasp_incar_param = { 'IBRION': -1, 'EDIFF': 1e-4, 'EDIFFG': 0.001, 'NSW': 0, } def_vasp_incar_param = { 'ISIF': 2, 'NELM': 99, 'IBRION': 2, 'EDIFF': 1e-6, 'EDIFFG': 0.001, 'NSW': 40, } kpoint_den = 6000 # End defaults ptcr_flag = True try: potcar = mpvis.get_potcar(struct) except: print ("VASP POTCAR folder not detected.\n" \ "Only INCAR, POSCAR, KPOINTS are generated.\n" \ "If you have VASP installed on this system, \n" \ "refer to pymatgen documentation for configuring the settings.") ptcr_flag = False vac = Vacancy(struct, {}, {}) scs = vac.make_supercells_with_defects(sc_scale) site_no = scs[0].num_sites if site_no > cellmax: max_sc_dim = max(sc_scale) i = sc_scale.index(max_sc_dim) sc_scale[i] -= 1 scs = vac.make_supercells_with_defects(sc_scale) for i in range(len(scs)): sc = scs[i] poscar = mpvis.get_poscar(sc) kpoints = Kpoints.automatic_density(sc, kpoint_den) incar = mpvis.get_incar(sc) if ptcr_flag: potcar = mpvis.get_potcar(sc) interdir = mpid if not i: fin_dir = os.path.join(interdir, 'bulk') try: os.makedirs(fin_dir) except: pass incar.update(blk_vasp_incar_param) incar.write_file(os.path.join(fin_dir, 'INCAR')) poscar.write_file(os.path.join(fin_dir, 'POSCAR')) if ptcr_flag: potcar.write_file(os.path.join(fin_dir, 'POTCAR')) kpoints.write_file(os.path.join(fin_dir, 'KPOINTS')) else: blk_str_sites = set(scs[0].sites) vac_str_sites = set(sc.sites) vac_sites = blk_str_sites - vac_str_sites vac_site = list(vac_sites)[0] site_mult = int( vac.get_defectsite_multiplicity(i - 1) / conv_prim_rat) vac_site_specie = vac_site.specie vac_symbol = vac_site.specie.symbol vac_dir = 'vacancy_{}_mult-{}_sitespecie-{}'.format( str(i), site_mult, vac_symbol) fin_dir = os.path.join(interdir, vac_dir) try: os.makedirs(fin_dir) except: pass incar.update(def_vasp_incar_param) poscar.write_file(os.path.join(fin_dir, 'POSCAR')) incar.write_file(os.path.join(fin_dir, 'INCAR')) if ptcr_flag: potcar.write_file(os.path.join(fin_dir, 'POTCAR')) kpoints.write_file(os.path.join(fin_dir, 'KPOINTS')) # Antisite generation at all vacancy sites struct_species = scs[0].types_of_specie for specie in set(struct_species) - set([vac_site_specie]): subspecie_symbol = specie.symbol anti_struct = sc.copy() anti_struct.append(specie, vac_site.frac_coords) poscar = mpvis.get_poscar(anti_struct) incar = mpvis.get_incar(anti_struct) incar.update(def_vasp_incar_param) as_dir = 'antisite_{}_mult-{}_sitespecie-{}_subspecie-{}'.format( str(i), site_mult, vac_symbol, subspecie_symbol) fin_dir = os.path.join(interdir, as_dir) try: os.makedirs(fin_dir) except: pass poscar.write_file(os.path.join(fin_dir, 'POSCAR')) incar.write_file(os.path.join(fin_dir, 'INCAR')) if ptcr_flag: potcar.write_file(os.path.join(fin_dir, 'POTCAR')) kpoints.write_file(os.path.join(fin_dir, 'KPOINTS'))
def substitute_def_struct_gen(args): mpid = args.mpid solute = args.solute mapi_key = args.mapi_key cellmax = args.cellmax if not mpid: print("============\nERROR: Provide an mpid\n============") return if not solute: print("============\nERROR: Provide solute atom\n============") return if not mapi_key: with MPRester() as mp: struct = mp.get_structure_by_material_id(mpid) else: with MPRester(mapi_key) as mp: struct = mp.get_structure_by_material_id(mpid) prim_struct_sites = len(struct.sites) struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure() conv_struct_sites = len(struct.sites) conv_prim_rat = int(conv_struct_sites / prim_struct_sites) mpvis = MPRelaxSet(struct, user_incar_settings={"LDAU": False}) # Begin defaults: All default settings. blk_vasp_incar_param = { 'IBRION': -1, 'EDIFF': 1e-4, 'EDIFFG': 0.001, 'NSW': 0, } def_vasp_incar_param = { 'ISIF': 2, 'NELM': 99, 'IBRION': 2, 'EDIFF': 1e-6, 'EDIFFG': 0.001, 'NSW': 40, } kpoint_den = 6000 # End defaults # Check if POTCAR file can be geneated ptcr_flag = True try: potcar = mpvis.potcar except: print ("VASP POTCAR folder not detected.\n" \ "Only INCAR, POSCAR, KPOINTS are generated.\n" \ "If you have VASP installed on this system, \n" \ "refer to pymatgen documentation for configuring the settings.") ptcr_flag = False vac = Vacancy(struct, {}, {}) sc_scale = get_sc_scale(struct, cellmax) scs = vac.make_supercells_with_defects(sc_scale) site_no = scs[0].num_sites if site_no > cellmax: max_sc_dim = max(sc_scale) i = sc_scale.index(max_sc_dim) sc_scale[i] -= 1 scs = vac.make_supercells_with_defects(sc_scale) interdir = mpid blk_str_sites = set(scs[0].sites) for i in range(1, len(scs)): sc = scs[i] vac_str_sites = set(sc.sites) vac_sites = blk_str_sites - vac_str_sites vac_site = list(vac_sites)[0] site_mult = int(vac.get_defectsite_multiplicity(i - 1) / conv_prim_rat) vac_site_specie = vac_site.specie vac_specie = vac_site.specie.symbol # Solute substitution defect generation at all vacancy sites struct_species = scs[0].types_of_specie solute_struct = sc.copy() solute_struct.append(solute, vac_site.frac_coords) mpvis = MPRelaxSet(solute_struct, user_incar_settings={"LDAU": False}) incar = mpvis.incar incar.update(def_vasp_incar_param) poscar = mpvis.poscar kpoints = Kpoints.automatic_density(solute_struct, kpoint_den) if ptcr_flag: potcar = mpvis.potcar sub_def_dir = 'solute_{}_mult-{}_sitespecie-{}_subspecie-{}'.format( str(i), site_mult, vac_specie, solute) fin_dir = os.path.join(interdir, sub_def_dir) try: os.makedirs(fin_dir) except: pass poscar.write_file(os.path.join(fin_dir, 'POSCAR')) incar.write_file(os.path.join(fin_dir, 'INCAR')) kpoints.write_file(os.path.join(fin_dir, 'KPOINTS')) if ptcr_flag: potcar.write_file(os.path.join(fin_dir, 'POTCAR'))