Esempio n. 1
0
def test_user_can_read_coord():
    with tempfile.NamedTemporaryFile(mode="w+", encoding="utf-8", suffix=".xyz") as f:
        f.write("$coord" + s)
        f.write("0.00000000000000 0.00000000000000 -1.06176434496059 c" + s)
        f.write("0.00000000000000 0.00000000000000  1.06176434496059 h" + s)
        f.write("$end")
        f.flush()
        fname = open(f.name)
        atoms = read(fname)
        fname.close()
        assert len(atoms) == 2
Esempio n. 2
0
def test_ignore_coordinates_after_marker():
    with tempfile.NamedTemporaryFile(mode="w+", encoding="utf-8", suffix=".xyz") as f:
        f.write("test" + s)
        f.write("$coord" + s)
        f.write("0.00000000000000 0.00000000000000 -1.06176434496059 c" + s)
        f.write("0.00000000000000 0.00000000000000  1.06176434496059 h" + s)
        f.write("$end")
        f.write("0.00000000000000 0.00000000000000  2.06176434496059 h" + s)
        f.flush()
        fname = open(f.name)
        atoms = read(fname)
        fname.close()
        assert len(atoms) == 2
        position = atoms[0].get("position")
        assert position[0] == 0.0
Esempio n. 3
0
def read(fileObject):
    """Method to first check the file type and then read

    the structure accordingly
    The returned atom coordinates will be in Bohr
    """

    fname = fileObject.name.lower()
    filetp = "unknown"

    lines = fileObject.readlines()

    if fname.endswith((".xyz")):
        filetp = "xyz"
    else:
        for line in lines:
            if line.strip().startswith("$coord"):
                filetp = "turbomole"
                break

    fileObject.close()

    atoms = []

    newfile = open(fname, "r+")

    if filetp == "turbomole":
        atoms = tm.read(newfile)
    elif filetp == "xyz":
        atoms = xyz.read(newfile)
    else:
        print('Error: file type of input "{0}" not recognized'.format(fname))
        exit(1)

    newfile.close()

    return atoms
Esempio n. 4
0
def read(fileObject):
    """Method to first check the file type and then read

    the structure accordingly
    The returned atom coordinates will be in Bohr
    """

    fname = fileObject.name.lower()
    filetp = "unknown"

    lines = fileObject.readlines()

    if fname.endswith((".xyz")):
        filetp = "xyz"
    else:
        for line in lines:
            if line.strip().startswith("$coord"):
                filetp = "turbomole"
                break

    fileObject.close()

    atoms = []

    newfile = open(fname, "r+")

    if filetp == "turbomole":
        atoms = tm.read(newfile)
    elif filetp == "xyz":
        atoms = xyz.read(newfile)
    else:
        errorbye("Input format erroneous or not implemented.")

    newfile.close()

    return atoms