def pre(self, ofile=None): self.jmfile = open("%s_jmol.spt"%self.name,'w') if not ofile==None: self.jmfile.write('load %s FILTER "nosort"\n'%ofile) self.jmfile.write ('mo titleformat ""\n\n') self.jmfile.write('background white\nmo fill\nmo cutoff 0.04\n') self.htmlfile = lib_file.htmlfile("%s.html"%self.name) self.htmlfile.pre(self.name)
def pre(self, ofile=None): self.jmfile = open("%s_jmol.spt" % self.name, 'w') if not ofile == None: self.jmfile.write('load %s FILTER "nosort"\n' % ofile) self.jmfile.write('mo titleformat ""\n\n') self.jmfile.write('background white\nmo fill\nmo cutoff 0.04\n') self.htmlfile = lib_file.htmlfile("%s.html" % self.name) self.htmlfile.pre(self.name)
def run(): print('jmol_MOs.py [<mldfile> [<mldfile2> ...]]\n') mldfiles = sys.argv[1:] if len(mldfiles) == 0: print("No file specified, generating generic script") mldfiles = [''] pref = '' elif len(mldfiles) == 1: print("Analyzing the file:", mldfiles[0]) pref = mldfiles[0] + '.' else: print("Analyzing the files:", mldfiles) pref = 'multi.' jopt = jmol_options('jmol.in') jopt.jmol_input() jo = lib_file.wfile('%sjmol_orbitals.spt'%pref) ho = lib_file.htmlfile('%sorbitals.html'%pref) lo = lib_file.latexfile('%sorbitals.tex'%pref) ho.pre('Orbitals') lo.pre(None, graphicx=True) for mldfile in mldfiles: print('Analyzing %s ...\n'%mldfile) if jopt['spec'] == 'sten': moc = mocoll(jopt['st_ind'], jopt['en_ind'], mldfile) elif jopt['spec'] == 'frontier': moc = mocollf(jopt['en_ind'], mldfile) elif jopt['spec'] == 'occ': moc = mocoll_occ(jopt['occmin'], jopt['occmax'], mldfile) else: raise error_handler.ElseError(self['spec'], 'spec') moout = mo_output_jmol(moc, jopt) moout.output(jo) moh = mo_output_html(moc, jopt) moh.output(ho) mol = mo_output_tex(moc, jopt) mol.output(lo) jo.post(lvprt=1) if mldfiles == [""]: print(" -> Open the Molden-file in jmol and execute the commands contained in this file.") else: print(" -> Now simply run \"jmol -n %s\" to plot all the orbitals.\n"%jo.name) ho.post(lvprt=1) print(" -> View in browser.") lo.post(lvprt=1) print(" -> Compile with pdflatex (or adjust first).")
def plot(self): """ Create the plots. For this purpose, self.data has to be rearranged. """ try: import matplotlib matplotlib.use('Agg') import pylab except: print("pylab/matplotlib not installed - plotting not possible") raise hfname = 'graphs.html' hfile = lib_file.htmlfile(hfname) hfile.pre('Property graphs') htable = lib_file.htmltable(ncol=4) #set1 = self.data[0][self['state_labels'][0]] # not used anywhere?? matplotlib.rc('font', size=self['fsize']) for key in self.main_header[1:]: if key == 'fname': continue print('Plotting %s ...'%key) pylab.figure(figsize=(6,4)) for state in self['state_labels']: ylist = [] for iana_dir in range(len(self['ana_dirs'])): try: ylist.append(self.data[iana_dir][state][key]) except KeyError: print(" ... not able to plot %s for %s."%(key, state)) break else: pylab.plot(list(range(len(ylist))), ylist, 'x-', label=state) pylab.title(key) numx = len(self['ana_dirs']) pylab.xticks(range(numx), self['ana_dirs'], rotation=30) #pylab.margins(0.20) pylab.subplots_adjust(bottom=0.15) pylab.xlim((-0.5, numx+1.5)) pylab.ylabel(key) pylab.legend() pname = '%s.%s'%(key, self['output_format']) pylab.savefig(pname) tel = '<img src="%s", border="1" width="400">'%pname htable.add_el(tel) hfile.write(htable.ret_table()) hfile.post() print(" HTML file %s containing the property graphs written."%hfname)
def plot(self): """ Create the plots. For this purpose, self.data has to be rearranged. """ try: import matplotlib matplotlib.use('Agg') import pylab except: print("pylab/matplotlib not installed - plotting not possible") raise hfname = 'graphs.html' hfile = lib_file.htmlfile(hfname) hfile.pre('Property graphs') htable = lib_file.htmltable(ncol=4) #set1 = self.data[0][self['state_labels'][0]] # not used anywhere?? matplotlib.rc('font', size=self['fsize']) for key in self.main_header[1:]: if key == 'fname': continue print('Plotting %s ...' % key) pylab.figure(figsize=(6, 4)) for state in self['state_labels']: ylist = [] for iana_dir in range(len(self['ana_dirs'])): try: ylist.append(self.data[iana_dir][state][key]) except KeyError: print(" ... not able to plot %s for %s." % (key, state)) break else: pylab.plot(list(range(len(ylist))), ylist, 'x-', label=state) pylab.title(key) numx = len(self['ana_dirs']) pylab.xticks(range(numx), self['ana_dirs'], rotation=30) #pylab.margins(0.20) pylab.subplots_adjust(bottom=0.15) pylab.xlim((-0.5, numx + 1.5)) pylab.ylabel(key) pylab.legend() pname = '%s.%s' % (key, self['output_format']) pylab.savefig(pname) tel = '<img src="%s", border="1" width="400">' % pname htable.add_el(tel) hfile.write(htable.ret_table()) hfile.post() print(" HTML file %s containing the property graphs written." % hfname)
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']) 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']: vmax = self['vmax'] else: vmax = state['OmFrag'].max() pylab.figure(figsize=(2,2)) pylab.pcolor(plot_arr, cmap=pylab.get_cmap(name=self['cmap']), vmin=0., vmax=vmax) if self['axis']: pylab.axis('on') if self['ticks']: 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.savefig(pname, dpi=self['plot_dpi']) 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=(2,2)) ax = pylab.axes() ax.arrow(0.15, 0.15, 0.5, 0., head_width=0.05, head_length=0.1, fc='k', ec='k') ax.text(0.20, 0.05, 'hole') ax.arrow(0.15, 0.15, 0., 0.5, head_width=0.05, head_length=0.1, fc='k', ec='k') ax.text(0.02, 0.20, 'electron', rotation='vertical') if self['sscale']: # pylab.figure(figsize=(2,2)) pylab.pcolor(numpy.zeros([1, 1]), cmap=pylab.get_cmap(name=self['cmap']), vmin=0., vmax=self.maxOm) pylab.colorbar() pylab.axis('off') 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)
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']) 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']: vmax = self['vmax'] else: vmax = state['OmFrag'].max() pylab.figure(figsize=(2, 2)) pylab.pcolor(plot_arr, cmap=pylab.get_cmap(name=self['cmap']), vmin=0., vmax=vmax) if self['axis']: pylab.axis('on') if self['ticks']: 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.savefig(pname, dpi=self['plot_dpi']) 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=(2, 2)) ax = pylab.axes() ax.arrow(0.15, 0.15, 0.5, 0., head_width=0.05, head_length=0.1, fc='k', ec='k') ax.text(0.20, 0.05, 'hole') ax.arrow(0.15, 0.15, 0., 0.5, head_width=0.05, head_length=0.1, fc='k', ec='k') ax.text(0.02, 0.20, 'electron', rotation='vertical') if self['sscale']: # pylab.figure(figsize=(2,2)) pylab.pcolor(numpy.zeros([1, 1]), cmap=pylab.get_cmap(name=self['cmap']), vmin=0., vmax=self.maxOm) pylab.colorbar() pylab.axis('off') 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)