def write_run(run, run_folder, write_vasprun=False): os.makedirs(run_folder, exist_ok=True) incar = Incar.from_dict(run['incar']) poscar = Poscar.from_dict(run['poscar']) kpoints = Kpoints.from_dict(run['kpoints']) energy = run['energy'] files = [ ('INCAR', incar), ('KPOINTS', kpoints), ('POSCAR', poscar), ] for filename, pymg_object in files: pymg_object.write_file(os.path.join(run_folder, filename)) with open(os.path.join(run_folder, 'energy.txt'), 'w') as f: f.write(str(energy)) if write_vasprun: if not os.path.exists(os.path.join(run_folder, 'vasprun.xml')): print(' Writing Vasprun') get_file(fs, run['vasprun'], new_file=os.path.join(run_folder, 'vasprun.xml'))
def add_to_string(string, base, ovac, bounds, weight=2, max_val=2): labels = ('material', 'barrier', 'ovac', 'density', 'fermi', 'o_p_band') labels = ('material', 'barrier', 'density', 'fermi', 'o_p_band') material = base['material'][1] if 'descriptors' in base and all( [x in base['descriptors'] for x in labels[3:]]): # if all labels are made descriptors = base['descriptors'] else: s = Structure.from_dict(base['poscar']['structure']) v_file = get_file(fs, base['vasprun']) v = Vasprun(v_file) os.remove(v_file) # set descriptors descriptors = { 'density': s.volume / len(s), 'bandgap': v.tdos.get_gap(), 'fermi': v.efermi, 'o_p_band': get_band_center(v, 'p', 'O'), 'p_band': get_band_center(v, 'p', 'O') } base['descriptors'] = descriptors db.database.update_one({'_id': base['_id']}, {'$set': { 'descriptors': descriptors }}) properties = [descriptors[label] for label in labels[2:]] predicted = ( 0.73118E+00 + 0.96547E-04 * ovac**6 + 0.75320E-02 * np.exp(ovac) * ovac / descriptors['o_p_band'] # -0.28972E+01 + # 0.45890E+02 * np.exp(descriptors['o_p_band']) * descriptors['density'] * descriptors['density'] ) format_string = '{} ' + '{:.4f} ' * len(labels[1:]) + '\n' if string == '': label_string = '{} ' * len(labels) + '\n' string = label_string.format(*labels) difference = abs(bounds[0] - bounds[1]) if difference > max_val: return string, predicted else: weight = max(2, weight * (max_val - difference) / max_val) for bound in np.linspace(bounds[0], bounds[1], weight): string += format_string.format(material, bound, *properties) # string += format_string.format(material, bound, ovac, *properties) return string, predicted
def fxn(self, unit, base, start, final): f = get_file(fs, unit['ICOHPLIST_lobster']) icohp = Icohplist(filename=f).icohpcollection os.remove(f) elements = unit['elements'].copy() elements.pop(elements.index('O')) elements.append('O') # Put O at end for easier referencing material = get_lower_material(unit) unit_s = Poscar.from_dict(unit['poscar']).structure summed_icohp = {} for i, site in enumerate(unit_s): icohp_dict = icohp.get_icohp_dict_of_site(i) for icohp_key in icohp_dict: icohp_value = icohp_dict[icohp_key].summed_icohp # print('{}: {:3.2f}'.format(pt['site_index'], pt['weight'])) if site.species_string in summed_icohp: summed_icohp[site.species_string] = ( summed_icohp[site.species_string][0] + icohp_value, summed_icohp[site.species_string][1] + 1) else: summed_icohp[site.species_string] = (icohp_value, 1) if material.find(elements[0].lower()) == 0 and material.find( elements[1].lower()) == 0: raise Exception('Both Could be Element A') elif material.find(elements[0].lower()) == 0: bonds = { 'A_Bonds': summed_icohp[elements[0]][0] / summed_icohp[elements[0]][1], 'B_Bonds': summed_icohp[elements[1]][0] / summed_icohp[elements[1]][1] } elif material.find(elements[1].lower()) == 0: bonds = { 'A_Bonds': summed_icohp[elements[1]][0] / summed_icohp[elements[1]][1], 'B_Bonds': summed_icohp[elements[0]][0] / summed_icohp[elements[0]][1] } else: raise Exception('Couldn\'t find A') bonds['O_bonds'] = summed_icohp['O'][0] / summed_icohp['O'][1] return bonds
] metals = ['bimno3'] for material in materials: print(material) # vaspruns[material] = {} for type in ['base', 'start']: try: vaspruns[material][type] except: try: vaspruns[material] except: vaspruns[material] = {} if type == 'lb': v_file = get_file(fs, mat_dict[material][type]['vasprun']) v_file = get_file(fs, mat_dict[material][type]['vasprun']) vaspruns[material][type] = Vasprun(v_file) os.remove(v_file) #%% Plot import Make_Dos from scipy.interpolate import spline figsize=(3,5.5) ylim = [0,3] xlim = [-10,10] #vasprun shift name plots = [
def get_vasprun(run): v = get_file(fs, run['vasprun'], 'vasprun') vasprun = Vasprun(v) os.remove(v) return vasprun
final_exists = True final = f if not final_exists: continue print(material) pairs = [ ('start', start), ('final', final), ] material_folder = os.path.join(folder, material) for name, d in pairs: run_folder = os.path.join(material_folder, name) os.makedirs(run_folder, exist_ok=True) incar = Incar.from_dict(d['incar']) poscar = Poscar.from_dict(d['poscar']) kpoints = Kpoints.from_dict(d['kpoints']) for f in ['OUTCAR', 'vasprun']: outcar_file = get_file(fs, d[f.lower()]) if f == 'vasprun': f = 'vasprun.xml' shutil.move(outcar_file, os.path.join(run_folder, f)) files = [ ('INCAR', incar), ('KPOINTS', kpoints), ('POSCAR', poscar), ] for filename, pymg_object in files: pymg_object.write_file(os.path.join(run_folder, filename))
yerr = np.array(err)/2 x = x[np.where(xerr < maxrange)] y = y[np.where(xerr < maxrange)] yerr = yerr[np.where(xerr < maxrange)] ll = np.array(label_list)[np.where(xerr < maxrange)] xerr = xerr[np.where(xerr < maxrange)] color = [] for material in ll: print(material) f=get_file(fs, mat_dict[material]['base']['vasprun']) vasprun = Vasprun(f) color.append(vasprun.get_band_structure().get_band_gap()['energy']) os.remove(f) # color.append(mat_dict[material]['base']['descriptors']['bandgap']) # #%% # maxbarrier = 5.5 plt.plot([0, maxbarrier], [0, maxbarrier], '--', color='gray') plt.errorbar(x, y, xerr=xerr, yerr=yerr, fmt='none', color='k') scat = plt.scatter(x, y, c=color, cmap='gnuplot2', marker='o') # scat = plt.scatter(x, y, marker='o) plt.colorbar(scat, label='Band Gap (eV)') # plt.colorbar(scat, label='V$_O$ Energy (eV)') plt.xlabel('V$_O$ Diffusion Barrier (eV)')
('INCAR', incar), ('KPOINTS', kpoints), ('00/POSCAR', start), ('01/POSCAR', relax), ('02/POSCAR', final), ] fs_files = [ (mat['start']['outcar'], os.path.join(run_folder, '00', 'OUTCAR')), (mat['start']['vasprun'],os.path.join(run_folder, '00', 'vasprun.xml')), (mat['finals'][i-1]['outcar'],os.path.join(run_folder, '02', 'OUTCAR')), (mat['finals'][i-1]['vasprun'],os.path.join(run_folder, '02', 'vasprun.xml')), ] for oid, location in fs_files: if not os.path.exists(location): get_file(fs, oid, new_file=location) for filename, pymg_object in files: pymg_object.write_file(os.path.join(run_folder, filename)) # with open(os.path.join(run_folder, 'energy.txt'), 'w') as f: # f.write(str(ub['energies'][ub_i])) with open(os.path.join(run_folder, 'potcar.txt'), 'w') as f: f.write('\n'.join(potcar)) neb = nebmake('', start.structure, final.structure, 4, tolerance=tolerance, write=False, quickfail=True) del incar['SPRING'] incar['IMAGES'] = 3 incar['LCLIMB'] = True
#!/usr/bin/env python from AddDB import load_db from Database_Tools import get_file from Classes_Pymatgen import Poscar,Kpoints import sys import os (db, fs, client) = load_db() match_criteria = { 'defect' : 'mn-vac', 'defect_charge' : 2 } matches = list(db.database.find(match_criteria)) print(len(matches)) if len(sys.argv) > 1 and sys.argv[1] == 'write': for match in matches[0:1]: name = '{}.{}'.format(''.join([x for x in match['material'] if 'mnte' not in x]), match['antiferromagnetic_label'][0]) os.makedirs(name, exist_ok=True) get_file(fs, match['outcar'], fix_as='outcar', new_file=os.path.join(name, 'OUTCAR')) Poscar.from_dict(match['poscar']).write_file(os.path.join(name, 'POSCAR')) Kpoints.from_dict(match['kpoints']).write_file(os.path.join(name, 'KPOINTS')) print(name)
gmean([lb_bars[i], ub_bars[i]]) if ub_bars[i] else 9999 for i in range(len(thermo)) ] lowest_ts_estimate = min(ts_estimates) i = ts_estimates.index(lowest_ts_estimate) - 1 i = 1 if i == -1: continue base = mat['base'] start = mat['start'] final = mat['finals'][i] o_nelect = 6 outcar_file = get_file(fs, base['outcar']) outcar = Outcar(outcar_file) os.remove(outcar_file) pairs = [ ('base', base), ('start', start), ('final.{}'.format(i), final), ] material_folder = os.path.join(folder, material) for name, d in pairs: run_folder = os.path.join(material_folder, name) os.makedirs(run_folder, exist_ok=True) incar = Incar.from_dict(d['incar']) poscar = Poscar.from_dict(d['poscar'])