Exemple #1
0
class PlotGraph(Action):

    name = 'plot_graph'

    _colt_description = 'Graph plotting for potential curves etc.'

    _lazy_imports = LazyImporter({
            '..theo_header': 'theo_header',
            '..lib_plot': 'lib_plot',
    })

    def run():
        theo_header.print_header(title=__class__._colt_description)
        infilen = 'graph.in'
        
        popt = lib_plot.write_plot_options(infilen)
        ropt = lib_plot.read_plot_options(infilen, False)

        if ropt.init == 0:
            copy = popt.ret_yn('Found %s. Use this file directly rather than performing an interactive input?'%infilen, True)
        else:
            copy = False    
        
        if copy:
            popt.copy(ropt)
        else:        
            popt.plot_input()
            popt.flush()
        
        popt.read_data()
        
        if popt['doplots']: popt.plot()
        if popt['dotxt']:   popt.txt_files()
        if popt['dognu']:   popt.gnu_inp()
Exemple #2
0
class Babel(Action):

    name = 'babel'

    _colt_description = 'Openbabel wrapper - conversion of coordinate files'

    _user_input = """
    # Input molecular structure file
    infile = :: existing_file
    # Output molecular structure file
    outfile = :: file
    # File type for input file
    intype = :: str, optional, alias=i
    # File type for output file
    outtype = :: str, optional, alias=o
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..lib_struc': 'lib_struc',
    })

    def run(infile, intype, outtype, outfile):
        theo_header.print_header(__class__._colt_description)

        if intype in lib_struc.veloc_types:  # special treatment of velocities
            veloc = struc_linalg.veloc()
            veloc.read_file(file_path=infile, file_type=intype)
            veloc.write_veloc(file_path=outfile, file_type=outtype)
        else:
            struc = lib_struc.structure()
            struc.read_file(file_path=infile, file_type=intype)
            struc.make_coord_file(file_path=outfile, file_type=outtype)

        print("Finished: file %s written." % outfile)
Exemple #3
0
class CC2Molden(Action):

    name = 'cc2molden'

    _user_input = """
    logfile = :: existing_file
    """
    _colt_description = "Convert a log-file to Molden format with the help of cclib."

    _lazy_imports = LazyImporter({
            '..theo_header': 'theo_header',
            '..cclib_interface': 'cclib_interface',
            '..error_handler': 'error_handler',
            '..input_options': 'input_options',
            '..lib_mo': 'lib_mo',
    })

    def run(logfile):
        theo_header.print_header(__class__._colt_description)
        print("  WARNING: This script is not well-tested and might fail for some of the quantum chemistry codes.")
        
        ioptions = input_options.dens_ana_options(ifile=None, check_init=False)
        ioptions['rtype'] = 'cclib'
        ioptions['rfile'] = logfile
        
        ccparser = cclib_interface.file_parser_cclib(ioptions)
        
        errcode = ccparser.check()
        if errcode == 0:
            mos = ccparser.read_mos()
            mos.write_molden_file(fname="cc.mld")
            print("\n Finished: molden format file cc.mld written.")
        else:
            print(" Conversion to Molden format not possible!")
            print(" %s does not contain all required information"%logfile)
Exemple #4
0
class PlotOmFrag(Action):

    _colt_description = 'Plot Omega matrices as pseudocolor matrix plot'

    name = 'plot_omfrag'

    _user_input = """
    # Use new colt interface
    use_new = False :: bool
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..input_options': 'input_options',
        '..lib_file': 'lib_file',
        '..error_handler': 'error_handler',
        'matplotlib': 'matplotlib',
        'pylab': 'pylab',
    })

    def run(use_new):
        matplotlib.use('Agg')
        theo_header.print_header(title=__class__._colt_description)
        Oopt = OmFrag_options('OmFrag.in')
        Oopt.read_OmFrag()

        Oopt.OmFrag_input(use_new=use_new)
        Oopt.flush()

        Oopt.plot()
Exemple #5
0
class FCD(Action):

    name = 'fcd'

    _colt_description = 'Fragment charge difference analysis'

    _user_input = """
    # name of the input file
    ifile = fcd.in :: existing_file, alias=f
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..input_options': 'input_options',
        '..lib_diab': 'lib_diab',
    })

    def run(ifile):
        theo_header.print_header(title=__class__._colt_description)

        ifile = 'fcd.in'

        ioptions = input_options.fcd_ana_options(ifile)

        fcda = lib_diab.fcd_ana(ioptions)
        fcda.read_mos()
        fcda.read_dens()

        fcda.do_pop_ana()
        fcda.do_fcd()
class ExtractMolden(Action):

    _user_input = """
    # List of MO files to analyse
    mo_files = :: list(existing_file)
    # Interpret energies as occupations
    ene = False :: bool, alias=e
    # Threshold for print-out
    thresh = 0.001 :: float, alias=t
    # Use alpha/beta labels for hole/electron
    alphabeta = False :: bool, alias=ab
    """

    name = 'extract_molden'

    _colt_description = 'Extract hole/particle parts from Molden file'

    _lazy_imports = LazyImporter({
            '..theo_header': 'theo_header',
            '..error_handler': 'error_handler',
            '..lib_mo': 'lib_mo',
    })

    def run(mo_files, ene, thresh, alphabeta):
        theo_header.print_header(title=__class__._colt_description)

        extr = extract_mld(thresh=thresh, rd_ene=ene, decompose=not alphabeta)
        mo_files = []

        for mo_file in mo_files:
            extr.extract(mo_file)
class PlotGraphNx(Action):

    name = 'plot_graph_nx'

    _colt_description = 'Graph plotting (Newton-X)'

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..input_options': 'input_options',
        '..lib_plot': 'lib_plot',
        '..lib_file': 'lib_file',
    })

    def run():
        theo_header.print_header(title=__class__._colt_description)
        infilen = 'graph.in'

        popt = write_plot_options_nx(infilen)

        popt.plot_input()
        popt.read_data()

        if popt['doplots']: popt.plot()
        if popt['dotxt']: popt.txt_files()
        if popt['dognu']: popt.gnu_inp()
Exemple #8
0
class Spectrum(Action):

    name = 'spectrum'

    _colt_description = 'Convoluted spectrum from analyze_tden output'

    _user_input = """
    # Files produced by analyze_tden.py
    tden_summs = :: list(existing_file)
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..units': 'units',
        '..lib_file': 'lib_file',
        '..input_options': 'input_options',
        '..error_handler': 'error_handler',
        'matplotlib': 'matplotlib',
        'pylab': 'pylab',
    })

    def run(tden_summs):
        matplotlib.use('Agg')
        theo_header.print_header(title=__class__._colt_description)

        sopt = spec_options('spectrum.in')
        sopt['ana_files'] = tden_summs
        sopt.spec_input()

        sopt.make_spec()
Exemple #9
0
class VMDPlots(Action):

    name = 'vmd_plots'

    _colt_description = 'Automatic plotting of cube files in VMD'

    _user_input = """
    # List of cube files (or other format VMD can read)
    pltfiles = :: list(existing_file)
    """

    _lazy_imports = LazyImporter({
        '..error_handler': 'error_handler',
        '..theo_header': 'theo_header',
        '..input_options': 'input_options',
        '..lib_struc': 'lib_struc',
        '..lib_file': 'lib_file',
        '..lib_util': 'lib_util',
    })

    def run(pltfiles):
        theo_header.print_header(title=__class__._colt_description)

        print('%i Files analyzed:' % len(pltfiles), end=' ')
        print(", ".join(os.path.basename(filename) for filename in pltfiles))

        vopt = vmd_options('vmd.in')
        vopt.vmd_input()
        auxfiles = []
        if vopt['dnto']:
            pltfiles, auxfiles = vopt.mod_pltfiles(pltfiles)

        vopt.write_lfile(pltfiles, auxfiles)
        vopt.write_pfile(pltfiles, auxfiles)
        vopt.write_cfile(pltfiles)
        vopt.write_hfile(pltfiles)

        print("Converting coordinate file ...")
        struc = lib_struc.structure()
        try:
            struc.read_file(file_path=pltfiles[0], file_type=None)
            struc.make_coord_file(file_path='coord.xyz',
                                  file_type='xyz',
                                  lvprt=1)
        except:
            print(
                "*** WARNING: The coordinate file coord.xyz could not be created. ***"
            )
            print("    Please create this file yourself.\n\n")

        print("""
Files created. Now do the following:
1. vmd coord.xyz
2.   File - Load Visualization State - %s
3.   Adjust the perspective
4.   File - Load Visualization State - %s
5. bash %s
6. Open in browser: %s
""" % (vopt['lfile'], vopt['pfile'], vopt['cfile'], vopt['hfile']))
class ParseLibwfa(Action):

    name = 'parse_libwfa'

    _colt_description = 'Parse libwfa output from Q-Chem or OpenMolcas'

    _user_input = """
    # Logfile from Q-Chem or OpenMolcas
    logfile = :: existing_file
    # Type of calculation (qcadc, qctddft, qctda, rassi)
    typ    = :: str :: qcadc, qctddft, qctda, rassi
    # Input file
    ifile = :: file, optional, alias=f
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..dens_ana_base': 'dens_ana_base',
        '..error_handler': 'error_handler',
        '..input_options': 'input_options',
    })

    def run(logfile, typ, ifile):
        #--------------------------------------------------------------------------#
        # Input options
        #--------------------------------------------------------------------------#

        ioptions = input_options.libwfa_parse_options(ifile, check_init=False)

        ioptions['rfile'] = logfile
        if typ is not None:
            ioptions['rtype'] = typ

        if ioptions['rtype'] == 'qctda':
            ioptions['TDA'] = True
            ioptions['rtype'] = 'qctddft'

        theo_header.print_header(__class__._colt_description,
                                 ioptions=ioptions)

        #--------------------------------------------------------------------------#
        # Parsing and computations
        #--------------------------------------------------------------------------#

        dena = dens_ana_base.dens_ana_base(ioptions)
        #sdena.read_mos()

        dena.read_dens()

        dena.print_summary()
class AnalyzeTdenEs2Es(Action):

    name = 'analyze_tden_es2es'

    _colt_description = 'Transition density matrix ana. (state-to-state)'

    _user_input = """
    # Main input file
    ifile = dens_ana.in :: existing_file, alias=f
    # Reference state
    iref  = 1 :: int, alias=r
    """

    _lazy_imports = LazyImporter({
            '..theo_header': 'theo_header',
            '..lib_tden': 'lib_tden',
            '..input_options': 'input_options'
    })

    @timeit
    def run(ifile, iref):
        ioptions = input_options.tden_ana_options(ifile)
        theo_header.print_header(title=__class__._colt_description, ioptions=ioptions, cfile=__name__)

        tdena = lib_tden.tden_ana(ioptions)
        if 'mo_file' in ioptions: tdena.read_mos()

        tdena.read_dens()
        tdena.compute_es2es_tden(iref=iref)

        if 'at_lists' in ioptions or ioptions['eh_pop'] >= 1:
            tdena.compute_all_OmAt()

        if 'at_lists' in ioptions:
            tdena.compute_all_OmFrag()
            if ioptions['print_OmFrag']: tdena.fprint_OmFrag()

        if ioptions['comp_ntos']:  tdena.compute_all_NTO()
        if ioptions['comp_p_h_dens']: tdena.compute_p_h_dens()
        if ioptions['comp_rho0n']: tdena.compute_rho_0_n()
        if 'Phe' in ioptions['prop_list']:
            tdena.compute_all_Phe()

        #--------------------------------------------------------------------------#
        # Print-out
        #--------------------------------------------------------------------------#    
        tdena.print_all_eh_pop()

        tdena.print_summary()
Exemple #12
0
class JMolVibs(Action):

    name = 'jmol_vibs'
    
    _colt_description = 'Plotting of vibrations in Jmol'

    _user_input = """
    # Molden file with info about vibrations
    vibfile = :: existing_file
    """

    _lazy_imports = LazyImporter({
            '..error_handler': 'error_handler',
            '..lib_file': 'lib_file',
            '..theo_header': 'theo_header',
            '..input_options': 'input_options',
    })

    def run(vibfile):

        theo_header.print_header(__class__._colt_description)

        jopt = jmol_vib_opts('jmol.in')
        jopt.input()
        
        jo = lib_file.wfile('jmol_vibs.spt')
        ho = lib_file.htmlfile('vibs.html')
        
        ho.pre('Vibrations')
        
        vibc = vibcoll(jopt['st_ind'], jopt['en_ind'], vibfile)

        vibout = vib_output_jmol(vibc, jopt)
        vibout.output(jo)
        
        vibh = vib_output_html(vibc, jopt)
        vibh.output(ho)

        ho.post(lvprt=1)
        jo.post(lvprt=1)
        if jopt['run_jmol']:
            import subprocess
            print("Running jmol ...")

            subprocess.call(["jmol", "-n", jo.name])
        else:
            print("  -> Now simply run \"jmol -n %s\" to plot all the orbitals.\n"%jo)
class AnalyzeSden(Action):

    name = 'analyze_sden'

    _colt_description = 'State density matrix analysis'

    _user_input = """
    ifile = dens_ana.in :: existing_file, alias=f
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..lib_sden': 'lib_sden',
        '..lib_exciton': 'lib_exciton',
        '..input_options': 'input_options'
    })

    @timeit
    def run(ifile):
        # header
        theo_header.print_header(__class__._colt_description, cfile=__name__)
        #
        ioptions = input_options.sden_ana_options(ifile)

        #--------------------------------------------------------------------------#
        # Parsing and computations
        #--------------------------------------------------------------------------#

        sdena = lib_sden.sden_ana(ioptions)
        if 'mo_file' in ioptions: sdena.read_mos()
        sdena.read_dens()

        if ioptions['NO_ana']: sdena.compute_all_NO()
        if ioptions['AD_ana']: sdena.compute_all_AD()
        if ioptions['BO_ana']: sdena.compute_all_BO()

        if ioptions['comp_rho']: sdena.compute_rho()

        #--------------------------------------------------------------------------#
        # Print out
        #--------------------------------------------------------------------------#
        if ioptions['pop_ana']: sdena.print_all_pop_table()
        if ioptions['BO_ana']: sdena.print_all_BO()
        if ioptions['mo_pop_type'] > 0:
            sdena.print_mo_pops(ioptions['mo_pop_type'])

        sdena.print_summary()
Exemple #14
0
class TheodoreInput(Action):

    name = 'theoinp'

    _user_input = ""

    _colt_description = "Input generation for TheoDORE"

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..input_options': 'input_options',
        '..lib_struc': 'lib_struc',
        '..error_handler': 'error_handler',
        '..orbkit_interface': 'orbkit_interface',
    })

    def run():
        theo_header.print_header(__class__._colt_description)
        run_theoinp()
class PlotFragDecomp(Action):
    name = 'plot_frag_decomp'

    _colt_description = 'Plot fragment decomposition of Omega matrix'

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..input_options': 'input_options',
        '..error_handler': 'error_handler',
        'matplotlib': 'matplotlib',
        'pylab': 'pylab',
    })

    def run():
        matplotlib.use('Agg')
        theo_header.print_header(__class__._colt_description)
        opt = decomp_options('plot.in')
        opt.read_OmFrag()

        opt.decomp_input()

        opt.plot()
class AnalyzeTdenSoc(Action):
    name = 'analyze_tden_soc'

    _colt_description = '1TDM analysis for spin-orbit coupled states'

    _user_input = """
    ifile = dens_ana.in :: existing_file, alias=f
    spin_comp = False :: bool, alias=s
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..lib_soc': 'lib_soc',
        '..error_handler': 'error_handler',
        '..input_options': 'input_options',
    })

    @timeit
    def run(ifile, spin_comp):
        ioptions = input_options.tden_ana_options(ifile)
        theo_header.print_header(__class__._colt_description,
                                 ioptions=ioptions,
                                 cfile=__file__)

        tdena = lib_soc.tden_ana_soc(ioptions)
        if 'mo_file' in ioptions: tdena.read_mos()
        tdena.read_dens()
        tdena.compute_all_OmAt(fullmat=True)
        tdena.soc_transform()

        tdena.print_info('mch')
        if spin_comp is True:
            tdena.print_info('aa')
            tdena.print_info('bb')
            tdena.print_info('ab')
            tdena.print_info('ba')
        tdena.print_info('soc')
class ConvertTable(Action):

    name = 'convert_table'

    _colt_description = 'Convert the output to latex/html table'

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..input_options': 'input_options',
        '..lib_file': 'lib_file',
        '..error_handler': 'error_handler',
    })

    def run():
        theo_header.print_header(title=__class__._colt_description)
        infilen = 'table.in'

        topt = write_table_options(infilen)
        ropt = read_table_options(infilen, False)

        if ropt.init == 0:
            copy = topt.ret_yn(
                'Found %s. Use this file directly rather than performing an interactive input?'
                % infilen, True)
        else:
            copy = False

        if copy:
            topt.copy(ropt)
        else:
            topt.table_input()

        topt.write_table()

        if not copy:
            topt.flush()
class DrawMoments(Action):
    name = 'draw_moments'

    _colt_description = 'Plotting of dipole and quadrupole moments'

    _user_input = """
    # File produced by analyze_tden
    ana_file = :: existing_file
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..units': 'units',
        '..input_options': 'input_options',
        '..lib_file': 'lib_file',
        '..error_handler': 'error_handler',
    })

    def run(ana_file):
        theo_header.print_header(title=__class__._colt_description)
        opt = mom_options('mom.in')
        opt['ana_file'] = ana_file
        opt.input()
        opt.write_afile()
class AnalyzeTdenUnr(Action):

    name = 'analyze_tden_unr'

    _colt_description = 'Transition density matrix analysis (UHF/UKS)'

    _user_input = """
    ifile = dens_ana.in :: existing_file, alias=f
    """

    _lazy_imports = LazyImporter({
            '..theo_header': 'theo_header',
            '..lib_tden': 'lib_tden',
            '..lib_exciton': 'lib_exciton',
            '..input_options': 'input_options'
    })

    @timeit
    def run(ifile):
        ioptions = input_options.tden_ana_options(ifile)
        theo_header.print_header(__class__._colt_description, ioptions=ioptions, cfile=__name__)

        ioptions['jmol_orbitals'] = False

        # ALPHA spin
        print("\nRunning alpha-spin analysis in directory ALPHA")
        ioptions['spin'] = 1

        tdena_alpha = lib_tden.tden_ana(ioptions)
        if 'mo_file' in ioptions: tdena_alpha.read_mos(spin=1)
        tdena_alpha.read_dens()

        try:
            os.mkdir('ALPHA')
        except OSError:
            pass
        os.chdir('ALPHA')
        if 'at_lists' in ioptions:
            tdena_alpha.compute_all_OmFrag()
            if ioptions['print_OmFrag']: tdena_alpha.fprint_OmFrag()
        if ioptions['comp_ntos']:  tdena_alpha.compute_all_NTO()

        print("\n *** ALPHA-spin results ***")
        tdena_alpha.print_summary()
        os.chdir('..')

        # BETA spin
        print("\nRunning beta-spin analysis in directory BETA")
        ioptions['spin'] = -1

        tdena_beta = lib_tden.tden_ana(ioptions)
        if 'mo_file' in ioptions: tdena_beta.read_mos(spin=-1)
        tdena_beta.read_dens()

        try:
            os.mkdir('BETA')
        except OSError:
            pass
        os.chdir('BETA')
        if 'at_lists' in ioptions:
            tdena_beta.compute_all_OmFrag()
            if ioptions['print_OmFrag']: tdena_beta.fprint_OmFrag()
        if ioptions['comp_ntos']:  tdena_beta.compute_all_NTO()

        print("\n *** BETA-spin results ***")
        tdena_beta.print_summary()
        os.chdir('..')

        # ALPHA+BETA
        print("Starting spin-summed analysis")
        # Add the alpha values on top of the beta values
        for i, state in enumerate(tdena_beta.state_list):
            # Add the things that are additive
            for aprop in ['Om', 'OmAt', 'OmFrag', 'S_HE']:
                if aprop in state:
                    state[aprop] += tdena_alpha.state_list[i][aprop]
            try:
                state['Z_HE'] = 2.**(state['S_HE'])
            except KeyError:
                pass

            # Delete the things that are non-additive
            for dprop in ['tden', 'PRNTO', 'Om_desc']:
                if dprop in state:
                    del state[dprop]

        if 'at_lists' in ioptions:
            tdena_beta.compute_all_OmFrag()
            if ioptions['print_OmFrag']: tdena_beta.fprint_OmFrag()

        print("\n *** Spin-summed results ***")
        tdena_beta.print_summary()
Exemple #20
0
class PlotVist(Action):

    name = 'plot_vist'

    _user_input = """

    # VIST for only these dummy atoms, e.g. -v '0 3 5'
    vist = :: ilist, optional, alias=v
    # Name of output file (for VMD)
    ofile    = VIST.vmd :: str, alias=o
    # Scale factor for VIST dumb-bells
    scale    = 1.0 :: float, alias=s
    # Create coordinate files (using cclib)
    coor  = false :: bool, alias=c
    # Render and plot all tensors separately
    plot_all = false :: bool, alias=p
    # Log files to be parsed
    logfiles = :: list(str)
    """

    _colt_description = "Read NICS values and prepare VIST plot"

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..lib_NICS': 'lib_NICS',
        '..error_handler': 'error_handler',
        '..cclib_interface': 'cclib_interface',
        '..input_options': 'input_options',
    })

    @timeit
    def run(vist, ofile, scale, coor, plot_all, logfiles):
        if vist is not None and len(vist) == 0:
            vist = None
        theo_header.print_header('Read NICS values and prepare VIST plot',
                                 cfile='plot_VIST.py')

        with open(ofile, 'w') as fh:
            pass

        ioptions = input_options.dens_ana_options(ifile=None, check_init=False)
        ioptions['rtype'] = 'cclib'

        nv = lib_NICS.NICS_parser_g09()
        for ilog, logfile in enumerate(logfiles):
            nv.read(logfile)
            nv.print_data()
            if coor:  # create coor file to be read by VMD
                ioptions['rfile'] = logfile
                ccparser = cclib_interface.file_parser_cclib(ioptions)
                struc = cclib_interface.structure_cclib()
                struc.read_cclib(ccparser.data)
                coorf = "coor%i.xyz" % ilog
                struc.make_coord_file(file_path=coorf, file_type='Bqxyz')
                open(ofile, 'a').write("mol new %s\n" % coorf)
            nv.vmd_tensors(ofile, vist, scale, plot_all)

        # Instructions for VMD
        if coor:
            print("""
        Input file for VMD and coordinate file(s) created. Now run:
           vmd -e %s
            """ % ofile)
        else:
            print("""
        Input file for VMD created. Now do the following:
        1. Open VMD and load coordinate file
        2.   File - Load Visualization State - %s
            """ % ofile)
Exemple #21
0
class TDenOv(Action):

    name = 'tden_ov'

    _colt_description = 'Transition density matrix overlap'

    _user_input = """
    dir1 = :: existing_folder
    dir2 = :: existing_folder
    ao_ov = :: existing_file, optional
    # name of the input file
    ifile = tden_OV.in :: existing_file, alias=f
    # name of input file for the second computation
    ifile2 = :: existing_file, optional, alias=f2
    """

    _lazy_imports = LazyImporter({
            '..theo_header': 'theo_header',
            '..lib_tden': 'lib_tden',
            '..error_handler': 'error_handler',
            '..input_options': 'input_options',
    })

    def run(dir1, dir2, ao_ov, ifile, ifile2):
        ifile = 'tden_OV.in'
        ifile2 = ''
        
        ioptions = input_options.tden_ana_options(ifile)
        theo_header.print_header(title=__class__._colt_description, ioptions=ioptions)
        
        if ifile2 is None:
            ioptions2 = ioptions
        else:
            ioptions2 = input_options.tden_ana_options(ifile2)
        
        sdir = os.getcwd()
        
        # Read info for the first job
        os.chdir(dir1)
        tdena1 = lib_tden.tden_ana(ioptions)
        if 'mo_file' in ioptions:
            tdena1.read_mos()
        tdena1.read_dens()
        os.chdir(sdir)
        
        # Read info for the second job
        os.chdir(dir2)
        tdena2 = lib_tden.tden_ana(ioptions2)
        if 'mo_file' in ioptions2:
            tdena2.read_mos()
        tdena2.read_dens()
        os.chdir(sdir)
        
        if AO_OV == None:
            print("Constructing AO-overlap matrix from MO-coefficients")
            tdena1.mos.compute_inverse()
            SMO = numpy.dot(tdena1.mos.inv_mo_mat, tdena2.mos.mo_mat)
            if ioptions['lvprt'] >= 2:
                SAO = numpy.dot(tdena1.mos.inv_mo_mat.T, tdena1.mos.inv_mo_mat)
        else:
            SAO  = numpy.array([[float(s) for s in line.split()] for line in open(AO_OV, 'r').readlines()[1:]])
        
            CS  = numpy.dot(tdena1.mos.mo_mat.T, SAO)
            SMO = numpy.dot(CS, tdena2.mos.mo_mat)
        
        if ioptions['lvprt'] >= 2:
            print("AO-overlap matrix:", SAO.shape)
            print(SAO)
            print()
        
            print("MO-overlap matrix:", SMO.shape)
            print(SMO)
            print()
        
        print("        ", end=' ')
        for state2 in tdena2.state_list:
            print("   |%7s>"%state2['name'], end=' ')
        print()
        
        for state1 in tdena1.state_list:
            print("<%7s|"%state1['name'], end=' ')
            tden1 = state1['tden']
            DS1 = numpy.dot(tden1, SMO)
            #print DS1.shape
            mdim = tden1.shape[0]
            SDS1 = numpy.dot(SMO[:mdim,:mdim], DS1)
            #print SDS1.shape
            for state2 in tdena2.state_list:
                #if (not 'mult' in state1 or not 'mult' in state2) or (state1['mult'] == state2['mult']):
                    tden2 = state2['tden']
                    #print tden2.shape
                    OV = sum((SDS1 * tden2).flatten())
                    print(" % .8f"%OV, end=' ')
                #else:
                    #print " % .1f       "%0.,
            print()
class AnalyzeNOs(Action):

    name = 'analyze_nos'

    _colt_description = 'Analysis of natural orbital (NO) files'

    _user_input = """
    # List of NO files in Molden format
    no_files = :: list(existing_file)
    # Input file (optional)
    ifile = dens_ana.in :: file, alias=f
    # Reference MO file for computing AO overlap matrix
    ref = :: existing_file, optional, alias=r
    # Multiply occupations with this factor
    occ_fac = :: float, optional, alias=o
    # Use if unrestricted orbitals are present
    unrestricted = false :: bool, alias=u
    # Interpret energies as occupations
    rd_ene = false :: bool, alias=e
    """

    _lazy_imports = LazyImporter({
            '..theo_header': 'theo_header',
            '..lib_sden': 'lib_sden',
            '..input_options': 'input_options'
    })

    def run(no_files, ifile, ref, occ_fac, unrestricted, rd_ene):
        theo_header.print_header(__class__._colt_description, cfile=__file__)

        # set options
        ioptions = input_options.sden_ana_options(ifile, check_init=False)
        ioptions['rtype'] = 'nos'
        if not occ_fac is None:
            ioptions['occ_fac'] = occ_fac
        ioptions['unrestricted'] = unrestricted
        ioptions['rd_ene'] = rd_ene

        # optionally use a manually specified MO file for computing the AO overlap matrix
        if ref is None:
            ioptions['mo_file'] = no_files[0]
        else:
            ioptions['mo_file'] = ref
        ioptions['ana_files'] = no_files

        #--------------------------------------------------------------------------#        
        # Parsing and computations
        #--------------------------------------------------------------------------#

        sdena = lib_sden.sden_ana(ioptions)
        if unrestricted:
            sdena.read_mos(spin=1)
        else:
            sdena.read_mos()
        sdena.read_dens()

        if unrestricted:
            sdena.compute_all_NO()
        if ioptions['AD_ana']:
            sdena.compute_all_AD()
        if ioptions['pop_ana']:
            sdena.print_all_pop_table()
        if ioptions['BO_ana']:
            sdena.compute_all_BO()
            sdena.print_all_BO()

        sdena.print_summary()
Exemple #23
0
class JMolMOs(Action):

    name = 'jmol_mos'

    _colt_description = 'Orbital plotting in Jmol'

    _user_input = """
    # List of Molden files with orbitals
    mldfiles = :: list(str), optional, alias=f
    """

    _lazy_imports = LazyImporter({
        '..lib_mo': 'lib_mo',
        '..theo_header': 'theo_header',
        '..error_handler': 'error_handler',
        '..input_options': 'input_options',
        '..lib_file': 'lib_file',
    })

    def run(mldfiles):
        theo_header.print_header(__class__._colt_description)

        if mldfiles is None:
            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()

        if jopt['preprocess']:
            jopt.preprocess(mldfiles)
            mldfiles = ['merged.mld']

        jo = lib_file.wfile('jmol_orbitals.spt')
        ho = lib_file.htmlfile('%sorbitals.html' % pref)
        lo = lib_file.latexfile('%sorbitals.tex' % pref)

        ho.pre('Orbitals')
        lo.pre(None, graphicx=True, docclass='{standalone}')

        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,
                                 jopt['eneocc'])
            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)

        ho.post(lvprt=1)
        print("  -> View in browser.")
        lo.post(lvprt=1)
        print("  -> Compile with pdflatex (or adjust first).")

        jo.post(lvprt=1)
        if mldfiles == [""]:
            print(
                "  -> Open the Molden-file in jmol and execute the commands contained in this file."
            )
        else:
            if jopt['run_jmol']:
                import subprocess
                print("Running jmol ...")

                subprocess.call(["jmol", "-n", jo.name])
            else:
                print(
                    "  -> Now simply run \"jmol -n %s\" to plot all the orbitals.\n"
                    % jo)
class DGridPrep(Action):

    name = 'dgrid_prep'

    _colt_description = 'Prepare input for DGrid'

    _user_input = """
    # Molden files
    mldfiles = :: list(existing_file)
    """

    _lazy_imports = LazyImporter({
        '..theo_header': 'theo_header',
        '..input_options': 'input_options'
    })

    def run(mldfiles):

        theo_header.print_header(title=__class__._colt_description)
        print("Using the Molden files:", mldfiles)

        dopt = dgrid_options('dgrid.in')
        dopt.input()

        wfile = open('run_dgrid.bash', 'w')
        wfile.write('#!/bin/bash\n')
        wfile.write('\n###\nDGRID=dgrid\n###\n\n')

        iproc = 0
        for mldfile in mldfiles:
            # adjust the names to be compatible with dgrid
            rind = mldfile.rfind('.')
            basen = mldfile if rind < 0 else mldfile[:rind]
            basen2 = basen.split('/')[-1]
            bfilen = basen + '.md'
            ifilen = basen + '.inp'

            print('\nAnalyzing %s -> %s ...' % (mldfile, bfilen))

            iproc += 1
            if iproc % dopt['nproc'] == 0:
                lend = '|| exit 1'
            else:
                lend = '&'

            wfile.write('echo " *** Running %s ..."\n' % mldfile)
            wfile.write('$DGRID %s && $DGRID %s %s\n' %
                        (mldfile, ifilen, lend))
            wfile.write('ln -s %s.md.rho_r %s.cube\n\n' % (basen, basen2))

            with open(ifilen, 'w') as ifile:
                ifile.write(f""":: dgrid_prep.py
basis={bfilen}
output=.

compute=rho
format=cube
mesh={dopt['msize']:.4f} {dopt['mborder']:.2f}\n""")

        wfile.close()
        print("File run_dgrid.bash written.\n  Run as:\n  bash run_dgrid.bash")
class AnalyzeTden(Action):
    """
    *** This is the docstring for analyze_tden. ***
    analyze_tden is used for analyzing transition density matrices.
    - Charge-transfer numbers
    - Natural transition orbitals
    - Exciton sizes
    """

    name = 'analyze_tden'

    _colt_description = 'Transition density matrix analysis'

    _user_input = """
    # Main input file
    ifile = dens_ana.in :: existing_file, alias=f
    """

    _lazy_imports = LazyImporter({
            '..theo_header': 'theo_header',
            '..lib_tden': 'lib_tden',
            '..lib_exciton': 'lib_exciton',
            '..input_options': 'input_options'
    })

    @timeit
    def run(ifile):
        ioptions = input_options.tden_ana_options(ifile)
        theo_header.print_header(title=__class__._colt_description, ioptions=ioptions, cfile=__name__)

        tdena = lib_tden.tden_ana(ioptions)
        if 'mo_file' in ioptions: tdena.read_mos()

        tdena.read_dens()

        if 'at_lists' in ioptions or ioptions['eh_pop'] >= 1:
            tdena.compute_all_OmAt()

        if 'at_lists' in ioptions:
            tdena.compute_all_OmFrag()
            if ioptions['print_OmFrag']: 
                tdena.fprint_OmFrag()

        if ioptions['comp_ntos']:  
            tdena.compute_all_NTO()
        if ioptions['comp_dntos']: 
            tdena.compute_all_DNTO()
        if ioptions['comp_p_h_dens']: 
            tdena.compute_p_h_dens()
        if ioptions['comp_rho0n']: 
            tdena.compute_rho_0_n()

        if 'RMSeh' in ioptions.get('prop_list') or 'MAeh' in ioptions.get('prop_list') or 'Eb' in ioptions.get('prop_list'):
            exca = lib_exciton.exciton_analysis()
            exca.get_distance_matrix(tdena.struc)
            tdena.analyze_excitons(exca)

        if 'Phe' in ioptions['prop_list']:
            tdena.compute_all_Phe()

        #--------------------------------------------------------------------------#
        # Print-out
        #--------------------------------------------------------------------------#

        tdena.print_all_eh_pop()

        tdena.print_summary()