Exemple #1
0
def pes_dictionary(mech_str, mech_type, spc_dct):
    """ Constructs the Potential-Energy-Surface dictionary for all of the
        channels of the user input utilizing the sorter functionality
        from mechanalyzer. Currently, we sort just via PES and then SUB-PES.

        Format: {(formula, pes idx, sub pes idx): ((chnl_idx, rcts, prds),)

        Also, currently prints the PES channels.

        :param mech_str: mechanism.dat input file string
        :type mech_str: str
        :param mech_type:
        :type mech_type: str
        :param spc_dct:
        :type spc_dct: dict[str: ____]
        :rtype: dict[tuple(str, int, int)] = tuple(int, tuple(str))
    """

    # Initialize values used for the basic PES-SUBPES sorting
    sort_str = ['pes', 'subpes', 0]
    isolate_species = ()

    # Build and print the full sorted PES dict
    _, mech_info, _ = parse_mechanism(mech_str, mech_type, spc_dct)
    srt_mch = sorter.sorting(mech_info, spc_dct, sort_str, isolate_species)
    pes_dct = srt_mch.return_pes_dct()

    pes.print_pes_channels(pes_dct)

    return pes_dct
Exemple #2
0
def pes_dictionary(mech_str, mech_type, spc_dct, printlog=True):
    """ Constructs the Potential-Energy-Surface dictionary for all of the
        channels of the user input utilizing the sorter functionality
        from mechanalyzer. Currently, we sort just via PES and then SUB-PES.

        Also, currently prints the PES channels.

        :param mech_str: mechanism.dat input file string
        :type mech_str: str
        :param mech_type: format of the mechanism string
        :type mech_type: str
        :param spc_dct: info for mechanism species and transition states
        :type spc_dct: mechdriver.spc_dct object
        :rtype: mechanalyer.pes.pes_dct object
    """

    def _fix_formula(pes_dct, spc_dct):
        """ have to fix fml since it is not parsed from file
        """
        new_pes_dct = {}
        for (_, pes_idx, subpes_idx), chnls in pes_dct.items():
            rcts = chnls[0][1][0]
            rct_ichs = tuple(spc_dct[rct]['inchi'] for rct in rcts)
            rct_ich = automol.inchi.join(rct_ichs)
            fml = automol.formula.string(automol.inchi.formula(rct_ich))
            new_pes_dct[(fml, pes_idx, subpes_idx)] = chnls
        return new_pes_dct

    # Initialize values used for the basic PES-SUBPES sorting
    sort_str = ['pes', 'subpes', 0]
    isolate_species = ()

    # Build and print the full sorted PES dict
    pes_dct = None
    if mech_str is not None:

        # Try and just read a PES dictionary from a file
        pes_dct = parse_pes_dct(mech_str)

        # If that fails then try and read a file normally and sort it
        if pes_dct is None:
            _, mech_info, _ = parse_mechanism(mech_str, mech_type, spc_dct)
            if mech_info is not None:
                srt_mch = sorter.sorting(
                    mech_info, spc_dct, sort_str, isolate_species)
                pes_dct = srt_mch.return_pes_dct()
        else:
            pes_dct = _fix_formula(pes_dct, spc_dct)
            print('Building PES dictionary from input file specification')

    if pes_dct is not None:
        if printlog:
            pes.print_pes_channels(pes_dct)

    return pes_dct
def test_sort_ktp():
    """ test mechanalyzer.parser.sort

        sort ktp dictionary according to highest rate values/ratios
    """
    results = {
        (('H2', 'O'), ('OH', 'H'), (None,)): '2.73e+149.2.27e+01',
        (('H', 'O'), ('OH',), ('(+M)',)): '2.73e+149.4.62e-16',
        (('H', 'O'), ('OH',), (None,)): '2.73e+149.3.97e-39',
        (('H', 'O2'), ('OH', 'O'), (None,)): '2.73e+149.1.30e-89',
        (('H2', 'O'), ('OH', 'OH'), (None,)): '2.73e+149.0.00e+00',
        (('H2', 'O2'), ('HO2V', 'H'), (None,)): '2.73e+149.0.00e+00',
        (('H2', 'O(S)'), ('OH', 'H'), (None,)): '4.80e+143.0.00e+00'
    }

    # Read mechanism files into strings
    spc_paths = [
        os.path.join(CWD, 'data', 'spc2.csv'),
        os.path.join(CWD, 'data', 'spc1.csv')]
    mech_path = None
    sort_path = None

    spc_str, _, _ = _read_files(spc_paths[1], mech_path, sort_path)

    # Build spc and mech information
    spc_dct_full = sparser.build_spc_dct(spc_str, SPC_TYPE)
    mech_info = mparser.mech_info(AL_KTP_DCT, spc_dct_full)

    # Sort the mechanism
    isolate_spc = []
    sort_lst = ['rxn_max_vals', 'rxn_max_ratio', 0]

    srt_mch = sorter.sorting(
        mech_info, spc_dct_full, sort_lst, isolate_spc)
    sorted_idx, cmts_dct, _ = srt_mch.return_mech_df()
    al_ktp_dct_sorted = sorter.reordered_mech(AL_KTP_DCT, sorted_idx)
    print('ktp dct sorted by max val and ratios test:')
    assert al_ktp_dct_sorted.keys() == results.keys()
    newdct = dict.fromkeys(al_ktp_dct_sorted.keys())
    for rxn in al_ktp_dct_sorted.keys():
        newdct[rxn] = cmts_dct[rxn]['cmts_inline'].split('ratio')[1].strip()

    assert newdct == results
    print('ok')
Exemple #4
0
def pes_dictionary(mech_str, mech_type, spc_dct):
    """ Build the PES dct

        Right now just resorts by pes and subpes, may need full suite later.
    """

    # Initialize values used for the basic PES-SUBPES sorting
    sort_str = ['pes', 'subpes', 0]
    isolate_species = ()

    # Build and print the full sorted PES dict
    _, mech_info, _ = parse_mechanism(mech_str, mech_type, spc_dct)
    srt_mch = sorter.sorting(mech_info, spc_dct, sort_str, isolate_species)
    pes_dct = srt_mch.return_pes_dct()

    pes.print_pes_channels(pes_dct)

    # return pes_dct, spc_dct
    return pes_dct
                 '--output',
                 default='surface.pdf',
                 help='name of output plot file (surface.pdf)')
OPTS = vars(PAR.parse_args())

# Parse the input based on the initial type
INP_SPC_STR = ioformat.pathtools.read_file(CWD, 'species.csv')
INP_MECH_STR = ioformat.pathtools.read_file(CWD, 'mechanism.dat')
if INP_SPC_STR is None and INP_MECH_STR is None:
    print('ERROR: Input species.csv or mechanism.dat not found')
    sys.exit()

# Parse the mechanism file
MECH_SPC_DCT = mechanalyzer.parser.spc.build_spc_dct(INP_SPC_STR, 'csv')
_, mech_info, _ = parse_mechanism(INP_MECH_STR, 'chemkin', MECH_SPC_DCT)
srt_mch = sorter.sorting(mech_info, MECH_SPC_DCT, ['pes', 'subpes', 0], ())
pes_dct = srt_mch.return_pes_dct()

# Grab the channels of the PES dct that was requested
PES = OPTS['pes']
[PESNUM, SUBPESNUM] = PES.split('_')
PESNUM, SUBPESNUM = int(PESNUM), int(SUBPESNUM)
print(f'Plotting PES-SubPES: {PESNUM}-{SUBPESNUM}')

CHNLS = ()
for (form, pidx, sidx), chnls in pes_dct.items():
    if pidx == PESNUM - 1 and sidx == SUBPESNUM - 1:
        CHNLS = chnls
        break
SPC_ICHS, SPC_NAMES = (), ()
CONN_LST = ()