예제 #1
0
def parser(name, data):
    """ Parse Empire specific xyz file """
    tmol = Molecule(name)
    nat = int(data[0])
    tmol.comment = data[1].strip()
    tmol.newAtoms(nat)
    for j in range(nat):
        line = data[j + 2].split()
        tmol.setAtom(j, line[0], line[1:4])
    tmol.setFmt("angstrom", scale=True)
    vec = [0, 0, 0]
    for i in range(3):
        vec[i] = [float(x) for x in data[nat + 3 + i].split()]
    tmol.setVec(vec)
    tmol.setCellDim(1, fmt="angstrom")
    return tmol, None
예제 #2
0
def parser(name, data):
    """ Parse Gaussian Cube file """
    tmol = Molecule(name)
    fmt = "bohr"
    # two lines of comments, combine
    tmol.comment = data[0] + ";" + data[1]
    # nat, origin[3]
    nat = int(data[2].split()[0])
    origin = [float(data[2].split()[i]) for i in [1, 2, 3]]
    # n of datapoints(dir), cell_vec[3]
    nvol = [0, 0, 0]
    tvec = [0, 0, 0]
    for i in [0, 1, 2]:
        line = data[i + 3].split()
        nvol[i] = int(line[0])
        if nvol[i] < 0:
            nvol[i] = -nvol[i]
            fmt = "angstrom"
        tvec[i] = [float(line[j]) * nvol[i] for j in [1, 2, 3]]
    tmol.setVec(tvec)
    pse = list(glob_pse.keys())
    tmol.newAtoms(nat)
    for i in range(nat):
        # line = Z, charge, coord(x, y, z)
        line = data[i + 6].split()
        tmol.setAtom(i, pse[int(line[0])], line[2:5], charge=float(line[1]))
    tmol.setFmt(fmt, scale=False)
    tmol.setCellDim(1, fmt=fmt)
    # rest of file has datagrid, x is outer loop, z inner
    vol = [[[0] * nvol[2] for i in range(nvol[1])] for j in range(nvol[0])]
    i = 6 + nat
    line = data[i].split()
    for x in range(nvol[0]):
        for y in range(nvol[1]):
            for z in range(nvol[2]):
                while not line and i < (len(data) - 1):
                    i += 1
                    line = data[i].split()
                vol[x][y][z] = float(line.pop(0))
    tmol.setVol(vol, origin)
    return tmol, None
예제 #3
0
def parser(name, data):
    """ Parse xyz files (angstrom) """
    # create list of mol, trajectory support
    tmol = Molecule(name, steps=0)
    i = 0
    while i < len(data):
            # handle empty lines at eof or between molecules
            if not data[i].strip().isdigit():
                    i += 1
                    continue
            # fixed format nat and comment
            tmol.newStep()
            nat = int(data[i])
            tmol.comment = data[i + 1].strip()
            # read coordinates and types
            tmol.newAtoms(nat)
            for j in range(nat):
                line = data[j + i + 2].split()
                tmol.setAtom(j, line[0], line[1:4])
            tmol.setFmt('angstrom', scale=True)
            i += nat + 2
    return tmol, None