def getInterstitials(ase_in,inter,spinpol): pmg_init = AseAtomsAdaptor.get_structure(ase_in) pmg_init2 = SpacegroupAnalyzer(pmg_init).get_conventional_standard_structure() interstitial = Interstitial(pmg_init2,None,covalent_radii) #accuracy=high breaks... os.system('cls' if os.name == 'nt' else 'clear') output = [] for i,site in enumerate(interstitial.enumerate_defectsites()): coordination = int(round(interstitial.get_defectsite_coordination_number(i))) mult = 0 # interstitial.get_defectsite_multiplicity(i) -- broken ??? insert = InsertSitesTransformation([inter],[site.coords],coords_are_cartesian=True) try: pmg_new = insert.apply_transformation(pmg_init2.copy()) ase_new = AseAtomsAdaptor.get_atoms(pmg_new) if coordination == 4: siteName='T' elif coordination == 6: siteName='O' else: siteName = '%d-fold'%coordination strname = '_%s-%s'%(inter,siteName) if spinpol: new_magmoms = [3 if e in misc.magElems else 0 for e in ase_new.get_chemical_symbols()] ase_new.set_initial_magnetic_moments(new_magmoms) output.append((ase_new,strname)) except ValueError: pass #ValueError: New site is too close to an existing site! return output
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 prim_struct_sites = len(struct.sites) struct = SpacegroupAnalyzer(struct).get_conventional_standard_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) 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) tmp = struct.copy() tmp.make_supercell(sc_scale) sc_tmp = tmp # Poscar(tmp).structure .make_supercell(list(sc_scale)) scs = list(VacancyGenerator(struct)) supercell = Poscar(sc_tmp) supercell.comment = str("bulk") + str("@") + str("cellmax") + str(cellmax) def_str.append(supercell) if write_file == True: supercell.write_file("POSCAR-" + str("bulk") + str(".vasp")) for i in range(len(scs)): sc = scs[i].generate_defect_structure(sc_scale) poscar = Poscar(sc) # mpvis.get_poscar(sc) pmg_name = str(scs[i].name).split("_") sitespecie = pmg_name[1] mult = pmg_name[2].split("mult")[1] name = (str("vacancy_") + str(i + 1) + str("_mult-") + str(mult) + str("_sitespecie-") + str(sitespecie) + str("@cellmax") + str(cellmax)) poscar.comment = str(name) def_str.append(poscar) if write_file == True: filename = (str("POSCAR-") + str("vacancy_") + str(i + 1) + str("_mult-") + str(mult) + str("_sitespecie-") + str(sitespecie) + str(".vasp")) poscar.write_file(filename) return def_str
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 main(): jIDs = [x[0] for x in plotQuery(['jobid'], CONSTRAINTS)] question = "Going to add an %s interstitial to %d bulk objects.\n(y/n)--> " % ( inter, len(jIDs)) if raw_input(question).lower() in ['y', 'yes']: for j in jIDs: aseinitID = query1('aseid', 'jobid', j) aseinit = asedb.get_atoms(id=aseinitID) # Access information about previous Job / Atoms object jobinit = db2object(j) xc, pw, kptden = jobinit.xc, jobinit.pw, jobinit.kptden psp, xtol, strain = jobinit.psp, jobinit.xtol, jobinit.strain precalc, dftcode = jobinit.precalc, jobinit.dftcode nameinit = jobinit.name() structure = jobinit.structure() vacancies = jobinit.vacancies() # Create conventional PyMatGen Object pmg_init = AseAtomsAdaptor.get_structure(aseinit) pmg_init2 = SpacegroupAnalyzer( pmg_init).get_conventional_standard_structure() interstitial = Interstitial( pmg_init2, None, covalent_radii) #accuracy=high breaks... os.system('cls' if os.name == 'nt' else 'clear') for i, site in enumerate(interstitial.enumerate_defectsites()): coordination = int( round(interstitial.get_defectsite_coordination_number(i))) mult = 0 # interstitial.get_defectsite_multiplicity(i) -- broken ??? insert = InsertSitesTransformation([inter], [site.coords], coords_are_cartesian=True) pmg_new = insert.apply_transformation(pmg_init2.copy()) ase_new = AseAtomsAdaptor.get_atoms(pmg_new) ase_new.set_calculator(EMT()) emt = ase_new.get_potential_energy() if coordination == 4: siteName = 'T' elif coordination == 6: siteName = 'O' else: siteName = '%d-fold' % coordination question = ('site: %s\ncoordination: %s\nmultiplicity: %s' % (site.coords, coordination, mult) + '\ninitial ase id: %d \nxc: %s \npw: %d ' % (aseinitID, xc, pw) + '\nkptden: %f \npsp: %s\nxtol: %f\nstrain: %f' % (kptden, psp, xtol, strain) + '\nprecalc: %s \ndftcode: %s' % (precalc, dftcode) + '\n\nDoes this structure look good?\n(y/n)--> ') view(ase_new) if raw_input(question).lower() in ['y', 'yes']: if checkForDuplicates(ase_new, structure, emt): newquestion = 'What structure does this have?\n(leave blank for general triclinic case)\n--> ' structure = raw_input(newquestion) if structure is '': structure = 'triclinic' info = { 'name': nameinit + '_%s-%s' % (inter, siteName), 'emt': emt # EMT for relaxed structures useless, only relevant for deciding when to relax something , 'relaxed': False # Could always doing this be a problem? , 'comments': 'Generated from initializeHydride.py', 'parent': aseinitID, 'kind': 'bulk', 'structure': structure, 'interstitial': siteName } if vacancies is not None: info['vacancies'] = vacancies newaseid = asedb.write(ase_new, key_value_pairs=info) newjob = Job(None, 'bulkrelax', newaseid, None, None, xc, pw, kptden, psp, xtol, strain, 2 if xc == 'mBEEF' else 1, precalc, dftcode, None, None, 'initialized') insertObject(newjob)