Ejemplo n.º 1
0
    def plot_dos(self,
                 filename='dos.png',
                 smear=None,
                 styles='t',
                 xlim=[-3, 3]):
        """export dos"""
        efermi = self.values['calculation']['efermi']
        tdos = np.array(self.values['calculation']['tdos'][0])
        tdos[:, 0] -= efermi
        e = tdos[:, 0]
        rows = (e > xlim[0]) & (e < xlim[1])
        e = e[rows]
        plt_obj = {}
        for option in styles.split('+'):
            if option == 'spd':
                option = ['s', 'p', 'd']
            else:
                option = [option]
            for style in option:
                mydos, labels = self.get_dos(rows, style)
                for data, label in zip(mydos, labels):
                    plt_obj[label] = data

        fig, ax = plt.subplots()
        lines1 = []
        lines2 = []
        labels1 = []
        labels2 = []
        for label in plt_obj.keys():
            e = np.reshape(e, [len(e), 1])
            data = np.reshape(plt_obj[label], [len(e), 1])
            if smear is not None:
                data = np.hstack((e, data))
                data = smear_data(data, smear)
                data = data[:, 1]
            if label.find('down') > 0:
                lines2 += ax.plot(e, data)
                labels2.append(label)
            else:
                lines1 += ax.plot(e, data)
                labels1.append(label)
        leg1 = ax.legend(lines1, [label for label in labels1],
                         fancybox=True,
                         loc='upper right')
        leg1.get_frame().set_alpha(0.5)
        if len(lines2) > 0:
            from matplotlib.legend import Legend
            leg2 = Legend(ax,
                          lines2, [label for label in labels2],
                          fancybox=True,
                          loc='lower right')
            ax.add_artist(leg2)
            leg2.get_frame().set_alpha(0.5)

        plt.xlabel("Energy (eV)")
        plt.ylabel("DOS")
        plt.xlim(xlim)
        plt.savefig(filename)
Ejemplo n.º 2
0
    def plot_dos(self,
                 filename=None,
                 smear=None,
                 styles='t',
                 xlim=[-3, 3],
                 dpi=300):
        """
        plot the DOS

        Args:
            filename: string
            styles: string (`t` or `s` or `t+spd`)
            xlim: list, the range of energy values on the x-axis, e.g. [-5, 3]
            smear: float (the width of smearing, defult: None) 

        Returns:
            A figure with band structure
        """
        efermi = self.values['calculation']['efermi']
        tdos = np.array(self.values['calculation']['tdos'][0])
        tdos[:, 0] -= efermi
        e = tdos[:, 0]
        rows = (e > xlim[0]) & (e < xlim[1])
        e = e[rows]
        plt_obj = {}
        for option in styles.split('+'):
            if option == 'spd':
                option = ['s', 'p', 'd']
            else:
                option = [option]
            for style in option:
                mydos, labels = self.get_dos(rows, style)
                for data, label in zip(mydos, labels):
                    plt_obj[label] = data

        fig, ax = plt.subplots()
        lines1 = []
        lines2 = []
        labels1 = []
        labels2 = []
        for label in plt_obj.keys():
            e = np.reshape(e, [len(e), 1])
            data = np.reshape(plt_obj[label], [len(e), 1])
            if smear is not None:
                data = np.hstack((e, data))
                data = smear_data(data, smear)
                data = data[:, 1]
            if label.find('down') > 0:
                lines2 += ax.plot(e, data)
                labels2.append(label)
            else:
                lines1 += ax.plot(e, data)
                labels1.append(label)
        leg1 = ax.legend(lines1, [label for label in labels1],
                         fancybox=True,
                         loc='upper right')
        leg1.get_frame().set_alpha(0.5)
        if len(lines2) > 0:
            from matplotlib.legend import Legend
            leg2 = Legend(ax,
                          lines2, [label for label in labels2],
                          fancybox=True,
                          loc='lower right')
            ax.add_artist(leg2)
            leg2.get_frame().set_alpha(0.5)

        plt.xlabel("Energy (eV)")
        plt.ylabel("DOS")
        plt.xlim(xlim)
        if filename is None:
            plt.show()
        else:
            plt.savefig(filename, dpi=dpi)
            plt.close()
Ejemplo n.º 3
0
    def plot_dos(self,
                 filename='dos.png',
                 smear=None,
                 styles=['t'],
                 xlim=[-3, 3]):
        """export dos"""
        efermi = self.values['calculation']['efermi']
        tdos = np.array(self.values['calculation']['tdos'][0])
        tdos[:, 0] -= efermi
        e = tdos[:, 0]
        rows = (e > xlim[0]) & (e < xlim[1])
        e = e[rows]
        plt_obj = {}
        for option in styles:
            # Seperate partial dos notation
            if ':' not in option:
                option = list(option)
            # Seperate partial dos notation with given atoms or elements
            else:
                ele, par = option.split(':')
                # atom, begin with number
                if ele[0].isdigit():
                    option = [ele + ':' + p for p in list(par)]
                # element
                else:
                    option = [
                        e + ':' + p for e in ele.split(',') for p in list(par)
                    ]

            for style in option:
                mydos, labels = self.get_dos(rows, style)
                for data, label in zip(mydos, labels):
                    plt_obj[label] = data

        fig, ax = plt.subplots()
        lines1 = []
        lines2 = []
        labels1 = []
        labels2 = []
        for label in plt_obj.keys():
            e = np.reshape(e, [len(e), 1])
            data = np.reshape(plt_obj[label], [len(e), 1])
            if smear is not None:
                data = np.hstack((e, data))
                data = smear_data(data, smear)
                data = data[:, 1]
            if label.find('down') > 0:
                lines2 += ax.plot(e, data)
                labels2.append(label)
            else:
                lines1 += ax.plot(e, data)
                labels1.append(label)
        leg1 = ax.legend(lines1, [label for label in labels1],
                         fancybox=True,
                         loc='upper right')
        leg1.get_frame().set_alpha(0.5)
        if len(lines2) > 0:
            from matplotlib.legend import Legend
            leg2 = Legend(ax,
                          lines2, [label for label in labels2],
                          fancybox=True,
                          loc='lower right')
            ax.add_artist(leg2)
            leg2.get_frame().set_alpha(0.5)

        plt.xlabel("Energy (eV)")
        plt.ylabel("DOS")
        plt.xlim(xlim)
        plt.savefig(filename)