Пример #1
0
    def plot(self, xunit=1, pname='spectrum.png', lvprt=1, weight=1):
        pylab.figure(figsize=(8, 6))

        if xunit.lower() == 'ev':
            xlist = self.en
            pylab.xlabel('Energy (eV)')
            plot_sticks = self.sticks
            (xmin, xmax) = (self.emin, self.emax)
        elif xunit.lower() == 'nm':
            xfac = units.energy['nm'] * units.energy['eV']
            xlist = self.lam
            #pylab.xlabel(r'$\lambda$') not working ...
            pylab.xlabel('Wavelength (nm)')
            plot_sticks = [(A, xfac / x0) for A, x0 in self.sticks]
            (xmin, xmax) = (xfac / self.emin, xfac / self.emax)
        elif xunit.lower() == 'rcm':
            xfac = 1. / units.energy['eV'] * units.energy['rcm']
            xlist = [en * xfac for en in self.en]
            pylab.xlabel('Wavenumber (1/cm)')
            plot_sticks = [(A, x0 * xfac) for A, x0 in self.sticks]
            (xmin, xmax) = (self.emin * xfac, self.emax * xfac)
        else:
            raise error_handler.ElseError('xunit', xunit)
        pylab.ylabel('Oscillator strength')

        if weight == 1:
            pylab.plot(xlist, self.spec / max(self.spec), 'k-')
            for A, x0 in plot_sticks:
                pylab.plot([x0, x0], [-1., A], 'rx-')
        elif weight == 2:
            pylab.plot(xlist, self.dos / max(self.dos), 'k-')
        else:
            raise error_handler.ElseError('weight', weight)

        pylab.axis(xmin=xmin, xmax=xmax, ymin=0., ymax=1.)
        pylab.savefig(pname)

        if lvprt >= 1:
            print("Spectrum file %s created." % pname)
Пример #2
0
    def write_table(self):
        sfile = lib_file.summ_file(self['ana_file'])
        header = sfile.ret_header()
        ddict = sfile.ret_ddict()
        state_labels = sfile.ret_state_labels()

        if self['prop_list'] == []:
            self['prop_list'] = header[1:]

        if self['output_format'] == 'html':
            wfile = lib_file.htmlfile
            wtable = lib_file.htmltable
        elif self['output_format'] == 'latex':
            wfile = lib_file.latexfile
            wtable = lib_file.latextable
        else:
            raise error_handler.ElseError(self['output_format'],
                                          'output_format')

        wf = wfile(self['fname'])
        wf.pre(title='TheoDORE data')

        wt = wtable(ncol=len(self['prop_list']) + 1)
        wt.add_row(['State'] + self['prop_list'])

        for state in state_labels:
            if not self['lformula']:
                wt.add_el(state)
            else:
                wt.add_el('$%s$' % (state.replace('(', '^').replace(')', '')))

            for prop in self['prop_list']:
                try:
                    wt.add_el(self['fformat'] % ddict[state][prop])
                except KeyError:
                    wt.add_el('-')

        wf.write(wt.ret_table())
        wf.post(lvprt=1)
Пример #3
0
#--------------------------------------------------------------------------#
# Parsing and computations
#--------------------------------------------------------------------------#

ifile = 'dens_ana.in'

arg = sys.argv.pop(0)
while len(sys.argv) > 0:
    arg = sys.argv.pop(0)
    if arg in ["-h", "-H", "--help"]:
        ihelp()
    elif arg == '-ifile' or arg == '-f':
        ifile = sys.argv.pop(0)
    else:
        raise error_handler.ElseError(arg, 'command line option')

if not os.path.exists(ifile):
    print('Input file %s not found!' % ifile)
    print(
        'Please create this file using theoinp or specify its location using -ifile\n'
    )
    ihelp()

ioptions = input_options.tden_ana_options(ifile)
theo_header.print_header('Transition density matrix analysis',
                         ioptions=ioptions)

tdena = lib_tden.tden_ana(ioptions)
if 'mo_file' in ioptions: tdena.read_mos()
Пример #4
0
    def plot(self):
        hfname = 'OmFrag.html'
        hfile = lib_file.htmlfile(hfname)
        hfile.pre('Electron-hole correlation plots')
        hfile.write(
            '<h2>Electron-hole correlation plots of the Omega matrices for the individual states.</h2>'
        )

        htable = lib_file.htmltable(ncol=4)

        matplotlib.rc('font', size=self['fsize'])

        if self['grid']:
            edgecolors = 'k'
        else:
            edgecolors = None

        for state in self.state_list:
            if self['plot_type'] == 1:
                plot_arr = state['OmFrag']
            elif self['plot_type'] == 2:
                plot_arr = numpy.sqrt(state['OmFrag'])
            else:
                raise error_handler.ElseError(str(self['plot_type']),
                                              'plot_type')

            if self['sscale']:
                vmin = self['vmin']
                vmax = self['vmax']
            else:
                vmin = 0.
                vmax = state['OmFrag'].max()

            # Completely delete the small elements
            # for x in numpy.nditer(plot_arr, op_flags = ['readwrite']):
            #     if x < vmin:
            #         x[...] = -1. # numpy.nan

            pylab.figure(figsize=(2, 2))
            pylab.pcolor(plot_arr,
                         cmap=pylab.get_cmap(name=self['cmap']),
                         vmin=vmin,
                         vmax=vmax,
                         edgecolors=edgecolors)

            # *** Different colouring of different parts ***
            # frag_lists = [[0, 2, 4, 6], [1, 3, 5]]
            # cmaps = ['Reds', 'Blues']
            # OmDim = len(plot_arr)
            # for frag in frag_lists:
            #     tmp_arr = numpy.array([[numpy.nan for i in range(OmDim)] for j in range(OmDim)])
            #     for i in frag:
            #         tmp_arr[i,i] = plot_arr[i,i]
            #     pylab.pcolor(tmp_arr, cmap=pylab.get_cmap(cmaps.pop(0)), vmin=0., vmax=vmax, edgecolors=edgecolors)

            if self['axis']:
                pylab.axis('on')
                if self['ticks']:
                    pylab.tick_params(which='both', length=0)
                    if self['cticks']:
                        pylab.xticks([x + 0.5 for x in range(len(plot_arr))],
                                     self['xticks'])
                        pylab.yticks([y + 0.5 for y in range(len(plot_arr))],
                                     self['yticks'])
                    else:
                        pylab.xticks([x + 0.5 for x in range(len(plot_arr))],
                                     [x + 1 for x in range(len(plot_arr))])
                        pylab.yticks([y + 0.5 for y in range(len(plot_arr))],
                                     [y + 1 for y in range(len(plot_arr))])
                else:
                    pylab.xticks([])
                    pylab.yticks([])
            else:
                pylab.axis('off')

            if self['cbar']: pylab.colorbar()

            pname = 'pcolor_%s.%s' % (state['name'], self['output_format'])
            print("Writing %s ..." % pname)
            pylab.tight_layout()
            pylab.savefig(pname, dpi=self['plot_dpi'])
            pylab.close()

            tel = '<img src="%s", border="1" width="200">\n' % pname
            tel += '<br>%s' % state['name']
            htable.add_el(tel)

        # create a plot with the e/h axes and optionally the scale
        pylab.figure(figsize=(3, 2))
        matplotlib.rc('font', size=14)
        ax = pylab.axes()
        ax.arrow(0.15,
                 0.15,
                 0.5,
                 0.,
                 head_width=0.05,
                 head_length=0.1,
                 fc='r',
                 ec='r')
        ax.text(0.20, 0.03, 'hole', color='r')
        ax.arrow(0.15,
                 0.15,
                 0.,
                 0.5,
                 head_width=0.05,
                 head_length=0.1,
                 fc='b',
                 ec='b')
        ax.text(0.02, 0.20, 'electron', rotation='vertical', color='b')

        pylab.axis('off')
        if self['sscale']:
            pylab.savefig('axes_no.%s' % self['output_format'],
                          dpi=self['plot_dpi'])
            #            pylab.figure(figsize=(2,2))

            pylab.pcolor(numpy.zeros([1, 1]),
                         cmap=pylab.get_cmap(name=self['cmap']),
                         vmin=self['vmin'],
                         vmax=self['vmax'])

            pylab.colorbar()

        pylab.savefig('axes.%s' % self['output_format'], dpi=self['plot_dpi'])

        tel = '<img src="axes.%s", border="1" width="200">\n' % self[
            'output_format']
        tel += '<br>Axes / Scale'
        htable.add_el(tel)

        hfile.write(htable.ret_table())
        hfile.post()

        print(
            " HTML file %s containing the electron-hole correlation plots written."
            % hfname)