Esempio n. 1
0
def read_class_dct(job_path):
    """ Read the class dictionary
    """
    cla_str = ptt.read_inp_str(job_path, CLA_INP)
    cla_str = cla_str if cla_str else 'REACTION,RCLASS\nEND'
    cla_dct = chemkin_io.parser.mechanism.reac_class_dct(cla_str, 'class')

    return cla_dct
Esempio n. 2
0
def read_es_tsks(job_path):
    """ Build a dictionary for all the theory keywords
    """
    run_str = ptt.read_inp_str(job_path, RUN_INP)
    es_tsks_str = es_tsks_block(run_str)
    assert es_tsks_str

    return es_tsks_str
Esempio n. 3
0
def build_run_jobs_lst(job_path):
    """ Build a dictionary for all the theory keywords
    """
    job_str = ptt.read_inp_str(job_path, RUN_INP)
    keyword_lst = ptt.build_keyword_lst(jobs_block(job_str))
    assert keyword_lst
    # assert check_run_keyword_dct(keyword_dct)

    return keyword_lst
Esempio n. 4
0
def build_spc_dct(job_path, spc_type):
    """ Get a dictionary of all the input species
        indexed by InChi string
    """
    spc_csv_str = ptt.read_inp_str(job_path, CSV_INP)
    if spc_type == 'csv':
        spc_dct = csv_dct(spc_csv_str, check_stereo=False)
    else:
        raise NotImplementedError

    # Modify spc dct with params from the AMech file
    mod_spc_dct = modify_spc_dct(job_path, spc_dct)

    return mod_spc_dct
Esempio n. 5
0
def read_spc_amech(job_path):
    """ Read an amech style input file for the species
    """

    spc_amech_str = ptt.read_inp_str(job_path, DAT_INP)

    spc_dct = {}
    if spc_amech_str:
        spc_sections = apf.all_captures(ptt.end_section_wname2('spc'),
                                        spc_amech_str)
        if spc_sections:
            for section in spc_sections:
                name = section[0]
                keyword_dct = ptt.build_keyword_dct(section[1])
                spc_dct[name] = keyword_dct

    return spc_dct
Esempio n. 6
0
def read_models_sections(job_path):
    """ species input
    """
    mod_str = ptt.read_inp_str(job_path, MODEL_INP)
    # Obtain the species string
    model_sections = apf.all_captures(ptt.end_section_wname2('model'), mod_str)
    # Make sure some section has been defined
    assert model_sections is not None

    # Build dictionary of models methods
    model_methods = {}
    for section in model_sections:
        name = section[0]
        keyword_dct = build_model_keyword_dct(section[1])
        model_methods[name] = keyword_dct

    return model_methods
Esempio n. 7
0
def build_thy_dct(job_path):
    """ species input
    """
    # Obtain the species string
    thy_str = ptt.read_inp_str(job_path, THY_INP)
    if thy_str:
        thy_sections = apf.all_captures(ptt.end_section_wname2('level'),
                                        thy_str)
        # Make sure some section has been defined
        assert thy_sections is not None

        # Build dictionary of theory methods
        thy_methods = {}
        for section in thy_sections:
            name = section[0]
            keyword_dct = build_thy_keyword_dct(section[1])
            thy_methods[name] = keyword_dct

    return thy_methods
Esempio n. 8
0
def parse_mechanism_file(job_path,
                         mech_type,
                         spc_dct,
                         run_obj_dct,
                         sort_rxns=False):
    """ Get the reactions and species from the mechanism input
    """
    # parsing moved to the input parsing module I am writing
    mech_str = ptt.read_inp_str(job_path, MECH_INP)
    if mech_type.lower() == 'chemkin':
        formulas, rct_names, prd_names, rxn_names = _parse_chemkin(
            mech_str, spc_dct, sort_rxns)
    # elif mech_type.lower() == 'json':
    #     spc_dct, rct_names, prd_names, rxn_name, form_strs = _parse_json(
    #         mech_path, mech_file, check_stereo, rad_rad_sort)
    else:
        raise NotImplementedError

    # Build the total PES dct
    pes_dct = build_pes_dct(formulas, rct_names, prd_names, rxn_names)

    # Print the channels
    print_pes_channels(pes_dct)

    # Reduce the PES dct to only what the user requests
    if run_obj_dct:
        pesnums = [idx_pair[0] for idx_pair in run_obj_dct]
    else:
        pesnums = [idx_pair[0] for idx_pair in run_obj_dct]
    reduced_pes_dct = reduce_pes_dct_to_user_inp(pes_dct, pesnums)

    # Get a dct for all of the connected channels
    conn_chnls_dct = determine_connected_pes_channels(reduced_pes_dct)

    # Form the pes dct that has info formatted to run
    # Get the models in here
    run_pes_dct = pes_dct_w_rxn_lsts(pes_dct, conn_chnls_dct, run_obj_dct)

    return run_pes_dct
Esempio n. 9
0
def objects_dct(job_path):
    """ Get the sections for the run block
    """
    run_str = ptt.read_inp_str(job_path, RUN_INP)
    obj_str = object_block(run_str)
    # Read one of a set of objects to run calcs on (only one supported)
    pes_block_str = apf.first_capture(ptt.paren_section('pes'), obj_str)
    pspc_block_str = apf.first_capture(ptt.paren_section('pspc'), obj_str)
    spc_block_str = apf.first_capture(ptt.paren_section('spc'), obj_str)
    # ts_block_str = apf.first_capture(paren_section('ts'), section_str)
    # wells_block_str = apf.first_capture(paren_section('wells'), section_str)

    # Build the run dictionary
    run_dct = {}
    if pes_block_str is not None:
        run_dct['pes'] = get_pes_idxs(ptt.remove_empty_lines(pes_block_str))
    else:
        run_dct['pes'] = []
    if pspc_block_str is not None:
        run_dct['pspc'] = get_pspc_idxs(ptt.remove_empty_lines(pspc_block_str))
    else:
        run_dct['pspc'] = []
    if spc_block_str is not None:
        run_dct['spc'] = get_spc_idxs(ptt.remove_empty_lines(spc_block_str))
    else:
        run_dct['spc'] = []
    # elif ts_block_str is not None:
    #     obj_str = ts_block_str
    # elif ts_block_str is not None:
    #     obj_str = ts_block_str
    # elif wells_block_str is not None:
    #     obj_str = wells_block_str
    # else:
    #    raise ValueError

    return run_dct