Beispiel #1
0
    def plot_edoses(self, dos_pos=None, method="gaussian", step=0.01, width=0.1, **kwargs):
        """
        Plot the band structure and the DOS.

        Args:
            dos_pos: Index of the task from which the DOS should be obtained. 
                     None is all DOSes should be displayed. Accepts integer or list of integers.
            method: String defining the method for the computation of the DOS.
            step: Energy step (eV) of the linear mesh.
            width: Standard deviation (eV) of the gaussian.
            kwargs: Keyword arguments passed to `plot` method to customize the plot.

        Returns:
            `matplotlib` figure.
        """
        if dos_pos is not None and not isinstance(dos_pos, (list, tuple)): dos_pos = [dos_pos]

        from abipy.electrons.ebands import ElectronDosPlotter
        plotter = ElectronDosPlotter()
        for i, task in enumerate(self.dos_tasks):
            if dos_pos is not None and i not in dos_pos: continue
            with task.open_gsr() as gsr:
                edos = gsr.ebands.get_edos(method=method, step=step, width=width)
                ngkpt = task.get_inpvar("ngkpt")
                plotter.add_edos("ngkpt %s" % str(ngkpt), edos)

        return plotter.plot(**kwargs)
Beispiel #2
0
    def OnCompareEdos(self, event):
        """Plot multiple electron DOSes"""
        # Open dialog to get DOS parameters.
        dialog = ewx.ElectronDosDialog(self)
        if dialog.ShowModal() == wx.ID_CANCEL: return
        dos_params = dialog.GetParams()

        plotter = ElectronDosPlotter()
        for path, ebands in zip(self.ebands_filepaths, self.ebands_list):
            try:
                edos = ebands.get_edos(**dos_params)
                label = os.path.relpath(path)
                plotter.add_edos(label, edos)
            except:
                awx.showErrorMessage(self)

        plotter.plot()
Beispiel #3
0
    def OnCompareEdos(self, event):
        """Plot multiple electron DOSes"""
        # Open dialog to get DOS parameters.
        dialog = ewx.ElectronDosDialog(self)
        if dialog.ShowModal() == wx.ID_CANCEL: return 
        dos_params = dialog.GetParams()

        plotter = ElectronDosPlotter()
        for path, ebands in zip(self.ebands_filepaths, self.ebands_list):
            try:
                edos = ebands.get_edos(**dos_params)
                label = os.path.relpath(path)
                plotter.add_edos(label, edos)
            except:
                awx.showErrorMessage(self)

        plotter.plot()
Beispiel #4
0
    def test_api(self):
        """Testing ElelectronDosPlotter API."""
        gsr_path = abidata.ref_file("si_scf_GSR.nc")
        gs_bands = ElectronBands.from_file(gsr_path)
        si_edos = gs_bands.get_edos()

        plotter = ElectronDosPlotter()
        plotter.add_edos("edos1", si_edos)
        with self.assertRaises(ValueError):
            plotter.add_edos("edos1", si_edos)
        plotter.add_edos("edos2", gsr_path, edos_kwargs=dict(method="gaussian", step=0.2, width=0.4))
        assert len(plotter.edos_list) == 2
        assert not plotter._can_use_basenames_as_labels()

        if self.has_matplotlib():
            assert plotter.combiplot(show=False)
            assert plotter.gridplot(show=False)

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

        if self.has_nbformat():
            assert plotter.write_notebook(nbpath=self.get_tmpname(text=True))
Beispiel #5
0
    def test_api(self):
        """Testing ElelectronDosPlotter API."""
        gsr_path = abidata.ref_file("si_scf_GSR.nc")
        gs_bands = ElectronBands.from_file(gsr_path)
        si_edos = gs_bands.get_edos()

        plotter = ElectronDosPlotter()
        plotter.add_edos("edos1", si_edos)
        with self.assertRaises(ValueError):
            plotter.add_edos("edos1", si_edos)
        plotter.add_edos("edos2",
                         gsr_path,
                         edos_kwargs=dict(method="gaussian",
                                          step=0.2,
                                          width=0.4))
        assert len(plotter.edos_list) == 2
        assert not plotter._can_use_basenames_as_labels()

        if self.has_matplotlib():
            assert plotter.combiplot(show=False)
            assert plotter.gridplot(show=False)

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

        if self.has_nbformat():
            assert plotter.write_notebook(nbpath=self.get_tmpname(text=True))
Beispiel #6
0
    def test_api(self):
        """Test ElelectronDosPlotter API."""
        gsr_path = abidata.ref_file("si_scf_GSR.nc")
        gs_bands = ElectronBands.from_file(gsr_path)
        edos = gs_bands.get_edos()

        plotter = ElectronDosPlotter()
        plotter.add_edos("edos1", edos)
        plotter.add_edos("edos2",
                         gsr_path,
                         edos_kwargs=dict(method="gaussian",
                                          step=0.2,
                                          width=0.4))
        assert len(plotter.edos_list) == 2

        if self.has_matplotlib():
            plotter.combiplot(show=False)
            plotter.gridplot(show=False)

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