def process_vasprun(self, dir_name, taskname, filename): """ Process a vasprun.xml file. """ vasprun_file = os.path.join(dir_name, filename) if self.parse_projected_eigen and (self.parse_projected_eigen != 'final' or \ taskname == self.runs[-1]): parse_projected_eigen = True else: parse_projected_eigen = False r = Vasprun(vasprun_file, parse_projected_eigen=parse_projected_eigen) d = r.as_dict() d["dir_name"] = os.path.abspath(dir_name) d["completed_at"] = \ str(datetime.datetime.fromtimestamp(os.path.getmtime( vasprun_file))) d["cif"] = str(CifWriter(r.final_structure)) d["density"] = r.final_structure.density if self.parse_dos and (self.parse_dos != 'final' \ or taskname == self.runs[-1]): try: d["dos"] = r.complete_dos.as_dict() except Exception: logger.warning( "No valid dos data exist in {}.\n Skipping dos".format( dir_name)) if taskname == "relax1" or taskname == "relax2": d["task"] = {"type": "aflow", "name": taskname} else: d["task"] = {"type": taskname, "name": taskname} d["oxide_type"] = oxide_type(r.final_structure) return d
def process_vasprun(self, dir_name, taskname, filename): """ Process a vasprun.xml file. """ vasprun_file = os.path.join(dir_name, filename) r = Vasprun(vasprun_file) d = r.as_dict() d["dir_name"] = os.path.abspath(dir_name) d["completed_at"] = \ str(datetime.datetime.fromtimestamp(os.path.getmtime( vasprun_file))) d["cif"] = str(CifWriter(r.final_structure)) d["density"] = r.final_structure.density if self.parse_dos and (self.parse_dos != 'final' \ or taskname == self.runs[-1]): try: d["dos"] = r.complete_dos.as_dict() except Exception: logger.warn("No valid dos data exist in {}.\n Skipping dos" .format(dir_name)) if taskname == "relax1" or taskname == "relax2": d["task"] = {"type": "aflow", "name": taskname} else: d["task"] = {"type": taskname, "name": taskname} return d
def process_vasprun(self, dir_name, taskname, filename): """ Adapted from matgendb.creator Process a vasprun.xml file. """ vasprun_file = os.path.join(dir_name, filename) if self.bandstructure_mode: vrun = Vasprun(vasprun_file, parse_eigen=True, parse_projected_eigen=True) else: vrun = Vasprun(vasprun_file) d = vrun.as_dict() for k, v in {"formula_pretty": "pretty_formula", "composition_reduced": "reduced_cell_formula", "composition_unit_cell": "unit_cell_formula"}.items(): d[k] = d.pop(v) for k in ["eigenvalues", "projected_eigenvalues"]: # large storage space breaks some docs if k in d["output"]: del d["output"][k] comp = Composition(d["composition_unit_cell"]) d["formula_anonymous"] = comp.anonymized_formula d["formula_reduced_abc"] = comp.reduced_composition.alphabetical_formula d["dir_name"] = os.path.abspath(dir_name) d["completed_at"] = str(datetime.datetime.fromtimestamp(os.path.getmtime(vasprun_file))) d["density"] = vrun.final_structure.density # replace 'crystal' with 'structure' d["input"]["structure"] = d["input"].pop("crystal") d["output"]["structure"] = d["output"].pop("crystal") for k, v in {"energy": "final_energy", "energy_per_atom": "final_energy_per_atom"}.items(): d["output"][k] = d["output"].pop(v) if self.parse_dos and self.parse_dos != 'final': try: d["dos"] = vrun.complete_dos.as_dict() except: raise ValueError("No valid dos data exist in {}.".format(dir_name)) if self.bandstructure_mode: bs = vrun.get_band_structure(line_mode=(self.bandstructure_mode == "line")) else: bs = vrun.get_band_structure() d["bandstructure"] = bs.as_dict() d["output"]["vbm"] = bs.get_vbm()["energy"] d["output"]["cbm"] = bs.get_cbm()["energy"] bs_gap = bs.get_band_gap() d["output"]["bandgap"] = bs_gap["energy"] d["output"]["is_gap_direct"] = bs_gap["direct"] d["output"]["is_metal"] = bs.is_metal() d["task"] = {"type": taskname, "name": taskname} # phonon-dfpt if hasattr(vrun, "force_constants"): d["output"]["force_constants"] = vrun.force_constants.tolist() d["output"]["normalmode_eigenvals"] = vrun.normalmode_eigenvals.tolist() d["output"]["normalmode_eigenvecs"] = vrun.normalmode_eigenvecs.tolist() return d
def process_vasprun(self, dir_name, taskname, filename): """ Adapted from matgendb.creator Process a vasprun.xml file. """ vasprun_file = os.path.join(dir_name, filename) vrun = Vasprun(vasprun_file) d = vrun.as_dict() # rename formula keys for k, v in {"formula_pretty": "pretty_formula", "composition_reduced": "reduced_cell_formula", "composition_unit_cell": "unit_cell_formula"}.items(): d[k] = d.pop(v) for k in ["eigenvalues", "projected_eigenvalues"]: # large storage space breaks some docs if k in d["output"]: del d["output"][k] comp = Composition(d["composition_unit_cell"]) d["formula_anonymous"] = comp.anonymized_formula d["formula_reduced_abc"] = comp.reduced_composition.alphabetical_formula d["dir_name"] = os.path.abspath(dir_name) d["completed_at"] = str(datetime.datetime.fromtimestamp(os.path.getmtime(vasprun_file))) d["density"] = vrun.final_structure.density # replace 'crystal' with 'structure' d["input"]["structure"] = d["input"].pop("crystal") d["output"]["structure"] = d["output"].pop("crystal") for k, v in {"energy": "final_energy", "energy_per_atom": "final_energy_per_atom"}.items(): d["output"][k] = d["output"].pop(v) if self.parse_dos == True or (str(self.parse_dos).lower() == "auto" and vrun.incar.get("NSW", 1) == 0): try: d["dos"] = vrun.complete_dos.as_dict() except: raise ValueError("No valid dos data exist in {}.".format(dir_name)) # Band structure parsing logic if str(self.bandstructure_mode).lower() == "auto": # if line mode nscf if vrun.incar.get("ICHARG", 0) > 10 and vrun.kpoints.num_kpts > 0: bs_vrun = BSVasprun(vasprun_file, parse_projected_eigen=True) bs = bs_vrun.get_band_structure(line_mode=True) # else if nscf elif vrun.incar.get("ICHARG", 0) > 10: bs_vrun = BSVasprun(vasprun_file, parse_projected_eigen=True) bs = bs_vrun.get_band_structure() # else just regular calculation else: bs = vrun.get_band_structure() # only save the bandstructure if not moving ions if vrun.incar["NSW"] == 0: d["bandstructure"] = bs.as_dict() # legacy line/True behavior for bandstructure_mode elif self.bandstructure_mode: bs_vrun = BSVasprun(vasprun_file, parse_projected_eigen=True) bs = bs_vrun.get_band_structure(line_mode=(str(self.bandstructure_mode).lower() == "line")) d["bandstructure"] = bs.as_dict() # parse bandstructure for vbm/cbm/bandgap but don't save else: bs = vrun.get_band_structure() # Parse electronic information if possible. # For certain optimizers this is broken and we don't get an efermi resulting in the bandstructure try: bs_gap = bs.get_band_gap() d["output"]["vbm"] = bs.get_vbm()["energy"] d["output"]["cbm"] = bs.get_cbm()["energy"] d["output"]["bandgap"] = bs_gap["energy"] d["output"]["is_gap_direct"] = bs_gap["direct"] d["output"]["is_metal"] = bs.is_metal() if not bs_gap["direct"]: d["output"]["direct_gap"] = bs.get_direct_band_gap() if isinstance(bs, BandStructureSymmLine): d["output"]["transition"] = bs_gap["transition"] except Exception: if self.bandstructure_mode is True: import traceback logger.error(traceback.format_exc()) logger.error("Error in " + os.path.abspath(dir_name) + ".\n" + traceback.format_exc()) raise logger.warning("Error in parsing bandstructure") if vrun.incar["IBRION"] == 1: logger.warning("Vasp doesn't properly output efermi for IBRION == 1") d["task"] = {"type": taskname, "name": taskname} d["output_file_paths"] = self.process_raw_data(dir_name, taskname=taskname) if "locpot" in d["output_file_paths"] and self.parse_locpot: locpot = Locpot.from_file(os.path.join(dir_name, d["output_file_paths"]["locpot"])) d["output"]["locpot"] = {i: locpot.get_average_along_axis(i) for i in range(3)} if hasattr(vrun, "force_constants"): # phonon-dfpt d["output"]["force_constants"] = vrun.force_constants.tolist() d["output"]["normalmode_eigenvals"] = vrun.normalmode_eigenvals.tolist() d["output"]["normalmode_eigenvecs"] = vrun.normalmode_eigenvecs.tolist() return d
def process_vasprun(self, dir_name, taskname, filename): """ Adapted from matgendb.creator Process a vasprun.xml file. """ vasprun_file = os.path.join(dir_name, filename) vrun = Vasprun(vasprun_file, parse_potcar_file=self.parse_potcar_file) d = vrun.as_dict() # rename formula keys for k, v in { "formula_pretty": "pretty_formula", "composition_reduced": "reduced_cell_formula", "composition_unit_cell": "unit_cell_formula" }.items(): d[k] = d.pop(v) for k in ["eigenvalues", "projected_eigenvalues" ]: # large storage space breaks some docs if k in d["output"]: del d["output"][k] comp = Composition(d["composition_unit_cell"]) d["formula_anonymous"] = comp.anonymized_formula d["formula_reduced_abc"] = comp.reduced_composition.alphabetical_formula d["dir_name"] = os.path.abspath(dir_name) d["completed_at"] = str( datetime.datetime.fromtimestamp(os.path.getmtime(vasprun_file))) d["density"] = vrun.final_structure.density # replace 'crystal' with 'structure' d["input"]["structure"] = d["input"].pop("crystal") d["output"]["structure"] = d["output"].pop("crystal") for k, v in { "energy": "final_energy", "energy_per_atom": "final_energy_per_atom" }.items(): d["output"][k] = d["output"].pop(v) # Process bandstructure and DOS if self.bandstructure_mode != False: bs = self.process_bandstructure(vrun) if bs: d["bandstructure"] = bs if self.parse_dos != False: dos = self.process_dos(vrun) if dos: d["dos"] = dos # Parse electronic information if possible. # For certain optimizers this is broken and we don't get an efermi resulting in the bandstructure try: bs = vrun.get_band_structure() bs_gap = bs.get_band_gap() d["output"]["vbm"] = bs.get_vbm()["energy"] d["output"]["cbm"] = bs.get_cbm()["energy"] d["output"]["bandgap"] = bs_gap["energy"] d["output"]["is_gap_direct"] = bs_gap["direct"] d["output"]["is_metal"] = bs.is_metal() if not bs_gap["direct"]: d["output"]["direct_gap"] = bs.get_direct_band_gap() if isinstance(bs, BandStructureSymmLine): d["output"]["transition"] = bs_gap["transition"] except Exception: logger.warning("Error in parsing bandstructure") if vrun.incar["IBRION"] == 1: logger.warning( "Vasp doesn't properly output efermi for IBRION == 1") if self.bandstructure_mode is True: logger.error(traceback.format_exc()) logger.error("Error in " + os.path.abspath(dir_name) + ".\n" + traceback.format_exc()) raise # Should roughly agree with information from .get_band_structure() above, subject to tolerances # If there is disagreement, it may be related to VASP incorrectly assigning the Fermi level try: band_props = vrun.eigenvalue_band_properties d["output"]["eigenvalue_band_properties"] = { "bandgap": band_props[0], "cbm": band_props[1], "vbm": band_props[2], "is_gap_direct": band_props[3] } except Exception: logger.warning("Error in parsing eigenvalue band properties") # store run name and location ,e.g. relax1, relax2, etc. d["task"] = {"type": taskname, "name": taskname} # include output file names d["output_file_paths"] = self.process_raw_data(dir_name, taskname=taskname) # parse axially averaged locpot if "locpot" in d["output_file_paths"] and self.parse_locpot: locpot = Locpot.from_file( os.path.join(dir_name, d["output_file_paths"]["locpot"])) d["output"]["locpot"] = { i: locpot.get_average_along_axis(i) for i in range(3) } if self.store_volumetric_data: for file in self.store_volumetric_data: if file in d["output_file_paths"]: try: # assume volumetric data is all in CHGCAR format data = Chgcar.from_file( os.path.join(dir_name, d["output_file_paths"][file])) d[file] = data.as_dict() except: raise ValueError("Failed to parse {} at {}.".format( file, d["output_file_paths"][file])) # parse force constants if hasattr(vrun, "force_constants"): d["output"]["force_constants"] = vrun.force_constants.tolist() d["output"][ "normalmode_eigenvals"] = vrun.normalmode_eigenvals.tolist() d["output"][ "normalmode_eigenvecs"] = vrun.normalmode_eigenvecs.tolist() # perform Bader analysis using Henkelman bader if self.parse_bader and "chgcar" in d["output_file_paths"]: suffix = '' if taskname == 'standard' else ".{}".format(taskname) bader = bader_analysis_from_path(dir_name, suffix=suffix) d["bader"] = bader return d
""" Import from my results """ file_path = '%03d_%s/2nd/' % (idx + 1.0, formula) try: oszicar = Oszicar(file_path + 'OSZICAR') tot_E = oszicar.ionic_steps[-1]['F'] tot_mag = oszicar.ionic_steps[-1]['mag'] df_bulk.total_E[idx+1] = tot_E df_bulk.tot_mag[idx+1] = tot_mag v = Vasprun(file_path + 'vasprun.xml') volume = v.as_dict()['output']['crystal']['lattice']['volume'] df_bulk.Volume[idx+1] = volume df_bulk.Err_V_percent[idx+1] = (volume_ref - volume) / volume_ref * 100 el = v.as_dict()['elements'] el.remove('O') fE = tot_E - ref_dict[el[0]] - ref_dict[el[1]] - 1.5*ref_dict['O2_corr'] if el[0] or el[1] in U_corr_dict: for x in range(len(el)): if el[x] in U_corr_dict: fE = fE - U_corr_dict[el[x]] fE = fE/5.0 # eV/atom
def process_vasprun(self, dir_name, taskname, filename): """ Adapted from matgendb.creator Process a vasprun.xml file. """ vasprun_file = os.path.join(dir_name, filename) vrun = Vasprun(vasprun_file) d = vrun.as_dict() # rename formula keys for k, v in {"formula_pretty": "pretty_formula", "composition_reduced": "reduced_cell_formula", "composition_unit_cell": "unit_cell_formula"}.items(): d[k] = d.pop(v) for k in ["eigenvalues", "projected_eigenvalues"]: # large storage space breaks some docs if k in d["output"]: del d["output"][k] comp = Composition(d["composition_unit_cell"]) d["formula_anonymous"] = comp.anonymized_formula d["formula_reduced_abc"] = comp.reduced_composition.alphabetical_formula d["dir_name"] = os.path.abspath(dir_name) d["completed_at"] = str(datetime.datetime.fromtimestamp(os.path.getmtime(vasprun_file))) d["density"] = vrun.final_structure.density # replace 'crystal' with 'structure' d["input"]["structure"] = d["input"].pop("crystal") d["output"]["structure"] = d["output"].pop("crystal") for k, v in {"energy": "final_energy", "energy_per_atom": "final_energy_per_atom"}.items(): d["output"][k] = d["output"].pop(v) # Process bandstructure and DOS if self.bandstructure_mode != False: bs = self.process_bandstructure(vrun) if bs: d["bandstructure"] = bs if self.parse_dos != False: dos = self.process_dos(vrun) if dos: d["dos"] = dos # Parse electronic information if possible. # For certain optimizers this is broken and we don't get an efermi resulting in the bandstructure try: bs = vrun.get_band_structure() bs_gap = bs.get_band_gap() d["output"]["vbm"] = bs.get_vbm()["energy"] d["output"]["cbm"] = bs.get_cbm()["energy"] d["output"]["bandgap"] = bs_gap["energy"] d["output"]["is_gap_direct"] = bs_gap["direct"] d["output"]["is_metal"] = bs.is_metal() if not bs_gap["direct"]: d["output"]["direct_gap"] = bs.get_direct_band_gap() if isinstance(bs, BandStructureSymmLine): d["output"]["transition"] = bs_gap["transition"] except Exception: logger.warning("Error in parsing bandstructure") if vrun.incar["IBRION"] == 1: logger.warning("Vasp doesn't properly output efermi for IBRION == 1") if self.bandstructure_mode is True: logger.error(traceback.format_exc()) logger.error("Error in " + os.path.abspath(dir_name) + ".\n" + traceback.format_exc()) raise # store run name and location ,e.g. relax1, relax2, etc. d["task"] = {"type": taskname, "name": taskname} # include output file names d["output_file_paths"] = self.process_raw_data(dir_name, taskname=taskname) # parse axially averaged locpot if "locpot" in d["output_file_paths"] and self.parse_locpot: locpot = Locpot.from_file(os.path.join(dir_name, d["output_file_paths"]["locpot"])) d["output"]["locpot"] = {i: locpot.get_average_along_axis(i) for i in range(3)} if self.parse_chgcar != False: # parse CHGCAR file only for static calculations # TODO require static run later # if self.parse_chgcar == True and vrun.incar.get("NSW", 0) < 1: try: chgcar = self.process_chgcar(os.path.join(dir_name, d["output_file_paths"]["chgcar"])) except: raise ValueError("No valid charge data exist") d["chgcar"] = chgcar if self.parse_aeccar != False: try: chgcar = self.process_chgcar(os.path.join(dir_name, d["output_file_paths"]["aeccar0"])) except: raise ValueError("No valid charge data exist") d["aeccar0"] = chgcar try: chgcar = self.process_chgcar(os.path.join(dir_name, d["output_file_paths"]["aeccar2"])) except: raise ValueError("No valid charge data exist") d["aeccar2"] = chgcar # parse force constants if hasattr(vrun, "force_constants"): d["output"]["force_constants"] = vrun.force_constants.tolist() d["output"]["normalmode_eigenvals"] = vrun.normalmode_eigenvals.tolist() d["output"]["normalmode_eigenvecs"] = vrun.normalmode_eigenvecs.tolist() # Try and perform bader if self.parse_bader: try: bader = bader_analysis_from_path(dir_name, suffix=".{}".format(taskname)) except Exception as e: bader = "Bader analysis failed: {}".format(e) d["bader"] = bader return d
def process_vasprun(self, dir_name, taskname, filename): """ Adapted from matgendb.creator Process a vasprun.xml file. """ vasprun_file = os.path.join(dir_name, filename) if self.bandstructure_mode: vrun = Vasprun(vasprun_file, parse_eigen=True, parse_projected_eigen=True) else: vrun = Vasprun(vasprun_file) d = vrun.as_dict() for k, v in { "formula_pretty": "pretty_formula", "composition_reduced": "reduced_cell_formula", "composition_unit_cell": "unit_cell_formula" }.items(): d[k] = d.pop(v) for k in ["eigenvalues", "projected_eigenvalues" ]: # large storage space breaks some docs if k in d["output"]: del d["output"][k] comp = Composition(d["composition_unit_cell"]) d["formula_anonymous"] = comp.anonymized_formula d["formula_reduced_abc"] = comp.reduced_composition.alphabetical_formula d["dir_name"] = os.path.abspath(dir_name) d["completed_at"] = str( datetime.datetime.fromtimestamp(os.path.getmtime(vasprun_file))) d["density"] = vrun.final_structure.density # replace 'crystal' with 'structure' d["input"]["structure"] = d["input"].pop("crystal") d["output"]["structure"] = d["output"].pop("crystal") for k, v in { "energy": "final_energy", "energy_per_atom": "final_energy_per_atom" }.items(): d["output"][k] = d["output"].pop(v) if self.parse_dos and self.parse_dos != 'final': try: d["dos"] = vrun.complete_dos.as_dict() except: raise ValueError( "No valid dos data exist in {}.".format(dir_name)) if self.bandstructure_mode: bs = vrun.get_band_structure( line_mode=(self.bandstructure_mode == "line")) else: bs = vrun.get_band_structure() d["bandstructure"] = bs.as_dict() d["output"]["vbm"] = bs.get_vbm()["energy"] d["output"]["cbm"] = bs.get_cbm()["energy"] bs_gap = bs.get_band_gap() d["output"]["bandgap"] = bs_gap["energy"] d["output"]["is_gap_direct"] = bs_gap["direct"] d["output"]["is_metal"] = bs.is_metal() d["task"] = {"type": taskname, "name": taskname} # phonon-dfpt if hasattr(vrun, "force_constants"): d["output"]["force_constants"] = vrun.force_constants.tolist() d["output"][ "normalmode_eigenvals"] = vrun.normalmode_eigenvals.tolist() d["output"][ "normalmode_eigenvecs"] = vrun.normalmode_eigenvecs.tolist() return d