def reaction_unit_names(mech_str): """ units specified in the reaction block """ block_str = remove_blanks(reactions_block(mech_str)) a_unit_names, _ = zip(*A_UNITS) e_unit_names, _ = zip(*E_UNITS) a_pattern = (STRING_START + maybe(one_of_these(e_unit_names) + LINESPACES) + capturing(one_of_these(a_unit_names))) e_pattern = (STRING_START + maybe(one_of_these(a_unit_names) + LINESPACES) + capturing(one_of_these(e_unit_names))) a_unit_name = find_first_capture(a_pattern, block_str) e_unit_name = find_first_capture(e_pattern, block_str) return a_unit_name, e_unit_name
def _block(mech_str, block_keys): start_key = one_of_these(block_keys) contents = capturing(one_or_more(WILDCARD, greedy=False)) pattern = start_key + contents + 'END' mech_str = remove_comments(mech_str) block = find_first_capture(pattern, mech_str) return find_strip_spaces(block) if block else None
def _interpret_reagent_count(rgt_cnt_str): _pattern = (STRING_START + capturing(maybe(DIGIT)) + capturing(one_or_more(NONSPACE))) cnt, rgt = find_first_capture(_pattern, rgt_cnt_str) cnt = int(cnt) if cnt else 1 rgts = (rgt, ) * cnt return rgts
def thermo_t_common_default(mech_str): """ temperature defaults from the thermo block """ block_str = remove_blanks(thermo_block(mech_str)) pattern = (STRING_START + UNSIGNED_FLOAT + LINESPACES + capturing(UNSIGNED_FLOAT) + LINESPACES + UNSIGNED_FLOAT) capture = find_first_capture(pattern, block_str) assert capture tmp_com_def = float(capture) return tmp_com_def
def thermo_data_temperatures(thm_dstr): """ get the common temperature from a thermo data string """ headline = find_split_lines(thm_dstr)[0] pattern = (LINESPACES + capturing(UNSIGNED_FLOAT) + LINESPACES + capturing(UNSIGNED_FLOAT) + LINESPACES + capturing(UNSIGNED_FLOAT)) captures = find_first_capture(pattern, headline) assert captures tmps = tuple(map(float, captures)) return tmps
def reaction_data_high_p_coeffs(rxn_dstr): """ get the high-pressure Arrhenius coefficients from a reaction data string """ headline = find_split_lines(rxn_dstr)[0] number = one_of_these( [EXPONENTIAL_FLOAT, EXPONENTIAL_INTEGER, FLOAT, INTEGER]) pattern = (LINESPACES + capturing(number) + LINESPACES + capturing(number) + LINESPACES + capturing(number)) captures = find_first_capture(pattern, headline) assert captures cfts = tuple(map(float, captures)) return cfts
def thermo_data_species_name(thm_dstr): """ get the species name from a thermo data string """ pattern = STRING_START + capturing(one_or_more(NONSPACE)) spc = find_first_capture(pattern, thm_dstr) return spc