Exemplo n.º 1
0
def _parse(blines, optimize=False):
    header_ln = blines.pop(0)  # noqa: F841
    nsets = int(blines.pop(0))
    basis = []
    for n in range(nsets):
        comp = [int(p) for p in blines.pop(0).split()]
        lmin, lmax, nexps, ncontractions = comp[1], comp[2], comp[3], comp[4:]
        basis_n = [[l] for l in range(lmin,lmax+1)]
        for nexp in range(nexps):
            line = blines.pop(0)
            dat = line.split()
            try:
                bfun = [float(x) for x in dat]
            except ValueError:
                if DISABLE_EVAL:
                    raise ValueError('Failed to parse basis %s' % line)
                else:
                    bfun = eval(','.join(dat))
            exp = bfun.pop(0)
            for i,l in enumerate(range(lmin,lmax+1)):
                cl = [exp]
                for c in range(ncontractions[i]):
                    cl.append(bfun.pop(0))
                basis_n[i].append(tuple(cl))
        basis.extend(basis_n)
    basis_sorted = []
    for l in range(MAXL):
        basis_sorted.extend([b for b in basis if b[0] == l])

    if optimize:
        basis_sorted = parse_nwchem.optimize_contraction(basis_sorted)

    basis_sorted = parse_nwchem.remove_zero(basis_sorted)
    return basis_sorted
Exemplo n.º 2
0
def _parse(blines, optimize=False):
    header_ln = blines.pop(0)
    nsets = int(blines.pop(0))
    basis = []
    for n in range(nsets):
        comp = [int(p) for p in blines.pop(0).split()]
        n, lmin, lmax, nexps, ncontractions = comp[0], comp[1], comp[2], comp[3], comp[4:]
        basis_n = [[l] for l in range(lmin,lmax+1)]
        for nexp in range(nexps):
            bfun = [float(x) for x in blines.pop(0).split()]
            exp = bfun.pop(0)
            for i,l in enumerate(range(lmin,lmax+1)):
                cl = [exp]
                for c in range(ncontractions[i]):
                    cl.append(bfun.pop(0))
                basis_n[i].append(tuple(cl))
        basis.extend(basis_n)
    basis_sorted = []
    for l in range(MAXL):
        basis_sorted.extend([b for b in basis if b[0] == l])

    if optimize:
        basis_sorted = parse_nwchem.optimize_contraction(basis_sorted)

    basis_sorted = parse_nwchem.remove_zero(basis_sorted)
    return basis_sorted
Exemplo n.º 3
0
def _parse(raw_basis, optimize=True):
    basis_add = []
    for line in raw_basis:
        dat = line.strip()
        if dat.startswith('!'):
            continue
        elif dat[0].isalpha():
            key = dat.split()
            if len(key) == 2:
                # skip the line which has only two items. It's the line for
                # element symbol
                continue
            elif key[0] == 'SP':
                basis_add.append([0])
                basis_add.append([1])
            else:
                basis_add.append([MAPSPDF[key[0]]])
        else:
            line = [float(x) for x in dat.replace('D','e').split()]
            if key[0] == 'SP':
                basis_add[-2].append([line[0], line[1]])
                basis_add[-1].append([line[0], line[2]])
            else:
                basis_add[-1].append(line)
    basis_sorted = []
    for l in range(MAXL):
        basis_sorted.extend([b for b in basis_add if b[0] == l])

    if optimize:
        basis_sorted = optimize_contraction(basis_sorted)

    basis_sorted = remove_zero(basis_sorted)
    return basis_sorted
Exemplo n.º 4
0
def _parse(raw_basis, optimize=True):
    # pass 1
    basis_add = []
    for dat in raw_basis:
        dat = dat.upper()
        if dat[0].isalpha():
            if ' ' not in dat:
                # Skip the line of comments
                continue
            status = dat
            val = []
            basis_add.append([status, val])
        else:
            val.append(dat)
    raw_basis = [[k, ' '.join(v)] for k, v in basis_add]

    # pass 2
    basis_add = []
    for status, valstring in raw_basis:
        tmp = status.split(':')
        key = tmp[0].split()
        l = MAPSPDF[key[1].upper()]
        #TODO if key[-1] == 'SV'
        val = tmp[1].split()
        np = int(val[0])
        nc = int(val[1])

        rawd = [float(x) for x in valstring.replace('D', 'e').split()]
        if nc == 0:
            for e in rawd:
                basis_add.append([l, [e, 1.]])
        else:
            exps = numpy.array(rawd[:np])
            coeff = numpy.zeros((np, nc))
            p1 = np
            for i in range(nc):
                start, end = val[2 + i].split('.')
                start, end = int(start), int(end)
                nd = end - start + 1
                p0, p1 = p1, p1 + nd
                coeff[start - 1:end, i] = rawd[p0:p1]

            bval = numpy.hstack((exps[:, None], coeff))
            basis_add.append([l] + bval.tolist())

    basis_sorted = []
    for l in range(MAXL):
        basis_sorted.extend([b for b in basis_add if b[0] == l])

    if optimize:
        basis_sorted = optimize_contraction(basis_sorted)

    basis_sorted = remove_zero(basis_sorted)
    return basis_sorted
Exemplo n.º 5
0
def _parse(raw_basis, optimize=True):
    # pass 1
    basis_add = []
    for dat in raw_basis:
        dat = dat.upper()
        if dat[0].isalpha():
            if ' ' not in dat:
                # Skip the line of comments
                continue
            status = dat
            val = []
            basis_add.append([status, val])
        else:
            val.append(dat)
    raw_basis = [[k, ' '.join(v)] for k,v in basis_add]

    # pass 2
    basis_add = []
    for status, valstring in raw_basis:
        tmp = status.split(':')
        key = tmp[0].split()
        l = MAPSPDF[key[1].upper()]
        #TODO if key[-1] == 'SV'
        val = tmp[1].split()
        np = int(val[0])
        nc = int(val[1])

        rawd = [float(x) for x in valstring.replace('D','e').split()]
        if nc == 0:
            for e in rawd:
                basis_add.append([l, [e, 1.]])
        else:
            exps = numpy.array(rawd[:np])
            coeff = numpy.zeros((np,nc))
            p1 = np
            for i in range(nc):
                start, end = val[2+i].split('.')
                start, end = int(start), int(end)
                nd = end - start + 1
                p0, p1 = p1, p1 + nd
                coeff[start-1:end,i] = rawd[p0:p1]

            bval = numpy.hstack((exps[:,None], coeff))
            basis_add.append([l] + bval.tolist())

    basis_sorted = []
    for l in range(MAXL):
        basis_sorted.extend([b for b in basis_add if b[0] == l])

    if optimize:
        basis_sorted = optimize_contraction(basis_sorted)

    basis_sorted = remove_zero(basis_sorted)
    return basis_sorted
Exemplo n.º 6
0
def convert_to(data, elem_list=elements.IUPAC_LIST):
    """
    Take a list of dicts containing the entries
        atnum:     atomic number
        functions: list of dict with the keys:
            angular_momentum  Angular momentum of the function
            coefficients      List of contraction coefficients
            exponents         List of contraction exponents
    and return a dictionary in the format expected by pscf.gto.Mole.

    Example:

    >>> from pyscf import gto
    >>> from look4bas.basis_format.pyscf import convert_to
    >>>
    >>> mol = gto.Mole()
    >>> mol.basis = convert_to(look4bas_data)
    """
    ret = {}
    for atom in data:
        symbol = elem_list[atom["atnum"]]["symbol"]

        bdef = []
        for fun in sorted(atom["functions"],
                          key=lambda x: x["angular_momentum"]):
            data_symbol = [fun["angular_momentum"]]

            if len(fun["coefficients"]) != len(fun["exponents"]):
                raise ValueError(
                    "Length of coefficients and length of exponents "
                    "in contraction specification need to agree")
            for i, coeff in enumerate(fun["coefficients"]):
                exp = fun["exponents"][i]
                data_symbol.append([exp, coeff])
            bdef.append(data_symbol)

        bdef = optimize_contraction(bdef)
        bdef = remove_zeros(bdef)
        ret[symbol] = bdef

    for atom in data:
        if "ecp" in atom:
            warn(convert_to.__name__ + " currently ignores any ECP "
                 "definitions parsed.")
            break

    return ret