Beispiel #1
0
 def test_to_hdf(self):
     if sys.version_info[0] >= 3:
         filename = os.path.join(
             os.path.dirname(os.path.abspath(__file__)),
             "../../static/dft/test_es_hdf.h5",
         )
         abs_filename = os.path.abspath(filename)
         hdf_obj = FileHDFio(abs_filename)
         es_obj_old = self.es_list[1]
         es_obj_old.to_hdf(hdf_obj, group_name="written_es")
         es_obj_new = ElectronicStructure()
         es_obj_new.from_hdf(hdf=hdf_obj, group_name="written_es")
         self.assertTrue(
             np.array_equal(
                 hdf_obj["written_es/dos/grand_dos_matrix"],
                 es_obj_old.grand_dos_matrix,
             ))
         self.assertEqual(es_obj_old.efermi, es_obj_new.efermi)
         self.assertEqual(es_obj_old.is_metal, es_obj_new.is_metal)
         self.assertEqual(es_obj_old.vbm, es_obj_new.vbm)
         self.assertEqual(es_obj_old.cbm, es_obj_new.cbm)
         self.assertTrue(
             np.array_equal(es_obj_new.grand_dos_matrix,
                            es_obj_old.grand_dos_matrix))
         self.assertTrue(
             np.array_equal(es_obj_new.resolved_densities,
                            es_obj_old.resolved_densities))
    def from_file(self, filename):
        with open(filename, "r") as f:
            es_obj = ElectronicStructure()
            lines = f.readlines()
            details_trigger = "# of k-points:"
            details_ready = False
            kpoint_trigger = "k-point"
            band_trigger = "band"
            num_atoms = 0
            for i, line in enumerate(lines):
                line = line.strip()
                if details_trigger in line:
                    num_kpts, num_bands, num_atoms = self._get_details(line)
                    details_ready = True
                if details_ready:
                    if kpoint_trigger in line.split():
                        kpt, weight = self._get_kpoint_details(line)
                        es_obj.add_kpoint(value=kpt, weight=weight)

                    if band_trigger in line.split():
                        eigenvalue, occupancy = self._get_band_details(line)
                        es_obj.kpoints[-1].add_band(eigenvalue=eigenvalue,
                                                    occupancy=occupancy)
                        band_obj = es_obj.kpoints[-1].bands[-1]
                        band_obj.resolved_dos_matrix, band_obj.orbital_resolved_dos, band_obj.atom_resolved_dos = self._get_dos_matrix(
                            lines[i + 2:i + num_atoms + 4])
        return es_obj
Beispiel #3
0
    def get_electronic_structure(self):
        """
        Gets the electronic structure instance from the hdf5 file

        Returns:
                pyiron.atomistics.waves.electronic.ElectronicStructure instance
        """
        if self.status not in ["finished", "warning", "not_converged"]:
            return
        else:
            with self.project_hdf5.open("output") as ho:
                es_obj = ElectronicStructure()
                es_obj.from_hdf(ho)
            return es_obj
Beispiel #4
0
 def setUpClass(cls):
     cls.es_list = list()
     cls.es_obj = ElectronicStructure()
     file_list = ["vasprun_1.xml", "vasprun_2.xml"]
     for f in file_list:
         vp = Vasprun()
         direc = os.path.abspath(
             os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          "../../static/vasp_test_files/vasprun_samples"))
         filename = posixpath.join(direc, f)
         vp.from_file(filename)
         es = vp.get_electronic_structure()
         cls.es_list.append(es)
Beispiel #5
0
 def test_from_hdf(self):
     filename = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             "../../static/dft/es_hdf.h5")
     abs_filename = os.path.abspath(filename)
     hdf_obj = FileHDFio(abs_filename)
     es_obj_old = ElectronicStructure()
     es_obj_old.from_hdf_old(hdf_obj, "es_old")
     es_obj_new = ElectronicStructure()
     es_obj_new.from_hdf(hdf=hdf_obj, group_name="es_new")
     self.assertEqual(es_obj_old.efermi, es_obj_new.efermi)
     self.assertEqual(es_obj_old.is_metal, es_obj_new.is_metal)
     self.assertEqual(es_obj_old.vbm, es_obj_new.vbm)
     self.assertEqual(es_obj_old.cbm, es_obj_new.cbm)
     self.assertTrue(
         np.array_equal(es_obj_new.grand_dos_matrix,
                        es_obj_old.grand_dos_matrix))
Beispiel #6
0
    def get_electronic_structure(self):
        """
        Get's the electronic structure from the VASP calculation

        Returns:
            pyiron.atomistics.waves.electronic.ElectronicStructure: The electronic structure object

        """
        es_obj = ElectronicStructure()
        es_obj.kpoint_list = self.vasprun_dict["kpoints"]["kpoint_list"]
        es_obj.kpoint_weights = self.vasprun_dict["kpoints"]["kpoint_weights"]
        es_obj.eigenvalue_matrix = self.vasprun_dict[
            "grand_eigenvalue_matrix"][0, :, :]
        es_obj.occupancy_matrix = self.vasprun_dict["grand_occupancy_matrix"][
            0, :, :]
        if "grand_dos_matrix" in self.vasprun_dict.keys():
            es_obj.grand_dos_matrix = self.vasprun_dict["grand_dos_matrix"]
        if "efermi" in self.vasprun_dict.keys():
            es_obj.efermi = self.vasprun_dict["efermi"]
        if "spin_dos_energies" in self.vasprun_dict.keys():
            es_obj.dos_energies = self.vasprun_dict["spin_dos_energies"][0]
            es_obj.dos_densities = self.vasprun_dict["spin_dos_density"]
            es_obj.dos_idensities = self.vasprun_dict["spin_dos_idensity"]
        if "resolved_dos_matrix" in self.vasprun_dict.keys():
            es_obj.resolved_densities = self.vasprun_dict[
                "resolved_dos_matrix"]
            es_obj.orbital_dict = self.vasprun_dict["orbital_dict"]
        es_obj.generate_from_matrices()
        return es_obj