Пример #1
0
def _format_grad_str(geom, grad):
    """ Formats the gradient into a string used for the ProjRot input file.

        :param geom: geometries (Angstrom)
        :type geom: list
        :param grads: gradients (Eh/Bohr)
        :type grads: list
        :rtype: str
    """

    atom_list = []
    for i, (sym, _) in enumerate(geom):
        atom_list.append(int(ptab.to_Z(sym)))

    # Format the strings for the xyz gradients
    full_grads_str = ''
    for i, grads in enumerate(grad):
        grads_str = '{0:>14.8f}{1:>14.8f}{2:>14.8f}'.format(
            grads[0], grads[1], grads[2])
        full_grads_str += '{0:2d}{1:4d}{2}\n'.format(i + 1, atom_list[i],
                                                     grads_str)

    return remove_trail_whitespace(full_grads_str)
Пример #2
0
def test__string_remove():
    """ test ioformat.remove_whitespace
        test ioformat.remove_trail_whitespace
        test ioformat.remove_comment_lines
    """

    out_str = ioformat.remove_whitespace_from_string(INI_STR)
    assert out_str == ('! From Theory\n'
                       'A + B = C + D    1.00 0.00 0.00\n'
                       'PLOG / 0.01  3.0E+8 2.0 100.0\n'
                       'A + D = E        2.00 0.00 0.00\n'
                       '! From Experiment\n'
                       'E = F            3.00 0.00 0.00\n'
                       'PLOG / 0.01  6.0 2.5 105\n')

    out_str = ioformat.remove_trail_whitespace(INI_STR)
    assert out_str == ('! From Theory\n'
                       'A + B = C + D    1.00 0.00 0.00\n'
                       '  PLOG / 0.01  3.0E+8 2.0 100.0\n'
                       'A + D = E        2.00 0.00 0.00\n'
                       '! From Experiment\n'
                       'E = F            3.00 0.00 0.00\n'
                       '  PLOG / 0.01  6.0 2.5 105\n')

    out_str = ioformat.remove_comment_lines(INI_STR, '!')
    assert out_str == ('\n'
                       'A + B = C + D    1.00 0.00 0.00  \n'
                       '  PLOG / 0.01  3.0E+8 2.0 100.0\n'
                       '\n'
                       'A + D = E        2.00 0.00 0.00  \n'
                       '\n'
                       '\n'
                       'E = F            3.00 0.00 0.00  \n'
                       '  PLOG / 0.01  6.0 2.5 105\n'
                       '\n'
                       '\n')
Пример #3
0
def mdhr_data(potentials, freqs=()):
    """ Writes the string for an auxiliary data file for MESS containing
        potentials and vibrational frequencies of a
        multidimensional hindered rotor, up to four dimensions.

        :param potentials: potential values along torsional modes of rotor
        :type potentials: list(list(float))
        :param freqs: vibrational frequenciess along torsional modes of rotor
        :type freqs: list(list(float))
        :rtype: str
    """

    # Determine the dimensions of the rotor potential list
    dims = numpy.array(potentials).shape
    ndims = len(dims)

    # Write top line string with number of points in potential
    if ndims == 1:
        dat_str = '{0:>6d}'.format(*dims)
        nfreqs = len(freqs[0]) if freqs else None
    elif ndims == 2:
        dat_str = '{0:>6d}{1:>6d}'.format(*dims)
        nfreqs = len(freqs[0][0]) if freqs else None
    elif ndims == 3:
        dat_str = '{0:>6d}{1:>6d}{2:>6d}'.format(*dims)
        nfreqs = len(freqs[0][0][0]) if freqs else None
    elif ndims == 4:
        dat_str = '{0:>6d}{1:>6d}{2:>6d}{3:>6d}'.format(*dims)
        nfreqs = len(freqs[0][0][0][0]) if freqs else None

    # Add the nofreq line
    if freqs:
        dat_str += '\n '
        dat_str += ' '.join('{0:d}'.format(idx + 1) for idx in range(nfreqs))
        dat_str += '\n\n'
    else:
        dat_str += '\n nofreq\n\n'

    # Write the strings with the potential values
    if ndims == 1:
        for i in range(dims[0]):
            dat_str += ('{0:>6d}{1:>15.8f}'.format(i + 1, potentials[i]))
            if freqs:
                ' {}'.join((freq for freq in freqs[i]))
            dat_str += '\n'
    elif ndims == 2:
        for i in range(dims[0]):
            for j in range(dims[1]):
                dat_str += ('{0:>6d}{1:>6d}{2:>15.8f}'.format(
                    i + 1, j + 1, potentials[i][j]))
                if freqs:
                    strs = ('{0:d}'.format(int(val)) for val in freqs[i][j])
                    dat_str += '  ' + ' '.join(strs)
                dat_str += '\n'
    elif ndims == 3:
        for i in range(dims[0]):
            for j in range(dims[1]):
                for k in range(dims[2]):
                    dat_str += ('{0:>6d}{1:>6d}{2:>6d}{3:>15.8f}'.format(
                        i + 1, j + 1, k + 1, potentials[i][j][k]))
                    if freqs:
                        ' {}'.join((freq for freq in freqs[i][j][k]))
                    dat_str += '\n'
    elif ndims == 4:
        for i in range(dims[0]):
            for j in range(dims[1]):
                for k in range(dims[2]):
                    for lma in range(dims[3]):
                        dat_str += (
                            '{0:>6d}{1:>6d}{2:>6d}{3:>6d}{4:>15.8f}'.format(
                                i + 1, j + 1, k + 1, lma + 1,
                                potentials[i][j][k][lma]))
                        if freqs:
                            ' {}'.join((freq for freq in freqs[i][j][k][lma]))
                        dat_str += '\n'

    return remove_trail_whitespace(dat_str)