def test_init(self): filepath = os.path.join(test_dir, 'OSZICAR') oszicar = Oszicar(filepath) self.assertEqual(len(oszicar.electronic_steps), len(oszicar.ionic_steps)) self.assertEqual(len(oszicar.all_energies), 60) self.assertAlmostEqual(oszicar.final_energy, -526.63928)
def assimilate(self, path): files = os.listdir(path) try: files_to_parse = {} if "relax1" in files and "relax2" in files: for filename in ("INCAR", "POTCAR", "POSCAR"): search_str = os.path.join(path, "relax1", filename + "*") files_to_parse[filename] = glob.glob(search_str)[0] for filename in ("CONTCAR", "OSZICAR"): search_str = os.path.join(path, "relax2", filename + "*") files_to_parse[filename] = glob.glob(search_str)[-1] else: files_to_parse["INCAR"] = glob.glob( os.path.join(path, "INCAR*"))[0] files_to_parse["POTCAR"] = glob.glob( os.path.join(path, "POTCAR*"))[-1] for filename in ("CONTCAR", "OSZICAR", "POSCAR"): files = glob.glob(os.path.join(path, filename + "*")) if len(files) == 1: files_to_parse[filename] = files[0] elif len(files) > 1: """ This is a bit confusing, since there maybe be multiple steps. By default, assimilate will try to find a file simply named filename, filename.bz2, or filename.gz. Failing which it will try to get a relax2 from an aflow style run if possible. Or else, a randomly chosen file is chosen. """ for fname in files: if fnmatch.fnmatch( os.path.basename(fname), "{}(\.gz|\.bz2)*".format(filename)): files_to_parse[filename] = fname break if fname == "POSCAR" and \ re.search("relax1", fname): files_to_parse[filename] = fname break if (fname in ("CONTCAR", "OSZICAR") and re.search("relax2", fname)): files_to_parse[filename] = fname break files_to_parse[filename] = fname poscar = Poscar.from_file(files_to_parse["POSCAR"]) contcar = Poscar.from_file(files_to_parse["CONTCAR"]) param = {} incar = Incar.from_file(files_to_parse["INCAR"]) if "LDAUU" in incar: param["hubbards"] = dict( zip(poscar.site_symbols, incar["LDAUU"])) else: param["hubbards"] = {} param["is_hubbard"] = (incar.get("LDAU", False) and sum(param["hubbards"].values()) > 0) param["run_type"] = "GGA+U" if param["is_hubbard"] else "GGA" param["history"] = _get_transformation_history(path) potcar = Potcar.from_file(files_to_parse["POTCAR"]) param["potcar_symbols"] = potcar.symbols oszicar = Oszicar(files_to_parse["OSZICAR"]) energy = oszicar.final_energy structure = contcar.structure initial_vol = poscar.structure.volume final_vol = contcar.structure.volume delta_volume = (final_vol / initial_vol - 1) data = {"filename": path, "delta_volume": delta_volume} if self._inc_structure: entry = ComputedStructureEntry(structure, energy, parameters=param, data=data) else: entry = ComputedEntry(structure.composition, energy, parameters=param, data=data) return entry except Exception as ex: logger.debug("error in {}: {}".format(path, ex)) return None