Exemple #1
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]
Exemple #2
0
def opt_geometry(output_str):
    """ Reads the optimized molecular geometry (in Cartesian coordinates) from
        the output file string. Returns the geometry in Bohr.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: automol molecular geometry data structure
    """

    nums, xyzs = ar.geom.read(
        output_str,
        start_ptt=app.padded(app.NEWLINE).join([
            app.escape('Standard orientation:'),
            app.LINE, app.LINE, app.LINE, app.LINE, '']),
        symb_ptt=app.UNSIGNED_INTEGER,
        line_start_ptt=app.UNSIGNED_INTEGER,
        line_sep_ptt=app.UNSIGNED_INTEGER,)

    if all(x is None for x in (nums, xyzs)):
        nums, xyzs = ar.geom.read(
            output_str,
            start_ptt=app.padded(app.NEWLINE).join([
                app.escape('Z-Matrix orientation:'),
                app.LINE, app.LINE, app.LINE, app.LINE, '']),
            symb_ptt=app.UNSIGNED_INTEGER,
            line_start_ptt=app.UNSIGNED_INTEGER,
            line_sep_ptt=app.UNSIGNED_INTEGER,)

    if all(x is not None for x in (nums, xyzs)):
        symbs = tuple(map(ptab.to_symbol, nums))
        geo = automol.geom.from_data(symbs, xyzs, angstrom=True)
    else:
        geo = None

    return geo
Exemple #3
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
Exemple #4
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
Exemple #5
0
def irc_geometry(output_str):
    """ Reads the molecular geometry at a point on the
        Intrinsic Reaction Coordinate. Returns the geometry in Bohr.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: tuple(automol geom data structure)
    """

    nums, xyzs = ar.geom.read(output_str,
                              start_ptt=app.padded(app.NEWLINE).join([
                                  app.escape('CURRENT STRUCTURE'), app.LINE,
                                  app.LINE, app.LINE, app.LINE, app.LINE, ''
                              ]),
                              symb_ptt=app.UNSIGNED_INTEGER,
                              line_start_ptt=app.UNSIGNED_INTEGER)
    if any(val is None for val in (nums, xyzs)):
        nums, xyzs = ar.geom.read(
            output_str,
            start_ptt=app.padded(app.NEWLINE).join([
                app.escape('Input orientation:'), app.LINE, app.LINE, app.LINE,
                app.LINE, ''
            ]),
            symb_ptt=app.UNSIGNED_INTEGER,
            line_start_ptt=app.UNSIGNED_INTEGER,
            line_sep_ptt=app.UNSIGNED_INTEGER,
        )

    if all(val is not None for val in (nums, xyzs)):
        syms = tuple(map(ptab.to_symbol, nums))
        geo = automol.geom.from_data(syms, xyzs, angstrom=True)
    else:
        geo = None

    return geo
Exemple #6
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_)
Exemple #7
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
Exemple #8
0
def opt_zmatrix(output_str):
    """ Reads the optimized Z-Matrix from the output file string.
        Returns the Z-Matrix in Bohr and Radians.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: automol molecular geometry data structure
    """

    # Read the matrix and the values from the output
    symbs, key_mat, name_mat, val_mat = ar.zmat.read(
        output_str,
        start_ptt=(
            app.padded(app.escape('Geometry (in Angstrom),'), app.NONNEWLINE) +
            2 * app.padded(app.NEWLINE)))

    # Call the automol constructor
    if all(x is not None for x in (symbs, key_mat, name_mat, val_mat)):
        zma = automol.zmat.from_data(symbs,
                                     key_mat,
                                     val_mat,
                                     name_mat,
                                     one_indexed=True,
                                     angstrom=True,
                                     degree=True)
    else:
        zma = None

    return zma
Exemple #9
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))
    """

    comp_ptt = app.UNSIGNED_INTEGER

    start_ptts = ((app.padded(app.NEWLINE).join([
        app.escape('## Gradient (Symmetry 0) ##'), app.LINE, '', app.LINE, '',
        ''
    ])), (app.padded(app.NEWLINE).join(
        [app.escape('-Total gradient:'), app.LINE, app.LINE,
         ''])), (app.padded(app.NEWLINE).join(
             [app.escape('-Total Gradient:'), app.LINE, app.LINE, ''])))

    for ptt in start_ptts:
        grad = ar.matrix.read(output_str,
                              start_ptt=ptt,
                              line_start_ptt=comp_ptt)
        if grad is not None:
            break

    return grad
Exemple #10
0
def inp_zmatrix(inp_str):
    """ Reads the input z-matrix from the input file string
        Returns the Z-Matrix in Bohr and Radians.

        :param output_str: string of the program's output file
        :type output_str: str
        :rtype: automol molecular geometry data structure
    """

    # Reads the matrix from the beginning of the input
    symbs, key_mat, name_mat = ar.vmat.read(
        inp_str,
        start_ptt=app.padded(app.NEWLINE).join([
            app.escape('comment:'), app.LINE, app.LINE, '']),
        symb_ptt=(ar.par.Pattern.ATOM_SYMBOL +
                  app.not_followed_by(app.SPACES + app.FLOAT) +
                  app.maybe(app.UNSIGNED_INTEGER)),
        key_ptt=app.one_of_these([app.UNSIGNED_INTEGER, app.VARIABLE_NAME]),
        line_end_ptt=app.maybe(app.UNSIGNED_INTEGER),
        last=False)

    # Reads the values from the input
    if all(x is not None for x in (symbs, key_mat, name_mat)):
        if len(symbs) == 1:
            # val_dct = {}
            val_mat = ((None, None, None),)
        else:
            val_dct = ar.setval.read(
                inp_str,
                start_ptt=app.padded(app.NEWLINE).join([
                    app.padded('Variables:', app.NONNEWLINE), '']),
                entry_sep_ptt='',
                entry_start_ptt='',
                sep_ptt=app.maybe(app.LINESPACES).join([
                    app.NEWLINE]),
                last=True)
            val_mat = ar.setval.convert_dct_to_matrix(val_dct, name_mat)

        # Check for the pattern
        # For the case when variable names are used instead of integer keys:
        # (otherwise, does nothing)
        key_dct = dict(map(reversed, enumerate(symbs)))
        key_dct[None] = 0
        key_mat = [
            [key_dct[val]+1 if not isinstance(val, numbers.Real) else val
             for val in row] for row in key_mat]
        symb_ptt = app.STRING_START + app.capturing(ar.par.Pattern.ATOM_SYMBOL)
        symbs = [apf.first_capture(symb_ptt, symb) for symb in symbs]

        # Call the automol constructor
        zma = automol.zmat.from_data(
            symbs, key_mat, val_mat, name_mat,
            one_indexed=True, angstrom=True, degree=True)
    else:
        zma = None

    return zma
Exemple #11
0
def dipole_moment(output_string):
    """
    Reads the dipole moment
    """
    pattern = (app.escape('Dipole moment (field-independent basis, Debye):') +
               app.NEWLINE + app.padded('X=') + app.capturing(app.FLOAT) +
               app.padded('Y=') + app.capturing(app.FLOAT) + app.padded('Z=') +
               app.capturing(app.FLOAT))
    vals = [float(val) for val in apf.last_capture(pattern, output_string)]
    return vals
Exemple #12
0
def test__geom():
    """ test autoread.geom
    """

    start_ptt = (app.padded(app.NEWLINE).join([
        app.escape('Standard orientation:'), app.LINE, app.LINE, app.LINE,
        app.LINE, ''
    ]))

    nums, xyzs = autoread.geom.read(
        GEO1_STR,
        start_ptt=start_ptt,
        symb_ptt=app.UNSIGNED_INTEGER,
        line_start_ptt=app.UNSIGNED_INTEGER,
        line_sep_ptt=app.UNSIGNED_INTEGER,
    )

    assert nums == (8, 8, 1, 1)
    assert xyzs == ((-0.0, 0.723527, -0.046053), (0.0, -0.723527, -0.046053),
                    (0.876174, 0.838634, 0.368421), (-0.876174, -0.838634,
                                                     0.368421))

    start_ptt = (app.padded(app.NEWLINE).join(
        [app.escape('Final (previous) structure:'), app.LINE, '']))

    symbs, xyzs = autoread.geom.read(GEO2_STR, start_ptt=start_ptt)

    assert symbs == ('O', 'O', 'H', 'H')
    assert xyzs == ((0.0, 0.7028389815, 0.0245676525), (0.0, -0.7028389815,
                                                        0.0245676525),
                    (-0.8761735478, 0.8179459165, -0.389906474),
                    (0.8761735478, -0.8179459165, -0.389906474))

    start_ptt = (app.padded(app.NEWLINE).join(
        [app.escape('ATOMIC COORDINATES'), app.LINE, app.LINE, app.LINE, '']))

    symbs, xyzs = autoread.geom.read(
        GEO3_STR,
        start_ptt=start_ptt,
        line_start_ptt=app.UNSIGNED_INTEGER,
        line_sep_ptt=app.FLOAT,
    )
    assert symbs == ('O', 'H', 'H')
    assert xyzs == ((0.0, 0.0, -0.109999068), (0.0, -1.635000492, 0.875999553),
                    (0.0, 1.635000492, 0.875999553))

    symbs, xyzs = autoread.geom.read_xyz(XYZ_STR)
    assert symbs == ('O', 'O', 'H', 'H')
    assert xyzs == ((0.0, 0.7028389815, 0.0245676525), (0.0, -0.7028389815,
                                                        0.0245676525),
                    (-0.8761735478, 0.8179459165, -0.389906474),
                    (0.8761735478, -0.8179459165, -0.389906474))

    with pytest.raises(ValueError):
        symbs, xyzs = autoread.geom.read_xyz(BAD_XYZ_STR)
Exemple #13
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
Exemple #14
0
def opt_geometry(output_string):
    """ get optimized geometry from output
    """
    syms, xyzs = ar.geom.read(
        output_string,
        start_ptt=app.padded(app.NEWLINE).join([
            app.padded(app.escape('CARTESIAN COORDINATES (ANGSTROEM)'),
                       app.NONNEWLINE), app.LINE, ''
        ]))
    geo = automol.geom.from_data(syms, xyzs, angstrom=True)
    return geo
Exemple #15
0
def dipole_moment(output_string):
    """
    Reads the dipole moment
    """
    pattern = app.padded((app.LINESPACES.join(
        [app.escape('Dipole moment [Debye]:'), app.FLOAT])) + app.NEWLINE +
                         app.padded('x=') + app.capturing(app.FLOAT) +
                         app.padded('y=') + app.capturing(app.FLOAT) +
                         app.padded('z=') + app.capturing(app.FLOAT))
    vals = [float(val) for val in apf.last_capture(pattern, output_string)]
    return vals
Exemple #16
0
def opt_zmatrix(output_string):
    """ get optimized z-matrix geometry from output
    """
    # read the matrix from the beginning of the output
    syms, key_mat, name_mat = ar.zmatrix.matrix.read(
        output_string,
        start_ptt=app.maybe(app.SPACES).join([
            'geometry', app.escape('='), app.escape('{'), '']),
        entry_start_ptt=app.maybe(','),
        entry_sep_ptt=',',
        last=False,
        case=False)

    # read the initial z-matrix values from the beginning out the output
    if len(syms) == 1:
        val_dct = {}
    else:
        val_dct = ar.zmatrix.setval.read(
            output_string,
            # name_ptt=MOLPRO_VAR_NAME_PATTERN,
            entry_start_ptt=MOLPRO_ENTRY_START_PATTERN,
            val_ptt=app.one_of_these([app.EXPONENTIAL_FLOAT_D, app.NUMBER]),
            last=True,
            case=False)
        print('val_dct:', val_dct)

    names = sorted(set(numpy.ravel(name_mat)) - {None})
    caps_names = list(map(str.upper, names))
    name_dct = dict(zip(caps_names, names))
    assert set(caps_names) <= set(val_dct)
    val_dct = {name_dct[caps_name]: val_dct[caps_name]
               for caps_name in caps_names}

    # read optimized z-matrix values from the end of the output
    VAR_STRING = app.one_of_these([
        app.padded('Optimized variables'),
        app.padded('Current variables')
    ])
    opt_val_dct = ar.zmatrix.setval.read(
        output_string,
        start_ptt=VAR_STRING + app.NEWLINE,
        entry_end_ptt=app.one_of_these(['ANGSTROM', 'DEGREE']),
        last=True,
        case=False)
    opt_val_dct = {name_dct[caps_name]: opt_val_dct[caps_name]
                   for caps_name in opt_val_dct.keys()}
    assert set(opt_val_dct) <= set(val_dct)
    val_dct.update(opt_val_dct)

    # call the automol constructor
    zma = automol.zmatrix.from_data(
        syms, key_mat, name_mat, val_dct,
        one_indexed=True, angstrom=True, degree=True)
    return zma
Exemple #17
0
def gradient(output_string):
    """ read gradient from the output string
    """
    grad = ar.matrix.read(
        output_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))
    grad = numpy.multiply(grad, -1.0)
    assert numpy.shape(grad)[1] == 3
    return grad
Exemple #18
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
Exemple #19
0
def gradient(output_string):
    """ read gradient from the output string
    """
    head_ptt = ('Atom' + app.SPACES + app.escape('dE/dx') + app.SPACES +
                app.escape('dE/dy') + app.SPACES + app.escape('dE/dz'))
    grad = ar.matrix.read(output_string,
                          start_ptt=app.padded(app.NEWLINE).join([
                              app.padded(head_ptt, app.NONNEWLINE), app.LINE,
                              ''
                          ]),
                          line_start_ptt=app.UNSIGNED_INTEGER)
    assert numpy.shape(grad)[1] == 3
    return grad
Exemple #20
0
def opt_zmatrix(output_string):
    """ get optimized z-matrix geometry from output
    """
    # read the matrix from the beginning of the output
    syms, key_mat, name_mat = ar.zmatrix.matrix.read(
        output_string,
        start_ptt=app.padded(app.NEWLINE).join(
            [app.escape('Symbolic Z-matrix:'), app.LINE, '']),
        sym_ptt=ar.par.Pattern.ATOM_SYMBOL + app.maybe(app.UNSIGNED_INTEGER),
        key_ptt=app.one_of_these([app.UNSIGNED_INTEGER, app.VARIABLE_NAME]),
        line_end_ptt=app.maybe(app.UNSIGNED_INTEGER),
        last=False)

    # read the values from the end of the output
    if len(syms) == 1:
        val_dct = {}
    else:
        val_dct = ar.zmatrix.setval.read(
            output_string,
            start_ptt=app.padded(app.NEWLINE).join([
                app.padded('Optimized Parameters', app.NONNEWLINE), app.LINE,
                app.LINE, app.LINE, app.LINE, ''
            ]),
            entry_sep_ptt='',
            entry_start_ptt=app.escape('!'),
            sep_ptt=app.maybe(app.LINESPACES).join([
                app.escape('-DE/DX ='), app.FLOAT,
                app.escape('!'), app.NEWLINE
            ]),
            last=True)

    # for the case when variable names are used instead of integer keys:
    # (otherwise, does nothing)
    key_dct = dict(map(reversed, enumerate(syms)))
    key_dct[None] = 0
    key_mat = [[
        key_dct[val] + 1 if not isinstance(val, numbers.Real) else val
        for val in row
    ] for row in key_mat]
    sym_ptt = app.STRING_START + app.capturing(ar.par.Pattern.ATOM_SYMBOL)
    syms = [apf.first_capture(sym_ptt, sym) for sym in syms]

    # call the automol constructor
    zma = automol.zmatrix.from_data(syms,
                                    key_mat,
                                    name_mat,
                                    val_dct,
                                    one_indexed=True,
                                    angstrom=True,
                                    degree=True)
    return zma
Exemple #21
0
def test__setval():
    """ test autoread.zmat.setval
    """

    val_dct = autoread.setval.read(ZMA_VAL1_STR)
    assert val_dct == {
        'A2': 96.772572, 'D3': 129.366995, 'R1': 1.4470582953, 'R2': 0.976073}

    start_ptt = app.padded(app.NEWLINE).join([
        app.escape('!   Optimized Parameters   !'),
        app.LINE, app.LINE, app.LINE, app.LINE, ''])

    val_dct = autoread.setval.read(
        ZMA_VAL2_STR,
        start_ptt=start_ptt,
        entry_sep_ptt='',
        entry_start_ptt=app.escape('!'),
        sep_ptt=app.maybe(app.LINESPACES).join([
            app.escape('-DE/DX ='), app.FLOAT, app.escape('!'), app.NEWLINE]))
    assert val_dct == {
        'R1': 1.4057, 'R2': 0.9761, 'A2': 96.7726, 'D3': 129.367}

    val_dct = autoread.setval.read(
        ZMA_VAL3_STR,
        sep_ptt=app.one_of_these(['', app.NEWLINE]))
    assert val_dct == {
        'R1': 2.73454, 'R2': 1.84451, 'A2': 96.7726, 'R3': 1.84451,
        'A3': 96.7726, 'D3': 129.367}

    val_dct = autoread.setval.read(
        ZMA_VAL4_STR,
        entry_start_ptt='SETTING',
        val_ptt=app.one_of_these([app.EXPONENTIAL_FLOAT_D, app.NUMBER]),
        last=False,
        case=False)
    assert val_dct == {
        'R1': 1.375861, 'R2': 1.058354, 'A2': 108.861981, 'R3': 1.058354,
        'A3': 108.861981, 'D3': 120.321137, 'R4': 1.058354, 'A4': 108.861981,
        'D4': 234.912696, 'R5': 0.952519, 'A5': 103.132403, 'D5': 297.938053,
        'SPIN': '0.00000000D+00', 'CHARGE': '0.00000000D+00'}

    val_dct = autoread.setval.read(
        ZMA_VAL5_STR,
        start_ptt=app.padded('Optimized variables') + app.NEWLINE,
        entry_end_ptt=app.one_of_these(['ANGSTROM', 'DEGREE']),
        last=True,
        case=False)
    assert val_dct == {
        'R1': 1.43218364, 'R2': 1.09538054, 'A2': 112.03775543,
        'R3': 1.09538307, 'A3': 112.04463832, 'R4': 1.09084803,
        'A4': 108.31761858, 'D4': 240.16203078, 'D5': 299.84441753}
Exemple #22
0
def gradient(output_string):
    """ read gradient from the output string
    """
    grad = ar.matrix.read(output_string,
                          start_ptt=app.padded(app.NEWLINE).join([
                              app.padded(app.escape('CARTESIAN GRADIENT'),
                                         app.NONNEWLINE), app.LINE, app.LINE,
                              ''
                          ]),
                          line_start_ptt=app.LINESPACES.join([
                              app.UNSIGNED_INTEGER,
                              app.one_or_more(app.LETTER), ':'
                          ]))
    assert numpy.shape(grad)[1] == 3
    return grad
Exemple #23
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_)
Exemple #24
0
def vibro_rot_alpha_matrix_reader(output_string):
    """ Get the Vibration-Rotation Alpha Matrix
    """

    begin_string = 'Vibro-Rot alpha Matrix (in cm^-1)'
    end_string = app.escape('Q( ') + app.UNSIGNED_INTEGER + app.escape(')')

    vib_rot_mat = ar.matrix.read(output_string,
                                 start_ptt=app.padded(app.NEWLINE).join([
                                     app.padded(app.escape(begin_string),
                                                app.NONNEWLINE), app.LINE,
                                     app.LINE, ''
                                 ]),
                                 line_start_ptt=end_string)
    return vib_rot_mat
Exemple #25
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
Exemple #26
0
def dipole_moment(output_string):
    """
    Reads the dipole moment
    """
    pattern = (app.escape('Dipole moment (field-independent basis, Debye):') +
               app.LINE_FILL + app.NEWLINE +
               app.padded('X=') + app.capturing(app.FLOAT) +
               app.padded('Y=') + app.capturing(app.FLOAT) +
               app.padded('Z=') + app.capturing(app.FLOAT))
    captures = apf.last_capture(pattern, output_string)
    vals = captures if captures is not None else []
    if vals:
        vals = [float(val) for val in vals]
    else:
        vals = None
    return vals
Exemple #27
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
Exemple #28
0
def entry_pattern(name_ptt=NAME_PATTERN,
                  val_ptt=VALUE_PATTERN,
                  sep_ptt=ENTRY_SEP_PATTERN,
                  start_ptt=None,
                  end_ptt=None):
    """ Builds pattern that match a line of a setvalue block where
        the value of a single coordinate of a Z-matrix is 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 sep_ptt: matches the separator between a variable name and
            its value, such as the equals sign in 'R1 = 5.00'
        :type sep_ptt: str
        :param start_ptt: matches at the start of a setval entry
        :type start_ptt: str
        :param end_ptt: matches at the end of a setval entry
        :rtype: str
    """

    parts = (([] if start_ptt is None else [start_ptt]) +
             [name_ptt] +
             [sep_ptt] +
             [val_ptt] +
             ([] if end_ptt is None else [end_ptt]))

    ptt = app.padded(app.maybe(app.LINESPACES).join(parts))

    return ptt
Exemple #29
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
Exemple #30
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