Beispiel #1
0
def atm_data(spc_dct, spc_name, pes_mod_dct_i, spc_mod_dct_i, run_prefix,
             save_prefix):
    """ Pull all neccessary info for the atom
    """

    spc_dct_i = spc_dct[spc_name]
    # Set up all the filesystem objects using models and levels
    pf_filesystems = filesys.models.pf_filesys(spc_dct_i, spc_mod_dct_i,
                                               run_prefix, save_prefix, False)

    ioprinter.info_message('Obtaining the geometry...', newline=1)
    geom = rot.read_geom(pf_filesystems)

    ioprinter.info_message('Obtaining the electronic energy...', newline=1)
    ene_chnlvl = ene.read_energy(spc_dct_i,
                                 pf_filesystems,
                                 spc_mod_dct_i,
                                 run_prefix,
                                 read_ene=True,
                                 read_zpe=False)

    ene_reflvl = None
    zpe_chnlvl = None

    hf0k, hf0k_trs, _, _ = basis.enthalpy_calculation(spc_dct,
                                                      spc_name,
                                                      ene_chnlvl, {},
                                                      pes_mod_dct_i,
                                                      spc_mod_dct_i,
                                                      run_prefix,
                                                      save_prefix,
                                                      pforktp='ktp',
                                                      zrxn=None)
    ene_chnlvl = hf0k * phycon.KCAL2EH
    hf0k_trs *= phycon.KCAL2EH

    # Create info dictionary
    inf_dct = {
        'geom': geom,
        'sym_factor': 1.0,
        'freqs': tuple(),
        'mess_hr_str': '',
        'mass': util.atom_mass(spc_dct_i),
        'elec_levels': spc_dct_i['elec_levels'],
        'ene_chnlvl': ene_chnlvl,
        'ene_reflvl': ene_reflvl,
        'ene_tsref': hf0k_trs,
        'zpe_chnlvl': zpe_chnlvl
    }

    return inf_dct
Beispiel #2
0
def mol_data(spc_name,
             spc_dct,
             pes_mod_dct_i,
             spc_mod_dct_i,
             chn_basis_ene_dct,
             run_prefix,
             save_prefix,
             calc_chn_ene=True,
             zrxn=None):
    """ Pull all of the neccessary information from the filesystem for a species
    """

    spc_dct_i = spc_dct[spc_name]
    ene_chnlvl = None
    ene_reflvl = None
    zpe = None
    hf0k_trs = None

    # Initialize all of the elements of the inf dct
    geom, sym_factor, freqs, imag, elec_levels = None, None, None, None, None
    allr_str, mdhr_dat = '', ''
    xmat, rovib_coups, rot_dists = None, None, None

    # Set up all the filesystem objects using models and levels
    pf_filesystems = filesys.models.pf_filesys(spc_dct_i,
                                               spc_mod_dct_i,
                                               run_prefix,
                                               save_prefix,
                                               zrxn is not None,
                                               name=spc_name)

    # Obtain rotation partition function information
    ioprinter.info_message('Obtaining info for rotation partition function...',
                           newline=1)
    geom = rot.read_geom(pf_filesystems)

    if typ.nonrigid_rotations(spc_mod_dct_i):
        rovib_coups, rot_dists = rot.read_rotational_values(pf_filesystems)

    # Obtain vibration partition function information
    ioprinter.info_message(
        'Preparing internal rotor info building partition functions...',
        newline=1)
    rotors = tors.build_rotors(spc_dct_i, pf_filesystems, spc_mod_dct_i)
    ioprinter.info_message(
        'Obtaining the vibrational frequencies and zpves...', newline=1)
    freqs, imag, zpe, tors_strs = vib.vib_analysis(spc_dct_i,
                                                   pf_filesystems,
                                                   spc_mod_dct_i,
                                                   run_prefix,
                                                   zrxn=zrxn)
    allr_str = tors_strs[0]

    # ioprinter.info_message('zpe in mol_data test:', zpe)
    if typ.anharm_vib(spc_mod_dct_i):
        xmat = vib.read_anharmon_matrix(pf_filesystems)

    # Obtain symmetry factor
    ioprinter.info_message('Determining the symmetry factor...', newline=1)

    zma = None
    if zrxn:
        [cnf_fs, cnf_save_path, min_cnf_locs, _, _] = pf_filesystems['harm']
        # Build the rotors
        if cnf_save_path:
            zma_fs = autofile.fs.zmatrix(cnf_save_path)
            zma = zma_fs[-1].file.zmatrix.read([0])

    sym_factor = symm.symmetry_factor(pf_filesystems,
                                      spc_mod_dct_i,
                                      spc_dct_i,
                                      rotors,
                                      grxn=zrxn,
                                      zma=zma)

    # Obtain electronic energy levels
    elec_levels = spc_dct_i['elec_levels']

    # Obtain energy levels
    ioprinter.info_message('Obtaining the electronic energy + zpve...',
                           newline=1)
    if calc_chn_ene:
        chn_ene = ene.read_energy(spc_dct_i,
                                  pf_filesystems,
                                  spc_mod_dct_i,
                                  run_prefix,
                                  read_ene=True,
                                  read_zpe=False,
                                  saddle=zrxn is not None)
        ene_chnlvl = chn_ene + zpe

        zma = None
        # Determine info about the basis species used in thermochem calcs
        hf0k, hf0k_trs, chn_basis_ene_dct, _ = basis.enthalpy_calculation(
            spc_dct,
            spc_name,
            ene_chnlvl,
            chn_basis_ene_dct,
            pes_mod_dct_i,
            spc_mod_dct_i,
            run_prefix,
            save_prefix,
            zrxn=zrxn)
        ene_chnlvl = hf0k * phycon.KCAL2EH
        hf0k_trs *= phycon.KCAL2EH

    ene_reflvl = None

    #  Build the energy transfer section strings
    if zrxn is None:
        ioprinter.info_message('Determining energy transfer parameters...',
                               newline=1)
        well_info = sinfo.from_dct(spc_dct_i)
        # ioprinter.debug_message('well_inf', well_info)
        # bath_info = ['InChI=1S/N2/c1-2', 0, 1]  # how to do...
        bath_info = ['InChI=1S/Ar', 0, 1]  # how to do...
        etrans_dct = etrans.build_etrans_dct(spc_dct_i)

        edown_str, collid_freq_str = etrans.make_energy_transfer_strs(
            well_info, bath_info, etrans_dct)
    else:
        edown_str, collid_freq_str = None, None

    # Create info dictionary
    keys = [
        'geom', 'sym_factor', 'freqs', 'imag', 'elec_levels', 'mess_hr_str',
        'mdhr_dat', 'xmat', 'rovib_coups', 'rot_dists', 'ene_chnlvl',
        'ene_reflvl', 'zpe_chnlvl', 'ene_tsref', 'edown_str', 'collid_freq_str'
    ]
    vals = [
        geom, sym_factor, freqs, imag, elec_levels, allr_str, mdhr_dat, xmat,
        rovib_coups, rot_dists, ene_chnlvl, ene_reflvl, zpe, hf0k_trs,
        edown_str, collid_freq_str
    ]
    inf_dct = dict(zip(keys, vals))

    return inf_dct, chn_basis_ene_dct
Beispiel #3
0
def run_tsk(tsk, spc_dct, rxn_lst, thy_dct, print_keyword_dct, model_dct,
            run_prefix, save_prefix):
    """ run an electronic structure task
    for generating a list of conformer or tau sampling geometries
    """

    # Print the head of the task
    ioprinter.output_task_header(tsk)
    ioprinter.obj('line_dash')
    ioprinter.output_keyword_list(print_keyword_dct, thy_dct)

    # Setup csv data dictionary for specific task
    csv_data = util.set_csv_data(tsk)
    chn_basis_ene_dct = {}
    spc_array = []

    # Loop over species to collect task info
    spc_queue = parser.species.build_spc_queue(rxn_lst)
    for spc_name, (pf_model, spc_model) in spc_queue:

        # print species
        ioprinter.obj('line_dash')
        ioprinter.info_message("Species: ", spc_name)

        # If species is unstable, set task to 'none'
        # stable = instab.check_unstable_species(
        #     tsk, spc_dct, spc_name, thy_info, save_prefix)
        # if not stable:
        #     ioprinter.info_message(
        #         'Properties for species {}'.format(spc_name),
        #         'will not be included in output',
        #         'because species is unstable')
        #     continue

        # Heat of formation basis molecules and coefficients
        # is not conformer specific
        if 'coeffs' in tsk:
            pf_levels, pf_models, _, _ = set_pf_info(model_dct, thy_dct,
                                                     pf_model, pf_model)
            thy_info = pf_levels['geo'][1]
            filelabel = 'coeffs'
            filelabel += '_{}'.format(pf_models['ref_scheme'])
            filelabel += '.csv'
            label = spc_name
            basis_dct, uniref_dct = basis.prepare_refs(pf_models['ref_scheme'],
                                                       spc_dct,
                                                       [[spc_name, None]],
                                                       run_prefix, save_prefix)
            # Get the basis info for the spc of interest
            spc_basis, coeff_basis = basis_dct[spc_name]
            coeff_array = []
            for spc_i in spc_basis:
                if spc_i not in spc_array:
                    spc_array.append(spc_i)
            for spc_i in spc_array:
                if spc_i in spc_basis:
                    coeff_array.append(coeff_basis[spc_basis.index(spc_i)])
                else:
                    coeff_array.append(0)
            csv_data[label] = [*coeff_array]

        else:
            # unpack spc and level info
            spc_dct_i = spc_dct[spc_name]
            if print_keyword_dct['geolvl']:
                thy_info = tinfo.from_dct(
                    thy_dct.get(print_keyword_dct['geolvl']))
            else:
                pf_levels, pf_models, _, _ = set_pf_info(
                    model_dct, thy_dct, pf_model, pf_model)
                thy_info = pf_levels['geo'][1]

                # Loop over conformers
            if print_keyword_dct['geolvl']:
                _, rng_cnf_locs_lst, rng_cnf_locs_path = util.conformer_list(
                    print_keyword_dct, save_prefix, run_prefix, spc_dct_i,
                    thy_dct)
                pf_levels, pf_models = None, None
            else:
                pf_levels, pf_models, _, _ = set_pf_info(
                    model_dct, thy_dct, spc_model, spc_model)
                ret = util.conformer_list_from_models(print_keyword_dct,
                                                      save_prefix, run_prefix,
                                                      spc_dct_i, thy_dct,
                                                      pf_levels, pf_models)
                _, rng_cnf_locs_lst, rng_cnf_locs_path = ret
            for locs, locs_path in zip(rng_cnf_locs_lst, rng_cnf_locs_path):

                label = spc_name + '_' + '_'.join(locs)
                _, cnf_fs = filesys.build_fs(run_prefix, save_prefix,
                                             'CONFORMER')
                if 'freq' in tsk:

                    filelabel = 'freq'
                    if pf_levels:
                        filelabel += '_m{}'.format(pf_levels['harm'][0])
                    else:
                        filelabel += '_{}'.format(print_keyword_dct['geolvl'])
                    filelabel += '.csv'

                    if pf_models:
                        pf_filesystems = filesys.models.pf_filesys(
                            spc_dct_i,
                            pf_levels,
                            run_prefix,
                            save_prefix,
                            saddle=False)
                        ret = vib.full_vib_analysis(spc_dct_i,
                                                    pf_filesystems,
                                                    pf_models,
                                                    pf_levels,
                                                    run_prefix,
                                                    saddle=False)
                        freqs, imag, tors_zpe, scale_fact, tors_freqs, all_freqs = ret
                        csv_data['tfreq'][label] = tors_freqs
                        csv_data['allfreq'][label] = all_freqs
                        csv_data['scalefactor'][label] = [scale_fact]
                    else:
                        es_model = util.freq_es_levels(print_keyword_dct)
                        pf_levels = parser.model.pf_level_info(
                            es_model, thy_dct)
                        try:
                            freqs, _, zpe = vib.read_locs_harmonic_freqs(
                                cnf_fs, locs_path, locs, saddle=False)
                        except:
                            freqs = []
                            zpe = 0

                    tors_zpe = 0.0
                    spc_data = []
                    zpe = tors_zpe + (sum(freqs) / 2.0) * phycon.WAVEN2EH
                    if freqs and print_keyword_dct['scale'] is not None:
                        freqs, zpe = vib.scale_frequencies(freqs,
                                                           tors_zpe,
                                                           pf_levels,
                                                           scale_method='3c')
                    spc_data = [locs_path, zpe, *freqs]
                    csv_data['freq'][label] = spc_data
                elif 'geo' in tsk:

                    filelabel = 'geo'
                    if pf_levels:
                        filelabel += '_{}'.format(pf_levels['harm'])
                    else:
                        filelabel += '_{}'.format(print_keyword_dct['geolvl'])
                    filelabel += '.txt'

                    if cnf_fs[-1].file.geometry.exists(locs):
                        geo = cnf_fs[-1].file.geometry.read(locs)
                        energy = cnf_fs[-1].file.energy.read(locs)
                        comment = 'energy: {0:>15.10f}'.format(energy)
                        xyz_str = automol.geom.xyz_string(geo, comment=comment)
                    else:
                        xyz_str = '\t -- Missing --'
                    spc_data = '\n\nSPC: {}\tConf: {}\tPath: {}\n'.format(
                        spc_name, locs, locs_path) + xyz_str

                    csv_data[label] = spc_data

                elif 'zma' in tsk:

                    filelabel = 'zmat'
                    if pf_levels:
                        filelabel += '_{}'.format(pf_levels['harm'])
                    else:
                        filelabel += '_{}'.format(print_keyword_dct['geolvl'])
                    filelabel += '.txt'

                    geo = cnf_fs[-1].file.geometry.read(locs)
                    zma = automol.geom.zmatrix(geo)
                    energy = cnf_fs[-1].file.energy.read(locs)
                    comment = 'energy: {0:>15.10f}\n'.format(energy)
                    zma_str = automol.zmat.string(zma)
                    spc_data = '\n\nSPC: {}\tConf: {}\tPath: {}\n'.format(
                        spc_name, locs, locs_path) + comment + zma_str
                    csv_data[label] = spc_data

                elif 'ene' in tsk:

                    filelabel = 'ene'
                    if pf_levels:
                        filelabel += '_{}'.format(pf_levels['harm'])
                        filelabel += '_{}'.format(pf_levels['ene'])
                    else:
                        filelabel += '_{}'.format(print_keyword_dct['geolvl'])
                        filelabel += '_{}'.format(print_keyword_dct['proplvl'])
                    filelabel += '.csv'

                    energy = None
                    if pf_levels:
                        pf_filesystems = filesys.models.pf_filesys(
                            spc_dct_i,
                            pf_levels,
                            run_prefix,
                            save_prefix,
                            saddle=False)
                        energy = ene.electronic_energy(spc_dct_i,
                                                       pf_filesystems,
                                                       pf_levels,
                                                       conf=(locs, locs_path,
                                                             cnf_fs))
                    else:
                        spc_info = sinfo.from_dct(spc_dct_i)
                        thy_info = tinfo.from_dct(
                            thy_dct.get(print_keyword_dct['proplvl']))
                        mod_thy_info = tinfo.modify_orb_label(
                            thy_info, spc_info)
                        sp_save_fs = autofile.fs.single_point(locs_path)
                        sp_save_fs[-1].create(mod_thy_info[1:4])
                        # Read the energy
                        sp_path = sp_save_fs[-1].path(mod_thy_info[1:4])
                        if os.path.exists(sp_path):
                            if sp_save_fs[-1].file.energy.exists(
                                    mod_thy_info[1:4]):
                                ioprinter.reading('Energy', sp_path)
                                energy = sp_save_fs[-1].file.energy.read(
                                    mod_thy_info[1:4])
                    csv_data[label] = [locs_path, energy]

                elif 'enthalpy' in tsk:
                    filelabel = 'enthalpy'
                    if pf_levels:
                        filelabel += '_{}'.format(pf_levels['harm'])
                        filelabel += '_{}'.format(pf_levels['ene'])
                    else:
                        filelabel += '_{}'.format(print_keyword_dct['geolvl'])
                        filelabel += '_{}'.format(print_keyword_dct['proplvl'])
                    filelabel = '.csv'

                    energy = None
                    pf_filesystems = filesys.models.pf_filesys(spc_dct_i,
                                                               pf_levels,
                                                               run_prefix,
                                                               save_prefix,
                                                               saddle=False)
                    ene_abs = ene.read_energy(spc_dct_i,
                                              pf_filesystems,
                                              pf_models,
                                              pf_levels,
                                              run_prefix,
                                              conf=(locs, locs_path, cnf_fs),
                                              read_ene=True,
                                              read_zpe=True,
                                              saddle=False)
                    ts_geom = None
                    hf0k, _, chn_basis_ene_dct, hbasis = basis.enthalpy_calculation(
                        spc_dct,
                        spc_name,
                        ts_geom,
                        ene_abs,
                        chn_basis_ene_dct,
                        pf_levels,
                        pf_models,
                        run_prefix,
                        save_prefix,
                        pforktp='pf',
                        saddle=False)
                    spc_basis, coeff_basis = hbasis[spc_name]
                    coeff_array = []
                    for spc_i in spc_basis:
                        if spc_i not in spc_array:
                            spc_array.append(spc_i)
                    for spc_i in spc_array:
                        if spc_i in spc_basis:
                            coeff_array.append(
                                coeff_basis[spc_basis.index(spc_i)])
                        else:
                            coeff_array.append(0)
                    csv_data[label] = [locs_path, ene_abs, hf0k, *coeff_array]

    util.write_csv_data(tsk, csv_data, filelabel, spc_array)