示例#1
0
def hessian(output_string):
    """ read hessian from the output string
    """
    try:
        comp_ptt = app.one_of_these(['X', 'Y', 'Z']) + app.UNSIGNED_INTEGER
        mat = ar.matrix.read(
            output_string,
            start_ptt=(app.escape('The second derivative matrix:') +
                       app.lpadded(app.NEWLINE)),
            block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                             app.padded(app.NEWLINE)),
            line_start_ptt=comp_ptt,
            tril=True)
    except TypeError:
        comp_ptt = app.UNSIGNED_INTEGER
        mat = ar.matrix.read(
            output_string,
            val_ptt=app.EXPONENTIAL_FLOAT_D,
            start_ptt=(
                app.escape('Force constants in Cartesian coordinates:') +
                app.lpadded(app.NEWLINE)),
            block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                             app.padded(app.NEWLINE)),
            line_start_ptt=comp_ptt,
            tril=True)

        mat = [[_cast(apf.replace('d', 'e', dst, case=False)) for dst in row]
               for row in mat]

    mat = tuple(map(tuple, mat))
    return mat
示例#2
0
def gradient(output_str):
    """ Reads the molecular gradient (in Cartesian coordinates) from
        the output file string. Returns the gradient in atomic units.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: tuple(tuple(float))
    """

    # Try to read the gradient from several differnt methods
    ptt1 = ('Gradient of SCF Energy' + app.NEWLINE + app.SPACES +
            app.series(app.INTEGER, app.SPACES) + app.NEWLINE)
    ptt2 = ('Full Analytical Gradient' + app.LINE_FILL + app.NEWLINE +
            app.SPACES + app.series(app.INTEGER, app.SPACES) + app.NEWLINE)
    start_ptt = app.one_of_these([ptt1, ptt2])

    grad = ar.matrix.read(output_str,
                          val_ptt=app.FLOAT,
                          start_ptt=start_ptt,
                          line_start_ptt=app.UNSIGNED_INTEGER)

    # Try and read a general tensor from a numerical gradient
    if grad is None:
        grad = _general_xyz_tensor(output_str)

    return grad
示例#3
0
def hessian(output_str):
    """ Reads the molecular Hessian (in Cartesian coordinates) from
        the output file string. Returns the Hessian in atomic units.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: tuple(tuple(float))
    """

    comp_ptt = app.one_of_these(['X', 'Y', 'Z']) + app.UNSIGNED_INTEGER
    mat = ar.matrix.read(
        output_str,
        start_ptt=(app.escape('The second derivative matrix:') +
                   app.lpadded(app.NEWLINE)),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=True)

    if mat is None:
        comp_ptt = app.UNSIGNED_INTEGER
        mat = ar.matrix.read(
            output_str,
            val_ptt=app.EXPONENTIAL_FLOAT_D,
            start_ptt=(
                app.escape('Force constants in Cartesian coordinates:') +
                app.lpadded(app.NEWLINE)),
            block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                             app.padded(app.NEWLINE)),
            line_start_ptt=comp_ptt,
            tril=True)

    if mat is not None:
        mat = [[_cast(apf.replace('d', 'e', dst, case=False)) for dst in row]
               for row in mat]
示例#4
0
def line_pattern(val_ptt=VALUE_PATTERN,
                 start_ptt=None,
                 capture_values=False):
    """ Build a pattern that matches a line from a block with a single matrix.

        :param val_ptt: matches numeric matrix entry
        :type val_ptt: str
        :param start_ptt: matches at start of the line of the block
        :type start_ptt: str
        :param capture_values: add capturing pattern for the values in the line
        :type capture_values: bool
        :rtype: list(float)
    """

    vals_ptt = app.series(val_ptt, app.LINESPACES)

    if capture_values:
        vals_ptt = app.capturing(vals_ptt)

    parts = (
        ([] if start_ptt is None else [start_ptt]) + [vals_ptt])

    ptt = app.LINE_START + app.padded(app.LINESPACES.join(parts))

    return ptt
示例#5
0
def block_pattern(name_ptt=NAME_PATTERN,
                  val_ptt=VALUE_PATTERN,
                  entry_sep_ptt=ENTRY_SEP_PATTERN,
                  entry_start_ptt=None,
                  entry_end_ptt=None,
                  sep_ptt=SEP_PATTERN):
    """ Builds pattern that match a single setvalue block where the values
        of a set of coordinates for a single Z-matrix are assigned.

        :param name_ptt: matches the variable name in the setval block
        :type name_ptt: str
        :param val_ptt: matches the numeric value in the setval block
        :type name_ptt: str
        :param entry_sep_ptt: matches the separator between a variable name and
            its value, such as the equals sign in 'R1 = 5.00'
        :type entry_sep_ptt: str
        :param entry_start_ptt: matches at the start of a setval entry
        :type entry_start_ptt: str
        :param entry_end_ptt: matches at the end of a setval entry
        :param sep_ptt: matches the separator between setval entries, such as a
            newline or comma
        :rtype: str
    """

    entry_ptt = entry_pattern(
        name_ptt=name_ptt,
        val_ptt=val_ptt,
        sep_ptt=entry_sep_ptt,
        start_ptt=entry_start_ptt,
        end_ptt=entry_end_ptt,
    )
    block_ptt = app.series(entry_ptt, app.padded(sep_ptt))

    return block_ptt
示例#6
0
def block_pattern(sym_ptt=par.Pattern.ATOM_SYMBOL,
                  key_ptt=KEY_PATTERN,
                  name_ptt=NAME_PATTERN,
                  entry_start_ptt=None,
                  entry_sep_ptt=ENTRY_SEP_PATTERN,
                  entry_end_ptt=None,
                  line_start_ptt=None,
                  line_end_ptt=None):
    """ matrix pattern (assumes more than one atom)
    """
    line_ptts = [
        line_pattern(
            num,
            sym_ptt=sym_ptt,
            key_ptt=key_ptt,
            name_ptt=name_ptt,
            entry_start_ptt=entry_start_ptt,
            entry_sep_ptt=entry_sep_ptt,
            entry_end_ptt=entry_end_ptt,
            start_ptt=line_start_ptt,
            end_ptt=line_end_ptt,
        ) for num in range(4)
    ]

    block_end_ptt = app.series(line_ptts[3], app.padded(app.NEWLINE))

    block_ptt = app.one_of_these([
        app.padded(app.NEWLINE).join(line_ptts[:3] + [block_end_ptt]),
        app.padded(app.NEWLINE).join(line_ptts[:3]),
        app.padded(app.NEWLINE).join(line_ptts[:2]),
        app.padded(app.NEWLINE).join(line_ptts[:1]),
    ])
    return block_ptt
示例#7
0
def block_pattern(val_ptt=VALUE_PATTERN,
                  start_ptt=None,
                  line_start_ptt=None,
                  capture_block=False):
    """ Build a pattern that matches a block with a single matrix.

        :param val_ptt: matches numeric matrix entry
        :type val_ptt: str
        :param start_ptt: pattern before start of the matrix block
        :type start_ptt: str
        :param line_start_ptt: matches at start of each line of each block
        :type line_start_ptt: str
        :param capture_blocks: add capturing pattern for the matrix block
        :type capture_blocks: bool
        :rtype: list(float)
    """

    line_ptt = line_pattern(val_ptt=val_ptt, start_ptt=line_start_ptt)
    block_ptt_ = app.series(line_ptt, app.padded(app.NEWLINE))

    if capture_block:
        block_ptt_ = app.capturing(block_ptt_)

    block_ptt_ = block_ptt_ if start_ptt is None else start_ptt + block_ptt_

    return app.padded(block_ptt_)
示例#8
0
def block_pattern(symb_ptt=par.Pattern.ATOM_SYMBOL,
                  val_ptt=par.Pattern.NUMERIC_VALUE,
                  line_sep_ptt=None,
                  line_start_ptt=None):
    """ Builds a pattern that can match a Cartesian molecular geometry from
        block of lines.

        :param symb_ptt: matches atom symbol in the first column of xyz lines
        :type symb_ptt: str
        :param val_ptt: matches coordinate values in columns 2-4 of xyz lines
        :type val_ptt: str
        :param line_sep_ptt: pattern that delimits columns of xyz line
        :type line_sep_ptt: str
        :param line_start_ptt: pattern preceding atom symbols of geometry block
        :type line_start_ptt: str
        :rtype: str
    """

    line_ptt = line_pattern(symb_ptt=symb_ptt,
                            val_ptt=val_ptt,
                            sep_ptt=line_sep_ptt,
                            start_ptt=line_start_ptt)
    block_ptt = app.series(line_ptt, app.padded(app.NEWLINE))

    return block_ptt
示例#9
0
def hessian(output_str):
    """ Reads the molecular Hessian (in Cartesian coordinates) from
        the output file string. Returns the Hessian in atomic units.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: tuple(tuple(float))
    """

    comp_ptt = (app.one_or_more(app.LETTER) +
                app.one_of_these(['X', 'Y', 'Z']) + app.UNSIGNED_INTEGER)
    mat = ar.matrix.read(
        output_str,
        start_ptt=(
            app.escape('Force Constants (Second Derivatives of the Energy) ') +
            app.escape('in [a.u.]') + app.lpadded(app.NEWLINE)),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=True)

    if mat is not None:
        mat = tuple(map(tuple, mat))

    return mat
示例#10
0
def anharmonicity_matrix(output_str):
    """ Reads the VPT2-computed anharmonicity matrix from the output file string.
        Returns the matrix in _.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: tuple(tuple(float))
    """

    start_string = 'Total Anharmonic X Matrix (in cm^-1)'
    comp_ptt = app.UNSIGNED_INTEGER
    mat = ar.matrix.read(
        output_str,
        val_ptt=app.EXPONENTIAL_FLOAT_D,
        start_ptt=app.padded(app.NEWLINE).join([
            app.padded(app.escape(start_string), app.NONNEWLINE), app.LINE, ''
        ]),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=True)

    mat = tuple(
        tuple(float(val.replace('D', 'E')) for val in row) for row in mat)

    return mat
示例#11
0
def hessian(output_str):
    """ Reads the molecular Hessian (in Cartesian coordinates) from
        the output file string. Returns the Hessian in atomic units.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: tuple(tuple(float))
    """

    comp_ptt = app.UNSIGNED_INTEGER
    mat = ar.matrix.read(
        output_str,
        val_ptt=app.FLOAT,
        start_ptt=(
            app.escape('Final Hessian.') +
            app.lpadded(app.NEWLINE)),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=False)

    if mat is not None:
        mat = tuple(map(tuple, mat))

    return mat
示例#12
0
def block_pattern(symb_ptt=par.Pattern.ATOM_SYMBOL,
                  key_ptt=KEY_PATTERN,
                  name_ptt=NAME_PATTERN,
                  entry_start_ptt=None,
                  entry_sep_ptt=ENTRY_SEP_PATTERN,
                  entry_end_ptt=None,
                  line_start_ptt=None,
                  line_end_ptt=None):
    """ Builds a pattern that can match a Z-matrix pattern from a block of
        lines (function currently assumes more than one atom).

        :param symb_ptt: matches atom symbol in first column of block
        :type symb_ptt: str
        :param key_ptt: matches key/index in columns 2, 4, 6 of block
        :type key_ptt: str
        :param name_ptt: matches z-matrix variable names in block in
            columns 3, 5, 7; can also match numbers at these positions
        :type name_ptt: str
        :param entry_start_ptt: matches before key_ptt
        :type entry_start_ptt: str
        :param entry_sep_ptt: matches between key_ptt and name_ptt
        :type entry_sep_ptt: str
        :param entry_end_ptt: matches after name_ptt
        :type entry_end_ptt: str
        :param line_start_ptt: matches at the start of a z-matrix block line
        :type line_start_ptt: str
        :param line_end_ptt: matches at the end of a z-matrix block line
        :type line_end_ptt: str
        :rtype: tuple
    """

    line_ptts = [
        line_pattern(
            num,
            symb_ptt=symb_ptt,
            key_ptt=key_ptt,
            name_ptt=name_ptt,
            entry_start_ptt=entry_start_ptt,
            entry_sep_ptt=entry_sep_ptt,
            entry_end_ptt=entry_end_ptt,
            start_ptt=line_start_ptt,
            end_ptt=line_end_ptt,
        )
        for num in range(4)]

    block_end_ptt = app.series(line_ptts[3], app.padded(app.NEWLINE))

    block_ptt = app.one_of_these([
        app.padded(app.NEWLINE).join(line_ptts[:3] + [block_end_ptt]),
        app.padded(app.NEWLINE).join(line_ptts[:3]),
        app.padded(app.NEWLINE).join(line_ptts[:2]),
        app.padded(app.NEWLINE).join(line_ptts[:1]),
    ])

    return block_ptt
示例#13
0
def block_pattern(sym_ptt=par.Pattern.ATOM_SYMBOL,
                  val_ptt=par.Pattern.NUMERIC_VALUE,
                  line_sep_ptt=None,
                  line_start_ptt=None):
    """ geometry block pattern
    """
    line_ptt = line_pattern(
        sym_ptt=sym_ptt, val_ptt=val_ptt, sep_ptt=line_sep_ptt,
        start_ptt=line_start_ptt)
    block_ptt = app.series(line_ptt, app.padded(app.NEWLINE))
    return block_ptt
示例#14
0
def line_pattern(val_ptt=VALUE_PATTERN, start_ptt=None, capture_values=False):
    """ matrix line pattern
    """
    vals_ptt = app.series(val_ptt, app.LINESPACES)

    if capture_values:
        vals_ptt = app.capturing(vals_ptt)

    parts = (([] if start_ptt is None else [start_ptt]) + [vals_ptt])

    ptt = app.LINE_START + app.padded(app.LINESPACES.join(parts))
    return ptt
示例#15
0
def hessian(output_string):
    """ get hessian from output
    """
    comp_ptt = app.UNSIGNED_INTEGER
    hess = ar.matrix.read(
        output_string,
        start_ptt=app.padded(app.NEWLINE).join([
            app.escape('## Hessian (Symmetry 0) ##'), app.LINE, '']),
        block_start_ptt=app.padded(app.NEWLINE).join([
            '', app.series(comp_ptt, app.LINESPACES), '', '']),
        line_start_ptt=comp_ptt)
    assert numpy.allclose(hess, numpy.transpose(hess))
    return hess
示例#16
0
def block_pattern(val_ptt=VALUE_PATTERN,
                  start_ptt=None,
                  line_start_ptt=None,
                  capture_block=False):
    """ matrix block pattern
    """
    line_ptt = line_pattern(val_ptt=val_ptt, start_ptt=line_start_ptt)
    block_ptt_ = app.series(line_ptt, app.padded(app.NEWLINE))

    if capture_block:
        block_ptt_ = app.capturing(block_ptt_)

    block_ptt_ = block_ptt_ if start_ptt is None else start_ptt + block_ptt_

    return app.padded(block_ptt_)
示例#17
0
def chebyshev_parameters(rxn_dstr):
    """ Parses the data string for a reaction in the reactions block
        for the lines containing the Chebyshevs fitting parameters,
        then reads the parameters from these lines.

        :param rxn_dstr: data string for species in reaction block
        :type rxn_dstr: str
        :return params: Chebyshev fitting parameters
        :rtype: dict[param: value]
    """

    temp_pattern = ('TCHEB' + app.zero_or_more(app.SPACE) + app.escape('/') +
                    app.SPACES + app.capturing(app.FLOAT) + app.SPACES +
                    app.capturing(app.FLOAT) + app.zero_or_more(app.SPACE) +
                    app.escape('/'))
    pressure_pattern = ('PCHEB' + app.zero_or_more(app.SPACE) +
                        app.escape('/') + app.SPACES +
                        app.capturing(app.FLOAT) + app.SPACES +
                        app.capturing(app.FLOAT) +
                        app.zero_or_more(app.SPACE) + app.escape('/'))
    alpha_dimension_pattern = ('CHEB' + app.zero_or_more(app.SPACE) +
                               app.escape('/') + app.SPACES +
                               app.capturing(app.INTEGER) + app.SPACES +
                               app.capturing(app.INTEGER) +
                               app.zero_or_more(app.SPACE) + app.escape('/'))
    alpha_elements_pattern = (
        'CHEB' + app.zero_or_more(app.SPACE) + app.escape('/') + app.series(
            app.capturing(app.SPACES + app.capturing(app.EXPONENTIAL_FLOAT)),
            app.SPACES) + app.zero_or_more(app.SPACE) + app.escape('/'))

    cheb_temps = apf.first_capture(temp_pattern, rxn_dstr)
    cheb_pressures = apf.first_capture(pressure_pattern, rxn_dstr)
    alpha_dims = apf.first_capture(alpha_dimension_pattern, rxn_dstr)
    alpha_elm = apf.all_captures(alpha_elements_pattern, rxn_dstr)
    if not alpha_elm:
        alpha_elm = None

    params_dct = {}
    if all(vals is not None
           for vals in (cheb_temps, cheb_pressures, alpha_dims, alpha_elm)):
        params_dct['t_limits'] = [float(val) for val in cheb_temps]
        params_dct['p_limits'] = [float(val) for val in cheb_pressures]
        params_dct['alpha_dim'] = [int(val) for val in alpha_dims]
        params_dct['alpha_elm'] = [list(map(float, row)) for row in alpha_elm]
    else:
        params_dct = None

    return params_dct
示例#18
0
def hessian2(output_string):
    """ read hessian from the output string
    """
    comp_ptt = app.UNSIGNED_INTEGER
    mat = ar.matrix.read(
        output_string,
        val_ptt=app.EXPONENTIAL_FLOAT_D,
        start_ptt=(app.escape('Force constants in Cartesian coordinates:') +
                   app.lpadded(app.NEWLINE)),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=True)

    mat = [[_cast(apf.replace('d', 'e', dst, case=False)) for dst in row]
           for row in mat]
示例#19
0
def hessian(output_string):
    """ read hessian from the output string
    """
    comp_ptt = app.UNSIGNED_INTEGER
    mat = ar.matrix.read(
        output_string,
        val_ptt=app.EXPONENTIAL_FLOAT,
        start_ptt=app.padded(app.NEWLINE).join(
            [app.escape('$hessian'), app.LINE, '']),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=False)

    mat = tuple(map(tuple, mat))
    return mat
示例#20
0
def hessian(output_string):
    """ read hessian from the output string
    """
    comp_ptt = (app.one_or_more(app.LETTER) +
                app.one_of_these(['X', 'Y', 'Z']) + app.UNSIGNED_INTEGER)
    mat = ar.matrix.read(
        output_string,
        start_ptt=(
            app.escape('Force Constants (Second Derivatives of the Energy) ') +
            app.escape('in [a.u.]') + app.lpadded(app.NEWLINE)),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=True)

    mat = tuple(map(tuple, mat))
    return mat
示例#21
0
def block_pattern(name_ptt=NAME_PATTERN,
                  val_ptt=VALUE_PATTERN,
                  entry_sep_ptt=ENTRY_SEP_PATTERN,
                  entry_start_ptt=None,
                  entry_end_ptt=None,
                  sep_ptt=SEP_PATTERN):
    """ a single setvalue entry
    """
    entry_ptt = entry_pattern(
        name_ptt=name_ptt,
        val_ptt=val_ptt,
        sep_ptt=entry_sep_ptt,
        start_ptt=entry_start_ptt,
        end_ptt=entry_end_ptt,
    )
    block_ptt = app.series(entry_ptt, app.padded(sep_ptt))
    return block_ptt
示例#22
0
def blocks_pattern(val_ptt=VALUE_PATTERN,
                   start_ptt=None,
                   block_start_ptt=None,
                   line_start_ptt=None,
                   capture_blocks=False):
    """ multi-block matrix pattern
    """
    block_ptt = block_pattern(val_ptt=val_ptt,
                              start_ptt=block_start_ptt,
                              line_start_ptt=line_start_ptt)

    blocks_ptt_ = app.series(block_ptt, app.padded(app.NEWLINE))

    if capture_blocks:
        blocks_ptt_ = app.capturing(blocks_ptt_)

    blocks_ptt_ = blocks_ptt_ if start_ptt is None else start_ptt + blocks_ptt_

    return blocks_ptt_
示例#23
0
def hessian(output_str):
    """ Reads the molecular Hessian (in Cartesian coordinates) from
        the output file string. Returns the Hessian in atomic units.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: tuple(tuple(float))
    """

    comp_ptt = app.UNSIGNED_INTEGER
    hess = ar.matrix.read(
        output_str,
        start_ptt=app.padded(app.NEWLINE).join([
            app.escape('## Hessian (Symmetry 0) ##'), app.LINE, '']),
        block_start_ptt=app.padded(app.NEWLINE).join([
            '', app.series(comp_ptt, app.LINESPACES), '', '']),
        line_start_ptt=comp_ptt)

    return hess
示例#24
0
def anharmonicity_matrix_reader(output_string):
    """ Get the Anharmonicity Matrix
    """

    # Set strings to find anharm matrix
    start_string = 'Total Anharmonic X Matrix (in cm^-1)'
    comp_ptt = app.UNSIGNED_INTEGER

    # Obtain the matrix
    mat = ar.matrix.read(
        output_string,
        val_ptt=app.EXPONENTIAL_FLOAT_D,
        start_ptt=app.padded(app.NEWLINE).join([
            app.padded(app.escape(start_string), app.NONNEWLINE), app.LINE, ''
        ]),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=True)

    return mat
示例#25
0
def chebyshev_parameters(rxn_dstr):
    """ chebyshev parameters
    """
    temp_pattern = ('TCHEB' + app.zero_or_more(app.SPACE) + app.escape('/') +
                    app.SPACES + app.capturing(app.FLOAT) + app.SPACES +
                    app.capturing(app.FLOAT) + app.zero_or_more(app.SPACE) +
                    app.escape('/'))
    pressure_pattern = ('PCHEB' + app.zero_or_more(app.SPACE) +
                        app.escape('/') + app.SPACES +
                        app.capturing(app.FLOAT) + app.SPACES +
                        app.capturing(app.FLOAT) +
                        app.zero_or_more(app.SPACE) + app.escape('/'))
    alpha_dimension_pattern = ('CHEB' + app.zero_or_more(app.SPACE) +
                               app.escape('/') + app.SPACES +
                               app.capturing(app.INTEGER) + app.SPACES +
                               app.capturing(app.INTEGER) +
                               app.zero_or_more(app.SPACE) + app.escape('/'))
    alpha_elements_pattern = (
        'CHEB' + app.zero_or_more(app.SPACE) + app.escape('/') + app.series(
            app.capturing(app.SPACES + app.capturing(app.EXPONENTIAL_FLOAT)),
            app.SPACES) + app.zero_or_more(app.SPACE) + app.escape('/'))

    cheb_temps = apf.first_capture(temp_pattern, rxn_dstr)
    cheb_pressures = apf.first_capture(pressure_pattern, rxn_dstr)
    alpha_dims = apf.first_capture(alpha_dimension_pattern, rxn_dstr)
    alpha_elms = apf.all_captures(alpha_elements_pattern, rxn_dstr)
    if not alpha_elms:
        alpha_elms = None

    if all(vals is not None
           for vals in (cheb_temps, cheb_pressures, alpha_dims, alpha_elms)):
        cheb_temps = [float(val) for val in cheb_temps]
        cheb_pressures = [float(val) for val in cheb_pressures]
        alpha_dims = [int(val) for val in alpha_dims]
        alpha_elms = [list(map(float, row)) for row in alpha_elms]
        cheb_params = cheb_temps, cheb_pressures, alpha_dims, alpha_elms
    else:
        cheb_params = None

    return cheb_params
示例#26
0
文件: test_.py 项目: snelliott/autoio
def test__matrix():
    """ test autoread.matrix
    """
    # gaussian gradient
    string = (' ***** Axes restored to original set *****\n'
              ' ------------------------------------------------------------\n'
              ' Center   Atomic              Forces (Hartrees/Bohr)\n'
              ' Number   Number         X              Y              Z\n'
              ' ------------------------------------------------------------\n'
              '    1       8       0.000000000   -0.000000000   -0.061240635\n'
              '    2       1       0.000000000   -0.021691602    0.030622057\n'
              '    3       1      -0.000000000    0.021691602    0.030622057\n'
              ' ------------------------------------------------------------\n'
              ' Cartesian Forces:  Max     0.061240635 RMS     0.027012111\n')

    mat = autoread.matrix.read(
        string,
        start_ptt=app.padded(app.NEWLINE).join([
            app.padded(app.escape('Forces (Hartrees/Bohr)'), app.NONNEWLINE),
            app.LINE, app.LINE, ''
        ]),
        line_start_ptt=app.LINESPACES.join([app.UNSIGNED_INTEGER] * 2))

    assert numpy.allclose(mat, ((0.0, -0.0, -0.061240635),
                                (0.0, -0.021691602, 0.030622057),
                                (-0.0, 0.021691602, 0.030622057)))

    # gaussian hessian
    string = (' The second derivative matrix:\n'
              '             X1    Y1    Z1    X2    Y2\n'
              '      X1   -0.21406\n'
              '      Y1   -0.00000  2.05336\n'
              '      Z1   -0.00000  0.12105  0.19177\n'
              '      X2   -0.06169 -0.00000  0.00000  0.03160\n'
              '      Y2    0.00000 -0.09598 -0.05579 -0.00000  0.12501\n'
              '      Z2    0.00000  0.08316 -0.38831 -0.00000 -0.06487\n'
              '      X3    0.27574  0.00000  0.00000  0.03009 -0.00000\n'
              '      Y3    0.00000 -1.95737 -0.06525  0.00000 -0.02902\n'
              '      Z3    0.00000 -0.20421  0.19654 -0.00000  0.12066\n'
              '             Z2    X3    Y3    Z3\n'
              '      Z2    0.44623\n'
              '      X3    0.00000 -0.30583\n'
              '      Y3   -0.01829 -0.00000  1.98640\n'
              '      Z3   -0.05792 -0.00000  0.08354 -0.13862\n'
              ' ITU= 0\n'
              '   Eigenvalues ---  0.06664  0.66895  3.25121\n')

    comp_ptt = app.one_of_these(['X', 'Y', 'Z']) + app.UNSIGNED_INTEGER
    mat = autoread.matrix.read(
        string,
        start_ptt=(app.escape('The second derivative matrix:') +
                   app.lpadded(app.NEWLINE)),
        block_start_ptt=(app.series(comp_ptt, app.LINESPACES) +
                         app.padded(app.NEWLINE)),
        line_start_ptt=comp_ptt,
        tril=True)

    assert numpy.allclose(
        mat,
        ((-0.21406, 0., 0., -0.06169, 0., 0., 0.27574, 0., 0.),
         (0., 2.05336, 0.12105, 0., -0.09598, 0.08316, 0., -1.95737, -0.20421),
         (0., 0.12105, 0.19177, 0., -0.05579, -0.38831, 0., -0.06525, 0.19654),
         (-0.06169, 0., 0., 0.0316, 0., 0., 0.03009, 0., 0.),
         (0., -0.09598, -0.05579, 0., 0.12501, -0.06487, 0., -0.02902,
          0.12066), (0., 0.08316, -0.38831, 0., -0.06487, 0.44623, 0.,
                     -0.01829, -0.05792),
         (0.27574, 0., 0., 0.03009, 0., 0., -0.30583, 0., 0.),
         (0., -1.95737, -0.06525, 0., -0.02902, -0.01829, 0., 1.9864, 0.08354),
         (0., -0.20421, 0.19654, 0., 0.12066, -0.05792, 0., 0.08354,
          -0.13862)))

    # psi4 gradient
    string = ('  ## Gradient (Symmetry 0) ##\n'
              '  Irrep: 1 Size: 3 x 3\n'
              '\n'
              '            1         2         3\n'
              '\n'
              '    1     0.000     0.000     0.997\n'
              '    2     0.000    -0.749    -0.488\n'
              '    3    -0.000     0.749    -0.488\n')

    mat = autoread.matrix.read(string,
                               start_ptt=app.padded(app.NEWLINE).join([
                                   app.escape('## Gradient (Symmetry 0) ##'),
                                   app.LINE, '', app.LINE, '', ''
                               ]),
                               line_start_ptt=app.UNSIGNED_INTEGER)

    assert numpy.allclose(mat, ((0.0, 0.0, 0.997), (0.0, -0.749, -0.488),
                                (-0.0, 0.749, -0.488)))

    # psi4 hessian
    string = ('-------------------------------------------\n'
              ' ## Hessian (Symmetry 0) ##\n'
              ' Irrep: 1 Size: 9 x 9\n'
              '\n'
              '       1     2     3     4     5 \n'
              '\n'
              '  1   0.000   0.000   0.000   0.000   0.000\n'
              '  2   0.000   0.959   0.000   0.000  -0.452\n'
              '  3   0.000   0.000   0.371   0.000   0.222\n'
              '  4   0.000   0.000   0.000   0.000   0.000\n'
              '  5   0.000  -0.479   0.279   0.000   0.455\n'
              '  6   0.000   0.251  -0.185   0.000  -0.247\n'
              '  7   0.000   0.000   0.000   0.000   0.000\n'
              '  8   0.000  -0.479  -0.279   0.000  -0.003\n'
              '  9   0.000  -0.251  -0.185   0.000   0.025\n'
              '\n'
              '       6     7     8     9\n'
              '\n'
              '  1   0.000   0.000   0.000   0.000\n'
              '  2   0.519   0.000  -0.477  -0.230\n'
              '  3  -0.555   0.000  -0.279  -0.128\n'
              '  4   0.000   0.000   0.000   0.000\n'
              '  5  -0.256   0.000  -0.017   0.051\n'
              '  6   0.607   0.000  -0.012   0.090\n'
              '  7   0.000   0.000   0.000   0.000\n'
              '  8  -0.263   0.000   0.494   0.279\n'
              '  9   0.947   0.000   0.292   0.137\n')

    mat = autoread.matrix.read(string,
                               start_ptt=app.padded(app.NEWLINE).join([
                                   app.escape('## Hessian (Symmetry 0) ##'),
                                   app.LINE, ''
                               ]),
                               block_start_ptt=app.padded(app.NEWLINE).join([
                                   '',
                                   app.series(app.UNSIGNED_INTEGER,
                                              app.LINESPACES), '', ''
                               ]),
                               line_start_ptt=app.UNSIGNED_INTEGER)

    assert numpy.allclose(
        mat, ((0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
              (0.0, 0.959, 0.0, 0.0, -0.452, 0.519, 0.0, -0.477, -0.23),
              (0.0, 0.0, 0.371, 0.0, 0.222, -0.555, 0.0, -0.279, -0.128),
              (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
              (0.0, -0.479, 0.279, 0.0, 0.455, -0.256, 0.0, -0.017, 0.051),
              (0.0, 0.251, -0.185, 0.0, -0.247, 0.607, 0.0, -0.012, 0.09),
              (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
              (0.0, -0.479, -0.279, 0.0, -0.003, -0.263, 0.0, 0.494, 0.279),
              (0.0, -0.251, -0.185, 0.0, 0.025, 0.947, 0.0, 0.292, 0.137)))
示例#27
0
CHEMKIN_ARROW = (app.maybe(app.escape('<')) + app.escape('=') +
                 app.maybe(app.escape('>')))
CHEMKIN_PLUS_EM = app.PLUS + 'M'
CHEMKIN_PAREN_PLUS_EM = app.escape('(') + app.PLUS + 'M' + app.escape(')')
CHEMKIN_PAREN_PLUS = app.escape('(') + app.PLUS
CHEMKIN_PAREN_CLOSE = app.escape(')')

SPECIES_NAME_PATTERN = (r'[^\s=+\-]' + app.zero_or_more(
    app.one_of_these([
        app.LETTER, app.DIGIT, r'[#,()\-_]',
        app.escape('*'),
        app.escape('(+)'),
        app.escape('['),
        app.escape(']')
    ])) + app.zero_or_more(app.PLUS))
SPECIES_NAMES_PATTERN = app.series(app.padded(SPECIES_NAME_PATTERN),
                                   app.padded(app.PLUS))

REACTION_PATTERN = (SPECIES_NAMES_PATTERN + app.padded(CHEMKIN_ARROW) +
                    SPECIES_NAMES_PATTERN)
COEFF_PATTERN = (app.NUMBER + app.LINESPACES + app.NUMBER + app.LINESPACES +
                 app.NUMBER)
COMMENTS_PATTERN = app.escape('!') + app.capturing(
    app.one_or_more(app.WILDCARD2))

BAD_STRS = ['inf', 'INF', 'nan']


def get_rxn_param_dct(block_str, ea_units, a_units):
    """ Parses all of the chemical equations and corresponding fitting
        parameters in the reactions block of the mechanism input file
        and subsequently pulls all of the species names and fitting
示例#28
0
def test__matrix():
    """ test autoread.matrix
    """

    # Gradients
    start_ptt = (app.padded(app.NEWLINE).join([
        app.padded(app.escape('Forces (Hartrees/Bohr)'), app.NONNEWLINE),
        app.LINE, app.LINE, ''
    ]))

    mat = autoread.matrix.read(GRAD1_STR,
                               start_ptt=start_ptt,
                               line_start_ptt=app.LINESPACES.join(
                                   [app.UNSIGNED_INTEGER] * 2))
    assert numpy.allclose(mat, ((0.0, -0.0, -0.061240635),
                                (0.0, -0.021691602, 0.030622057),
                                (-0.0, 0.021691602, 0.030622057)))

    start_ptt = (app.padded(app.NEWLINE).join([
        app.escape('## Gradient (Symmetry 0) ##'), app.LINE, '', app.LINE, '',
        ''
    ]))

    mat = autoread.matrix.read(GRAD2_STR,
                               start_ptt=start_ptt,
                               line_start_ptt=app.UNSIGNED_INTEGER)
    assert numpy.allclose(mat, ((0.0, 0.0, 0.997), (0.0, -0.749, -0.488),
                                (-0.0, 0.749, -0.488)))

    # Hessians
    start_ptt = (app.escape('The second derivative matrix:') +
                 app.lpadded(app.NEWLINE))
    comp_ptt = app.one_of_these(['X', 'Y', 'Z']) + app.UNSIGNED_INTEGER
    block_start_ptt = (app.series(comp_ptt, app.LINESPACES) +
                       app.padded(app.NEWLINE))

    mat = autoread.matrix.read(HESS1_STR,
                               start_ptt=start_ptt,
                               block_start_ptt=block_start_ptt,
                               line_start_ptt=comp_ptt,
                               tril=True)
    assert numpy.allclose(
        mat,
        ((-0.21406, 0., 0., -0.06169, 0., 0., 0.27574, 0., 0.),
         (0., 2.05336, 0.12105, 0., -0.09598, 0.08316, 0., -1.95737, -0.20421),
         (0., 0.12105, 0.19177, 0., -0.05579, -0.38831, 0., -0.06525, 0.19654),
         (-0.06169, 0., 0., 0.0316, 0., 0., 0.03009, 0., 0.),
         (0., -0.09598, -0.05579, 0., 0.12501, -0.06487, 0., -0.02902,
          0.12066), (0., 0.08316, -0.38831, 0., -0.06487, 0.44623, 0.,
                     -0.01829, -0.05792),
         (0.27574, 0., 0., 0.03009, 0., 0., -0.30583, 0., 0.),
         (0., -1.95737, -0.06525, 0., -0.02902, -0.01829, 0., 1.9864, 0.08354),
         (0., -0.20421, 0.19654, 0., 0.12066, -0.05792, 0., 0.08354,
          -0.13862)))

    start_ptt = (app.padded(app.NEWLINE).join(
        [app.escape('## Hessian (Symmetry 0) ##'), app.LINE, '']))
    block_start_ptt = (app.padded(app.NEWLINE).join(
        ['', app.series(app.UNSIGNED_INTEGER, app.LINESPACES), '', '']))

    mat = autoread.matrix.read(HESS2_STR,
                               start_ptt=start_ptt,
                               block_start_ptt=block_start_ptt,
                               line_start_ptt=app.UNSIGNED_INTEGER)
    assert numpy.allclose(
        mat, ((0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
              (0.0, 0.959, 0.0, 0.0, -0.452, 0.519, 0.0, -0.477, -0.23),
              (0.0, 0.0, 0.371, 0.0, 0.222, -0.555, 0.0, -0.279, -0.128),
              (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
              (0.0, -0.479, 0.279, 0.0, 0.455, -0.256, 0.0, -0.017, 0.051),
              (0.0, 0.251, -0.185, 0.0, -0.247, 0.607, 0.0, -0.012, 0.09),
              (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
              (0.0, -0.479, -0.279, 0.0, -0.003, -0.263, 0.0, 0.494, 0.279),
              (0.0, -0.251, -0.185, 0.0, 0.025, 0.947, 0.0, 0.292, 0.137)))

    # Test finding nothing
    mat = autoread.matrix.read('',
                               start_ptt=start_ptt,
                               block_start_ptt=block_start_ptt,
                               line_start_ptt=app.UNSIGNED_INTEGER)
    assert mat is None
示例#29
0
def _parse_sort_order_from_aux_info(aux_info):
    ptt = app.escape('/N:') + app.capturing(
        app.series(app.UNSIGNED_INTEGER, ','))
    num_str = apf.first_capture(ptt, aux_info)
    nums = tuple(map(int, num_str.split(',')))
    return nums
示例#30
0
def _parse_sort_order_from_aux_info(aux_info):
    ptt = app.escape('/N:') + app.capturing(
        app.series(app.UNSIGNED_INTEGER, app.one_of_these(',;')))
    num_strs = apf.first_capture(ptt, aux_info).split(';')
    nums_lst = ap_cast(tuple(s.split(',') for s in num_strs))
    return nums_lst