Beispiel #1
0
 def test_api(self):
     """Testing PhononDos API with fake data."""
     dos = PhononDos(mesh=[1,2,3], values=[4,5,6])
     assert dos.mesh.tolist() == [1,2,3] and dos.h == 1 and dos.values.tolist() == [4,5,6]
     print(dos)
     dos.idos
     dos.plot(show=False)
     h = dos.get_harmonic_thermo(1, 10)
     assert h is not None
Beispiel #2
0
 def test_api(self):
     """Testing PhononDos API with fake data."""
     dos = PhononDos(mesh=[1, 2, 3], values=[4, 5, 6])
     assert dos.mesh.tolist() == [
         1, 2, 3
     ] and dos.h == 1 and dos.values.tolist() == [4, 5, 6]
     print(dos)
     dos.idos
     assert PhononDos.as_phdos(dos, {}) is dos
     assert dos.iw0 == 0
Beispiel #3
0
 def test_api(self):
     """Testing PhononDos API with fake data."""
     dos = PhononDos(mesh=[1, 2, 3], values=[4, 5, 6])
     assert dos.mesh.tolist() == [
         1, 2, 3
     ] and dos.h == 1 and dos.values.tolist() == [4, 5, 6]
     print(dos)
     dos.idos
     dos.plot(show=False)
     h = dos.get_harmonic_thermo(1, 10)
     assert h is not None
Beispiel #4
0
    def from_files(cls, gsr_files_paths, phdos_files_paths, ind_doses):
        """
        Creates an instance of QHA from a list og GSR files and a list PHDOS.nc files.
        The list should have the same size and the volumes should match.

        Args:
            gsr_files_paths: list of paths to GSR files.
            phdos_files_paths: list of paths to three PHDOS.nc files.
            ind_doses: list of three values indicating, for each of the three doses, the index of the
                corresponding gsr_file in "gsr_files_paths".

        Returns:
            A new instance of QHA
        """

        energies = []
        structures = []
        for gp in gsr_files_paths:
            with GsrFile.from_file(gp) as g:
                energies.append(g.energy)
                structures.append(g.structure)

        doses = [PhononDos.as_phdos(dp) for dp in phdos_files_paths]

        return cls(structures, doses, energies, ind_doses)
Beispiel #5
0
    def from_files(cls, gsr_files_paths, phdos_files_paths, ind_doses):
        """
        Creates an instance of QHA from a list og GSR files and a list PHDOS.nc files.
        The list should have the same size and the volumes should match.

        Args:
            gsr_files_paths: list of paths to GSR files.
            phdos_files_paths: list of paths to three PHDOS.nc files.
            ind_doses: list of three values indicating, for each of the three doses, the index of the
                corresponding gsr_file in "gsr_files_paths".

        Returns:
            A new instance of QHA
        """

        energies = []
        structures = []
        for gp in gsr_files_paths:
            with GsrFile.from_file(gp) as g:
                energies.append(g.energy)
                structures.append(g.structure)

        doses = [PhononDos.as_phdos(dp) for dp in phdos_files_paths]

        return cls(structures, doses, energies, ind_doses)
Beispiel #6
0
    def phdos(self):
        """
        The |PhononDos| corresponding to iv0, if present in the file, None otherwise.
        """
        if not self.doses:
            return None

        return PhononDos(self.doses['wmesh'], self.doses['gruns_wdos'][0])
Beispiel #7
0
    def test_api(self):
        """Testing PhononDos API with fake data."""
        phdos = PhononDos(mesh=[1, 2, 3], values=[4, 5, 6])
        assert phdos.mesh.tolist() == [1, 2, 3] and phdos.h == 1 and phdos.values.tolist() == [4, 5, 6]
        repr(phdos); str(phdos)
        phdos.idos
        with self.assertRaises(TypeError):
            PhononDos.as_phdos({}, {})

        assert PhononDos.as_phdos(phdos, {}) is phdos
        assert phdos.iw0 == 0

        # From pickle file.
        tmp_path = self.get_tmpname(suffix=".pickle")
        with open(tmp_path, "wb") as fh:
            pickle.dump(phdos, fh)
        same_phdos = PhononDos.as_phdos(tmp_path)
        same_phdos == phdos

        phdos.to_pymatgen()
Beispiel #8
0
    def test_api(self):
        """Testing PhononDos API with fake data."""
        phdos = PhononDos(mesh=[1, 2, 3], values=[4, 5, 6])
        assert phdos.mesh.tolist() == [1, 2, 3] and phdos.h == 1 and phdos.values.tolist() == [4, 5, 6]
        repr(phdos); str(phdos)
        phdos.idos
        with self.assertRaises(TypeError):
            PhononDos.as_phdos({}, {})

        assert PhononDos.as_phdos(phdos, {}) is phdos
        assert phdos.iw0 == 0

        # From pickle file.
        tmp_path = self.get_tmpname(suffix=".pickle")
        with open(tmp_path, "wb") as fh:
            pickle.dump(phdos, fh)
        same_phdos = PhononDos.as_phdos(tmp_path)
        same_phdos == phdos

        phdos.to_pymatgen()
Beispiel #9
0
    def from_files(cls, gsr_files_paths, phdos_files_paths):
        """
        Creates an instance of QHA from a list of GSR files and a list of PHDOS.nc files.
        The list should have the same size and the volumes should match.

        Args:
            gsr_files_paths: list of paths to GSR files.
            phdos_files_paths: list of paths to PHDOS.nc files.

        Returns:
            A new instance of QHA
        """
        energies = []
        structures = []
        for gp in gsr_files_paths:
            with GsrFile.from_file(gp) as g:
                energies.append(g.energy)
                structures.append(g.structure)

        doses = [PhononDos.as_phdos(dp) for dp in phdos_files_paths]

        return cls(structures, doses, energies)
Beispiel #10
0
    def from_files(cls, gsr_files_paths, phdos_files_paths):
        """
        Creates an instance of QHA from a list og GSR files and a list PHDOS.nc files.
        The list should have the same size and the volumes should match.

        Args:
            gsr_files_paths: list of paths to GSR files.
            phdos_files_paths: list of paths to PHDOS.nc files.

        Returns:
            A new instance of QHA
        """

        energies = []
        structures = []
        for gp in gsr_files_paths:
            with GsrFile.from_file(gp) as g:
                energies.append(g.energy)
                structures.append(g.structure)

        doses = [PhononDos.as_phdos(dp) for dp in phdos_files_paths]

        return cls(structures, doses, energies)
Beispiel #11
0
    def test_from_phdosfile(self):
        """Testing PHDOS from netcdf file."""
        ncfile = PhdosFile(abidata.ref_file("trf2_5.out_PHDOS.nc"))
        repr(ncfile); str(ncfile)
        assert ncfile.to_string(verbose=1)
        assert hasattr(ncfile, "structure")
        nw = len(ncfile.wmesh)
        assert nw == 461
        natom3 = len(ncfile.structure) * 3

        # Read PJDOSes
        assert list(ncfile.pjdos_symbol.keys()) == ["Al", "As"]
        od = ncfile.reader.read_pjdos_symbol_xyz_dict()
        assert list(od.keys()) == ["Al", "As"]
        assert all(v.shape == (3, nw) for v in od.values())

        arr = ncfile.reader.read_pjdos_atdir()
        assert arr.shape == (len(ncfile.structure), 3, nw)

        phdos = ncfile.phdos
        # Test integrals of DOS (the tolerance is a bit low likely due to too coarse meshes)
        self.assert_almost_equal(phdos.integral_value, natom3, decimal=1)

        # Summing projected DOSes over types should give the total DOS.
        pj_sum = sum(pjdos.integral_value for pjdos in ncfile.pjdos_symbol.values())
        self.assert_almost_equal(phdos.integral_value, pj_sum)

        # Summing projected DOSes over types and directions should give the total DOS.
        # phdos_rc_type[ntypat, 3, nomega]
        values = ncfile.reader.read_value("pjdos_rc_type").sum(axis=(0, 1))
        tot_dos = abilab.Function1D(phdos.mesh, values)
        self.assert_almost_equal(phdos.integral_value, tot_dos.integral_value)

        assert phdos == PhononDos.as_phdos(abidata.ref_file("trf2_5.out_PHDOS.nc"))

        # Test Thermodinamics in the Harmonic approximation
        self.assert_almost_equal(phdos.zero_point_energy.to("Ha"), 0.0030872835637731303)

        u = phdos.get_internal_energy()
        self.assert_almost_equal(u.values[0], 0.084009326574073395)
        self.assert_almost_equal(u.values[-1], 0.17270110252071791)

        s = phdos.get_entropy()
        self.assert_almost_equal(s.values[0], 1.6270193052583423e-08)
        self.assert_almost_equal(s.values[-1], 0.00058238779354717)

        cv = phdos.get_cv()
        self.assert_almost_equal(cv.values[0], 5.3715488328604253e-08)
        self.assert_almost_equal(cv.values[-1], 0.00045871909188672578)

        f = phdos.get_free_energy()
        self.assert_almost_equal(f.values, (u - s.mesh * s.values).values)

        self.assertAlmostEqual(phdos.debye_temp, 469.01524830328606)
        self.assertAlmostEqual(phdos.get_acoustic_debye_temp(len(ncfile.structure)), 372.2576492728813)

        assert ncfile.to_pymatgen()

        if self.has_matplotlib():
            assert ncfile.plot_pjdos_type(show=False)
            assert ncfile.plot_pjdos_type(units="cm-1", stacked=False, colormap="viridis", show=False)
            assert ncfile.plot_pjdos_cartdirs_type(units="Thz", stacked=True, show=False)
            assert ncfile.plot_pjdos_cartdirs_type(units="meV", stacked=False, alpha=0.5, show=False)
            assert ncfile.plot_pjdos_cartdirs_site(units="meV", stacked=False, alpha=0.5, show=False)
            assert ncfile.plot_pjdos_cartdirs_site(units="meV", view="all", stacked=True, alpha=0.5, show=False)

            assert phdos.plot(units="cm-1", show=False)
            assert phdos.plot_harmonic_thermo(tstar=20, tstop=350, units="eV", formula_units=1, show=False)
            assert phdos.plot_harmonic_thermo(tstar=20, tstop=350, units="Jmol", formula_units=2, show=False)

        # Test notebook
        if self.has_nbformat():
            ncfile.write_notebook(nbpath=self.get_tmpname(text=True))

        ncfile.close()
Beispiel #12
0
    def test_from_phdosfile(self):
        """Testing PHDOS from netcdf file."""
        ncfile = PhdosFile(abidata.ref_file("trf2_5.out_PHDOS.nc"))
        repr(ncfile)
        str(ncfile)
        assert ncfile.to_string(verbose=1)
        assert hasattr(ncfile, "structure")
        nw = len(ncfile.wmesh)
        assert nw == 461
        natom3 = len(ncfile.structure) * 3

        # Read PJDOSes
        assert list(ncfile.pjdos_symbol.keys()) == ["Al", "As"]
        od = ncfile.reader.read_pjdos_symbol_xyz_dict()
        assert list(od.keys()) == ["Al", "As"]
        assert all(v.shape == (3, nw) for v in od.values())

        arr = ncfile.reader.read_pjdos_atdir()
        assert arr.shape == (len(ncfile.structure), 3, nw)

        phdos = ncfile.phdos
        # Test integrals of DOS (the tolerance is a bit low likely due to too coarse meshes)
        self.assert_almost_equal(phdos.integral_value, natom3, decimal=1)

        # Summing projected DOSes over types should give the total DOS.
        pj_sum = sum(pjdos.integral_value
                     for pjdos in ncfile.pjdos_symbol.values())
        self.assert_almost_equal(phdos.integral_value, pj_sum)

        # Summing projected DOSes over types and directions should give the total DOS.
        # phdos_rc_type[ntypat, 3, nomega]
        values = ncfile.reader.read_value("pjdos_rc_type").sum(axis=(0, 1))
        tot_dos = abilab.Function1D(phdos.mesh, values)
        self.assert_almost_equal(phdos.integral_value, tot_dos.integral_value)

        assert phdos == PhononDos.as_phdos(
            abidata.ref_file("trf2_5.out_PHDOS.nc"))

        # Test Thermodinamics in the Harmonic approximation
        self.assert_almost_equal(phdos.zero_point_energy.to("Ha"),
                                 0.0030872835637731303)

        u = phdos.get_internal_energy()
        self.assert_almost_equal(u.values[0], 0.084009326574073395)
        self.assert_almost_equal(u.values[-1], 0.17270110252071791)

        s = phdos.get_entropy()
        self.assert_almost_equal(s.values[0], 1.6270193052583423e-08)
        self.assert_almost_equal(s.values[-1], 0.00058238779354717)

        cv = phdos.get_cv()
        self.assert_almost_equal(cv.values[0], 5.3715488328604253e-08)
        self.assert_almost_equal(cv.values[-1], 0.00045871909188672578)

        f = phdos.get_free_energy()
        self.assert_almost_equal(f.values, (u - s.mesh * s.values).values)

        self.assertAlmostEqual(phdos.debye_temp, 469.01524830328606)
        self.assertAlmostEqual(
            phdos.get_acoustic_debye_temp(len(ncfile.structure)),
            372.2576492728813)

        assert ncfile.to_pymatgen()

        if self.has_matplotlib():
            assert ncfile.plot_pjdos_type(show=False)
            assert ncfile.plot_pjdos_type(units="cm-1",
                                          stacked=False,
                                          colormap="viridis",
                                          show=False)
            assert ncfile.plot_pjdos_type(units="eV",
                                          stacked=True,
                                          colormap="jet",
                                          exchange_xy=True,
                                          fontsize=8,
                                          show=False)
            assert ncfile.plot_pjdos_cartdirs_type(units="Thz",
                                                   stacked=True,
                                                   show=False)
            assert ncfile.plot_pjdos_cartdirs_type(units="meV",
                                                   stacked=False,
                                                   alpha=0.5,
                                                   show=False)
            assert ncfile.plot_pjdos_cartdirs_site(units="meV",
                                                   stacked=False,
                                                   alpha=0.5,
                                                   show=False)
            assert ncfile.plot_pjdos_cartdirs_site(units="meV",
                                                   view="all",
                                                   stacked=True,
                                                   alpha=0.5,
                                                   show=False)

            assert phdos.plot(units="cm-1", show=False)
            assert phdos.plot_harmonic_thermo(tstar=20,
                                              tstop=350,
                                              units="eV",
                                              formula_units=1,
                                              show=False)
            assert phdos.plot_harmonic_thermo(tstar=20,
                                              tstop=350,
                                              units="Jmol",
                                              formula_units=2,
                                              show=False)

        # Test notebook
        if self.has_nbformat():
            ncfile.write_notebook(nbpath=self.get_tmpname(text=True))

        ncfile.close()