Example #1
0
def mol_data(spc_name,
             spc_dct,
             chn_pf_models,
             chn_pf_levels,
             ref_pf_models,
             ref_pf_levels,
             chn_basis_ene_dct,
             run_prefix,
             save_prefix,
             calc_chn_ene=True,
             saddle=False):
    """ 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, chn_pf_levels,
                                               run_prefix, save_prefix, saddle)

    # Set information for transition states
    [cnf_fs, _, min_cnf_locs, _, _] = pf_filesystems['harm']
    # cnf_path = cnf_fs[-1].path(min_cnf_locs)
    frm_bnd_keys, brk_bnd_keys = util.get_bnd_keys(cnf_fs, min_cnf_locs,
                                                   saddle)
    print('bnd keys in mol_data', frm_bnd_keys, brk_bnd_keys)
    rxn_class = util.set_rxn_class(spc_dct_i, saddle)

    # Obtain rotor information used to determine new information
    print('\nPreparing internal rotor info building partition functions...')
    rotors = tors.build_rotors(spc_dct_i,
                               pf_filesystems,
                               chn_pf_models,
                               chn_pf_levels,
                               rxn_class=rxn_class,
                               frm_bnd_keys=frm_bnd_keys,
                               brk_bnd_keys=brk_bnd_keys)
    print('Frm and brk key in model build', frm_bnd_keys, brk_bnd_keys)
    if typ.nonrigid_tors(chn_pf_models, rotors):
        run_path = filesys.models.make_run_path(pf_filesystems, 'tors')
        tors_strs = tors.make_hr_strings(
            rotors,
            run_path,
            chn_pf_models['tors'],
        )
        [allr_str, hr_str, _, prot_str, mdhr_dat] = tors_strs

    # Obtain rotation partition function information
    print('\nObtaining info for rotation partition function...')
    geom = rot.read_geom(pf_filesystems)

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

    # Obtain vibration partition function information
    print('\nObtaining the vibrational frequencies and zpves...')
    if typ.nonrigid_tors(chn_pf_models, rotors):
        # Calculate initial proj. freqs, unproj. imag, tors zpe and scale fact
        freqs, imag, tors_zpe, pot_scalef = vib.tors_projected_freqs_zpe(
            pf_filesystems, hr_str, prot_str, run_prefix, saddle=saddle)
        # Make final hindered rotor strings and get corrected tors zpe
        if typ.scale_1d(chn_pf_models):
            tors_strs = tors.make_hr_strings(rotors,
                                             run_path,
                                             chn_pf_models['tors'],
                                             scale_factor=pot_scalef)
            [allr_str, hr_str, _, prot_str, mdhr_dat] = tors_strs
            _, _, tors_zpe, _ = vib.tors_projected_freqs_zpe(pf_filesystems,
                                                             hr_str,
                                                             prot_str,
                                                             run_prefix,
                                                             saddle=saddle)
            # Calculate current zpe assuming no freq scaling: tors+projfreq
        zpe = tors_zpe + (sum(freqs) / 2.0) * phycon.WAVEN2EH

        # For mdhrv model no freqs needed in MESS input, zero out freqs lst
        if 'mdhrv' in chn_pf_models['tors']:
            freqs = ()
    else:
        freqs, imag, zpe = vib.read_harmonic_freqs(pf_filesystems,
                                                   saddle=saddle)
        tors_zpe = 0.0

    # Scale the frequencies
    if freqs:
        freqs, zpe = vib.scale_frequencies(freqs,
                                           tors_zpe,
                                           chn_pf_levels,
                                           scale_method='3c')

    # print('zpe in mol_data test:', zpe)
    if typ.anharm_vib(chn_pf_models):
        xmat = vib.read_anharmon_matrix(pf_filesystems)

    # Obtain symmetry factor
    print('\nDetermining the symmetry factor...')
    sym_factor = sym.symmetry_factor(pf_filesystems,
                                     chn_pf_models,
                                     spc_dct_i,
                                     rotors,
                                     frm_bnd_keys=frm_bnd_keys,
                                     brk_bnd_keys=brk_bnd_keys)

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

    # Obtain energy levels
    print('\nObtaining the electronic energy + zpve...')
    if calc_chn_ene:
        chn_ene = ene.read_energy(spc_dct_i,
                                  pf_filesystems,
                                  chn_pf_models,
                                  chn_pf_levels,
                                  run_prefix,
                                  read_ene=True,
                                  read_zpe=False,
                                  saddle=saddle)
        print('zpe in models build ', zpe)
        print('elec ene in models build ', chn_ene)
        ene_chnlvl = chn_ene + zpe
        print('ene_chnlvl: ', ene_chnlvl)

        ref_scheme = chn_pf_models['ref_scheme']
        ref_enes = chn_pf_models['ref_enes']

        zma = None
        if saddle:
            cnf_path = cnf_fs[-1].path(min_cnf_locs)
            zma_fs = autofile.fs.manager(cnf_path, 'ZMATRIX')
            zma = zma_fs[-1].file.zmatrix.read((0, ))

        # Determine info about the basis species used in thermochem calcs
        basis_dct, uniref_dct = basis.prepare_refs(ref_scheme,
                                                   spc_dct, [[spc_name, None]],
                                                   ts_geom=(geom, zma,
                                                            brk_bnd_keys,
                                                            frm_bnd_keys))

        print('basis_dct test in mol_data:', basis_dct)

        # Get the basis info for the spc of interest
        spc_basis, coeff_basis = basis_dct[spc_name]

        print('spc_basis test in mol_data:', spc_basis)
        ene_spc = ene_chnlvl
        ene_basis = []
        energy_missing = False
        for spc_basis_i in spc_basis:
            if not isinstance(spc_basis_i, str):
                basreacs, basprods = spc_basis_i
                spc_basis_i = ''
                for entry in basreacs:
                    spc_basis_i += entry
                for entry in basprods:
                    spc_basis_i += entry
            if spc_basis_i in chn_basis_ene_dct:
                print('Energy already found for basis species: ', spc_basis_i)
                ene_basis.append(chn_basis_ene_dct[spc_basis_i])
            else:
                print('Energy will be determined for basis species: ',
                      spc_basis_i)
                energy_missing = True

        # Get the energies for the spc and its basis
        if energy_missing:
            _, ene_basis = basis.basis_energy(spc_name, spc_basis, uniref_dct,
                                              spc_dct, chn_pf_levels,
                                              chn_pf_models, run_prefix,
                                              save_prefix)
            for spc_basis_i, ene_basis_i in zip(spc_basis, ene_basis):
                if not isinstance(spc_basis_i, str):
                    basreacs, basprods = spc_basis_i
                    spc_basis_i = ''
                    for entry in basreacs:
                        spc_basis_i += entry
                    for entry in basprods:
                        spc_basis_i += entry
                chn_basis_ene_dct[spc_basis_i] = ene_basis_i
        print('ene from thmroutines: ', ene_spc)

        # Calculate and store the 0 K Enthalpy
        hf0k = heatform.calc_hform_0k(ene_spc,
                                      ene_basis,
                                      spc_basis,
                                      coeff_basis,
                                      ref_set=ref_enes)

        #if rxn_class in basis.IMPLEMENTED_CBH_TS_CLASSES:
        #    ts_ref_scheme = 'cbh0'
        #else:
        #    ts_ref_scheme = None
        if 'basic' in ref_scheme:
            ts_ref_scheme = 'basic'
        else:
            ts_ref_scheme = 'cbh0'
            if '_' in ref_scheme:
                ts_ref_scheme = 'cbh' + ref_scheme.split('_')[1]
        print('ts_ref_scheme test:', ts_ref_scheme)
        if not saddle:
            if ref_scheme != ts_ref_scheme:
                basis_dct_trs, uniref_dct_trs = basis.prepare_refs(
                    ts_ref_scheme,
                    spc_dct, [[spc_name, None]],
                    ts_geom=(geom, brk_bnd_keys, frm_bnd_keys))
                spc_basis_trs, coeff_basis_trs = basis_dct_trs[spc_name]
                ene_basis_trs = []
                energy_missing = False
                for spc_basis_i in spc_basis_trs:
                    if spc_basis_i in chn_basis_ene_dct:
                        print('Energy already found for basis species: ',
                              spc_basis_i)
                        ene_basis_trs.append(chn_basis_ene_dct[spc_basis_i])
                    else:
                        print('Energy will be determined for basis species: ',
                              spc_basis_i)
                        energy_missing = True
                if energy_missing:
                    _, ene_basis_trs = basis.basis_energy(
                        spc_name, spc_basis_trs, uniref_dct_trs, spc_dct,
                        chn_pf_levels, chn_pf_models, run_prefix, save_prefix)
                    for spc_basis_i, ene_basis_i in zip(
                            spc_basis_trs, ene_basis_trs):
                        chn_basis_ene_dct[spc_basis_i] = ene_basis_i
                ene_spc_trs = ene_chnlvl
                hf0K_trs = heatform.calc_hform_0k(ene_spc_trs,
                                                  ene_basis_trs,
                                                  spc_basis_trs,
                                                  coeff_basis_trs,
                                                  ref_set=ref_enes)
            else:
                hf0K_trs = hf0k
        else:
            hf0K_trs = 0.0

        print('ABS Energy: ', ene_chnlvl)
        print('Hf0K Energy: ', hf0k * phycon.KCAL2KJ)
        ene_chnlvl = hf0k * phycon.KCAL2EH
        hf0K_trs *= phycon.KCAL2EH

    ene_reflvl = None
    _, _ = ref_pf_models, ref_pf_levels
    # if chn_model == ref_model:
    #     ene_reflvl = ene_chnlvl
    # else:
    #     ene_reflvl = get_fs_ene_zpe(spc_dct, prod,
    #                                 thy_dct, model_dct, model,
    #                                 save_prefix, saddle=False,
    #                                 read_ene=True, read_zpe=True)

    #  Build the energy transfer section strings
    if not saddle:
        print('\n Determining energy transfer parameters...')
        well_info = filesys.inf.get_spc_info(spc_dct_i)
        print('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
Example #2
0
def tau_data(spc_dct_i,
             chn_pf_models,
             chn_pf_levels,
             run_prefix,
             save_prefix,
             saddle=False):
    """ Read the filesystem to get information for TAU
    """

    frm_bnd_keys = ()
    brk_bnd_keys = ()

    # Set up all the filesystem objects using models and levels
    pf_filesystems = filesys.models.pf_filesys(spc_dct_i, chn_pf_levels,
                                               run_prefix, save_prefix, saddle)
    [harm_cnf_fs, _, harm_min_locs, harm_save, _] = pf_filesystems['harm']
    # [tors_cnf_fs, _, tors_min_locs, _, _] = pf_filesystems['tors']

    # Get the conformer filesys for the reference geom and energy
    if harm_min_locs:
        geom = harm_cnf_fs[-1].file.geometry.read(harm_min_locs)
        min_ene = harm_cnf_fs[-1].file.energy.read(harm_min_locs)

    # Set the filesystem
    tau_save_fs = autofile.fs.tau(harm_save)

    # Set the ground and reference energy to set values for now
    rxn_class = None

    # Get the rotor info
    rotors = tors.build_rotors(spc_dct_i,
                               pf_filesystems,
                               chn_pf_models,
                               chn_pf_levels,
                               rxn_class=rxn_class,
                               frm_bnd_keys=frm_bnd_keys,
                               brk_bnd_keys=brk_bnd_keys)

    run_path = filesys.models.make_run_path(pf_filesystems, 'tors')
    tors_strs = tors.make_hr_strings(rotors, run_path, chn_pf_models['tors'])
    [_, hr_str, flux_str, prot_str, _] = tors_strs

    # Use model to determine whether to read grads and hessians
    vib_model = chn_pf_models['vib']
    freqs = ()
    _, _, proj_zpve, harm_zpve = vib.tors_projected_freqs_zpe(pf_filesystems,
                                                              hr_str,
                                                              prot_str,
                                                              run_prefix,
                                                              saddle=False)
    zpe_chnlvl = proj_zpve * phycon.EH2KCAL

    # Set reference energy to harmonic zpve
    db_style = 'directory'
    reference_energy = harm_zpve * phycon.EH2KCAL
    if vib_model == 'tau':
        if db_style == 'directory':
            tau_locs = [
                locs for locs in tau_save_fs[-1].existing()
                if tau_save_fs[-1].file.hessian.exists(locs)
            ]
        elif db_style == 'jsondb':
            tau_locs = [
                locs for locs in tau_save_fs[-1].json_existing()
                if tau_save_fs[-1].json.hessian.exists(locs)
            ]
    else:
        if db_style == 'directory':
            tau_locs = tau_save_fs[-1].existing()
        elif db_style == 'jsondb':
            tau_locs = tau_save_fs[-1].json_existing()

    # Read the geom, ene, grad, and hessian for each sample
    samp_geoms, samp_enes, samp_grads, samp_hessians = [], [], [], []
    for locs in tau_locs:

        # print('Reading tau info at path {}'.format(
        #     tau_save_fs[-1].path(locs)))

        if db_style == 'directory':
            geo = tau_save_fs[-1].file.geometry.read(locs)
        elif db_style == 'jsondb':
            geo = tau_save_fs[-1].json.geometry.read(locs)

        geo_str = autofile.data_types.swrite.geometry(geo)
        samp_geoms.append(geo_str)

        if db_style == 'directory':
            tau_ene = tau_save_fs[-1].file.energy.read(locs)
        elif db_style == 'jsondb':
            tau_ene = tau_save_fs[-1].json.energy.read(locs)
        rel_ene = (tau_ene - min_ene) * phycon.EH2KCAL
        ene_str = autofile.data_types.swrite.energy(rel_ene)
        samp_enes.append(ene_str)

        if vib_model == 'tau':
            if db_style == 'directory':
                grad = tau_save_fs[-1].file.gradient.read(locs)
            elif db_style == 'jsondb':
                grad = tau_save_fs[-1].json.gradient.read(locs)
            grad_str = autofile.data_types.swrite.gradient(grad)
            samp_grads.append(grad_str)

            if db_style == 'directory':
                hess = tau_save_fs[-1].file.hessian.read(locs)
            elif db_style == 'jsondb':
                hess = tau_save_fs[-1].json.hessian.read(locs)
            hess_str = autofile.data_types.swrite.hessian(hess)
            samp_hessians.append(hess_str)

    # Read a geometry, grad, and hessian for a reference geom if needed
    ref_geom, ref_grad, ref_hessian = [], [], []
    if vib_model != 'tau':

        # Get harmonic filesystem information
        [harm_save_fs, _, harm_min_locs, _, _] = pf_filesystems['harm']

        # Read the geometr, gradient, and Hessian
        geo = harm_save_fs[-1].file.geometry.read(harm_min_locs)
        geo_str = autofile.data_types.swrite.geometry(geo)
        ref_geom.append(geo_str)

        grad = harm_save_fs[-1].file.gradient.read(harm_min_locs)
        grad_str = autofile.data_types.swrite.gradient(grad)
        ref_grad.append(grad_str)

        hess = harm_save_fs[-1].file.hessian.read(harm_min_locs)
        hess_str = autofile.data_types.swrite.hessian(hess)
        ref_hessian.append(hess_str)

    # Obtain symmetry factor
    print('\nDetermining the symmetry factor...')
    sym_factor = sym.symmetry_factor(pf_filesystems,
                                     chn_pf_models,
                                     spc_dct_i,
                                     rotors,
                                     frm_bnd_keys=(),
                                     brk_bnd_keys=())

    # Create info dictionary
    keys = [
        'geom', 'sym_factor', 'elec_levels', 'freqs', 'flux_mode_str',
        'samp_geoms', 'samp_enes', 'samp_grads', 'samp_hessians', 'ref_geom',
        'ref_grad', 'ref_hessian', 'zpe_chnlvl', 'reference_energy'
    ]
    vals = [
        geom, sym_factor, spc_dct_i['elec_levels'], freqs, flux_str,
        samp_geoms, samp_enes, samp_grads, samp_hessians, ref_geom, ref_grad,
        ref_hessian, zpe_chnlvl, reference_energy
    ]
    inf_dct = dict(zip(keys, vals))

    return inf_dct
Example #3
0
def zero_point_energy(spc_dct_i,
                      pf_filesystems, pf_models, pf_levels, run_prefix, saddle=False):
    """ compute the ZPE including torsional and anharmonic corrections
    """

    print('- Calculating zero-point energy')

    # spc_dct_i = spc_dct[spc_name]
    [cnf_fs, _, min_cnf_locs, _, _] = pf_filesystems['harm']
    frm_bnd_keys, brk_bnd_keys = util.get_bnd_keys(
        cnf_fs, min_cnf_locs, saddle)
    # frm_bnd_keys, brk_bnd_keys = util.get_bnd_keys(spc_dct_i, saddle)
    rxn_class = util.set_rxn_class(spc_dct_i, saddle)

    # Calculate ZPVE
    is_atom = False
    if not saddle:
        if typ.is_atom(spc_dct_i):
            is_atom = True
    if is_atom:
        zpe = 0.0
    else:
        rotors = tors.build_rotors(
            spc_dct_i, pf_filesystems, pf_models, pf_levels,
            rxn_class=rxn_class,
            frm_bnd_keys=frm_bnd_keys, brk_bnd_keys=brk_bnd_keys)

        if typ.nonrigid_tors(pf_models, rotors):
            run_path = fmod.make_run_path(pf_filesystems, 'tors')
            tors_strs = tors.make_hr_strings(
                rotors, run_path, pf_models['tors'],
                )
            [_, hr_str, _, prot_str, _] = tors_strs

        if typ.nonrigid_tors(pf_models, rotors):
            # Calculate init proj. freqs, unproj. imag, tors zpe and scale fact
            freqs, _, tors_zpe, pot_scalef = vib.tors_projected_freqs_zpe(
                pf_filesystems, hr_str, prot_str, run_prefix, saddle=saddle)
            # Make final hindered rotor strings and get corrected tors zpe
            if typ.scale_1d(pf_models):
                tors_strs = tors.make_hr_strings(
                    rotors, run_path, pf_models['tors'],
                    scale_factor=pot_scalef)
                [_, hr_str, _, prot_str, _] = tors_strs
                _, _, tors_zpe, _ = vib.tors_projected_freqs_zpe(
                    pf_filesystems, hr_str, prot_str, run_prefix, saddle=saddle)
                # Calculate current zpe assuming no freq scaling: tors+projfreq
            zpe = tors_zpe + (sum(freqs) / 2.0) * phycon.WAVEN2EH

            # For mdhrv model no freqs needed in MESS input, zero out freqs lst
            if 'mdhrv' in pf_models['tors']:
                freqs = ()
        else:
            freqs, _, zpe = vib.read_harmonic_freqs(
                pf_filesystems, saddle=saddle)
            tors_zpe = 0.0

        # Scale the frequencies
        if freqs:
            freqs, zpe = vib.scale_frequencies(
                freqs, tors_zpe, pf_levels, scale_method='3c')

        # print('zpe in zero_point_energy test:', zpe, freqs)
    return zpe