def CdotD(self, D, trnsp=False, inv=False): """ Left-multiplication of matrix D with the MO-coefficients. Optionally, D can be a rectangular matrix of dimension occ x (occ + virt). """ if self.ret_num_mo() == len(D): return numpy.dot(self.ret_mo_mat(trnsp, inv), D) # Handling of special cases elif self.ret_num_mo() > len(D): if not trnsp and not inv: # take only the occ. subblock Csub = self.mo_mat.transpose()[:len(D)] return numpy.dot(Csub.transpose(), D) elif trnsp and inv: # take only the occ. subblock Csub = self.inv_mo_mat[:len(D)] return numpy.dot(Csub.transpose(), D) else: raise error_handler.ElseError('"transpose xor inverse"', 'CdotD') elif self.ret_num_mo() < len(D): print "\n WARNING: C/D mismatch" print " C: %i x %i" % (self.ret_num_mo(), self.ret_num_bas()) print " D: %i x %i" % (len(D), len(D[0])) # raise error_handler.ElseError('C < D', 'MO matrix') Dsub = D[:self.ret_num_mo()] return numpy.dot(self.ret_mo_mat(trnsp, inv), Dsub)
def jmol_input(self): self.read_float('Cutoff value', 'cutoff', 0.05) #print "" self.choose_list( 'Specification of the orbital indices to be plotted', 'spec', [ ('sten', 'Start and end indices'), ('frontier', 'Number of frontier orbitals'), ('occ', 'Occupation threshold') ] ) #self.read_yn('Specification in terms of frontier orbitals', 'fr_mos') if self['spec'] == 'sten': self.read_int('First orbital index to be plotted', 'st_ind', 1) self.read_int('Last orbital index to be plotted', 'en_ind', 10) elif self['spec'] == 'frontier': self.read_int('Number of frontier orbitals', 'en_ind', 3) elif self['spec'] == 'occ': self.read_float('Minimal occupancy', 'occmin', 0.01) self.read_float('Maximal occupancy', 'occmax', 1.99) else: raise error_handler.ElseError(self['spec'], 'spec') self.read_yn('Use "rotate best" command (only available in Jmol 14)', 'rot_best') self.read_yn('Additional custom rotation of the molecule?', 'rot_custom') if self['rot_custom']: self.read_float('Rotation around the x-axis', 'rot_x', 0.) self.read_float('Rotation around the y-axis', 'rot_y', 0.) self.read_float('Rotation around the z-axis', 'rot_z', 0.) self.read_int('Width of images in output html file', 'width', 400)
def read_dens(self): """ Read the (transition) density matrices and some supplementary information. """ rtype = self.ioptions.get('rtype') if self.ioptions['read_libwfa']: self.mos = None if rtype == 'ricc2': self.state_list = file_parser.file_parser_ricc2( self.ioptions).read(self.mos) elif rtype in ['tddft', 'escf', 'tmtddft']: self.state_list = file_parser.file_parser_escf(self.ioptions).read( self.mos) elif rtype == 'libwfa': self.state_list = file_parser.file_parser_libwfa( self.ioptions).read() elif rtype == 'qcadc': self.state_list = file_parser.file_parser_qcadc( self.ioptions).read() elif rtype == 'qctddft': self.state_list = file_parser.file_parser_qctddft( self.ioptions).read(self.mos) elif rtype in ['mcscf', 'colmcscf']: self.state_list = file_parser.file_parser_col_mcscf( self.ioptions).read(self.mos) elif rtype in ['mrci', 'colmrci']: self.state_list = file_parser.file_parser_col_mrci( self.ioptions).read(self.mos) elif rtype in ['rassi', 'molcas']: self.state_list = file_parser.file_parser_rassi( self.ioptions).read(self.mos) elif rtype.lower() == 'nos': self.state_list = file_parser.file_parser_nos(self.ioptions).read( self.mos) elif rtype.lower() in ['cclib', 'gamess', 'orca']: # these are parsed with the external cclib library ccli = cclib_interface.file_parser_cclib(self.ioptions) errcode = ccli.check() if errcode >= 2: raise error_handler.MsgError( "The file cannot be parsed by cclib") print self.mos = ccli.read_mos() self.read2_mos() self.state_list = ccli.read(self.mos) # Write a Molden file if possible if errcode == 0: self.mos.write_molden_file(fname='MOs.mld') self.ioptions['mo_file'] = 'MOs.mld' else: self.ioptions['molden_orbitals'] = False else: raise error_handler.ElseError(rtype, 'rtype') self.extra_info()
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 extract(self, mo_file): print("Extracting %s ..." % mo_file) os.chdir(self.stdir) mos = lib_mo.MO_set_molden(file=mo_file) mos.read() orb_dir = "%s.dir" % mo_file try: os.chdir(orb_dir) except: os.makedirs(orb_dir) os.chdir(orb_dir) if self.decompose: self.ex_hp(mos, 1.) self.ex_hp(mos, -1.) else: raise error_handler.ElseError('False', 'decompose')
def symsort(self, irrep_labels, sepov=True): """ Sort MOs by symmetry (in case they are sorted by energy). This is more of a hack than a clean and stable routine... """ print "Sorting MOs by symmetry" occorbs = {} virtorbs = {} for il in irrep_labels: occorbs[il] = [] virtorbs[il] = [] for imo, sym in enumerate(self.syms): for il in irrep_labels: if il in sym: if self.occs[imo] == 0.: virtorbs[il].append((sym, imo)) else: occorbs[il].append((sym, imo)) T = numpy.zeros([self.ret_num_mo(), self.ret_num_mo()], int) orblist = [] if sepov: for il in irrep_labels: orblist += occorbs[il] for il in irrep_labels: orblist += virtorbs[il] else: raise error_handler.ElseError('False', 'sepov') self.syms = [] for jmo, orb in enumerate(orblist): T[jmo, orb[1]] = 1 self.syms.append(orb[0]) assert (jmo == self.ret_num_mo() - 1) self.mo_mat = numpy.dot(self.mo_mat, T.transpose()) self.compute_inverse()
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)
#--------------------------------------------------------------------------# # 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) tdena = lib_tden.tden_ana(ioptions) if 'mo_file' in ioptions: tdena.read_mos() tdena.read_dens()
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)