Exemplo n.º 1
0
    def test_phbands_plotter(self):
        """Testing phbands plotter."""
        phbst_paths = 2 * [abidata.ref_file("trf2_5.out_PHBST.nc")]
        phdos_paths = 2 * [abidata.ref_file("trf2_5.out_PHDOS.nc")]

        plotter = PhononBandsPlotter()
        plotter.add_phbands("AlAs", phbst_paths[0], phdos=phdos_paths[0])
        plotter.add_phbands("Same-AlAs", phbst_paths[1], phdos=phdos_paths[1])
        repr(plotter)
        str(plotter)

        assert len(plotter.phbands_list) == 2
        assert len(plotter.phdoses_list) == 2
        assert plotter.has_same_formula()

        # __add__ merges two plotters:
        p2 = plotter.add_plotter(plotter)
        assert len(p2.phbands_list) == 2
        assert len(p2.phdoses_list) == 2

        df = dataframe_from_phbands(plotter.phbands_list)
        assert "nqpt" in df

        df = plotter.get_phbands_frame()
        assert df is not None

        if self.has_matplotlib():
            assert plotter.combiplot(units="eV", show=True)
            assert plotter.gridplot(units="meV", show=True)
            assert plotter.boxplot(units="cm-1", show=True)
            assert plotter.combiboxplot(units="Thz", show=True)
            assert plotter.animate(show=False)

        if self.has_nbformat():
            plotter.write_notebook(nbpath=self.get_tmpname(text=True))

        if self.has_ipywidgets():
            assert plotter.ipw_select_plot() is not None

        # Plotter without PHDOS
        plotter = PhononBandsPlotter(
            key_phbands=[("foo", phbst_paths[0]), ("bar", phbst_paths[1])])

        if self.has_matplotlib():
            assert plotter.combiplot(units="EV", show=True)
            assert plotter.gridplot(units="MEV", show=True)
            assert plotter.boxplot(units="cm^-1",
                                   mode_range=[0, 3],
                                   swarm=True,
                                   show=True)
            assert plotter.combiboxplot(units="THZ",
                                        mode_range=[0, 3],
                                        show=True)
Exemplo n.º 2
0
    def test_phbands_plotter(self):
        """Testing phbands plotter."""
        phbst_paths = 2 * [abidata.ref_file("trf2_5.out_PHBST.nc")]
        phdos_paths = 2 * [abidata.ref_file("trf2_5.out_PHDOS.nc")]

        plotter = PhononBandsPlotter()
        plotter.add_phbands("AlAs", phbst_paths[0], phdos=phdos_paths[0])
        plotter.add_phbands("Same-AlAs", phbst_paths[1], phdos=phdos_paths[1])
        repr(plotter); str(plotter)

        assert len(plotter.phbands_list) == 2
        assert len(plotter.phdoses_list) == 2
        assert plotter.has_same_formula()

        # __add__ merges two plotters:
        p2 = plotter.add_plotter(plotter)
        assert len(p2.phbands_list) == 2
        assert len(p2.phdoses_list) == 2

        df = dataframe_from_phbands(plotter.phbands_list)
        assert "nqpt" in df

        df = plotter.get_phbands_frame()
        assert df is not None

        if self.has_matplotlib():
            assert plotter.combiplot(units="eV", show=True)
            assert plotter.gridplot(units="meV", show=True)
            assert plotter.boxplot(units="cm-1", show=True)
            assert plotter.combiboxplot(units="Thz", show=True)
            assert plotter.animate(show=False)

        if self.has_nbformat():
            plotter.write_notebook(nbpath=self.get_tmpname(text=True))

        if self.has_ipywidgets():
            assert plotter.ipw_select_plot() is not None

        # Plotter without PHDOS
        plotter = PhononBandsPlotter(key_phbands=[("foo", phbst_paths[0]), ("bar", phbst_paths[1])])

        if self.has_matplotlib():
            assert plotter.combiplot(units="EV", show=True)
            assert plotter.gridplot(units="MEV", show=True)
            assert plotter.boxplot(units="cm^-1", mode_range=[0, 3], swarm=True, show=True)
            assert plotter.combiboxplot(units="THZ", mode_range=[0, 3], show=True)
Exemplo n.º 3
0
    def plot_phbs(self,
                  phbands,
                  temperatures=None,
                  t_max=1000,
                  colormap="plasma",
                  **kwargs):
        """
        Given a list of |PhononBands| plots the band structures with a color depending on
        the temperature using a |PhononBandsPlotter|.
        If temperatures are not given they will be deduced inverting the dependence of volume
        with respect to the temperature. If a unique volume could not be identified an error will
        be raised.

        Args:
            phbands: list of |PhononBands| objects.
            temperatures: list of temperatures.
            t_max: maximum temperature considered for plotting.
            colormap: matplotlib color map.

        Returns: |matplotlib-Figure|
        """

        if temperatures is None:
            tv = self.get_t_for_vols([b.structure.volume for b in phbands],
                                     t_max=t_max)
            temperatures = []
            for b, t in zip(phbands, tv):
                if len(t) != 1:
                    raise ValueError(
                        "Couldn't find a single temperature for structure with "
                        "volume {}. Found {}: {}".format(
                            b.structure.volume, len(t), list(t)))
                temperatures.append(t[0])

        temperatures_str = ["{:.0f} K".format(t) for t in temperatures]

        import matplotlib.pyplot as plt
        cmap = plt.get_cmap(colormap)
        colors = [cmap(t / max(temperatures)) for t in temperatures]
        labels_phbs = zip(temperatures_str, phbands)

        pbp = PhononBandsPlotter(labels_phbs)
        pbp._LINE_COLORS = colors
        pbp._LINE_STYLES = ['-']

        fig = pbp.combiplot(show=False, **kwargs)

        return fig
Exemplo n.º 4
0
Arquivo: qha.py Projeto: gmatteo/abipy
    def plot_phbs(self, phbands, temperatures=None, t_max=1000, colormap="plasma", **kwargs):
        """
        Given a list of |PhononBands| plots the band structures with a color depending on
        the temperature using a |PhononBandsPlotter|.
        If temperatures are not given they will be deduced inverting the dependence of volume
        with respect to the temperature. If a unique volume could not be identified an error will
        be raised.

        Args:
            phbands: list of |PhononBands| objects.
            temperatures: list of temperatures.
            t_max: maximum temperature considered for plotting.
            colormap: matplotlib color map.

        Returns: |matplotlib-Figure|
        """

        if temperatures is None:
            tv = self.get_t_for_vols([b.structure.volume for b in phbands], t_max=t_max)
            temperatures = []
            for b, t in zip(phbands, tv):
                if len(t) != 1:
                    raise ValueError("Couldn't find a single temperature for structure with "
                                     "volume {}. Found {}: {}".format(b.structure.volume, len(t), list(t)))
                temperatures.append(t[0])

        temperatures_str = ["{:.0f} K".format(t) for t in temperatures]

        import matplotlib.pyplot as plt
        cmap = plt.get_cmap(colormap)
        colors = [cmap(t / max(temperatures)) for t in temperatures]
        labels_phbs = zip(temperatures_str, phbands)

        pbp = PhononBandsPlotter(labels_phbs)
        pbp._LINE_COLORS = colors
        pbp._LINE_STYLES = ['-']

        fig = pbp.combiplot(show=False, **kwargs)

        return fig