예제 #1
0
def test__transition_state():
    """ test thermfit.._basis.prepare_basis
    """

    ref_dct1 = {
        'ts_1_1_1': (
            ('InChI=1S/H2/h1H', 'InChI=1S/CH4/h1H4', 'InChI=1S/H2O/h1H2'),
            numpy.array([-7.5,  7.0,  2.0])
        )
    }
    ref_dct2 = {
        'ts_1_1_1': (
            ['InChI=1S/CH4/h1H4', 'InChI=1S/H2O/h1H2',
             (('InChI=1S/CH3/h1H3', 'InChI=1S/H2O/h1H2'),
              ('InChI=1S/CH4/h1H4', 'InChI=1S/HO/h1H')),
             'InChI=1S/H2/h1H'],
            [6.0, 1.0, 1.0, -7.0]
        )
    }
    ref_dct3 = {
        'ts_1_1_1': (
            ['InChI=1S/CH4O/c1-2/h2H,1H3', 'InChI=1S/C2H6/c1-2/h1-2H3',
             (('InChI=1S/CH3/h1H3', 'InChI=1S/H2O2/c1-2/h1-2H'),
              ('InChI=1S/CH4/h1H4', 'InChI=1S/HO2/c1-2/h1H')),
             (('InChI=1S/C2H5/c1-2/h1H2,2H3', 'InChI=1S/H2O/h1H2'),
              ('InChI=1S/C2H6/c1-2/h1-2H3', 'InChI=1S/HO/h1H')),
             'InChI=1S/CH4/h1H4', 'InChI=1S/H2O/h1H2',
             (('InChI=1S/CH3/h1H3', 'InChI=1S/H2O/h1H2'),
              ('InChI=1S/CH4/h1H4', 'InChI=1S/HO/h1H'))],
            [1.0, 3.0, 1.0, 2.0, -3, -1, -2]
        )
    }
    ref_dct4 = {
        'ts_1_1_1': (
            ['InChI=1S/CH4/h1H4', 'InChI=1S/H2O/h1H2',
             (('InChI=1S/CH3/h1H3', 'InChI=1S/H2O/h1H2'),
              ('InChI=1S/CH4/h1H4', 'InChI=1S/HO/h1H')),
             'InChI=1S/H2/h1H'],
            [6.0, 1.0, 1.0, -7.0]
        )
    }

    dct1 = thermfit.prepare_basis(
        'basic', SPC_DCT, TS_NAMES,
        nprocs='auto', print_log=False, zrxn=HABS_ZRXN)
    dct2 = thermfit.prepare_basis(
        'cbh0', SPC_DCT, TS_NAMES,
        nprocs='auto', print_log=False, zrxn=HABS_ZRXN)
    dct3 = thermfit.prepare_basis(
        'cbh1', SPC_DCT, TS_NAMES,
        nprocs='auto', print_log=False, zrxn=HABS_ZRXN)
    dct4 = thermfit.prepare_basis(
        'cbh1_0', SPC_DCT, TS_NAMES,
        nprocs='auto', print_log=False, zrxn=HABS_ZRXN)

    _check_dct(ref_dct1, dct1)
    _check_dct(ref_dct2, dct2)
    _check_dct(ref_dct3, dct3)
    _check_dct(ref_dct4, dct4)
예제 #2
0
def test__species():
    """ test thermfit.._basis.prepare_basis
    """

    ref_dct1 = {
        'C2H6': (
            ('InChI=1S/H2/h1H', 'InChI=1S/CH4/h1H4'),
            numpy.array([-1.,  2.])
        )
    }

    dct1 = thermfit.prepare_basis(
        'basic', SPC_DCT, SPC_NAMES,
        nprocs='auto', print_log=False, zrxn=None)

    _check_dct(ref_dct1, dct1)
예제 #3
0
def add_heat_of_formation_basis(spc_dct,
                                ref_schemes=('cbh0', 'cbh1', 'cbh2'),
                                nprocs='auto'):
    """ Adds all species required to form the basis set for requested CBHn
        heat-of-formation calculations for all species in the mechanism
        species dictionary.

        Function will loop over all species in the input dictionary,
        determine the basis and check if each basis currently in dictionary.

        If species is missing it is assigned a name:
        cbh{N}_{smiles} where smiles is the smiles string, and N is the
        lowest order cbh scheme for which a basis species was found.
    """
    def _filter_redundant_basis(cbh_ref_dct, ref_scheme, cbh_smiles):
        """ Get only spc of cbh_ref_dct that have smiles not already added
            to spc_dctfrom earlier CBHn schemes
        """
        new_dct = {}
        for dct in cbh_ref_dct.values():
            tempn_smiles = automol.inchi.smiles(dct['inchi'])
            if tempn_smiles not in cbh_smiles:
                # Add to new dictionry
                tempn = ref_scheme + '_' + tempn_smiles
                new_dct[tempn] = dct
                new_dct[tempn]['smiles'] = tempn_smiles
                # Add smiles to new smiles bookkeeping list
                cbh_smiles.append(tempn_smiles)

        return new_dct, cbh_smiles

    # Find all references
    cbh_smiles = []
    for ref_scheme in ref_schemes:
        basis_dct = thermfit.prepare_basis(ref_scheme,
                                           spc_dct,
                                           tuple(spc_dct.keys()),
                                           nprocs=nprocs,
                                           print_log=True)
        uniref_dct = thermfit.unique_basis_species(basis_dct, spc_dct)
        nonred_dct, cbh_smiles = _filter_redundant_basis(
            uniref_dct, ref_scheme, cbh_smiles)
        spc_dct.update(nonred_dct)

    return spc_dct
예제 #4
0
def get_heats_of_formation(spc_locs_dct, spc_dct, spc_mods, spc_mod_dct,
                           ref_scheme, ref_enes, run_prefix, save_prefix):
    """ gather the hof
    """
    chn_basis_ene_dct = {}
    # Determine info about the basis species used in thermochem calcs
    for spc_mod in spc_mods:
        spc_mod = spc_mods[0]
        spc_mod_dct_i = spc_mod_dct[spc_mod]
        chn_basis_ene_dct[spc_mod] = {}
        basis_dct = thermfit.prepare_basis(ref_scheme, spc_dct,
                                           (*spc_locs_dct.keys(), ))
        uniref_dct = thermfit.unique_basis_species(basis_dct, spc_dct)
        # uniich_lst = [uniref_dct[key]['inchi'] for key in uniref_dct]
        basis_ichs = []
        for parent_spc_name in basis_dct:
            for basis_spc_name in basis_dct[parent_spc_name][0]:
                if basis_spc_name not in basis_ichs:
                    basis_ichs.append(basis_spc_name)
        _, ene_basis = thmbasis.basis_energy(None,
                                             basis_ichs,
                                             uniref_dct,
                                             spc_dct,
                                             spc_mod_dct_i,
                                             run_prefix,
                                             save_prefix,
                                             read_species=False)
        for spc_basis_i, ene_basis_i in zip(basis_ichs, ene_basis):
            chn_basis_ene_dct[spc_mod][spc_basis_i] = ene_basis_i

    for spc_name in spc_locs_dct:
        for idx, spc_locs in enumerate(spc_locs_dct[spc_name]):
            spc_locs = tuple(spc_locs)
            for spc_mod in spc_mods:
                # Take species model and add it to the chn_basis_ene dct
                spc_mod = spc_mods[0]
                spc_mod_dct_i = spc_mod_dct[spc_mod]
                hf0k, chn_basis_ene_dct = _get_heat_of_formation(
                    spc_name, spc_dct, spc_mod, spc_locs, spc_mod_dct_i,
                    basis_dct, ref_enes, chn_basis_ene_dct, run_prefix,
                    save_prefix)
                spc_dct = _add_hf_to_spc_dct(hf0k, spc_dct, spc_name, idx,
                                             spc_mod)
    return spc_dct
예제 #5
0
def coeffs(spc_name, spc_dct, model_dct, spc_array):
    """ get the heat of formation reference molecules for one species.
    """

    spc_dct_i = spc_dct[spc_name]
    zrxn = spc_dct_i.get('zrxn')

    basis_dct = thermfit.prepare_basis(model_dct['therm_fit']['ref_scheme'],
                                       spc_dct, (spc_name, ),
                                       zrxn=zrxn)
    # 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)
    return [*coeff_array], spc_array
예제 #6
0
def enthalpy_calculation(spc_dct,
                         spc_name,
                         ene_chnlvl,
                         chn_basis_ene_dct,
                         pes_mod_dct_i,
                         spc_mod_dct_i,
                         run_prefix,
                         save_prefix,
                         pforktp='ktp',
                         zrxn=None):
    """ Calculate the Enthalpy.
    """

    ref_scheme = pes_mod_dct_i['therm_fit']['ref_scheme']
    ref_enes = pes_mod_dct_i['therm_fit']['ref_enes']

    basis_dct = thermfit.prepare_basis(ref_scheme,
                                       spc_dct, (spc_name, ),
                                       zrxn=zrxn)
    uniref_dct = thermfit.unique_basis_species(basis_dct, spc_dct)

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

    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 = ''.join(basreacs)
            spc_basis_i += ''.join(basprods)
        if spc_basis_i in chn_basis_ene_dct:
            ioprinter.debug_message('Energy already found for basis species: ',
                                    spc_basis_i)
            ene_basis.append(chn_basis_ene_dct[spc_basis_i])
        else:
            ioprinter.debug_message(
                '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_energy(spc_name,
                                    spc_basis,
                                    uniref_dct,
                                    spc_dct,
                                    spc_mod_dct_i,
                                    run_prefix,
                                    save_prefix,
                                    read_species=False)
        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 = ''.join(basreacs)
                spc_basis_i += ''.join(basprods)
            chn_basis_ene_dct[spc_basis_i] = ene_basis_i

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

    if pforktp == 'ktp':
        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]
        if zrxn is None:
            if ref_scheme != ts_ref_scheme:
                basis_dct_trs = thermfit.prepare_basis(ts_ref_scheme,
                                                       spc_dct, (spc_name, ),
                                                       zrxn=zrxn)
                uniref_dct_trs = thermfit.unique_basis_species(
                    basis_dct_trs, spc_dct)

                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:
                        ioprinter.info_message(
                            'Energy already found for basis species: ',
                            spc_basis_i)
                        ene_basis_trs.append(chn_basis_ene_dct[spc_basis_i])
                    else:
                        ioprinter.info_message(
                            'Energy will be determined for basis species: ',
                            spc_basis_i)
                        energy_missing = True
                if energy_missing:
                    _, ene_basis_trs = basis_energy(spc_name,
                                                    spc_basis_trs,
                                                    uniref_dct_trs,
                                                    spc_dct,
                                                    spc_mod_dct_i,
                                                    run_prefix,
                                                    save_prefix,
                                                    read_species=False)
                    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 = thermfit.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
    else:
        hf0k_trs = None
    ioprinter.info_message('ABS Energy  (hart): ', ene_chnlvl)
    ioprinter.info_message('Hf0K Energy (hart): ', hf0k * phycon.KCAL2KJ)

    return hf0k, hf0k_trs, chn_basis_ene_dct, basis_dct