Example #1
0
def objects_dct(job_path):
    """ Get the sections for the run block
    """

    # Read the obj section
    run_str = ptt.read_inp_str(job_path, RUN_INP, remove_comments='#')
    obj_str = object_block(run_str)

    # Read the sections of the obj section
    pes_block_str = apf.first_capture(ptt.paren_section('pes'), obj_str)
    spc_block_str = apf.first_capture(ptt.paren_section('spc'), obj_str)

    # Check if the obj section has been specified
    check_obj_spec(obj_str, pes_block_str, spc_block_str)

    # Build the run dictionary
    run_dct = {}
    if pes_block_str is not None:
        run_dct['pes'] = get_pes_idxs(
            ioformat.remove_whitespace(pes_block_str))
    else:
        run_dct['pes'] = []
    if spc_block_str is not None:
        run_dct['spc'] = get_spc_idxs(
            ioformat.remove_whitespace(spc_block_str))
    else:
        run_dct['spc'] = []

    return run_dct
Example #2
0
def build_pes_dct(job_path, mech_type, spc_dct, run_obj_dct, sort_rxns=True):
    """Build the PES dct
    """

    # Read the string
    mech_str = ptt.read_inp_str(job_path, MECH_INP, remove_comments='!')

    # Build the total PES dct
    mech_info = mechanalyzer.parser.pes.read_mechanism_file(
        mech_str, mech_type, spc_dct, sort_rxns=sort_rxns)
    pes_dct = mechanalyzer.parser.pes.build_pes_dct(*mech_info)

    # Build an index dct relating idx to formula
    idx_dct, form_dct = build_pes_idx_dct(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 with the PESs to run
    conn_chnls_dct = mechanalyzer.parser.pes.connected_channels_dct(
        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(reduced_pes_dct, idx_dct, form_dct,
                                     conn_chnls_dct, run_obj_dct)

    # Print the channels for the whole mechanism file
    print_pes_channels(pes_dct)

    return run_pes_dct
Example #3
0
def read_spc_amech(job_path):
    """ Read an amech style input file for the species
    """

    # Read the AMech species string
    if os.path.exists(os.path.join(job_path, DAT_INP)):
        spc_amech_str = ptt.read_inp_str(
            job_path, DAT_INP, remove_comments='#')
        print('Found species.dat. Reading file...')
    else:
        spc_amech_str = ''
        print('No species.dat file...')

    # Build the keyword dcts
    amech_dct = {}
    if spc_amech_str:
        # Read each of the species sections and build the dcts
        spc_sections = apf.all_captures(
            ptt.end_section_wname2('spc'), spc_amech_str)
        if spc_sections:
            # Get the global species section
            for section in spc_sections:
                if section[0] == 'global':
                    # Build the global species section
                    keyword_dct = ptt.build_keyword_dct(section[1])
                    amech_dct['global'] = keyword_dct
                else:
                    # Build each species dct to overwrite global dct
                    name = section[0]
                    keyword_dct = ptt.build_keyword_dct(section[1])
                    amech_dct[name] = keyword_dct

    return amech_dct
Example #4
0
def build_spc_dct(job_path, spc_type):
    """ Build the species dct
    """

    spc_str = ptt.read_inp_str(job_path, CSV_INP)
    spc_dct = mechanalyzer.parser.spc.build_spc_dct(spc_str, spc_type)

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

    return mod_spc_dct
Example #5
0
def build_run_jobs_lst(job_path):
    """ Build a dictionary for all the theory keywords
    """

    # Read the jobs section
    job_str = ptt.read_inp_str(job_path, RUN_INP, remove_comments='#')
    keyword_lst = ptt.build_keyword_lst(jobs_block(job_str))

    # Check the jobs sectuib
    check_run_jobs_section(job_str, keyword_lst)

    return keyword_lst
Example #6
0
def parse_rxn_class_file(job_path):
    """ Read the class dictionary
    """

    if os.path.exists(os.path.join(job_path, CLA_INP)):
        print('  class.dat found. Reading contents...')
        cla_str = ptt.read_inp_str(job_path, CLA_INP, remove_comments='#')
        cla_dct = _build_cla_dct(cla_str)
    else:
        print('  No class.dat found.')
        cla_dct = {}

    return cla_dct
Example #7
0
def read_es_tsks(job_path):
    """ Build a dictionary for all the theory keywords
    """

    # Read the electronic structure tasks section
    run_str = ptt.read_inp_str(job_path, RUN_INP, remove_comments='#')
    es_tsks_str = es_tsks_block(run_str)

    # Check if section is there
    if es_tsks_str is None:
        print('*ERROR: No "es_tsks" section defined in run.dat')
        sys.exit()

    return es_tsks_str
Example #8
0
def read_models_sections(job_path):
    """ species input
    """
    mod_str = ptt.read_inp_str(job_path, MODEL_INP, remove_comments='#')

    # Build a dictionary for the PES models
    pes_model_sections = apf.all_captures(ptt.end_section_wname2('pes_model'),
                                          mod_str)
    assert pes_model_sections is not None

    pes_model_methods = {}
    glob_pes_model_methods = {}
    for section in pes_model_sections:
        if section[0] == 'global':
            name = section[0]
            keyword_dct = build_pes_model_keyword_dct(section[1])
            glob_pes_model_methods = keyword_dct
            break
    pes_model_methods['global'] = glob_pes_model_methods
    for section in pes_model_sections:
        if section[0] != 'global':
            name = section[0]
            keyword_dct = build_pes_model_keyword_dct(section[1])
            pes_model_methods[name] = combine_glob_and_spc_dct(
                glob_pes_model_methods, keyword_dct)

    # Build a dictionary for the spc models
    spc_model_sections = apf.all_captures(ptt.end_section_wname2('spc_model'),
                                          mod_str)
    assert spc_model_sections is not None

    spc_model_methods = {}
    glob_spc_model_methods = {}
    for section in spc_model_sections:
        if section[0] == 'global':
            name = section[0]
            keyword_dct = build_spc_model_keyword_dct(section[1])
            glob_spc_model_methods = keyword_dct
            break
    spc_model_methods['global'] = glob_spc_model_methods
    for section in spc_model_sections:
        if section[0] != 'global':
            name = section[0]
            keyword_dct = build_spc_model_keyword_dct(section[1])
            spc_model_methods[name] = combine_glob_and_spc_dct(
                glob_spc_model_methods, keyword_dct)

    return pes_model_methods, spc_model_methods
Example #9
0
def build_thy_dct(job_path):
    """ species input
    """
    # Obtain the species string
    thy_str = ptt.read_inp_str(job_path, THY_INP, remove_comments='#')

    # Obtain any thy_sections
    thy_sections = apf.all_captures(
        ptt.end_section_wname2('level'), thy_str)
    check_thy_sections_nonempty(thy_sections)

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

    return thy_methods
Example #10
0
def build_run_inp_dct(job_path):
    """ Build a dictionary for all the theory keywords
    """

    # Read the input section
    run_str = ptt.read_inp_str(job_path, RUN_INP, remove_comments='#')
    keyword_dct = ptt.build_keyword_dct(inp_block(run_str))

    # Add defaults
    if 'mech' not in keyword_dct:
        keyword_dct['mech'] = 'chemkin'
    if 'spc' not in keyword_dct:
        keyword_dct['spc'] = 'csv'
    if 'print_mech' not in keyword_dct:
        keyword_dct['print_mech'] = False

    # Check if section specified fully and supported
    check_run_keyword_dct(keyword_dct)

    return keyword_dct
Example #11
0
def modify_spc_dct(job_path, spc_dct):
    """ Modify the species dct using input from the additional AMech file
    """

    # Read in other dcts
    amech_dct = read_spc_amech(job_path)
    geom_dct = geometry_dictionary(job_path)

    mod_spc_dct = {}
    for spc in spc_dct:
        # Set the ich and mult
        ich = spc_dct[spc]['inchi']
        mul = spc_dct[spc]['mult']
        chg = spc_dct[spc]['charge']
        mod_spc_dct[spc] = {}
        mod_spc_dct[spc]['inchi'] = ich
        mod_spc_dct[spc]['mult'] = mul
        mod_spc_dct[spc]['charge'] = chg

        # Add params from global dct in amech dct
        if 'global' in amech_dct:
            for key, val in amech_dct['global'].items():
                mod_spc_dct[spc][key] = val

        # Add/Reset the parameters from the species specific dct
        if spc in amech_dct:
            for key, val in amech_dct[spc].items():
                mod_spc_dct[spc][key] = val

    # Second loop for transtion states defined in species.dat
    for spc in amech_dct:
        if 'ts' in spc:
            mod_spc_dct[spc] = {}
            # Add params from global dct in amech dct
            if 'global' in amech_dct:
                for key, val in amech_dct['global'].items():
                    mod_spc_dct[spc][key] = val
            # Add the ts stuff
            mod_spc_dct[spc] = amech_dct[spc]

    # Add global to mod_spc_dct for other TS stuff later
    if 'global' in amech_dct:
        mod_spc_dct['global'] = amech_dct['global']

    # Final loop to add in things that are needed but could be missing
    for spc in mod_spc_dct:
        if spc != 'global' and 'ts_' not in spc:
            ich, mul = mod_spc_dct[spc]['inchi'], mod_spc_dct[spc]['mult']
            if 'elec_levels' not in mod_spc_dct[spc]:
                if (ich, mul) in eleclvl.DCT:
                    mod_spc_dct[spc]['elec_levels'] = eleclvl.DCT[(ich, mul)]
                else:
                    mod_spc_dct[spc]['elec_levels'] = [[0.0, mul]]
            if 'sym_factor' not in mod_spc_dct[spc]:
                if (ich, mul) in symm.DCT:
                    mod_spc_dct[spc]['sym_factor'] = symm.DCT[(ich, mul)]

        # Add defaults here for now
        if 'hind_inc' not in mod_spc_dct[spc]:
            mod_spc_dct[spc]['hind_inc'] = 30.0
        if 'kickoff' not in mod_spc_dct[spc]:
            mod_spc_dct[spc]['kickoff'] = [0.1, False]
        if 'tau_nsamp' not in mod_spc_dct[spc]:
            mod_spc_dct[spc]['tau_nsamp'] = [True, 12, 1, 3, 100, 25]
        if 'mc_nsamp' not in mod_spc_dct[spc]:
            mod_spc_dct[spc]['mc_nsamp'] = [True, 12, 1, 3, 100, 25]
        if 'pst_params' not in mod_spc_dct[spc]:
            mod_spc_dct[spc]['pst_params'] = [1.0, 6]

        # Set active space stuff
        if 'active' not in mod_spc_dct[spc]:
            mod_spc_dct[spc]['active_space'] = None
        else:
            aspace = mod_spc_dct[spc].get('active')
            assert len(aspace) == 4, (
                'active must be length 4: {}'.format(aspace)
            )
            wfn_file = aspace[3]
            wfn_inp = os.path.join(os.path.join(job_path, 'inp/'+wfn_file))
            if os.path.exists(wfn_inp):
                wfn_str = ptt.read_inp_str(job_path, wfn_inp)
                print('Found file: {}. Reading file...'.format(wfn_file))
            else:
                wfn_str = None
                print('No file: {}. Reading file...'.format(wfn_file))
            mod_spc_dct[spc]['active_space'] = (
                aspace[0], aspace[1], aspace[2], wfn_str)

        # Perform conversions as needed
        mod_spc_dct[spc]['hind_inc'] *= phycon.DEG2RAD
        # if 'ts' in spc:
        #     print(mod_spc_dct[spc]['hind_inc'])

        # Add geoms from geo dct (prob switch to amech file)
        if ich in geom_dct:
            mod_spc_dct[spc]['geo_inp'] = geom_dct[ich]

    return mod_spc_dct